RISC-V: PR27584, surpress local and empty name symbols for nm.

Message ID 1618371080-27628-1-git-send-email-nelson.chu@sifive.com
State New
Headers show
Series
  • RISC-V: PR27584, surpress local and empty name symbols for nm.
Related show

Commit Message

Nelson Chu April 14, 2021, 3:31 a.m.
The local ".L0" symbol are usually generated to mark where the
auipc instruction is, and clang also uses ".LBB" to do the same
thing.  Besides, clang also uses the empty name symbols for label
differences.  Arm surpress their mapping symbols by regarding them
as special symbols, and MIPS surpress all local symbols.  Therefore,
maybe RISC-V also need to surpress the local and empty name symbols
for nm and related tools.  User can use "--special-syms" to show
these surpressed symbols if they want.

bfd/
    * elfnn-riscv.c (riscv_elf_is_target_special_symbol): Added to
    omit local and empty symbols since they usually generated to
    mark the auipc instructions.
---
 bfd/elfnn-riscv.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

-- 
2.7.4

Comments

Palmer Dabbelt April 14, 2021, 3:38 a.m. | #1
On Tue, 13 Apr 2021 20:31:20 PDT (-0700), nelson.chu@sifive.com wrote:
> The local ".L0" symbol are usually generated to mark where the

> auipc instruction is, and clang also uses ".LBB" to do the same

> thing.  Besides, clang also uses the empty name symbols for label

> differences.  Arm surpress their mapping symbols by regarding them

> as special symbols, and MIPS surpress all local symbols.  Therefore,

> maybe RISC-V also need to surpress the local and empty name symbols

> for nm and related tools.  User can use "--special-syms" to show

> these surpressed symbols if they want.

>

> bfd/

>     * elfnn-riscv.c (riscv_elf_is_target_special_symbol): Added to

>     omit local and empty symbols since they usually generated to

>     mark the auipc instructions.

> ---

>  bfd/elfnn-riscv.c | 11 +++++++++++

>  1 file changed, 11 insertions(+)

>

> diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c

> index 5e29278..a944b33 100644

> --- a/bfd/elfnn-riscv.c

> +++ b/bfd/elfnn-riscv.c

> @@ -5094,6 +5094,16 @@ riscv_elf_obj_attrs_arg_type (int tag)

>    return (tag & 1) != 0 ? ATTR_TYPE_FLAG_STR_VAL : ATTR_TYPE_FLAG_INT_VAL;

>  }

>

> +/* PR27584, Omit local and empty symbols since they usually generated

> +   for pcrel relocations.  */

> +

> +static bool

> +riscv_elf_is_target_special_symbol (bfd *abfd, asymbol *sym)

> +{

> +  return (!strcmp (sym->name, "")

> +	  || _bfd_elf_is_local_label_name (abfd, sym->name));

> +}

> +

>  #define TARGET_LITTLE_SYM			riscv_elfNN_vec

>  #define TARGET_LITTLE_NAME			"elfNN-littleriscv"

>  #define TARGET_BIG_SYM				riscv_elfNN_be_vec

> @@ -5106,6 +5116,7 @@ riscv_elf_obj_attrs_arg_type (int tag)

>  #define bfd_elfNN_bfd_reloc_type_lookup		riscv_reloc_type_lookup

>  #define bfd_elfNN_bfd_merge_private_bfd_data \

>    _bfd_riscv_elf_merge_private_bfd_data

> +#define bfd_elfNN_bfd_is_target_special_symbol	riscv_elf_is_target_special_symbol

>

>  #define elf_backend_copy_indirect_symbol	riscv_elf_copy_indirect_symbol

>  #define elf_backend_create_dynamic_sections	riscv_elf_create_dynamic_sections


LGTM.  IIRC we already suppress these elsewhere, so this is either a 
regression or we forgot to look at nm.

Thanks!
Nelson Chu April 15, 2021, 2:34 a.m. | #2
Thanks, Palmer :)  Committed.

Nelson

On Wed, Apr 14, 2021 at 11:38 AM Palmer Dabbelt <palmer@dabbelt.com> wrote:
>

> On Tue, 13 Apr 2021 20:31:20 PDT (-0700), nelson.chu@sifive.com wrote:

> > The local ".L0" symbol are usually generated to mark where the

> > auipc instruction is, and clang also uses ".LBB" to do the same

> > thing.  Besides, clang also uses the empty name symbols for label

> > differences.  Arm surpress their mapping symbols by regarding them

> > as special symbols, and MIPS surpress all local symbols.  Therefore,

> > maybe RISC-V also need to surpress the local and empty name symbols

> > for nm and related tools.  User can use "--special-syms" to show

> > these surpressed symbols if they want.

> >

> > bfd/

> >     * elfnn-riscv.c (riscv_elf_is_target_special_symbol): Added to

> >     omit local and empty symbols since they usually generated to

> >     mark the auipc instructions.

> > ---

> >  bfd/elfnn-riscv.c | 11 +++++++++++

> >  1 file changed, 11 insertions(+)

> >

> > diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c

> > index 5e29278..a944b33 100644

> > --- a/bfd/elfnn-riscv.c

> > +++ b/bfd/elfnn-riscv.c

> > @@ -5094,6 +5094,16 @@ riscv_elf_obj_attrs_arg_type (int tag)

> >    return (tag & 1) != 0 ? ATTR_TYPE_FLAG_STR_VAL : ATTR_TYPE_FLAG_INT_VAL;

> >  }

> >

> > +/* PR27584, Omit local and empty symbols since they usually generated

> > +   for pcrel relocations.  */

> > +

> > +static bool

> > +riscv_elf_is_target_special_symbol (bfd *abfd, asymbol *sym)

> > +{

> > +  return (!strcmp (sym->name, "")

> > +       || _bfd_elf_is_local_label_name (abfd, sym->name));

> > +}

> > +

> >  #define TARGET_LITTLE_SYM                    riscv_elfNN_vec

> >  #define TARGET_LITTLE_NAME                   "elfNN-littleriscv"

> >  #define TARGET_BIG_SYM                               riscv_elfNN_be_vec

> > @@ -5106,6 +5116,7 @@ riscv_elf_obj_attrs_arg_type (int tag)

> >  #define bfd_elfNN_bfd_reloc_type_lookup              riscv_reloc_type_lookup

> >  #define bfd_elfNN_bfd_merge_private_bfd_data \

> >    _bfd_riscv_elf_merge_private_bfd_data

> > +#define bfd_elfNN_bfd_is_target_special_symbol       riscv_elf_is_target_special_symbol

> >

> >  #define elf_backend_copy_indirect_symbol     riscv_elf_copy_indirect_symbol

> >  #define elf_backend_create_dynamic_sections  riscv_elf_create_dynamic_sections

>

> LGTM.  IIRC we already suppress these elsewhere, so this is either a

> regression or we forgot to look at nm.

>

> Thanks!

Patch

diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index 5e29278..a944b33 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -5094,6 +5094,16 @@  riscv_elf_obj_attrs_arg_type (int tag)
   return (tag & 1) != 0 ? ATTR_TYPE_FLAG_STR_VAL : ATTR_TYPE_FLAG_INT_VAL;
 }
 
+/* PR27584, Omit local and empty symbols since they usually generated
+   for pcrel relocations.  */
+
+static bool
+riscv_elf_is_target_special_symbol (bfd *abfd, asymbol *sym)
+{
+  return (!strcmp (sym->name, "")
+	  || _bfd_elf_is_local_label_name (abfd, sym->name));
+}
+
 #define TARGET_LITTLE_SYM			riscv_elfNN_vec
 #define TARGET_LITTLE_NAME			"elfNN-littleriscv"
 #define TARGET_BIG_SYM				riscv_elfNN_be_vec
@@ -5106,6 +5116,7 @@  riscv_elf_obj_attrs_arg_type (int tag)
 #define bfd_elfNN_bfd_reloc_type_lookup		riscv_reloc_type_lookup
 #define bfd_elfNN_bfd_merge_private_bfd_data \
   _bfd_riscv_elf_merge_private_bfd_data
+#define bfd_elfNN_bfd_is_target_special_symbol	riscv_elf_is_target_special_symbol
 
 #define elf_backend_copy_indirect_symbol	riscv_elf_copy_indirect_symbol
 #define elf_backend_create_dynamic_sections	riscv_elf_create_dynamic_sections