From b9410061e2ad6fe91bb3910c3adc7d4a315b7ce9 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 16 Apr 2018 20:12:12 -0400 Subject: [PATCH] use explicit dynamic-list rather than symbolic-functions for linking we have always bound symbols at libc.so link time rather than runtime to minimize startup-time relocations and overhead of calls through the PLT, and possibly also to preclude interposition that would not work correctly anyway if allowed. historically, binding at link-time was also necessary for the dynamic linker to work, but the dynamic linker bootstrap overhaul in commit f3ddd173806fd5c60b3f034528ca24542aecc5b9 made it unnecessary. our use of -Bsymbolic-functions, rather than -Bsymbolic, was chosen because the latter is incompatible with public global data; it makes it incompatible with copy relocations in the main program. however, not all global data needs to be public. by using --dynamic-list instead with an explicit list, we can reduce the number of symbolic relocations left for runtime. this change will also allow us to permit interposition of specific functions (e.g. the allocator) if/when we want to, by adding them to the dynamic list. --- configure | 10 ++++++---- dynamic.list | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 dynamic.list diff --git a/configure b/configure index 1e59c461..09a0c436 100755 --- a/configure +++ b/configure @@ -590,10 +590,12 @@ tryldflag LDFLAGS_AUTO -Wl,--no-undefined # versions built without shared library support and pcc are broken. tryldflag LDFLAGS_AUTO -Wl,--exclude-libs=ALL -# Linking with -Bsymbolic-functions is no longer mandatory for -# the dynamic linker to work, but enable it if it works as -# a linking optimization. -tryldflag LDFLAGS_AUTO -Wl,-Bsymbolic-functions +# Public data symbols must be interposable to allow for copy +# relocations, but otherwise we want to bind symbols at libc link +# time to eliminate startup relocations and PLT overhead. Use +# --dynamic-list rather than -Bsymbolic-functions for greater +# control over what symbols are left unbound. +tryldflag LDFLAGS_AUTO -Wl,--dynamic-list="$srcdir/dynamic.list" # Find compiler runtime library test -z "$LIBCC" && tryldflag LIBCC -lgcc && tryldflag LIBCC -lgcc_eh diff --git a/dynamic.list b/dynamic.list new file mode 100644 index 00000000..8b4f2366 --- /dev/null +++ b/dynamic.list @@ -0,0 +1,35 @@ +{ +environ; +__environ; + +stdin; +stdout; +stderr; + +timezone; +daylight; +tzname; +__timezone; +__daylight; +__tzname; + +signgam; +__signgam; + +optarg; +optind; +opterr; +optreset; +__optreset; + +getdate_err; + +h_errno; + +program_invocation_name; +program_invocation_short_name; +__progname; +__progname_full; + +__stack_chk_guard; +}; -- 2.25.1