Bug 6992 - constant strings don't get relocated properly in a relocatable built with gold
Summary: constant strings don't get relocated properly in a relocatable built with gold
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: 2.20
: P2 normal
Target Milestone: ---
Assignee: Ian Lance Taylor
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-10-28 16:47 UTC by Andy Chittenden
Modified: 2009-02-28 17:56 UTC (History)
2 users (show)

See Also:
Host: x86_64-unknown-linux-gnu
Target: x86_64-unknown-linux-gnu
Build: x86_64-unknown-linux-gnu
Last reconfirmed:


Attachments
contains the source files that I used to generate the failing program. (423 bytes, application/x-compressed)
2008-10-28 16:49 UTC, Andy Chittenden
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andy Chittenden 2008-10-28 16:47:45 UTC
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???
       #
Comment 1 Andy Chittenden 2008-10-28 16:49:50 UTC
Created attachment 3034 [details]
contains the source files that I used to generate the failing program.
Comment 2 Sourceware Commits 2009-02-28 17:53:30 UTC
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

Comment 3 Ian Lance Taylor 2009-02-28 17:56:44 UTC
The problem of course only arose when using a linker script with -r.

This should now be fixed.  Thanks for reporting it.