This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fix MIPS multi-GOT -Bsymbolic link failure


This patch fixes a link failure for MIPS multi-GOT with -Bsymbolic.

The testcase, as added to the testsuite, is the existing multi-got-1
testcase but with -Bsymbolic added to the linker options.  Symbols
that are only binding locally because of -Bsymbolic get global rather
than local GOT entries - the code is very complicated, but I must
presume it is deliberate that not all symbols binding locally (as
indicated by SYMBOL_REFERENCES_LOCAL or _bfd_elf_symbol_refs_local_p)
get local entries, given that for example
mips_elf_calculate_relocation sets local_p based on
_bfd_elf_symbol_refs_local_p only for some types of relocations.
_bfd_mips_elf_finish_dynamic_symbol iterates over global GOT entries,
and ends up calling mips_elf_create_dynamic_relocation with a NULL sec
value, while the code in mips_elf_create_dynamic_relocation checks
SYMBOL_REFERENCES_LOCAL and on that basis reaches code requiring a
non-NULL sec.  In turn the link fails with "final link failed: Bad
value".  This patch arranges for NULL sec to go through the global
rather than the local case.

Tested with no regressions with cross to mips-linux-gnu.  OK to
commit?

bfd:
2010-08-26  Joseph Myers  <joseph@codesourcery.com>

	* elfxx-mips.c (mips_elf_create_dynamic_relocation): Handle sec ==
	NULL as a global symbol.

ld/testsuite:
2010-08-26  Joseph Myers  <joseph@codesourcery.com>

	* ld-mips-elf/multi-got-1-symbolic.d: New.
	* ld-mips-elf/mips-elf.exp: Run multi-got-1-symbolic test.

Index: bfd/elfxx-mips.c
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-mips.c,v
retrieving revision 1.270
diff -u -p -r1.270 elfxx-mips.c
--- bfd/elfxx-mips.c	25 Aug 2010 14:53:45 -0000	1.270
+++ bfd/elfxx-mips.c	26 Aug 2010 15:36:50 -0000
@@ -5754,8 +5754,10 @@ mips_elf_create_dynamic_relocation (bfd 
     }
 
   /* We must now calculate the dynamic symbol table index to use
-     in the relocation.  */
-  if (h != NULL && ! SYMBOL_REFERENCES_LOCAL (info, &h->root))
+     in the relocation.  sec == NULL can arise from
+     _bfd_mips_elf_finish_dynamic_symbol handling a global GOT entry
+     with -Bsymbolic, so treat that case as a global symbol.  */
+  if (h != NULL && (sec == NULL || ! SYMBOL_REFERENCES_LOCAL (info, &h->root)))
     {
       indx = h->root.dynindx;
       if (SGI_COMPAT (output_bfd))
Index: ld/testsuite/ld-mips-elf/mips-elf.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-mips-elf/mips-elf.exp,v
retrieving revision 1.65
diff -u -p -r1.65 mips-elf.exp
--- ld/testsuite/ld-mips-elf/mips-elf.exp	9 Aug 2010 19:54:13 -0000	1.65
+++ ld/testsuite/ld-mips-elf/mips-elf.exp	26 Aug 2010 15:36:50 -0000
@@ -124,6 +124,7 @@ run_dump_test "branch-misc-1"
 # the "traditional" emulations.
 if { $linux_gnu } {
     run_dump_test "multi-got-1"
+    run_dump_test "multi-got-1-symbolic"
     run_dump_test "multi-got-no-shared"
     run_dump_test "multi-got-hidden-1"
     run_dump_test "multi-got-hidden-2"
Index: ld/testsuite/ld-mips-elf/multi-got-1-symbolic.d
===================================================================
RCS file: ld/testsuite/ld-mips-elf/multi-got-1-symbolic.d
diff -N ld/testsuite/ld-mips-elf/multi-got-1-symbolic.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-mips-elf/multi-got-1-symbolic.d	26 Aug 2010 15:36:50 -0000
@@ -0,0 +1,32 @@
+#name: MIPS multi-got-1-symbolic
+#as: -EB -32 -KPIC
+#source: multi-got-1-1.s
+#source: multi-got-1-2.s
+#ld: -melf32btsmip -shared -Bsymbolic
+#readelf: -d -r
+
+Dynamic section at offset 0xec contains 18 entries:
+  Tag        Type                         Name/Value
+ 0x00000010 \(SYMBOLIC\)                   0x0
+ 0x00000004 \(HASH\)                       0x[0-9a-f]+
+ 0x00000005 \(STRTAB\)                     0x[0-9a-f]+
+ 0x00000006 \(SYMTAB\)                     0x[0-9a-f]+
+ 0x0000000a \(STRSZ\)                      [0-9]+ \(bytes\)
+ 0x0000000b \(SYMENT\)                     16 \(bytes\)
+ 0x00000003 \(PLTGOT\)                     0x[0-9a-f]+
+ 0x00000011 \(REL\)                        0x[0-9a-f]+
+ 0x00000012 \(RELSZ\)                      65544 \(bytes\)
+ 0x00000013 \(RELENT\)                     8 \(bytes\)
+ 0x70000001 \(MIPS_RLD_VERSION\)           1
+ 0x70000005 \(MIPS_FLAGS\)                 NOTPOT
+ 0x70000006 \(MIPS_BASE_ADDRESS\)          0
+ 0x7000000a \(MIPS_LOCAL_GOTNO\)           2
+ 0x70000011 \(MIPS_SYMTABNO\)              [0-9]+
+ 0x70000012 \(MIPS_UNREFEXTNO\)            [0-9]+
+ 0x70000013 \(MIPS_GOTSYM\)                0x[0-9a-f]+
+ 0x00000000 \(NULL\)                       0x0
+
+Relocation section '\.rel\.dyn' at offset 0x[0-9a-f]+ contains 8193 entries:
+ Offset     Info    Type            Sym\.Value  Sym\. Name
+00000000  00000000 R_MIPS_NONE      
+#...

-- 
Joseph S. Myers
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]