[PATCH] D42748: [ELF] Don't create a .dynamic section when linking with -Bstatic

Alexander Richardson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 1 05:25:21 PST 2018


arichardson added a comment.

The dynamic symbol table is still included, it's only the PT_DYNAMIC, .dynamic and the _DYNAMIC symbol that are excluded.

I noticed this while testing for MIPS/CHERI but it might also affect other architectures. Looking at the code there are a lot of cases where code checks for `_DYNAMIC == NULL` to determine whether the executable is statically or dynamically linked:
 libc/gen.auxv.c <https://github.com/freebsd/freebsd/blob/master/lib/libc/gen/auxv.c#L64>,  libc/csu/mips/crt1.c <https://github.com/freebsd/freebsd/blob/master/lib/csu/mips/crt1.c#L74> (This one also exists for amd64, i386, riscv, sparc, aarch64, etc, etc), libc/csu/mips/crt1.c <https://github.com/freebsd/freebsd/blob/master/lib/libc/net/nsdispatch.c#L106>

For this case it would be enough to not add the _DYNAMIC symbol, and keep PT_DYNAMIC and .dynamic. What do you need the dynamic section for?
However,  the `file` tool prints "dynamically linked" for all executables that contain a PT_DYNAMIC header <https://github.com/freebsd/freebsd/blob/master/contrib/file/src/readelf.c#L1500> .


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D42748





More information about the llvm-commits mailing list