PR24511, nm should not mark symbols in .init_array as "t"
authorAlan Modra <amodra@gmail.com>
Fri, 3 May 2019 12:06:46 +0000 (21:36 +0930)
committerAlan Modra <amodra@gmail.com>
Sat, 4 May 2019 07:27:33 +0000 (16:57 +0930)
This patch restricts the section names matched in coff_section_type,
a function that translates section names to symbol type, and arranges
to translate section flags to symbol type before looking at names.
The latter change resulted in various test failures due to improper
section flags being used in tests, and by the plugin support, so fix
that too.

The new test fails on many ELF targets that lack .init/fini_array
in their scripts.  I've just xfailed those.  pru-elf oddly defines
__init_array_begin rather than __init_array_start.  I've left that
target as a FAIL, and pj-elf too which reports an error for undefined
weak symbols.

bfd/
PR 24511
* syms.c (coff_section_type): Only allow '.', '$' and numeric
following the standard section names.
(bfd_decode_symclass): Prioritize section flag tests in
decode_section_type before name tests in coff_section_type.
* plugin.c (bfd_plugin_canonicalize_symtab): Init fake_section
and fake_common_section using BFD_FAKE_SECTION.  Use "fake" as
their names and choose standard .text section flags for
fake_section.
ld/
PR 24511
* testsuite/ld-elf/pr14156a.d: Allow for .init/.fini being a
data section on hppa64.
* testsuite/ld-elf/pr14156b.d: Likewise.
* testsuite/ld-scripts/pr18963.t: Map standard sections to set
output section flags.
* testsuite/ld-scripts/sane1.t: Likewise.
* testsuite/ld-elf/init-fini-arrays.s: Reference __init_array_start
and __fini_array_start.  Define __start et al.
* testsuite/ld-elf/pr24511.d: New test.

bfd/ChangeLog
bfd/plugin.c
bfd/syms.c
ld/ChangeLog
ld/testsuite/ld-elf/init-fini-arrays.s
ld/testsuite/ld-elf/pr14156a.d
ld/testsuite/ld-elf/pr14156b.d
ld/testsuite/ld-elf/pr24511.d [new file with mode: 0644]
ld/testsuite/ld-scripts/pr18963.t
ld/testsuite/ld-scripts/sane1.t

index 676f4ad221b3fd1fde43bb0f3e126ff5cab42d66..6f7f19a80f2b3f9c6611f4b1a14e66d620460d6c 100644 (file)
@@ -1,3 +1,15 @@
+2019-05-04  Alan Modra  <amodra@gmail.com>
+
+       PR 24511
+       * syms.c (coff_section_type): Only allow '.', '$' and numeric
+       following the standard section names.
+       (bfd_decode_symclass): Prioritize section flag tests in
+       decode_section_type before name tests in coff_section_type.
+       * plugin.c (bfd_plugin_canonicalize_symtab): Init fake_section
+       and fake_common_section using BFD_FAKE_SECTION.  Use "fake" as
+       their names and choose standard .text section flags for
+       fake_section.
+
 2019-05-02  Nick Clifton  <nickc@redhat.com>
 
        PR 24493
index 8cb44ceb5dab6b5712c501595b8f9c7cd60a0a51..376e92cdb3e7117b464e2a5a941486d9a67ddc2d 100644 (file)
@@ -530,13 +530,13 @@ bfd_plugin_canonicalize_symtab (bfd *abfd,
   struct plugin_data_struct *plugin_data = abfd->tdata.plugin_data;
   long nsyms = plugin_data->nsyms;
   const struct ld_plugin_symbol *syms = plugin_data->syms;
-  static asection fake_section;
-  static asection fake_common_section;
+  static asection fake_section
+    = BFD_FAKE_SECTION (fake_section, NULL, "plug", 0,
+                       SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS);
+  static asection fake_common_section
+    = BFD_FAKE_SECTION (fake_common_section, NULL, "plug", 0, SEC_IS_COMMON);
   int i;
 
-  fake_section.name = ".text";
-  fake_common_section.flags = SEC_IS_COMMON;
-
   for (i = 0; i < nsyms; i++)
     {
       asymbol *s = bfd_alloc (abfd, sizeof (asymbol));
index fe7e7dfac8e64da6cd3503d56a8c9c4b94966a04..da1c90d52ebeb7badb5722d58ed2f1ddfd081b1d 100644 (file)
@@ -595,8 +595,9 @@ static const struct section_to_type stt[] =
 /* Return the single-character symbol type corresponding to
    section S, or '?' for an unknown COFF section.
 
-   Check for any leading string which matches, so .text5 returns
-   't' as well as .text */
+   Check for leading strings which match, followed by a number, '.',
+   or '$' so .text5 matches the .text entry, but .init_array doesn't
+   match the .init entry.  */
 
 static char
 coff_section_type (const char *s)
@@ -604,8 +605,12 @@ coff_section_type (const char *s)
   const struct section_to_type *t;
 
   for (t = &stt[0]; t->section; t++)
-    if (!strncmp (s, t->section, strlen (t->section)))
-      return t->type;
+    {
+      size_t len = strlen (t->section);
+      if (strncmp (s, t->section, len) == 0
+         && memchr (".$0123456789", s[len], 13) != 0)
+       return t->type;
+    }
 
   return '?';
 }
@@ -700,9 +705,9 @@ bfd_decode_symclass (asymbol *symbol)
     c = 'a';
   else if (symbol->section)
     {
-      c = coff_section_type (symbol->section->name);
+      c = decode_section_type (symbol->section);
       if (c == '?')
-       c = decode_section_type (symbol->section);
+       c = coff_section_type (symbol->section->name);
     }
   else
     return '?';
index 40b90fbc1a636d36b947cea1cfbe5bc52b611388..722e65669cc10fc4ce557ee4e45d0bd5dcd5004b 100644 (file)
@@ -1,3 +1,16 @@
+2019-05-04  Alan Modra  <amodra@gmail.com>
+
+       PR 24511
+       * testsuite/ld-elf/pr14156a.d: Allow for .init/.fini being a
+       data section on hppa64.
+       * testsuite/ld-elf/pr14156b.d: Likewise.
+       * testsuite/ld-scripts/pr18963.t: Map standard sections to set
+       output section flags.
+       * testsuite/ld-scripts/sane1.t: Likewise.
+       * testsuite/ld-elf/init-fini-arrays.s: Reference __init_array_start
+       and __fini_array_start.  Define __start et al.
+       * testsuite/ld-elf/pr24511.d: New test.
+
 2019-04-30  Alan Modra  <amodra@gmail.com>
 
        * testsuite/ld-powerpc/elfv2exe.d: Update.
index 6740ed6793a91bded5a80640d971b3e06c727251..b8adc29a3c0348becbc0f1e63275e8fad2d467a2 100644 (file)
@@ -1,7 +1,20 @@
  .section .init_array.01000,"aw",%init_array
  .p2align 2
- .word 0
+ .weak __init_array_start, ___init_array_start
+ .dc.a __init_array_start
+ .dc.a ___init_array_start
 
  .section .fini_array.01000,"aw",%fini_array
  .p2align 2
- .word 0
+ .weak __fini_array_start, ___fini_array_start
+ .dc.a __fini_array_start
+ .dc.a ___fini_array_start
+
+ .text
+ .globl main, _main, start, _start, __start
+main:
+_main:
+start:
+_start:
+__start:
+ .dc.a 0
index cf38ee1016f78d5c1066f68e15c9fc27ac18a95d..535ac3e159c94f18b92adbd8496d5914c4f5ec5a 100644 (file)
@@ -7,10 +7,10 @@
 #nm: -n
 
 #...
-[0-9a-f]+ T foo
-[0-9a-f]+ t foo1
+[0-9a-f]+ [TD] foo
+[0-9a-f]+ [td] foo1
 #...
-[0-9a-f]+ t foo2
-[0-9a-f]+ t foo3
-[0-9a-f]+ t last
+[0-9a-f]+ [td] foo2
+[0-9a-f]+ [td] foo3
+[0-9a-f]+ [td] last
 #pass
index f965f74e6e10dc71a23076520082b371b76d9124..27da0166f408610e1b9bbe29f0944fc28fb0bfab 100644 (file)
@@ -7,10 +7,10 @@
 #nm: -n
 
 #...
-[0-9a-f]+ T foo
-[0-9a-f]+ t foo1
+[0-9a-f]+ [TD] foo
+[0-9a-f]+ [td] foo1
 #...
-[0-9a-f]+ t foo2
-[0-9a-f]+ t foo3
-[0-9a-f]+ t last
+[0-9a-f]+ [td] foo2
+[0-9a-f]+ [td] foo3
+[0-9a-f]+ [td] last
 #pass
diff --git a/ld/testsuite/ld-elf/pr24511.d b/ld/testsuite/ld-elf/pr24511.d
new file mode 100644 (file)
index 0000000..f77a43b
--- /dev/null
@@ -0,0 +1,18 @@
+#source: init-fini-arrays.s
+#ld:
+#nm: -n
+# Most targets with their own scripts don't support init/fini_array and
+# thus don't define __init/fini_array_start.
+#xfail: avr-*-* cr16-*-* crx-*-* d10v-*-* d30v-*-* dlx-*-* ft32-*-* iq2000-*-*
+#xfail: m68hc1*-*-* mep-*-* microblaze*-*-elf* s12z-*-* v850-*-* visium-*-*
+#xfail: xgate-*-* xstormy*-*-*
+# Some targets with their own scripts haven't kept up with elf.sc and
+# PROVIDE __init_array_start rather than using PROVIDE_HIDDEN.  These
+# result in D symbols.  rx-elf makes .init/fini_array SHF_EXECINSTR so
+# gets t symbols.
+
+#...
+[0-9a-f]+ [dDt] _?__init_array_start
+#...
+[0-9a-f]+ [dDt] _?__fini_array_start
+#pass
index b0cd7421eb61662d57eec4cec83e8e9442652c77..830ded78dd916d6f505e1909f8faaef8ca25b4c0 100644 (file)
@@ -5,16 +5,19 @@ SECTIONS
   .text :
   {
     _start = .;
+    *(.text)
     . = 0x10000;
   }
   B = .;
   .data :
   {
+    *(.data)
     . = 0x10000;
   }
   C = .;
   .bss :
   {
+    *(.bss)
     . = 0x10000;
   }
   D = A - C + B;
index 037a62c856b645f1ba2e5615f530f7e8ee463d85..90ee9b62d0dc58697c8dc139f7242df6d4ec27f0 100644 (file)
@@ -20,6 +20,7 @@ SECTIONS
     s4 = ABSOLUTE (d1) - 2;
     s5 = ABSOLUTE (d2) % 5;
     s6 = ABSOLUTE (d2) / 5;
+    *(.data)
   }
   /DISCARD/ : {*(*)}
 
This page took 0.032155 seconds and 4 git commands to generate.