Observations
When the Linux executable is compiled as PIE (Position Independent Executable, default on Ubuntu 18.04), the symbols from shared libraries (e.g. libc) will be resolved when the program starts executing, setting LD_BIND_NOW environment variable to null will not defer this process.
However, if the executable is compiled with the -no-pie
flag, the symbol resolution can be controlled by LD_BIND_NOW.
Question
Is it possible to control when the symbols from share libraries to be resolved on a ELF PIE executable?
Below is the test code and system info,
ubuntu: 18.04
kernel: Linux 4.15.0-50-generic #54-Ubuntu SMP Mon May 6 18:46:08 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
gcc: gcc (Ubuntu 7.4.0-1ubuntu1~18.04) 7.4.0
$ gcc -o helloworld helloworld.c
$ file helloworld
helloworld: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/l, for GNU/Linux 3.2.0, BuildID[sha1]=70143fcc329797b2d0af84143ce0125775ab330f, not stripped
#include <stdio.h>
int main() {
printf("Hello world!\n");
}