This is the mail archive of the binutils-cvs@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]

[binutils-gdb] MIPS/BFD: Fix section symbol name fetching in relocation


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ceab86af75e9870ecf2da772a0d867ca12521a24

commit ceab86af75e9870ecf2da772a0d867ca12521a24
Author: Maciej W. Rozycki <macro@imgtec.com>
Date:   Fri May 27 20:41:40 2016 +0100

    MIPS/BFD: Fix section symbol name fetching in relocation
    
    Symbol table entries for section symbols are different between IRIX and
    traditional MIPS ELF targets in that IRIX entries have their `st_name'
    member pointing at the section's name in the string table section, while
    traditional entries have 0 there and the section header string table has
    to be referred via the relevant section header's `shn_name' member
    instead.
    
    This is chosen with the `elf_backend_name_local_section_symbols' backend
    and can be observed with `readelf -s' output for an IRIX object:
    
    Symbol table '.symtab' contains 12 entries:
       Num:    Value  Size Type    Bind   Vis      Ndx Name
         0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
         1: 00000000     0 SECTION LOCAL  DEFAULT    1 .text
         2: 00000000     0 SECTION LOCAL  DEFAULT    3 .data
         3: 00000000     0 SECTION LOCAL  DEFAULT    4 .bss
         4: 00000000     0 SECTION LOCAL  DEFAULT    5 .reginfo
         5: 00000000     0 SECTION LOCAL  DEFAULT    6 .MIPS.abiflags
         6: 00000000     0 SECTION LOCAL  DEFAULT    7 .pdr
         7: 00000000     0 SECTION LOCAL  DEFAULT    9 .gnu.attributes
         8: 00002000    16 FUNC    GLOBAL DEFAULT    1 foo
         9: 00004008     0 FUNC    LOCAL  DEFAULT    1 abar
        10: 00002008     0 FUNC    LOCAL  DEFAULT    1 afoo
        11: 00004000    16 FUNC    GLOBAL DEFAULT    1 bar
    
    and a corresponding traditional object:
    
    Symbol table '.symtab' contains 12 entries:
       Num:    Value  Size Type    Bind   Vis      Ndx Name
         0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
         1: 00000000     0 SECTION LOCAL  DEFAULT    1
         2: 00000000     0 SECTION LOCAL  DEFAULT    3
         3: 00000000     0 SECTION LOCAL  DEFAULT    4
         4: 00004008     0 FUNC    LOCAL  DEFAULT    1 abar
         5: 00002008     0 FUNC    LOCAL  DEFAULT    1 afoo
         6: 00000000     0 SECTION LOCAL  DEFAULT    5
         7: 00000000     0 SECTION LOCAL  DEFAULT    6
         8: 00000000     0 SECTION LOCAL  DEFAULT    7
         9: 00000000     0 SECTION LOCAL  DEFAULT    9
        10: 00002000    16 FUNC    GLOBAL DEFAULT    1 foo
        11: 00004000    16 FUNC    GLOBAL DEFAULT    1 bar
    
    respectively.  Consequently the right way to retrieve a section symbol's
    name has to be chosen in `mips_elf_calculate_relocation' for the purpose
    of error reporting.
    
    Originally we produced symbol tables in the traditional object format
    only and we handled it correctly until it was lost in a rewrite with:
    
    commit 7403cb6305f5660fccc8869d3333a731102ae978
    Author: Mark Mitchell <mark@codesourcery.com>
    Date:   Wed Jun 30 20:13:43 1999 +0000
    
    probably because of the extra pointer indirection added which made the
    same expression have a different meaning.
    
    With the addition of IRIX symbol table format with:
    
    commit 174fd7f9556183397625dbfa99ef68ecd325c74b
    Author: Richard Sandiford <rdsandiford@googlemail.com>
    Date:   Mon Feb 9 08:04:00 2004 +0000
    
    the bug has been partially covered and now when a relocation error is
    triggered with an IRIX object the offending section symbol is correctly
    reported:
    
    tmpdir/dump0.o: In function `foo':
    (.text+0x2000): relocation truncated to fit: R_MIPS_26 against `.text'
    tmpdir/dump0.o: In function `bar':
    (.text+0x4000): relocation truncated to fit: R_MIPS_26 against `.text'
    
    because `bfd_elf_string_from_elf_section' retrieves the name from the
    string table section.  With a traditional object however the function
    returns an empty string and consequently `no symbol' is printed instead:
    
    tmpdir/dump0.o: In function `foo':
    (.text+0x2000): relocation truncated to fit: R_MIPS_26 against `no symbol'
    tmpdir/dump0.o: In function `bar':
    (.text+0x4000): relocation truncated to fit: R_MIPS_26 against `no symbol'
    
    Restore the original semantics so that the section name is always
    correctly retrieved.
    
    	bfd/
    	* elfxx-mips.c (mips_elf_calculate_relocation): Also use the
    	section name if `bfd_elf_string_from_elf_section' returns an
    	empty string.
    
    	ld/
    	* testsuite/ld-mips-elf/reloc-local-overflow.d: New test.
    	* testsuite/ld-mips-elf/reloc-local-overflow.s: Source for the
    	new test.
    	* testsuite/ld-mips-elf/mips-elf.exp: Run the new test.

Diff:
---
 bfd/ChangeLog                                   | 6 ++++++
 bfd/elfxx-mips.c                                | 2 +-
 ld/ChangeLog                                    | 7 +++++++
 ld/testsuite/ld-mips-elf/mips-elf.exp           | 2 ++
 ld/testsuite/ld-mips-elf/reloc-local-overflow.d | 7 +++++++
 ld/testsuite/ld-mips-elf/reloc-local-overflow.s | 8 ++++++++
 6 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index bb9cb3c..5bace1e 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2016-05-27  Maciej W. Rozycki  <macro@imgtec.com>
+
+	* elfxx-mips.c (mips_elf_calculate_relocation): Also use the
+	section name if `bfd_elf_string_from_elf_section' returns an
+	empty string.
+
 2016-05-26  Maciej W. Rozycki  <macro@imgtec.com>
 
 	* elfxx-mips.c (_bfd_mips_elf_relocate_section)
diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
index 3e7b488..2fff306 100644
--- a/bfd/elfxx-mips.c
+++ b/bfd/elfxx-mips.c
@@ -5322,7 +5322,7 @@ mips_elf_calculate_relocation (bfd *abfd, bfd *input_bfd,
       *namep = bfd_elf_string_from_elf_section (input_bfd,
 						symtab_hdr->sh_link,
 						sym->st_name);
-      if (*namep == '\0')
+      if (*namep == NULL || **namep == '\0')
 	*namep = bfd_section_name (input_bfd, sec);
 
       target_is_16_bit_code_p = ELF_ST_IS_MIPS16 (sym->st_other);
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 4462450..1d683ac 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,10 @@
+2016-05-27  Maciej W. Rozycki  <macro@imgtec.com>
+
+	* testsuite/ld-mips-elf/reloc-local-overflow.d: New test.
+	* testsuite/ld-mips-elf/reloc-local-overflow.s: Source for the
+	new test.
+	* testsuite/ld-mips-elf/mips-elf.exp: Run the new test.
+
 2016-05-26  Maciej W. Rozycki  <macro@imgtec.com>
 
 	* testsuite/ld-mips-elf/unaligned-jalx-0.d: Fold
diff --git a/ld/testsuite/ld-mips-elf/mips-elf.exp b/ld/testsuite/ld-mips-elf/mips-elf.exp
index f9bbcec..0c2a93b 100644
--- a/ld/testsuite/ld-mips-elf/mips-elf.exp
+++ b/ld/testsuite/ld-mips-elf/mips-elf.exp
@@ -440,6 +440,8 @@ if { $has_newabi } {
 	    "reloc-6b"]]
 }
 
+run_dump_test "reloc-local-overflow" [list [list ld $abi_ldflags(o32)]]
+
 if {$has_newabi && $linux_gnu} {
     run_dump_test "eh-frame1-n32"
     run_dump_test "eh-frame1-n64"
diff --git a/ld/testsuite/ld-mips-elf/reloc-local-overflow.d b/ld/testsuite/ld-mips-elf/reloc-local-overflow.d
new file mode 100644
index 0000000..b5512ee
--- /dev/null
+++ b/ld/testsuite/ld-mips-elf/reloc-local-overflow.d
@@ -0,0 +1,7 @@
+#name: MIPS reloc against local symbol overflow
+#source: reloc-local-overflow.s
+#as: -EB -32
+#ld: -EB -Tdata 0x10000 -e 0
+#error: \A[^\n]*:\(\.data\+0x1000\): relocation truncated to fit: R_MIPS_16 against `\.data'\Z
+
+# Verify that the section name (`.data') is printed rather than `no symbol'.
diff --git a/ld/testsuite/ld-mips-elf/reloc-local-overflow.s b/ld/testsuite/ld-mips-elf/reloc-local-overflow.s
new file mode 100644
index 0000000..a07255c
--- /dev/null
+++ b/ld/testsuite/ld-mips-elf/reloc-local-overflow.s
@@ -0,0 +1,8 @@
+	.data
+	.space	0x1000
+
+	.align	2
+	.type	bar, @object
+bar:
+	.half	bar
+	.size	bar, . - bar


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