Bug 12507 - Can't build a program with -flto -nostdlib
Summary: Can't build a program with -flto -nostdlib
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.22
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-23 06:50 IST by Dmitry Gorbachev
Modified: 2012-12-07 20:13 IST (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry Gorbachev 2011-02-23 06:50:51 IST
$ cat > prog.c
void _start(void) { }
^D

$ gcc-4.6 -flto -nostdlib prog.c

Works with ld.gold, does not work with ld.bfd or ld.hjl. GOLD marks _start as PREVAILING_DEF, BFD LD as PREVAILING_DEF_IRONLY.
Comment 1 Dmitry Gorbachev 2011-02-23 07:02:20 IST
The same problem with symbol given in --entry=... option.
Comment 2 H.J. Lu 2011-02-24 22:33:46 IST
All of linkers, ld.gold, ld.bfd and ld.hjl, are wrong.

gold:

/usr/gcc-4.6/bin/gcc -B./ -flto   -c -o prog.o prog.c
/usr/gcc-4.6/bin/gcc -B./ -flto -nostdlib -o prog prog.o
readelf -s prog

Symbol table '.symtab' contains 7 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000000000     0 SECTION LOCAL  DEFAULT    1 
     2: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS ccqnpwDf.ltrans0.o
     3: 0000000000400078     0 NOTYPE  GLOBAL DEFAULT    1 _start
     4: 0000000000601000     0 NOTYPE  GLOBAL DEFAULT  ABS __bss_start
     5: 0000000000601000     0 NOTYPE  GLOBAL DEFAULT  ABS _edata
     6: 0000000000601000     0 NOTYPE  GLOBAL DEFAULT  ABS _end
[hjl@gnu-6 pr12507]$ 

ld.bfd:

[hjl@gnu-6 pr12507]$ make
/usr/gcc-4.6/bin/gcc -B./ -flto   -c -o prog.o prog.c
/usr/gcc-4.6/bin/gcc -B./ -flto -nostdlib -o prog prog.o
readelf -s prog

Symbol table '.symtab' contains 7 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000000000     0 SECTION LOCAL  DEFAULT    1 
     2: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS cccAjlEb.ltrans0.o
     3: 0000000000400078     0 NOTYPE  GLOBAL DEFAULT    1 _start
     4: 0000000000601000     0 NOTYPE  GLOBAL DEFAULT  ABS __bss_start
     5: 0000000000601000     0 NOTYPE  GLOBAL DEFAULT  ABS _edata
     6: 0000000000601000     0 NOTYPE  GLOBAL DEFAULT  ABS _end
[hjl@gnu-6 pr12507]$ 

ld.hjl:

[hjl@gnu-6 pr12507]$ make
/usr/gcc-4.6/bin/gcc -B./ -flto   -c -o prog.o prog.c
/usr/gcc-4.6/bin/gcc -B./ -flto -nostdlib -o prog prog.o
./ld: warning: cannot find entry symbol _start; defaulting to 0000000000400078
readelf -s prog

Symbol table '.symtab' contains 6 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000000000     0 SECTION LOCAL  DEFAULT    1 
     2: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS ccAazRGl.ltrans0.o
     3: 0000000000601000     0 NOTYPE  GLOBAL DEFAULT  ABS __bss_start
     4: 0000000000601000     0 NOTYPE  GLOBAL DEFAULT  ABS _edata
     5: 0000000000601000     0 NOTYPE  GLOBAL DEFAULT  ABS _end
[hjl@gnu-6 pr12507]$ 

I will fix ld.hjl.
Comment 3 cvs-commit@gcc.gnu.org 2011-02-24 22:58:08 IST
CVSROOT:	/cvs/src
Module name:	src
Changes by:	hjl@sourceware.org	2011-02-24 22:58:05

Modified files:
	ld             : ChangeLog plugin.c 

Log message:
	Don't mark entry symbol IR only.
	
	2011-02-24  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR ld/12507
	* plugin.c (get_symbols): Don't mark entry symbol IR only.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ChangeLog.diff?cvsroot=src&r1=1.2284&r2=1.2285
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/plugin.c.diff?cvsroot=src&r1=1.23&r2=1.24
Comment 4 H.J. Lu 2011-02-24 23:00:34 IST
BFD linker is fixed. Gold is still broken.
Comment 5 cvs-commit@gcc.gnu.org 2011-02-26 04:38:38 IST
CVSROOT:	/cvs/src
Module name:	src
Changes by:	hjl@sourceware.org	2011-02-26 04:38:35

Modified files:
	ld             : ChangeLog plugin.c 

Log message:
	Add entry_symbol chain into non_ironly_hash.
	
	2011-02-24  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR ld/12507
	* plugin.c (get_symbols): Don't check entry symbol here.
	(init_non_ironly_hash): Add entry_symbol chain into
	non_ironly_hash.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ChangeLog.diff?cvsroot=src&r1=1.2285&r2=1.2286
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/plugin.c.diff?cvsroot=src&r1=1.24&r2=1.25
Comment 6 H.J. Lu 2011-02-28 15:34:32 IST
Fixed.
Comment 7 cvs-commit@gcc.gnu.org 2011-04-27 07:17:51 IST
CVSROOT:	/cvs/src
Module name:	src
Branch: 	binutils-2_21-branch
Changes by:	amodra@sourceware.org	2011-04-27 07:17:45

Modified files:
	bfd            : ChangeLog bfd-in2.h bfd.c coff-aux.c elf-bfd.h 
	                 elf.c elf32-i386.c elf32-ppc.c elf32-sparc.c 
	                 elf64-ppc.c elf64-sparc.c elf64-x86-64.c 
	                 elfcode.h elflink.c linker.c opncls.c plugin.c 
	                 simple.c xcofflink.c 
	gas/testsuite  : ChangeLog 
	gas/testsuite/gas/elf: elf.exp 
	include        : ChangeLog bfdlink.h 
	ld             : ChangeLog ld.texinfo ldfile.c ldlang.c ldlang.h 
	                 ldmain.c lexsup.c plugin.c plugin.h 
	ld/testsuite   : ChangeLog 
	ld/testsuite/ld-plugin: plugin-7.d plugin-8.d plugin.exp 
Added files:
	gas/testsuite/gas/elf: section9.d section9.s 
	ld/testsuite/ld-plugin: plugin-12.d 
	ld/testsuite/ld-unique: unique.exp unique.s unique_empty.s 
	                        unique_shared.s 

Log message:
	PR ld/12696
	PR ld/12672
	PR ld/12507
	PR ld/12365
	PR 10549
	Backport fixes for these PRs.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.5180.2.26&r2=1.5180.2.27
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/bfd-in2.h.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.522.2.1&r2=1.522.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/bfd.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.114.2.1&r2=1.114.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/coff-aux.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.10&r2=1.10.10.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf-bfd.h.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.313.2.1&r2=1.313.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.524.2.1&r2=1.524.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf32-i386.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.241&r2=1.241.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf32-ppc.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.290.2.2&r2=1.290.2.3
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf32-sparc.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.94&r2=1.94.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf64-ppc.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.339.2.7&r2=1.339.2.8
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf64-sparc.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.124&r2=1.124.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf64-x86-64.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.202&r2=1.202.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elfcode.h.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.103&r2=1.103.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elflink.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.388.2.1&r2=1.388.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/linker.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.77.2.1&r2=1.77.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/opncls.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.66&r2=1.66.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/plugin.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.9.2.1&r2=1.9.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/simple.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.34&r2=1.34.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/xcofflink.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.76.2.1&r2=1.76.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.1802.2.8&r2=1.1802.2.9
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/elf/section9.d.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=NONE&r2=1.1.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/elf/section9.s.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=NONE&r2=1.1.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/elf/elf.exp.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.69.2.1&r2=1.69.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/include/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.510.2.1&r2=1.510.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/include/bfdlink.h.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.82&r2=1.82.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.2222.2.18&r2=1.2222.2.19
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ld.texinfo.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.267.2.1&r2=1.267.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ldfile.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.58.2.1&r2=1.58.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ldlang.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.347.2.2&r2=1.347.2.3
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ldlang.h.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.91.2.1&r2=1.91.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ldmain.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.145.2.2&r2=1.145.2.3
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/lexsup.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.120.2.1&r2=1.120.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/plugin.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.7.2.3&r2=1.7.2.4
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/plugin.h.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.2.2.2&r2=1.2.2.3
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.1322.2.8&r2=1.1322.2.9
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-plugin/plugin-12.d.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=NONE&r2=1.1.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-plugin/plugin-7.d.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.1&r2=1.1.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-plugin/plugin-8.d.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.1&r2=1.1.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-plugin/plugin.exp.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.5&r2=1.5.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-unique/unique.exp.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=NONE&r2=1.1.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-unique/unique.s.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=NONE&r2=1.1.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-unique/unique_empty.s.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=NONE&r2=1.1.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-unique/unique_shared.s.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=NONE&r2=1.1.2.1
Comment 8 H.J. Lu 2012-12-07 20:13:19 IST
Works in 2.23 and tracked by "LTO 16a symbol"/"LTO 16b symbol" tests.