public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Named local symbols in the ELF dynamic symbol table
@ 2022-12-06 17:11 Florian Weimer
  2022-12-08 13:19 ` Nick Clifton
  2022-12-14 21:44 ` H.J. Lu
  0 siblings, 2 replies; 7+ messages in thread
From: Florian Weimer @ 2022-12-06 17:11 UTC (permalink / raw)
  To: binutils

The symbol table of /lib/ld-linux-ia64.so.2 starts like this:

Symbol table [ 3] '.dynsym' contains 65 entries:
 33 local symbols  String table: [ 4] '.dynstr'
  Num:            Value   Size Type    Bind   Vis          Ndx Name
    0: 0000000000000000      0 NOTYPE  LOCAL  DEFAULT    UNDEF 
    1: 00000000000318c0    160 FUNC    LOCAL  DEFAULT       10 _dl_error_free
    2: 00000000000234c0     16 FUNC    LOCAL  DEFAULT       10 __GI__dl_debug_state
    3: 0000000000029f80    368 FUNC    LOCAL  DEFAULT       10 _dl_tls_get_addr_soft
    4: 000000000002be00   1728 FUNC    LOCAL  DEFAULT       10 _dl_open
    5: 0000000000001550     64 FUNC    LOCAL  DEFAULT       10 _start
    6: 0000000000031540    784 FUNC    LOCAL  DEFAULT       10 _dl_runtime_profile
    7: 0000000000031440    208 FUNC    LOCAL  DEFAULT       10 _dl_runtime_resolve
    8: 00000000000312c0    384 FUNC    LOCAL  DEFAULT       10 _dl_close
    9: 0000000000018240  10720 FUNC    LOCAL  DEFAULT       10 _dl_lookup_symbol_x
   10: 000000000003ab40     80 FUNC    LOCAL  DEFAULT       10 _rtld_catch_error

The interesting aspect is that these symbols are named, but are not
covered by the GNU_HASH table (because they are local).

Is there a way to get the same effect on other targets?  I want to
preserve the names of the functions that IFUNC resolvers return,
eventually improving diagnostics around IFUNC resolution.  It would best
if I wouldn't have to bloat the entire symbol table for that.

Thanks,
Florian


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

* Re: Named local symbols in the ELF dynamic symbol table
  2022-12-06 17:11 Named local symbols in the ELF dynamic symbol table Florian Weimer
@ 2022-12-08 13:19 ` Nick Clifton
  2022-12-09 17:34   ` Florian Weimer
  2022-12-14 21:44 ` H.J. Lu
  1 sibling, 1 reply; 7+ messages in thread
From: Nick Clifton @ 2022-12-08 13:19 UTC (permalink / raw)
  To: Florian Weimer, binutils

Hi Florian,

> Is there a way to get the same effect on other targets?

How are the loaders for other targets linked ?  If they include the
-X or --discard-locals option on the command line, then removing that
option might achieve the result that you desire.

> It would best
> if I wouldn't have to bloat the entire symbol table for that.

I don't think that you have symbol names without having entries in
the symbol table.  Although as you say, if they are local symbols
then they will not also take up room in the GNU_HASH table.

Cheers
   Nick



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

* Re: Named local symbols in the ELF dynamic symbol table
  2022-12-08 13:19 ` Nick Clifton
@ 2022-12-09 17:34   ` Florian Weimer
  2022-12-14 15:31     ` Nick Clifton
  2022-12-14 20:05     ` Fangrui Song
  0 siblings, 2 replies; 7+ messages in thread
From: Florian Weimer @ 2022-12-09 17:34 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils

* Nick Clifton:

> Hi Florian,
>
>> Is there a way to get the same effect on other targets?
>
> How are the loaders for other targets linked ?  If they include the
> -X or --discard-locals option on the command line, then removing that
> option might achieve the result that you desire.

I'm using:

  gcc -nostdlib -nostartfiles -shared -o …/build/elf/ld.so.new \
          -Wl,-z,relro -Wl,-z,defs \
          …/build/elf/librtld.os -Wl,--version-script=…/build/ld.map \
          -Wl,-soname=ld-linux-x86-64.so.2

gcc -v tells me:

/usr/libexec/gcc/x86_64-redhat-linux/11/collect2 \
  -plugin /usr/libexec/gcc/x86_64-redhat-linux/11/liblto_plugin.so \
  -plugin-opt=/usr/libexec/gcc/x86_64-redhat-linux/11/lto-wrapper \
  -plugin-opt=-fresolution=/tmp/ccHaMg3U.res --build-id --no-add-needed \
  --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -shared \
  -o …/build/elf/ld.so.new -L/usr/lib/gcc/x86_64-redhat-linux/11 \
  -L/usr/lib/gcc/x86_64-redhat-linux/11/../../../../lib64 -L/lib/../lib64 \
  -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/11/../../.. \
  -z relro -z defs …/build/elf/librtld.os --version-script=…/build/ld.map \
  -soname=ld-linux-x86-64.so.2

So it seems that -X or --discard-locals is the default?  How do I
override that, preferably for specific symbols only?

>> It would best
>> if I wouldn't have to bloat the entire symbol table for that.
>
> I don't think that you have symbol names without having entries in
> the symbol table.  Although as you say, if they are local symbols
> then they will not also take up room in the GNU_HASH table.

Yeah, should have said symbol hash table.  I really want them in .dynsym
actually.

Thanks,
Florian


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

* Re: Named local symbols in the ELF dynamic symbol table
  2022-12-09 17:34   ` Florian Weimer
@ 2022-12-14 15:31     ` Nick Clifton
  2022-12-14 20:05     ` Fangrui Song
  1 sibling, 0 replies; 7+ messages in thread
From: Nick Clifton @ 2022-12-14 15:31 UTC (permalink / raw)
  To: Florian Weimer; +Cc: binutils

Hi Florian,

> So it seems that -X or --discard-locals is the default?

It is not clear. -{  The sources do not appear to initialise
the fields concerned with this in the link_info structure.

>  How do I
> override that, preferably for specific symbols only?

Please try -Wl,--no-strip-discarded and/or -Wl,--discard-none

Not sure what will happen....

Cheers
   Nick


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

* Re: Named local symbols in the ELF dynamic symbol table
  2022-12-09 17:34   ` Florian Weimer
  2022-12-14 15:31     ` Nick Clifton
@ 2022-12-14 20:05     ` Fangrui Song
  1 sibling, 0 replies; 7+ messages in thread
From: Fangrui Song @ 2022-12-14 20:05 UTC (permalink / raw)
  To: Florian Weimer; +Cc: Nick Clifton, binutils

I have only seen one reason where STB_LOCAL symbols in .dynsym are useful:
unaligned absolute relocations for ppc32/ppc64
https://sourceware.org/bugzilla/show_bug.cgi?id=24896 .

If the ia64 .dynsym STB_LOCAL symbols are not used by special
relocations, it's likely a minor issue/missing improvement in ld's ia64
port.

On 2022-12-09, Florian Weimer via Binutils wrote:
>* Nick Clifton:
>
>> Hi Florian,
>>
>>> Is there a way to get the same effect on other targets?
>>
>> How are the loaders for other targets linked ?  If they include the
>> -X or --discard-locals option on the command line, then removing that
>> option might achieve the result that you desire.
>
>I'm using:
>
>  gcc -nostdlib -nostartfiles -shared -o …/build/elf/ld.so.new \
>          -Wl,-z,relro -Wl,-z,defs \
>          …/build/elf/librtld.os -Wl,--version-script=…/build/ld.map \
>          -Wl,-soname=ld-linux-x86-64.so.2
>
>gcc -v tells me:
>
>/usr/libexec/gcc/x86_64-redhat-linux/11/collect2 \
>  -plugin /usr/libexec/gcc/x86_64-redhat-linux/11/liblto_plugin.so \
>  -plugin-opt=/usr/libexec/gcc/x86_64-redhat-linux/11/lto-wrapper \
>  -plugin-opt=-fresolution=/tmp/ccHaMg3U.res --build-id --no-add-needed \
>  --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -shared \
>  -o …/build/elf/ld.so.new -L/usr/lib/gcc/x86_64-redhat-linux/11 \
>  -L/usr/lib/gcc/x86_64-redhat-linux/11/../../../../lib64 -L/lib/../lib64 \
>  -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/11/../../.. \
>  -z relro -z defs …/build/elf/librtld.os --version-script=…/build/ld.map \
>  -soname=ld-linux-x86-64.so.2
>
>So it seems that -X or --discard-locals is the default?  How do I
>override that, preferably for specific symbols only?

-X should be irrelevant for .dynsym entries.

-X is not the default for almost all ports, but ld/emultempl/riscvelf.em
has a hack to default to --discard-locals. That was copied by loongarch
[Facepalm]. The proper way is to encode the logic in compiler drivers
(I did this for Clang in https://reviews.llvm.org/D127826).

>>> It would best
>>> if I wouldn't have to bloat the entire symbol table for that.
>>
>> I don't think that you have symbol names without having entries in
>> the symbol table.  Although as you say, if they are local symbols
>> then they will not also take up room in the GNU_HASH table.
>
>Yeah, should have said symbol hash table.  I really want them in .dynsym
>actually.
>
>Thanks,
>Florian
>

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

* Re: Named local symbols in the ELF dynamic symbol table
  2022-12-06 17:11 Named local symbols in the ELF dynamic symbol table Florian Weimer
  2022-12-08 13:19 ` Nick Clifton
@ 2022-12-14 21:44 ` H.J. Lu
  2022-12-14 21:53   ` Florian Weimer
  1 sibling, 1 reply; 7+ messages in thread
From: H.J. Lu @ 2022-12-14 21:44 UTC (permalink / raw)
  To: Florian Weimer; +Cc: binutils

On Tue, Dec 6, 2022 at 9:11 AM Florian Weimer via Binutils
<binutils@sourceware.org> wrote:
>
> The symbol table of /lib/ld-linux-ia64.so.2 starts like this:
>
> Symbol table [ 3] '.dynsym' contains 65 entries:
>  33 local symbols  String table: [ 4] '.dynstr'
>   Num:            Value   Size Type    Bind   Vis          Ndx Name
>     0: 0000000000000000      0 NOTYPE  LOCAL  DEFAULT    UNDEF
>     1: 00000000000318c0    160 FUNC    LOCAL  DEFAULT       10 _dl_error_free
>     2: 00000000000234c0     16 FUNC    LOCAL  DEFAULT       10 __GI__dl_debug_state
>     3: 0000000000029f80    368 FUNC    LOCAL  DEFAULT       10 _dl_tls_get_addr_soft
>     4: 000000000002be00   1728 FUNC    LOCAL  DEFAULT       10 _dl_open
>     5: 0000000000001550     64 FUNC    LOCAL  DEFAULT       10 _start
>     6: 0000000000031540    784 FUNC    LOCAL  DEFAULT       10 _dl_runtime_profile
>     7: 0000000000031440    208 FUNC    LOCAL  DEFAULT       10 _dl_runtime_resolve
>     8: 00000000000312c0    384 FUNC    LOCAL  DEFAULT       10 _dl_close
>     9: 0000000000018240  10720 FUNC    LOCAL  DEFAULT       10 _dl_lookup_symbol_x
>    10: 000000000003ab40     80 FUNC    LOCAL  DEFAULT       10 _rtld_catch_error
>
> The interesting aspect is that these symbols are named, but are not
> covered by the GNU_HASH table (because they are local).
>
> Is there a way to get the same effect on other targets?  I want to
> preserve the names of the functions that IFUNC resolvers return,
> eventually improving diagnostics around IFUNC resolution.  It would best
> if I wouldn't have to bloat the entire symbol table for that.
>

Are you interested in R_X86_64_IRELATIVE symbols or something
else?

-- 
H.J.

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

* Re: Named local symbols in the ELF dynamic symbol table
  2022-12-14 21:44 ` H.J. Lu
@ 2022-12-14 21:53   ` Florian Weimer
  0 siblings, 0 replies; 7+ messages in thread
From: Florian Weimer @ 2022-12-14 21:53 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils

* H. J. Lu:

> On Tue, Dec 6, 2022 at 9:11 AM Florian Weimer via Binutils
> <binutils@sourceware.org> wrote:
>>
>> The symbol table of /lib/ld-linux-ia64.so.2 starts like this:
>>
>> Symbol table [ 3] '.dynsym' contains 65 entries:
>>  33 local symbols  String table: [ 4] '.dynstr'
>>   Num:            Value   Size Type    Bind   Vis          Ndx Name
>>     0: 0000000000000000      0 NOTYPE  LOCAL  DEFAULT    UNDEF
>>     1: 00000000000318c0    160 FUNC    LOCAL  DEFAULT       10 _dl_error_free
>>     2: 00000000000234c0     16 FUNC    LOCAL  DEFAULT       10 __GI__dl_debug_state
>>     3: 0000000000029f80    368 FUNC    LOCAL  DEFAULT       10 _dl_tls_get_addr_soft
>>     4: 000000000002be00   1728 FUNC    LOCAL  DEFAULT       10 _dl_open
>>     5: 0000000000001550     64 FUNC    LOCAL  DEFAULT       10 _start
>>     6: 0000000000031540    784 FUNC    LOCAL  DEFAULT       10 _dl_runtime_profile
>>     7: 0000000000031440    208 FUNC    LOCAL  DEFAULT       10 _dl_runtime_resolve
>>     8: 00000000000312c0    384 FUNC    LOCAL  DEFAULT       10 _dl_close
>>     9: 0000000000018240  10720 FUNC    LOCAL  DEFAULT       10 _dl_lookup_symbol_x
>>    10: 000000000003ab40     80 FUNC    LOCAL  DEFAULT       10 _rtld_catch_error
>>
>> The interesting aspect is that these symbols are named, but are not
>> covered by the GNU_HASH table (because they are local).
>>
>> Is there a way to get the same effect on other targets?  I want to
>> preserve the names of the functions that IFUNC resolvers return,
>> eventually improving diagnostics around IFUNC resolution.  It would best
>> if I wouldn't have to bloat the entire symbol table for that.
>>
>
> Are you interested in R_X86_64_IRELATIVE symbols or something
> else?

Not particularly.  For ld.so --list-diagnostics, I want to iterate
through .dynsym, call all IFUNC resolvers, and report the results (for
libc, libm, libmvec at least).  To make the IFUNC resolver *result* more
meaningful, I want to map back the addresses to symbols like
__memmove_avx_unaligned_erms, but at the same time, I do not want to
make the symbol name __memmove_avx_unaligned_erms available for symbol
binding.  A local symbol in .dynsym would be a good fit here.

We can do this for IRELATIVE relocations, too, but it might be less
beneficial.

Thanks,
Florian


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

end of thread, other threads:[~2022-12-14 21:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-06 17:11 Named local symbols in the ELF dynamic symbol table Florian Weimer
2022-12-08 13:19 ` Nick Clifton
2022-12-09 17:34   ` Florian Weimer
2022-12-14 15:31     ` Nick Clifton
2022-12-14 20:05     ` Fangrui Song
2022-12-14 21:44 ` H.J. Lu
2022-12-14 21:53   ` Florian Weimer

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).