Build of chroot-jail fails with invalid linker script

Building the chroot-jail package fails on Ubuntu karmic on amd64:

make[1]: Entering directory `/work/plash/chroot-jail/elf-chainloader'
cc -static -nostartfiles -nostdlib /usr/lib/diet/lib/libc.a -Wl,-z,noexecstack -Wl,--verbose 2>/dev/null | \
          LC_ALL=C \
          sed -e '/^=========/,/^=========/!d;/^=========/d'    \
            -e 's/0x08048000/0x80000000/g # for i386' \
            -e 's/0x400000/0x80000000/g # for x86-64' \
            > link.lds
cc -O2 -Wall -Werror -fno-stack-protector -isystem /usr/lib/diet/include -DLOADER=chainloader_given_fd entry.o loader.c \
                -static -nostartfiles -nostdlib /usr/lib/diet/lib/libc.a -Wl,-z,noexecstack -Wl,-T,link.lds -o chainloader
/usr/bin/ld: EOF in comment
collect2: ld returned 1 exit status
make[1]: *** [chainloader] Error 1

Looking at the linker script generated shows that it has been truncated. elf-chainloader/link.lds ends with:

  .ctors          :
  {
    /* gcc uses crtbegin.o to find the start of
       the constructors, so we make sure it is
       first.  Because this is a wildcard, it
       doesn't matter if the user does not
       actually link against crtbegin.o; the
       linker won't l

The cause is apparently a segfault in ld. It looks like gcc reads ld's output and forwards it on, and detects the segfault but does not propagate the failure:

$ gcc -static -nostartfiles -nostdlib /usr/lib/diet/lib/libc.a -Wl,-z,noexecstack -Wl,--verbose
collect2: ld terminated with signal 11 [Segmentation fault]
GNU ld (GNU Binutils for Ubuntu) 2.19.51.20090805
  Supported emulations:
   elf_x86_64
   elf_i386
   i386linux
   elf_l1om
using internal linker script:
==================================================
...
[linker script is truncated in the same way as above]

The bug may have something to do with whether gcc/ld can write the file a.out - if I run the command from the root directory, the problem goes away (I get /usr/bin/ld: cannot open output file a.out: Permission denied instead).

If I remove the argument /usr/lib/diet/lib/libc.a, the problem goes away.

This more minimal invocation of ld reproduces the problem:

ld --build-id --verbose /usr/lib/diet/lib/libc.a

This starts printing a linker script but gives a segmentation fault part way. The --build-id argument is crucial - removing it makes the problem go away.

Actually, the --verbose option is not essential for giving the segfault.

I have raised a bug on GNU Binutils: Bug 10555

I raised a Launchpad bug on Ubuntu in case this is Ubuntu-specific: Bug 418210

Worked around the problem by not passing /usr/lib/diet/lib/libc.a as an argument when getting the linker script.

PlashIssues/EofInComment (last edited 2009-08-24 22:14:17 by MarkSeaborn)