[PATCH] D42748: [ELF] Don't create a .dynamic section when linking with -Bstatic
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 23 01:20:03 PDT 2019
MaskRay added a comment.
>> And if you decide to support static pie, you also need _DYNAMIC.
>
> Are you sure about this ? For static PIE, as I understand, we miss some kind of relocator in csu.
On the linker side, static pie is `-static -pie --no-dynamic-linker`. The `-pie` causes lld to create dynamic sections.
void
_start(char **ap, void (*cleanup)(void))
{
int argc;
char **argv;
char **env;
argc = *(long *)(void *)ap;
argv = ap + 1;
env = ap + 2 + argc;
handle_argv(argc, argv, env);
if (&_DYNAMIC != NULL) {
atexit(cleanup);
} else {
process_irelocs();
_init_tls();
}
If FreeBSD used to differentiate dynamically/statically linked programs with `&_DYNAMIC != NULL`, I think it is probably time to revisit.
We have two ways to have dynamic sections in a statically linked program, `--export-dynamic` (https://reviews.llvm.org/rL295240) or `-pie` (static pie). If the distinction of dynamic/static is whether the program is interpreted by PT_INTERP, isn't testing this property directly more straightforward?
> However, I'm pretty sure I saw some application level code use the check to determine if they are dynamically linked.
I think that is extremely rare, but they should also be updated to make static pie work.
> Also I just had a look in llvm-project.git and it seems that compiler-rt/lib/sanitizer_common/sanitizer_linux.cc uses the following: level = &_DYNAMIC == nullptr ? AndroidDetectApiLevelStatic(). I think this may be a common way of checking for the presence of a dynamic linker so emitting it for static binaries could be problematic.
It is used by `AndroidDetectApiLevelStatic()`. If Android ever supports static pie, that piece of code has to change.
Repository:
rLLD LLVM Linker
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D42748/new/
https://reviews.llvm.org/D42748
More information about the llvm-commits
mailing list