From 47618209d05a0e77932038f21c6bba2425bd75c6 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Fri, 15 Jan 2021 12:49:24 +0000 Subject: Use hidden visibility for early static PIE code Extern symbol access in position independent code usually involves GOT indirection which needs RELATIVE reloc in a static linked PIE. (On some targets this is avoided e.g. because the linker can relax a GOT access to a pc-relative access, but this is not generally true.) Code that runs before static PIE self relocation must avoid relying on dynamic relocations which can be ensured by using hidden visibility. However we cannot just make all symbols hidden: On i386, all calls to IFUNC functions must go through PLT and calls to hidden functions CANNOT go through PLT in PIE since EBX used in PIE PLT may not be set up for local calls to hidden IFUNC functions. This patch aims to make symbol references hidden in code that is used before and by _dl_relocate_static_pie when building a static PIE libc. Note: for an object that is used in the startup code, its references and definition may not have consistent visibility: it is only forced hidden in the startup code. This is needed for fixing bug 27072. Co-authored-by: H.J. Lu Reviewed-by: Adhemerval Zanella --- csu/libc-start.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'csu') diff --git a/csu/libc-start.c b/csu/libc-start.c index 5b9ce1d158..a2f6e12728 100644 --- a/csu/libc-start.c +++ b/csu/libc-start.c @@ -15,6 +15,10 @@ License along with the GNU C Library; if not, see . */ +/* Mark symbols hidden in static PIE for early self relocation to work. */ +#if BUILD_PIE_DEFAULT +# pragma GCC visibility push(hidden) +#endif #include #include #include -- cgit 1.4.1