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

Konstantin Belousov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 23 05:15:31 PDT 2019


kib added a comment.

In D42748#1513202 <https://reviews.llvm.org/D42748#1513202>, @MaskRay wrote:

> >> 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?


No, it is not.  PT_INTERP requires the program (csu) to find out the aux vector, parse it to find the binary base, and then parse ELF header and program headers.  All this while the binary itself is not relocated. This is significant blow of the crt, and added complexity, which also means that every binary (not only static) now carry a code which we cannot fix because it is statically linked even into dynamic binaries.

Also, as I noted above, PT_INTERP absence does not really mean that the binary is static.


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