Here's a program: # cat main.cpp #include <stdio.h> int main() { printf("hello world\n"); return 0; } I have a script that builds that program: # cat buildit.sh LD=${LD:-'ld'} g++ -c main.cpp $LD -r -o relocatable.o --script script.lnk main.o g++ -o main relocatable.o ./main If I build the relocatable with the traditional linker, then the program prints "hello world" as expected. If I build the relocatable with gold, then the program prints garbage: ???H??? #
Created attachment 3034 [details] contains the source files that I used to generate the failing program.
Subject: Bug 6992 CVSROOT: /cvs/src Module name: src Changes by: ian@sourceware.org 2009-02-28 17:53:16 Modified files: gold : ChangeLog object.cc symtab.cc Log message: PR 6992 * symtab.cc (Symbol_table::sized_write_section_symbol): In a relocatable link set the value of the section symbol to zero. * object.cc (Sized_relobj::do_finalize_local_symbols): In a relocatable link don't include the section address in the local symbol value. Patches: http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gold/ChangeLog.diff?cvsroot=src&r1=1.185&r2=1.186 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gold/object.cc.diff?cvsroot=src&r1=1.86&r2=1.87 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gold/symtab.cc.diff?cvsroot=src&r1=1.116&r2=1.117
The problem of course only arose when using a linker script with -r. This should now be fixed. Thanks for reporting it.