Named local symbols in the ELF dynamic symbol table

Florian Weimer fweimer@redhat.com
Fri Dec 9 17:34:47 GMT 2022


* 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



More information about the Binutils mailing list