public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* PR24511, nm should not mark symbols in .init_array as "t"
@ 2019-05-04  7:57 Alan Modra
  2020-02-26 17:09 ` KONRAD Frederic
  0 siblings, 1 reply; 6+ messages in thread
From: Alan Modra @ 2019-05-04  7:57 UTC (permalink / raw)
  To: binutils

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.

diff --git a/bfd/plugin.c b/bfd/plugin.c
index 8cb44ceb5d..376e92cdb3 100644
--- a/bfd/plugin.c
+++ b/bfd/plugin.c
@@ -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));
diff --git a/bfd/syms.c b/bfd/syms.c
index fe7e7dfac8..da1c90d52e 100644
--- a/bfd/syms.c
+++ b/bfd/syms.c
@@ -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 '?';
diff --git a/ld/testsuite/ld-elf/init-fini-arrays.s b/ld/testsuite/ld-elf/init-fini-arrays.s
index 6740ed6793..b8adc29a3c 100644
--- a/ld/testsuite/ld-elf/init-fini-arrays.s
+++ b/ld/testsuite/ld-elf/init-fini-arrays.s
@@ -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
diff --git a/ld/testsuite/ld-elf/pr14156a.d b/ld/testsuite/ld-elf/pr14156a.d
index cf38ee1016..535ac3e159 100644
--- a/ld/testsuite/ld-elf/pr14156a.d
+++ b/ld/testsuite/ld-elf/pr14156a.d
@@ -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/pr14156b.d b/ld/testsuite/ld-elf/pr14156b.d
index f965f74e6e..27da0166f4 100644
--- a/ld/testsuite/ld-elf/pr14156b.d
+++ b/ld/testsuite/ld-elf/pr14156b.d
@@ -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
index 0000000000..f77a43b9e2
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr24511.d
@@ -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
diff --git a/ld/testsuite/ld-scripts/pr18963.t b/ld/testsuite/ld-scripts/pr18963.t
index b0cd7421eb..830ded78dd 100644
--- a/ld/testsuite/ld-scripts/pr18963.t
+++ b/ld/testsuite/ld-scripts/pr18963.t
@@ -5,16 +5,19 @@ SECTIONS
   .text :
   {
     _start = .;
+    *(.text)
     . = 0x10000;
   }
   B = .;
   .data :
   {
+    *(.data)
     . = 0x10000;
   }
   C = .;
   .bss :
   {
+    *(.bss)
     . = 0x10000;
   }
   D = A - C + B;
diff --git a/ld/testsuite/ld-scripts/sane1.t b/ld/testsuite/ld-scripts/sane1.t
index 037a62c856..90ee9b62d0 100644
--- a/ld/testsuite/ld-scripts/sane1.t
+++ b/ld/testsuite/ld-scripts/sane1.t
@@ -20,6 +20,7 @@ SECTIONS
     s4 = ABSOLUTE (d1) - 2;
     s5 = ABSOLUTE (d2) % 5;
     s6 = ABSOLUTE (d2) / 5;
+    *(.data)
   }
   /DISCARD/ : {*(*)}
 

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PR24511, nm should not mark symbols in .init_array as "t"
  2019-05-04  7:57 PR24511, nm should not mark symbols in .init_array as "t" Alan Modra
@ 2020-02-26 17:09 ` KONRAD Frederic
  2020-02-27  6:56   ` Alan Modra
  0 siblings, 1 reply; 6+ messages in thread
From: KONRAD Frederic @ 2020-02-26 17:09 UTC (permalink / raw)
  To: Alan Modra, binutils

Hi Alan,

It seems that this patch has the side effect of marking the symbols in .idata as
"D" instead of "I" previously.  Is that expected?

Thanks,
Fred

Le 5/4/19 à 9:57 AM, Alan Modra a écrit :
> 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.
> 
> diff --git a/bfd/plugin.c b/bfd/plugin.c
> index 8cb44ceb5d..376e92cdb3 100644
> --- a/bfd/plugin.c
> +++ b/bfd/plugin.c
> @@ -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));
> diff --git a/bfd/syms.c b/bfd/syms.c
> index fe7e7dfac8..da1c90d52e 100644
> --- a/bfd/syms.c
> +++ b/bfd/syms.c
> @@ -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 '?';
> diff --git a/ld/testsuite/ld-elf/init-fini-arrays.s b/ld/testsuite/ld-elf/init-fini-arrays.s
> index 6740ed6793..b8adc29a3c 100644
> --- a/ld/testsuite/ld-elf/init-fini-arrays.s
> +++ b/ld/testsuite/ld-elf/init-fini-arrays.s
> @@ -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
> diff --git a/ld/testsuite/ld-elf/pr14156a.d b/ld/testsuite/ld-elf/pr14156a.d
> index cf38ee1016..535ac3e159 100644
> --- a/ld/testsuite/ld-elf/pr14156a.d
> +++ b/ld/testsuite/ld-elf/pr14156a.d
> @@ -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/pr14156b.d b/ld/testsuite/ld-elf/pr14156b.d
> index f965f74e6e..27da0166f4 100644
> --- a/ld/testsuite/ld-elf/pr14156b.d
> +++ b/ld/testsuite/ld-elf/pr14156b.d
> @@ -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
> index 0000000000..f77a43b9e2
> --- /dev/null
> +++ b/ld/testsuite/ld-elf/pr24511.d
> @@ -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
> diff --git a/ld/testsuite/ld-scripts/pr18963.t b/ld/testsuite/ld-scripts/pr18963.t
> index b0cd7421eb..830ded78dd 100644
> --- a/ld/testsuite/ld-scripts/pr18963.t
> +++ b/ld/testsuite/ld-scripts/pr18963.t
> @@ -5,16 +5,19 @@ SECTIONS
>     .text :
>     {
>       _start = .;
> +    *(.text)
>       . = 0x10000;
>     }
>     B = .;
>     .data :
>     {
> +    *(.data)
>       . = 0x10000;
>     }
>     C = .;
>     .bss :
>     {
> +    *(.bss)
>       . = 0x10000;
>     }
>     D = A - C + B;
> diff --git a/ld/testsuite/ld-scripts/sane1.t b/ld/testsuite/ld-scripts/sane1.t
> index 037a62c856..90ee9b62d0 100644
> --- a/ld/testsuite/ld-scripts/sane1.t
> +++ b/ld/testsuite/ld-scripts/sane1.t
> @@ -20,6 +20,7 @@ SECTIONS
>       s4 = ABSOLUTE (d1) - 2;
>       s5 = ABSOLUTE (d2) % 5;
>       s6 = ABSOLUTE (d2) / 5;
> +    *(.data)
>     }
>     /DISCARD/ : {*(*)}
>   
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PR24511, nm should not mark symbols in .init_array as "t"
  2020-02-26 17:09 ` KONRAD Frederic
@ 2020-02-27  6:56   ` Alan Modra
  2020-02-27  7:07     ` Alan Modra
  2020-02-27 15:03     ` KONRAD Frederic
  0 siblings, 2 replies; 6+ messages in thread
From: Alan Modra @ 2020-02-27  6:56 UTC (permalink / raw)
  To: KONRAD Frederic; +Cc: binutils

On Wed, Feb 26, 2020 at 06:08:46PM +0100, KONRAD Frederic wrote:
> It seems that this patch has the side effect of marking the symbols in .idata as
> "D" instead of "I" previously.  Is that expected?

I guess so, but also wrong.  The patch should not have changed the
order of decode_section_type and coff_section_type calls.  I'm going
to commit this to trunk and a patch that just reverses the calls to
the branch, after testing.

	* syms.c (stt): Trim off all but 'e', 'i' and 'p' entries.
	(coff_section_type): Adjust comment.
	(decode_section_type): Likewise.  Call coff_section_type before
	decode_section_type.
	(bfd_decode_symclass): Use 'c' for common sections other than
	the standard one.

diff --git a/bfd/syms.c b/bfd/syms.c
index 8a5c89767a..c1de8ebab1 100644
--- a/bfd/syms.c
+++ b/bfd/syms.c
@@ -565,30 +565,15 @@ struct section_to_type
   char type;
 };
 
-/* Map section names to POSIX/BSD single-character symbol types.
+/* Map special section names to POSIX/BSD single-character symbol types.
    This table is probably incomplete.  It is sorted for convenience of
    adding entries.  Since it is so short, a linear search is used.  */
 static const struct section_to_type stt[] =
 {
-  {".bss", 'b'},
-  {"code", 't'},		/* MRI .text */
-  {".data", 'd'},
-  {"*DEBUG*", 'N'},
-  {".debug", 'N'},		/* MSVC's .debug (non-standard debug syms) */
   {".drectve", 'i'},		/* MSVC's .drective section */
   {".edata", 'e'},		/* MSVC's .edata (export) section */
-  {".fini", 't'},		/* ELF fini section */
   {".idata", 'i'},		/* MSVC's .idata (import) section */
-  {".init", 't'},		/* ELF init section */
   {".pdata", 'p'},		/* MSVC's .pdata (stack unwind) section */
-  {".rdata", 'r'},		/* Read only data.  */
-  {".rodata", 'r'},		/* Read only data.  */
-  {".sbss", 's'},		/* Small BSS (uninitialized data).  */
-  {".scommon", 'c'},		/* Small common.  */
-  {".sdata", 'g'},		/* Small initialized data.  */
-  {".text", 't'},
-  {"vars", 'd'},		/* MRI .data */
-  {"zerovars", 'b'},		/* MRI .bss */
   {0, 0}
 };
 
@@ -596,8 +581,7 @@ static const struct section_to_type stt[] =
    section S, or '?' for an unknown COFF section.
 
    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.  */
+   or '$' so .idata5 matches the .idata entry.  */
 
 static char
 coff_section_type (const char *s)
@@ -619,7 +603,7 @@ coff_section_type (const char *s)
    SECTION, or '?' for an unknown section.  This uses section flags to
    identify sections.
 
-   FIXME These types are unhandled: c, i, e, p.  If we handled these also,
+   FIXME These types are unhandled: e, i, p.  If we handled these also,
    we could perhaps obsolete coff_section_type.  */
 
 static char
@@ -668,7 +652,12 @@ bfd_decode_symclass (asymbol *symbol)
   char c;
 
   if (symbol->section && bfd_is_com_section (symbol->section))
-    return 'C';
+    {
+      if (symbol->section == bfd_com_section_ptr)
+	return 'C';
+      else
+	return 'c';
+    }
   if (bfd_is_und_section (symbol->section))
     {
       if (symbol->flags & BSF_WEAK)
@@ -705,9 +694,9 @@ bfd_decode_symclass (asymbol *symbol)
     c = 'a';
   else if (symbol->section)
     {
-      c = decode_section_type (symbol->section);
+      c = coff_section_type (symbol->section->name);
       if (c == '?')
-	c = coff_section_type (symbol->section->name);
+	c = decode_section_type (symbol->section);
     }
   else
     return '?';

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PR24511, nm should not mark symbols in .init_array as "t"
  2020-02-27  6:56   ` Alan Modra
@ 2020-02-27  7:07     ` Alan Modra
  2020-02-27 17:28       ` Hans-Peter Nilsson
  2020-02-27 15:03     ` KONRAD Frederic
  1 sibling, 1 reply; 6+ messages in thread
From: Alan Modra @ 2020-02-27  7:07 UTC (permalink / raw)
  To: Hans-Peter Nilsson; +Cc: binutils, KONRAD Frederic

On Thu, Feb 27, 2020 at 05:26:10PM +1030, Alan Modra wrote:
> 	* syms.c (stt): Trim off all but 'e', 'i' and 'p' entries.
> 	(coff_section_type): Adjust comment.
> 	(decode_section_type): Likewise.  Call coff_section_type before
> 	decode_section_type.
> 	(bfd_decode_symclass): Use 'c' for common sections other than
> 	the standard one.

With the bfd_decode_symclass change, ld SIZEOF test fails due to
data_end being reported as type '?'.

Does this look a reasonable solution, Hans-Peter?

bfd/
	* mmo.c (mmo_scan): Set SEC_DATA for .data.
ld/
	* testsuite/ld-mmix/b-fixo2.d: Adjust for .data change.
	* testsuite/ld-mmix/sec-2.d: Likewise.
	* testsuite/ld-mmix/sec-3.d: Likewise.
	* testsuite/ld-mmix/sec-4.d: Likewise.
	* testsuite/ld-mmix/spec802.d: Likewise.
	* testsuite/ld-mmix/spec803.d: Likewise.
	* testsuite/ld-mmix/spec804.d: Likewise.
	* testsuite/ld-mmix/spec805.d: Likewise.
	* testsuite/ld-mmix/spec806.d: Likewise.
	* testsuite/ld-mmix/spec807.d: Likewise.
	* testsuite/ld-mmix/spec808.d: Likewise.

diff --git a/bfd/mmo.c b/bfd/mmo.c
index 9ac689d042..073c37c0ac 100644
--- a/bfd/mmo.c
+++ b/bfd/mmo.c
@@ -2074,7 +2074,7 @@ mmo_scan (bfd *abfd)
   if (sec != NULL
       && (bfd_section_flags (sec) & SEC_HAS_CONTENTS)
       && !bfd_set_section_flags (sec, (bfd_section_flags (sec)
-				       | SEC_ALLOC | SEC_LOAD)))
+				       | SEC_ALLOC | SEC_LOAD | SEC_DATA)))
     error = TRUE;
 
   /* Free whatever resources we took.  */
diff --git a/ld/testsuite/ld-mmix/b-fixo2.d b/ld/testsuite/ld-mmix/b-fixo2.d
index e8e2ff845f..3db01eb32d 100644
--- a/ld/testsuite/ld-mmix/b-fixo2.d
+++ b/ld/testsuite/ld-mmix/b-fixo2.d
@@ -16,7 +16,7 @@ Idx Name          Size      VMA               LMA               File off  Algn
   0 \.text         0+8  0+  0+  0+  2\*\*2
                   CONTENTS, ALLOC, LOAD, CODE
   1 \.data         0+4  2068098510aa5564  2068098510aa5564  0+  2\*\*2
-                  CONTENTS, ALLOC, LOAD
+                  CONTENTS, ALLOC, LOAD, DATA
 SYMBOL TABLE:
 0+4 g       \.text Main
 0+4 g       \.text a
diff --git a/ld/testsuite/ld-mmix/sec-2.d b/ld/testsuite/ld-mmix/sec-2.d
index 10623f354c..10a9a521ac 100644
--- a/ld/testsuite/ld-mmix/sec-2.d
+++ b/ld/testsuite/ld-mmix/sec-2.d
@@ -13,7 +13,7 @@ Idx Name          Size      VMA               LMA               File off  Algn
   1 \.other        0+50  1000000000000000  1000000000000000  0+  2\*\*2
                   CONTENTS, ALLOC, LOAD, CODE, DATA
   2 \.data         0+4  2000000000000004  2000000000000004  0+  2\*\*2
-                  CONTENTS, ALLOC, LOAD
+                  CONTENTS, ALLOC, LOAD, DATA
 Contents of section \.text:
  0100 e3fd0001                             .*
 Contents of section \.other:
diff --git a/ld/testsuite/ld-mmix/sec-3.d b/ld/testsuite/ld-mmix/sec-3.d
index 290052b99e..8074e834e1 100644
--- a/ld/testsuite/ld-mmix/sec-3.d
+++ b/ld/testsuite/ld-mmix/sec-3.d
@@ -15,7 +15,7 @@ Idx Name          Size      VMA               LMA               File off  Algn
   2 \.a\.fourth\.section 0+10  0+20  0+20  0+  2\*\*2
                   CONTENTS, ALLOC, LOAD, READONLY, DATA
   3 \.data         0+4  2000000000000004  2000000000000004  0+  2\*\*2
-                  CONTENTS, ALLOC, LOAD
+                  CONTENTS, ALLOC, LOAD, DATA
   4 anothersec    0+13  2000000000000008  2000000000000008  0+  2\*\*2
                   CONTENTS, ALLOC, LOAD, DATA
   5 thirdsec      0+a  0+  0+  0+  2\*\*2
diff --git a/ld/testsuite/ld-mmix/sec-4.d b/ld/testsuite/ld-mmix/sec-4.d
index 251f6a28d0..16b65896a7 100644
--- a/ld/testsuite/ld-mmix/sec-4.d
+++ b/ld/testsuite/ld-mmix/sec-4.d
@@ -11,7 +11,7 @@ Idx Name          Size      VMA               LMA               File off  Algn
   0 \.text         0+4  0+100  0+100  0+  2\*\*2
                   CONTENTS, ALLOC, LOAD, CODE
   1 \.data         0+4  2000000000000004  2000000000000004  0+  2\*\*2
-                  CONTENTS, ALLOC, LOAD
+                  CONTENTS, ALLOC, LOAD, DATA
   2 \.other        0+c  1000000000000000  1000000000000000  0+  2\*\*2
                   CONTENTS, ALLOC, LOAD, READONLY, CODE
 Contents of section \.text:
diff --git a/ld/testsuite/ld-mmix/spec802.d b/ld/testsuite/ld-mmix/spec802.d
index ea0ebc3d65..cea7de2ee5 100644
--- a/ld/testsuite/ld-mmix/spec802.d
+++ b/ld/testsuite/ld-mmix/spec802.d
@@ -13,7 +13,7 @@ Idx Name          Size      VMA               LMA               File off  Algn
   0 \.text         0+4  0+  0+  0+  2\*\*2
                   CONTENTS, ALLOC, LOAD, CODE
   1 \.data         0+4  2000000000000000  2000000000000000  0+  2\*\*2
-                  CONTENTS, ALLOC, LOAD
+                  CONTENTS, ALLOC, LOAD, DATA
   2 \.MMIX\.spec_data\.80 0+4  0+  0+  0+  2\*\*2
                   CONTENTS
 Contents of section \.text:
diff --git a/ld/testsuite/ld-mmix/spec803.d b/ld/testsuite/ld-mmix/spec803.d
index b933d6ca7d..cc63844425 100644
--- a/ld/testsuite/ld-mmix/spec803.d
+++ b/ld/testsuite/ld-mmix/spec803.d
@@ -13,7 +13,7 @@ Idx Name          Size      VMA               LMA               File off  Algn
   0 \.text         0+4  0+  0+  0+  2\*\*2
                   CONTENTS, ALLOC, LOAD, CODE
   1 \.data         0+4  2000000000000000  2000000000000000  0+  2\*\*2
-                  CONTENTS, ALLOC, LOAD
+                  CONTENTS, ALLOC, LOAD, DATA
   2 \.MMIX\.spec_data\.80 0+c  0+  0+  0+  2\*\*2
                   CONTENTS
 Contents of section \.text:
diff --git a/ld/testsuite/ld-mmix/spec804.d b/ld/testsuite/ld-mmix/spec804.d
index 170bc5e0bd..fd8f0bf376 100644
--- a/ld/testsuite/ld-mmix/spec804.d
+++ b/ld/testsuite/ld-mmix/spec804.d
@@ -13,7 +13,7 @@ Idx Name          Size      VMA               LMA               File off  Algn
   0 \.text         0+4  0+  0+  0+  2\*\*2
                   CONTENTS, ALLOC, LOAD, CODE
   1 \.data         0+4  2000000000000000  2000000000000000  0+  2\*\*2
-                  CONTENTS, ALLOC, LOAD
+                  CONTENTS, ALLOC, LOAD, DATA
   2 \.MMIX\.spec_data\.80 0+10  0+  0+  0+  2\*\*2
                   CONTENTS
 Contents of section \.text:
diff --git a/ld/testsuite/ld-mmix/spec805.d b/ld/testsuite/ld-mmix/spec805.d
index c4cdd02f23..d0562eb138 100644
--- a/ld/testsuite/ld-mmix/spec805.d
+++ b/ld/testsuite/ld-mmix/spec805.d
@@ -13,7 +13,7 @@ Idx Name          Size      VMA               LMA               File off  Algn
   0 \.text         0+4  0+  0+  0+  2\*\*2
                   CONTENTS, ALLOC, LOAD, CODE
   1 \.data         0+4  2000000000000000  2000000000000000  0+  2\*\*2
-                  CONTENTS, ALLOC, LOAD
+                  CONTENTS, ALLOC, LOAD, DATA
   2 \.MMIX\.spec_data\.80 0+14  0+  0+  0+  2\*\*2
                   CONTENTS
 Contents of section \.text:
diff --git a/ld/testsuite/ld-mmix/spec806.d b/ld/testsuite/ld-mmix/spec806.d
index 7f64948971..64d8bf9cf6 100644
--- a/ld/testsuite/ld-mmix/spec806.d
+++ b/ld/testsuite/ld-mmix/spec806.d
@@ -13,7 +13,7 @@ Idx Name          Size      VMA               LMA               File off  Algn
   0 \.text         0+4  0+  0+  0+  2\*\*2
                   CONTENTS, ALLOC, LOAD, CODE
   1 \.data         0+4  2000000000000000  2000000000000000  0+  2\*\*2
-                  CONTENTS, ALLOC, LOAD
+                  CONTENTS, ALLOC, LOAD, DATA
   2 \.MMIX\.spec_data\.80 0+18  0+  0+  0+  2\*\*2
                   CONTENTS
 Contents of section \.text:
diff --git a/ld/testsuite/ld-mmix/spec807.d b/ld/testsuite/ld-mmix/spec807.d
index f37e57a4d5..ef2edb93d3 100644
--- a/ld/testsuite/ld-mmix/spec807.d
+++ b/ld/testsuite/ld-mmix/spec807.d
@@ -13,7 +13,7 @@ Idx Name          Size      VMA               LMA               File off  Algn
   0 \.text         0+4  0+  0+  0+  2\*\*2
                   CONTENTS, ALLOC, LOAD, CODE
   1 \.data         0+4  2000000000000000  2000000000000000  0+  2\*\*2
-                  CONTENTS, ALLOC, LOAD
+                  CONTENTS, ALLOC, LOAD, DATA
   2 \.MMIX\.spec_data\.80 0+1c  0+  0+  0+  2\*\*2
                   CONTENTS
 Contents of section \.text:
diff --git a/ld/testsuite/ld-mmix/spec808.d b/ld/testsuite/ld-mmix/spec808.d
index e1d678485e..00a5347f99 100644
--- a/ld/testsuite/ld-mmix/spec808.d
+++ b/ld/testsuite/ld-mmix/spec808.d
@@ -13,7 +13,7 @@ Idx Name          Size      VMA               LMA               File off  Algn
   0 \.text         0+4  0+  0+  0+  2\*\*2
                   CONTENTS, ALLOC, LOAD, CODE
   1 \.data         0+4  2000000000000000  2000000000000000  0+  2\*\*2
-                  CONTENTS, ALLOC, LOAD
+                  CONTENTS, ALLOC, LOAD, DATA
   2 \.MMIX\.spec_data\.80 0+20  0+  0+  0+  2\*\*2
                   CONTENTS
 Contents of section \.text:

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PR24511, nm should not mark symbols in .init_array as "t"
  2020-02-27  6:56   ` Alan Modra
  2020-02-27  7:07     ` Alan Modra
@ 2020-02-27 15:03     ` KONRAD Frederic
  1 sibling, 0 replies; 6+ messages in thread
From: KONRAD Frederic @ 2020-02-27 15:03 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils



Le 2/27/20 à 7:56 AM, Alan Modra a écrit :
> On Wed, Feb 26, 2020 at 06:08:46PM +0100, KONRAD Frederic wrote:
>> It seems that this patch has the side effect of marking the symbols in .idata as
>> "D" instead of "I" previously.  Is that expected?
> 
> I guess so, but also wrong.  The patch should not have changed the
> order of decode_section_type and coff_section_type calls.  I'm going
> to commit this to trunk and a patch that just reverses the calls to
> the branch, after testing.
> 
> 	* syms.c (stt): Trim off all but 'e', 'i' and 'p' entries.
> 	(coff_section_type): Adjust comment.
> 	(decode_section_type): Likewise.  Call coff_section_type before
> 	decode_section_type.
> 	(bfd_decode_symclass): Use 'c' for common sections other than
> 	the standard one.

Thanks for the fast answer,

I confirm that the patch below fix the behavior I had.

> 
> diff --git a/bfd/syms.c b/bfd/syms.c
> index 8a5c89767a..c1de8ebab1 100644
> --- a/bfd/syms.c
> +++ b/bfd/syms.c
> @@ -565,30 +565,15 @@ struct section_to_type
>     char type;
>   };
>   
> -/* Map section names to POSIX/BSD single-character symbol types.
> +/* Map special section names to POSIX/BSD single-character symbol types.
>      This table is probably incomplete.  It is sorted for convenience of
>      adding entries.  Since it is so short, a linear search is used.  */
>   static const struct section_to_type stt[] =
>   {
> -  {".bss", 'b'},
> -  {"code", 't'},		/* MRI .text */
> -  {".data", 'd'},
> -  {"*DEBUG*", 'N'},
> -  {".debug", 'N'},		/* MSVC's .debug (non-standard debug syms) */
>     {".drectve", 'i'},		/* MSVC's .drective section */
>     {".edata", 'e'},		/* MSVC's .edata (export) section */
> -  {".fini", 't'},		/* ELF fini section */
>     {".idata", 'i'},		/* MSVC's .idata (import) section */
> -  {".init", 't'},		/* ELF init section */
>     {".pdata", 'p'},		/* MSVC's .pdata (stack unwind) section */
> -  {".rdata", 'r'},		/* Read only data.  */
> -  {".rodata", 'r'},		/* Read only data.  */
> -  {".sbss", 's'},		/* Small BSS (uninitialized data).  */
> -  {".scommon", 'c'},		/* Small common.  */
> -  {".sdata", 'g'},		/* Small initialized data.  */
> -  {".text", 't'},
> -  {"vars", 'd'},		/* MRI .data */
> -  {"zerovars", 'b'},		/* MRI .bss */
>     {0, 0}
>   };
>   
> @@ -596,8 +581,7 @@ static const struct section_to_type stt[] =
>      section S, or '?' for an unknown COFF section.
>   
>      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.  */
> +   or '$' so .idata5 matches the .idata entry.  */
>   
>   static char
>   coff_section_type (const char *s)
> @@ -619,7 +603,7 @@ coff_section_type (const char *s)
>      SECTION, or '?' for an unknown section.  This uses section flags to
>      identify sections.
>   
> -   FIXME These types are unhandled: c, i, e, p.  If we handled these also,
> +   FIXME These types are unhandled: e, i, p.  If we handled these also,
>      we could perhaps obsolete coff_section_type.  */
>   
>   static char
> @@ -668,7 +652,12 @@ bfd_decode_symclass (asymbol *symbol)
>     char c;
>   
>     if (symbol->section && bfd_is_com_section (symbol->section))
> -    return 'C';
> +    {
> +      if (symbol->section == bfd_com_section_ptr)
> +	return 'C';
> +      else
> +	return 'c';
> +    }
>     if (bfd_is_und_section (symbol->section))
>       {
>         if (symbol->flags & BSF_WEAK)
> @@ -705,9 +694,9 @@ bfd_decode_symclass (asymbol *symbol)
>       c = 'a';
>     else if (symbol->section)
>       {
> -      c = decode_section_type (symbol->section);
> +      c = coff_section_type (symbol->section->name);
>         if (c == '?')
> -	c = coff_section_type (symbol->section->name);
> +	c = decode_section_type (symbol->section);
>       }
>     else
>       return '?';
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PR24511, nm should not mark symbols in .init_array as "t"
  2020-02-27  7:07     ` Alan Modra
@ 2020-02-27 17:28       ` Hans-Peter Nilsson
  0 siblings, 0 replies; 6+ messages in thread
From: Hans-Peter Nilsson @ 2020-02-27 17:28 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils, KONRAD Frederic

On Thu, 27 Feb 2020, Alan Modra wrote:

> On Thu, Feb 27, 2020 at 05:26:10PM +1030, Alan Modra wrote:
> > 	* syms.c (stt): Trim off all but 'e', 'i' and 'p' entries.
> > 	(coff_section_type): Adjust comment.
> > 	(decode_section_type): Likewise.  Call coff_section_type before
> > 	decode_section_type.
> > 	(bfd_decode_symclass): Use 'c' for common sections other than
> > 	the standard one.
>
> With the bfd_decode_symclass change, ld SIZEOF test fails due to
> data_end being reported as type '?'.
>
> Does this look a reasonable solution, Hans-Peter?
>
> bfd/
> 	* mmo.c (mmo_scan): Set SEC_DATA for .data.
> ld/
> 	* testsuite/ld-mmix/b-fixo2.d: Adjust for .data change.
> 	* testsuite/ld-mmix/sec-2.d: Likewise.
> 	* testsuite/ld-mmix/sec-3.d: Likewise.
> 	* testsuite/ld-mmix/sec-4.d: Likewise.
> 	* testsuite/ld-mmix/spec802.d: Likewise.
> 	* testsuite/ld-mmix/spec803.d: Likewise.
> 	* testsuite/ld-mmix/spec804.d: Likewise.
> 	* testsuite/ld-mmix/spec805.d: Likewise.
> 	* testsuite/ld-mmix/spec806.d: Likewise.
> 	* testsuite/ld-mmix/spec807.d: Likewise.
> 	* testsuite/ld-mmix/spec808.d: Likewise.


Correcting data sections to be classified as DATA?
Certainly LGTM! :)  Thanks.

brgds, H-P

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-02-27 17:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-04  7:57 PR24511, nm should not mark symbols in .init_array as "t" Alan Modra
2020-02-26 17:09 ` KONRAD Frederic
2020-02-27  6:56   ` Alan Modra
2020-02-27  7:07     ` Alan Modra
2020-02-27 17:28       ` Hans-Peter Nilsson
2020-02-27 15:03     ` KONRAD Frederic

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).