Bug 3206 - Segmentation fault when using Linux kernel link script
Summary: Segmentation fault when using Linux kernel link script
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.17
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-09-14 17:44 UTC by Matthew L. Creech
Modified: 2006-12-12 10:42 UTC (History)
3 users (show)

See Also:
Host: arm-none-linux-gnueabi
Target:
Build: i686-pc-linux-gnu
Last reconfirmed:


Attachments
Tarball of test files (4.42 KB, application/gzip)
2006-09-14 17:49 UTC, Matthew L. Creech
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew L. Creech 2006-09-14 17:44:13 UTC
When objects have been built with gcc's "-fasynchronous-unwind-tables" option,
linking them can produce a segfault in ld.  This occurred when trying to build a
recent Linux kernel with frame unwinding information.  I've narrowed it down to
a simpler test case, which uses the kernel's link script and a couple of test C
files.  Enabling "-fasynchronous-unwind-tables" when building the objects causes
a subsequent link to crash ld, while disabling that option causes ld to continue
successfully (giving the user an error and then exiting).

ARM EABI toolchain: binutils 2.17, gcc 4.1.1, built with CrossTool 0.42
Also tried CodeSourcery's 2006q1-6 toolchain (uses binutils 2.16.91), which
experiences the same problem

Will follow up with test files
Comment 1 Matthew L. Creech 2006-09-14 17:49:18 UTC
Created attachment 1296 [details]
Tarball of test files

1. Install arm[-none]-linux-gnueabi toolchain
2. Extract tarball contents
3. Set CROSS_COMPILE appropriately
4. Type 'make' to build and attempt to link the objects

You should see a segfault at the link stage.  Note that changing the CFLAGS to
omit "-fasynchronous-unwind-tables" will stop the segfault from occurring.
Comment 2 Matthew L. Creech 2006-09-14 18:30:27 UTC
Additional info. provided by Kevin Kilman at MontaVista:

[Quote]
FYI... I've seen the same thing using a MontaVista gcc 4.1.2, ld 2.17.
However, after a binutils update to 2.17.50 20060808, it no longer
segfaults, but fails to link with the following error:

  LD      init/built-in.o
  LD      .tmp_vmlinux1
/opt/fdb060906_0601451/montavista/foundation/devkit/arm/xscale_be/bin/xscale_be\-ld:
.tmp_vmlinux1: sh_link of section `.ARM.exidx.exit.text' points to
discard\ed section `.exit.text' of `arch/arm/kernel/built-in.o'
/opt/fdb060906_0601451/montavista/foundation/devkit/arm/xscale_be/bin/xscale_be\-ld:
final link failed: Bad value

I also noted that gcc-3.4.3/ldd-2.15.94 compiled and linked the same
kernel and .config just fine.
Comment 3 H.J. Lu 2006-09-14 19:05:00 UTC
It is because -fasynchronous-unwind-tables adds .ARM.exidx sections.
Please try to change kernel linker script from


        /DISCARD/ : {                   /* Exit code and data           */
                *(.exit.text)
                *(.exit.data)
                *(.exitcall.exit)
        }

to

       /DISCARD/ : {                   /* Exit code and data           */
                *(.exit.text)
                *(.ARM.exidx.exit.text)
                ^^^^^^^^^^^^^^^^^^^^^^^ A new line.
                *(.exit.data)
                *(.exitcall.exit)
        }



Comment 4 Matthew L. Creech 2006-09-14 20:09:20 UTC
I tried both:

*(.exit.text)
*(.ARM.exidx.exit.text)
*(.exit.data)
*(.exitcall.exit)

as well as

*(.ARM.exidx.exit.text)
*(.exit.data)
*(.exitcall.exit)

and both still trigger a segfault.
Comment 5 Matthew L. Creech 2006-09-14 21:10:27 UTC
Interestingly, though, if I change this portion to:

*(.exit.text)
*(.ARM.exidx)
*(.ARM.extab)
*(.exit.data)
*(.exitcall.exit)

it no longer segfaults for this test case.  This isn't a proper fix, though, as
within the larger kernel build the segfault still occurs.
Comment 6 H.J. Lu 2006-09-14 22:19:29 UTC
Please check out binutils in CVS. If you can provide a testcase with assembly
files so that I can produce it with binutils only, I will take a look.
Comment 7 Matthew L. Creech 2006-09-15 13:55:53 UTC
Okay, I got around to building a binutils snapshot (9/13), and I now get the
behavior described by Kevin Hilman:

  LD      .tmp_vmlinux1
arm-linux-gnueabi-ld: .tmp_vmlinux1: sh_link of section
`.ARM.exidx.exit.text' points to discarded section `.exit.text' of
`fs/built-in.o'
arm-linux-gnueabi-ld: final link failed: Bad value

So it's still not working, but no more segfault, so the ball now seems to be
back in the kernel guys' court.  Thanks for the help