Bug 11138 - ld: internal error when DSO is before object files
Summary: ld: internal error when DSO is before object files
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.20
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-01-05 15:06 UTC by Matthias Klose
Modified: 2010-01-08 03:04 UTC (History)
2 users (show)

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


Attachments
x.ii (1.94 KB, application/octet-stream)
2010-01-05 15:07 UTC, Matthias Klose
Details
foo.o (3.77 KB, application/x-object)
2010-01-05 15:07 UTC, Matthias Klose
Details
A simple testcase (492 bytes, application/octet-stream)
2010-01-07 15:45 UTC, H.J. Lu
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Klose 2010-01-05 15:06:55 UTC
[forwarded from http://bugs.debian.org/562822]

I (mistakenly) tried to link a file using -lstdc++ before the object file:
$ ld --version-script=ExportMap.map -lstdc++ foo.o

However ld has crashed, and told me to file a bugreport:
ld: BFD (GNU Binutils for Debian) 2.20 internal error, aborting at
../../bfd/elflink.c line 8450 in elf_link_check_versioned_symbol
ld: Please report this bug.

Attached is a reduced testcase, to reproduce:
$ cat >ExportMap.map <<EOF
{
        global: main;
        local: *;
};
EOF
$ g++ -c x.ii -o foo.o
$ ld --version-script=ExportMap.map -lstdc++ foo.o
ld: warning: cannot find entry symbol _start; defaulting to 0000000000400610
foo.o: In function `__static_initialization_and_destruction_0(int, int)':
x.ii:(.text+0x5e): undefined reference to `__dso_handle'
ld: BFD (GNU Binutils for Debian) 2.20 internal error, aborting at
../../bfd/elflink.c line 8450 in elf_link_check_versioned_symbol

ld: Please report this bug.

If I put -lstdc++ after the object file then ld doesn't crash:
$ ld --version-script=ExportMap.map  foo.o -lstdc++
ld: warning: cannot find entry symbol _start; defaulting to 0000000000400610
foo.o: In function `__static_initialization_and_destruction_0(int, int)':
x.ii:(.text+0x5e): undefined reference to `__dso_handle'

Also if I don't use the export map it doesn't crash:
$ ld -lstdc++ foo.o
ld: warning: cannot find entry symbol _start; defaulting to 0000000000400640
foo.o: In function `__static_initialization_and_destruction_0(int, int)':
x.ii:(.text+0x5e): undefined reference to `__dso_handle'

$ ld -v
GNU ld (GNU Binutils for Debian) 2.20
Comment 1 Matthias Klose 2010-01-05 15:07:25 UTC
Created attachment 4492 [details]
x.ii
Comment 2 Matthias Klose 2010-01-05 15:07:51 UTC
Created attachment 4493 [details]
foo.o
Comment 3 H.J. Lu 2010-01-07 15:45:51 UTC
Created attachment 4501 [details]
A simple testcase

[hjl@gnu-6 pr11138]$ make
cc    -c -o foo.o foo.c
cc    -c -o bar.o bar.c
./ld -o libbar.so -shared --version-script=bar.map bar.o
./ld -e main --version-script=foo.map  -o bar foo.o libbar.so
./ld -e main --version-script=foo.map  -o foo libbar.so foo.o
./ld: BFD (GNU Binutils) 2.20.51.20100107 internal error, aborting at
/export/gnu/import/git/binutils/bfd/elflink.c line 8499 in
elf_link_check_versioned_symbol

./ld: Please report this bug.

make: *** [foo] Error 1
[hjl@gnu-6 pr11138]$
Comment 4 H.J. Lu 2010-01-07 15:56:05 UTC
This should fix it. I will submit a proper patch.

--
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 297d46b..b587ef6 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -8492,10 +8492,15 @@ elf_link_check_versioned_symbol (struct bfd_link_info *i
nfo,
 
 	  _bfd_elf_swap_versym_in (input, ever, &iver);
 
-	  if ((iver.vs_vers & VERSYM_HIDDEN) == 0)
+	  if ((iver.vs_vers & VERSYM_HIDDEN) == 0
+	      && !(h->def_regular
+		   && h->forced_local
+		   && !h->dynamic_def))
 	    {
 	      /* If we have a non-hidden versioned sym, then it should
-		 have provided a definition for the undefined sym.  */
+		 have provided a definition for the undefined sym unless
+		 it is defined in a non-shared object and forced local.
+	       */
 	      abort ();
 	    }
 
--
Comment 5 H.J. Lu 2010-01-07 17:51:14 UTC
A patch is posted at

http://sourceware.org/ml/binutils/2010-01/msg00145.html
Comment 6 Sourceware Commits 2010-01-08 03:03:35 UTC
Subject: Bug 11138

CVSROOT:	/cvs/src
Module name:	src
Changes by:	hjl@sourceware.org	2010-01-08 03:03:17

Modified files:
	bfd            : ChangeLog elflink.c 
	ld/testsuite   : ChangeLog 
	ld/testsuite/ld-elf: shared.exp 
Added files:
	ld/testsuite/ld-elf: pr11138-1.c pr11138-1.map pr11138-2.c 
	                     pr11138-2.map pr11138.out 

Log message:
	Fix PR ld/11138
	
	bfd/
	
	2010-01-07  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR ld/11138
	* elflink.c (elf_link_check_versioned_symbol): Don't abort if
	a symbol referenced by DSO is is defined in a non-shared object
	and forced local.
	
	ld/testsuite/
	
	2010-01-07  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR ld/11138
	* ld-elf/pr11138-1.c: New.
	* ld-elf/pr11138-1.map: Likewise.
	* ld-elf/pr11138-2.c: Likewise.
	* ld-elf/pr11138-2.map: Likewise.
	* ld-elf/pr11138.out: Likewise.
	
	* ld-elf/shared.exp (build_tests): Add libpr11138-1.so and
	libpr11138-2.o.
	(run_tests): Add 2 tests for PR ld/11138.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.4876&r2=1.4877
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/bfd/elflink.c.diff?cvsroot=src&r1=1.364&r2=1.365
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1203&r2=1.1204
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/pr11138-1.c.diff?cvsroot=src&r1=NONE&r2=1.1
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/pr11138-1.map.diff?cvsroot=src&r1=NONE&r2=1.1
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/pr11138-2.c.diff?cvsroot=src&r1=NONE&r2=1.1
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/pr11138-2.map.diff?cvsroot=src&r1=NONE&r2=1.1
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/pr11138.out.diff?cvsroot=src&r1=NONE&r2=1.1
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/shared.exp.diff?cvsroot=src&r1=1.14&r2=1.15

Comment 7 H.J. Lu 2010-01-08 03:04:16 UTC
Fixed.