From a3a72ad210e1b2d71005ea1ada662b80470dfc45 Mon Sep 17 00:00:00 2001 From: Michael Kerrisk Date: Mon, 16 Jan 2017 09:32:14 +1300 Subject: [PATCH] ld.so.8: LD_BIND_NOT has effect only for function symbols As far as I can tell from testing and a short read of the glibc source code, LD_BIND_NOT has an effect only for function symbols. This is consistent also with the Solaris documentation, which says: When the runtime linker performs a function relocation, it rewrites data associated with the functions .plt so that any subsequent calls will go directly to the function. The environment variable LD_BIND_NOT can be set to any value to prevent this data update. By using this variable together with the debugging request for detailed bindings, you can get a complete runtime account of all function binding. Test case: $ cat prog.c int main(int argc, char *argv[]) { for (;;) { sleep(1); optind = 0; } exit(EXIT_SUCCESS); } $ cc prog.c And then in the run below, in each loop, we see repeated resolutions only for the function symbol, sleep() (and not for optind). $ LD_BIND_NOT=1 LD_DEBUG=symbols,bindings ./a.out ... 30481: transferring control: ./t 30481: 30481: symbol=sleep; lookup in file=./t [0] 30481: symbol=sleep; lookup in file=/lib64/libc.so.6 [0] 30481: binding file ./t [0] to /lib64/libc.so.6 [0]: normal symbol `sleep' [GLIBC_2.2.5] 30481: symbol=sleep; lookup in file=./t [0] 30481: symbol=sleep; lookup in file=/lib64/libc.so.6 [0] 30481: binding file ./t [0] to /lib64/libc.so.6 [0]: normal symbol `sleep' [GLIBC_2.2.5] 30481: symbol=sleep; lookup in file=./t [0] 30481: symbol=sleep; lookup in file=/lib64/libc.so.6 [0] 30481: binding file ./t [0] to /lib64/libc.so.6 [0]: normal symbol `sleep' [GLIBC_2.2.5] 30481: symbol=sleep; lookup in file=./t [0] 30481: symbol=sleep; lookup in file=/lib64/libc.so.6 [0] 30481: binding file ./t [0] to /lib64/libc.so.6 [0]: normal symbol `sleep' [GLIBC_2.2.5] 30481: symbol=sleep; lookup in file=./t [0] 30481: symbol=sleep; lookup in file=/lib64/libc.so.6 [0] 30481: binding file ./t [0] to /lib64/libc.so.6 [0]: normal symbol `sleep' [GLIBC_2.2.5] 30481: symbol=sleep; lookup in file=./t [0] 30481: symbol=sleep; lookup in file=/lib64/libc.so.6 [0] 30481: binding file ./t [0] to /lib64/libc.so.6 [0]: normal symbol `sleep' [GLIBC_2.2.5] Signed-off-by: Michael Kerrisk --- man8/ld.so.8 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man8/ld.so.8 b/man8/ld.so.8 index 6b09b61f6..49c6499e1 100644 --- a/man8/ld.so.8 +++ b/man8/ld.so.8 @@ -354,7 +354,7 @@ in the chapter .BR LD_BIND_NOT " (since glibc 2.1.95)" If this environment variable is set to a nonempty string, do not update the GOT (global offset table) and PLT (procedure linkage table) -after resolving a symbol. +after resolving a function symbol. .TP .BR LD_DEBUG " (since glibc 2.1)" Output verbose debugging information about the dynamic linker.