http://sourceware.org/bugzilla/show_bug.cgi?id=15860
Bug ID: 15860 Summary: gold+linker script specifying alignment: resulting binary segfaults (Linux x86_64) Product: binutils Version: 2.23 Status: NEW Severity: normal Priority: P2 Component: gold Assignee: ian at airs dot com Reporter: s at martinien dot de CC: ccoutant at google dot com Created attachment 7154 --> http://sourceware.org/bugzilla/attachment.cgi?id=7154&action=edit Reproduction files Hi, contained in the attachment is a minimized program that runs successfully when linked using a linker script with ld on binutils 2.21.1 and binutils 2.23.1, but not when linked with the corresponding gold. The linker script was created from "ld --verbose". ALIGN() specifiers were added to the sections .got, .plt, .got.plt, .data and .text. In make.sh you have to set the path to your LINKER (or remove -B$LINKER in the last line). It is assumed that the linker is called "ld", please adjust if that is not the case. Also, choose the appropriate LINKERSCRIPT line and comment out the other. Then run make.sh. This will build and link main.cpp and CxaThrowHookNoFwd.cpp. The resulting executable segfaults when built with gold with this backtrace: (gdb) bt #0 0x0000000000401c60 in cxa_throw_notify_local () #1 0x00000000004005be in call_gmon_start () #2 0x00002aaaaad85e20 in ?? () from /sapmnt/appl_sw/gcc-4.7.3-193474//lib64/libstdc++.so.6 #3 0x0000000000400529 in _init () #4 0x00002aaaab48aaa0 in ?? () from /lib64/libc.so.6 #5 0x00000000004007e5 in __libc_csu_init (argc=1, argv=0x7fffffff8638, envp=0x7fffffff8648) at elf-init.c:120 #6 0x00002aaaab499b52 in __libc_start_main () from /lib64/libc.so.6 #7 0x00000000004005a9 in _start () at ../sysdeps/x86_64/elf/start.S:113 CxaThrowHookNoFwd.cpp contains a hook of the glibc function __cxa_throw(). The hook redirects the call to function cxa_throw_notify_local() defined in another shared object, but this should only happen when the shared object is linked. Otherwise the function pointer cxa_throw_notify_local is 0 and the function is not called. In this example, I have set cxa_throw_notify_local to 0 directly. With one of the following changes the gold binary works: 1) In make.sh, use FILE=main_preproc.cpp instead of FILE=main.cpp This builds the preprocessed file main.cpp (which consists of <iostream> and int main() only), but without this line: static ios_base::Init __ioinit; Apparantly the static initialization of ios_base somehow interferes with the other stuff going on. 2) In CxaThrowHookNoFwd.cpp, change __attribute__((visibility("default"))) to __attribute__((visibility("hidden"))) 3) In CxaThrowHookNoFwd.cpp, comment out the call to cxa_throw_notify_local. 4) In the linker script, remove the ALIGN() specifiers for .got and .plt This was tested on SLES 11 SP1 and SP2 with gcc 4.7.3. Interestingly it works with a very old gcc 4.3.4. By the way, the only reason a linker script is used here is for changing the alignment of the sections .got, .plt and .got.plt. If there is a better way to achieve this, please let me know. The alignment needs to be 16 byte because some 16-byte PLT entries are changed atomically by the program, and this is only possible on aligned data on x86_64. Best regards, Martin -- You are receiving this mail because: You are on the CC list for the bug. _______________________________________________ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils