[Patch] Prevent cloned symbols from being assigned to the wrong section

Catherine Moore clm@codesourcery.com
Tue Dec 11 01:14:00 GMT 2007


This patch fixes a problem that was showing up when the directive .set 
was used to redefine a symbol. The symbol was being placed in the symbol 
table instead of the absolute section.  This eventually caused problems 
when the executable was stripped.

The solution is to prevent the copying of the shndx in 
elf_copy_private_symbol_data if the shndx is undefined.

Okay to commit?

Thanks,
Catherine

bfd/ChangeLog:

         * elf.c (_bfd_elf_copy_private_symbol_data): Don't copy shndx if
         the symbol's section is the undefined section.

gas/testsuite/ChangeLog:

         elf/symtab.s: New test.
         elf/symtab.d: New expected output.
         elf/elf.exp: Run the new symbtab test.

Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.425
diff -p -r1.425 elf.c
*** bfd/elf.c   10 Dec 2007 23:44:23 -0000      1.425
--- bfd/elf.c   11 Dec 2007 00:12:55 -0000
*************** _bfd_elf_copy_private_symbol_data (bfd *
*** 6046,6051 ****
--- 6046,6052 ----
     osym = elf_symbol_from (obfd, osymarg);

     if (isym != NULL
+       && isym->internal_elf_sym.st_shndx != 0
         && osym != NULL
         && bfd_is_abs_section (isym->symbol.section))
       {
Index: gas/testsuite/gas/elf/elf.exp
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/elf/elf.exp,v
retrieving revision 1.45
diff -p -r1.45 elf.exp
*** gas/testsuite/gas/elf/elf.exp       30 Nov 2007 23:47:55 -0000      1.45
--- gas/testsuite/gas/elf/elf.exp       11 Dec 2007 00:12:55 -0000
*************** if { ([istarget "*-*-*elf*"]
*** 109,114 ****
--- 109,115 ----
       run_dump_test "section4"
       run_elf_list_test "section5" "" "-al" "-SW" "| grep \" 
\\\\.test\\\[0-9\\\]\""
       run_dump_test "struct"
+     run_dump_test "symtab"
       run_dump_test "symver"
       run_elf_list_test "type" "" "" "-s" "| grep \"1 \\\[FONTC\\\]\""
       run_dump_test "section6"
Index: gas/testsuite/gas/elf/symtab.d
===================================================================
RCS file: gas/testsuite/gas/elf/symtab.d
diff -N gas/testsuite/gas/elf/symtab.d
*** /dev/null   1 Jan 1970 00:00:00 -0000
--- gas/testsuite/gas/elf/symtab.d      11 Dec 2007 00:12:55 -0000
***************
*** 0 ****
--- 1,6 ----
+ #readelf: -s
+ #name: .set with expression
+
+ #...
+ .*ABS.*shift.*
+ #pass
Index: gas/testsuite/gas/elf/symtab.s
===================================================================
RCS file: gas/testsuite/gas/elf/symtab.s
diff -N gas/testsuite/gas/elf/symtab.s
*** /dev/null   1 Jan 1970 00:00:00 -0000
--- gas/testsuite/gas/elf/symtab.s      11 Dec 2007 00:12:55 -0000
***************
*** 0 ****
--- 1,5 ----
+ .text
+       .global foo
+ foo:
+       .set    shift, 32
+       .set    shift, shift - 1



More information about the Binutils mailing list