Bug 12934 - Multilib gold mixes up 32 and 64 bit when relinking empty lib
Summary: Multilib gold mixes up 32 and 64 bit when relinking empty lib
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: 2.22
: P2 normal
Target Milestone: ---
Assignee: Ian Lance Taylor
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-26 14:54 UTC by David Kozub
Modified: 2011-06-28 23:17 UTC (History)
0 users

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


Attachments
Test showing the relink with ld.bfd and ld.gold. (134 bytes, text/x-sh)
2011-06-26 14:54 UTC, David Kozub
Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Kozub 2011-06-26 14:54:31 UTC
Created attachment 5821 [details]
Test showing the relink with ld.bfd and ld.gold.

Using gold on x86_64 with -m elf_i386 produces an ELF64 object when used like this:

# create an empty static lib
ar rc empty.a

# relink with gold
ld.gold -m elf_i386 -r -o relinked-gold.o empty.a

file relinked-gold.o
relinked-gold.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped

while the output should be an ELF32 object.

With ld.bfd the output is as expected (ELF32 object). Reproducible with 2.21 and with cvs HEAD.

As soon as any non-empty ELF32 object is added to the invocation of gold the result is correct (ELF32).

While this is a strange usecase, it appears in real world - I run into it when building linux kernel for x86 on x86_64.
Comment 1 Sourceware Commits 2011-06-28 23:12:35 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	ian@sourceware.org	2011-06-28 23:12:32

Modified files:
	gold           : ChangeLog arm.cc freebsd.h i386.cc options.cc 
	                 options.h parameters.cc powerpc.cc script.cc 
	                 sparc.cc target-select.cc target-select.h 
	                 x86_64.cc 
	gold/testsuite : testfile.cc 

Log message:
	PR gold/12934
	* target-select.cc (Target_selector::Target_selector): Add
	emulation parameter.  Change all callers.
	(select_target_by_bfd_name): Rename from select_target_by_name.
	Change all callers.
	(select_target_by_emulation): New function.
	(supported_emulation_names): New function.
	* target-select.h (class Target_selector): Add emulation_ field.
	Update declarations.
	(Target_selector::recognize_by_bfd_name): Rename from
	recognize_by_name.  Change all callers.
	(Target_selector::supported_bfd_names): Rename from
	supported_names.  Change all callers.
	(Target_selector::recognize_by_emulation): New function.
	(Target_selector::supported_emulations): New function.
	(Target_selector::emulation): New function.
	(Target_selector::do_recognize_by_bfd_name): Rename from
	do_recognize_by_name.  Change all callers.
	(Target_selector::do_supported_bfd_names): Rename from
	do_supported_names.  Change all callers.
	(Target_selector::do_recognize_by_emulation): New function.
	(Target_selector::do_supported_emulations): New function.
	(select_target_by_bfd_name): Change name in declaration.
	(select_target_by_emulation): Declare.
	(supported_emulation_names): Declare.
	* parameters.cc (parameters_force_valid_target): Try to find
	target based on emulation from -m option.
	* options.h (class General_options): Change doc string for -m.
	* options.cc (help): Print emulations.
	(General_options::parse_V): Likewise.
	* freebsd.h (Target_selector_freebsd::Target_selector_freebsd):
	Add emulation parameter.  Change all callers.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/ChangeLog.diff?cvsroot=src&r1=1.771&r2=1.772
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/arm.cc.diff?cvsroot=src&r1=1.136&r2=1.137
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/freebsd.h.diff?cvsroot=src&r1=1.5&r2=1.6
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/i386.cc.diff?cvsroot=src&r1=1.130&r2=1.131
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/options.cc.diff?cvsroot=src&r1=1.109&r2=1.110
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/options.h.diff?cvsroot=src&r1=1.160&r2=1.161
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/parameters.cc.diff?cvsroot=src&r1=1.35&r2=1.36
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/powerpc.cc.diff?cvsroot=src&r1=1.38&r2=1.39
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/script.cc.diff?cvsroot=src&r1=1.82&r2=1.83
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/sparc.cc.diff?cvsroot=src&r1=1.47&r2=1.48
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/target-select.cc.diff?cvsroot=src&r1=1.13&r2=1.14
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/target-select.h.diff?cvsroot=src&r1=1.12&r2=1.13
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/x86_64.cc.diff?cvsroot=src&r1=1.129&r2=1.130
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/testsuite/testfile.cc.diff?cvsroot=src&r1=1.20&r2=1.21
Comment 2 Ian Lance Taylor 2011-06-28 23:17:34 UTC
This should now be fixed in the development sources.  Thanks for reporting it.