From patchwork Wed Nov 11 01:36:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 41014 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9756538438E4; Wed, 11 Nov 2020 01:36:56 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from hera.aquilenet.fr (hera.aquilenet.fr [IPv6:2a0c:e300::1]) by sourceware.org (Postfix) with ESMTPS id 2C7783857000 for ; Wed, 11 Nov 2020 01:36:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2C7783857000 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=samuel.thibault@ens-lyon.org Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 64F19D85; Wed, 11 Nov 2020 02:36:51 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id V16EfJmaPkKr; Wed, 11 Nov 2020 02:36:50 +0100 (CET) Received: from function.youpi.perso.aquilenet.fr (lfbn-bor-1-56-204.w90-50.abo.wanadoo.fr [90.50.148.204]) by hera.aquilenet.fr (Postfix) with ESMTPSA id EC255B97; Wed, 11 Nov 2020 02:36:49 +0100 (CET) Received: from samy by function.youpi.perso.aquilenet.fr with local (Exim 4.94) (envelope-from ) id 1kcf45-000j8l-CR; Wed, 11 Nov 2020 02:36:49 +0100 From: Samuel Thibault To: libc-alpha@sourceware.org Subject: [hurd,commited] hurd: keep only required PLTs in ld.so Date: Wed, 11 Nov 2020 02:36:49 +0100 Message-Id: <20201111013649.173478-1-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: commit-hurd@gnu.org Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" We need NO_RTLD_HIDDEN because of the need for PLT calls in ld.so. See Roland's comment in https://sourceware.org/bugzilla/show_bug.cgi?id=15605 "in the Hurd it's crucial that calls like __mmap be the libc ones instead of the rtld-local ones after the bootstrap phase, when the dynamic linker is being used for dlopen and the like." We used to just avoid all hidden use in the rtld ; this commit switches to keeping only those that should use PLT calls, i.e. essentially those defined in sysdeps/mach/hurd/dl-sysdep.c: __assert_fail __assert_perror_fail __*stat64 _exit This fixes a few startup issues, notably the call to __tunable_get_val that is made before PLTs are set up. --- elf/dl-minimal.c | 4 ++++ include/dirent.h | 2 +- include/libc-internal.h | 2 +- include/libc-symbols.h | 2 +- include/setjmp.h | 2 +- include/signal.h | 2 +- include/stdlib.h | 2 +- include/string.h | 2 +- include/sys/utsname.h | 2 +- include/unistd.h | 2 ++ sysdeps/generic/_itoa.h | 2 +- sysdeps/i386/dl-tlsdesc.S | 4 ---- sysdeps/mach/hurd/_exit.c | 2 ++ sysdeps/mach/hurd/dl-sysdep.c | 4 ++-- sysdeps/mach/hurd/i386/ld.abilist | 1 - sysdeps/mach/hurd/i386/localplt.data | 15 +-------------- sysdeps/x86_64/dl-tlsdesc.S | 4 ---- 17 files changed, 20 insertions(+), 34 deletions(-) diff --git a/elf/dl-minimal.c b/elf/dl-minimal.c index b37abfaff9..1168ac786e 100644 --- a/elf/dl-minimal.c +++ b/elf/dl-minimal.c @@ -292,7 +292,9 @@ Inconsistency detected by ld.so: %s: %u: %s%sAssertion `%s' failed!\n", assertion); } +# ifndef NO_RTLD_HIDDEN rtld_hidden_weak (__assert_fail) +# endif void weak_function __assert_perror_fail (int errnum, @@ -306,7 +308,9 @@ Inconsistency detected by ld.so: %s: %u: %s%sUnexpected error: %s.\n", __strerror_r (errnum, errbuf, sizeof errbuf)); } +# ifndef NO_RTLD_HIDDEN rtld_hidden_weak (__assert_perror_fail) +# endif #endif #undef _itoa diff --git a/include/dirent.h b/include/dirent.h index 8325a19e5f..f1d7e8359c 100644 --- a/include/dirent.h +++ b/include/dirent.h @@ -81,7 +81,7 @@ extern int __scandir64_tail (DIR *dp, libc_hidden_proto (__rewinddir) extern __typeof (scandirat) __scandirat; -# if IS_IN (rtld) && !defined NO_RTLD_HIDDEN +# if IS_IN (rtld) extern __typeof (__rewinddir) __rewinddir attribute_hidden; # endif # endif diff --git a/include/libc-internal.h b/include/libc-internal.h index 729db7918e..915613c030 100644 --- a/include/libc-internal.h +++ b/include/libc-internal.h @@ -43,7 +43,7 @@ extern void __libc_thread_freeres (void); /* Define and initialize `__progname' et. al. */ extern void __init_misc (int, char **, char **) attribute_hidden; -# if IS_IN (rtld) && !defined NO_RTLD_HIDDEN +# if IS_IN (rtld) extern __typeof (__profile_frequency) __profile_frequency attribute_hidden; # endif diff --git a/include/libc-symbols.h b/include/libc-symbols.h index 60153bb50d..b8103b98bb 100644 --- a/include/libc-symbols.h +++ b/include/libc-symbols.h @@ -643,7 +643,7 @@ for linking") # define libc_hidden_data_ver(local, name) #endif -#if IS_IN (rtld) && !defined NO_RTLD_HIDDEN +#if IS_IN (rtld) # define rtld_hidden_proto(name, attrs...) hidden_proto (name, ##attrs) # define rtld_hidden_tls_proto(name, attrs...) hidden_tls_proto (name, ##attrs) # define rtld_hidden_def(name) hidden_def (name) diff --git a/include/setjmp.h b/include/setjmp.h index e13017edd2..0a8e4d2eaf 100644 --- a/include/setjmp.h +++ b/include/setjmp.h @@ -27,7 +27,7 @@ extern void __libc_longjmp (sigjmp_buf env, int val) libc_hidden_proto (_setjmp) libc_hidden_proto (__sigsetjmp) -# if IS_IN (rtld) && !defined NO_RTLD_HIDDEN +# if IS_IN (rtld) extern __typeof (__sigsetjmp) __sigsetjmp attribute_hidden; # endif diff --git a/include/signal.h b/include/signal.h index 544d701bce..2a278697c1 100644 --- a/include/signal.h +++ b/include/signal.h @@ -67,7 +67,7 @@ extern int __xpg_sigpause (int sig); /* Allocate real-time signal with highest/lowest available priority. */ extern int __libc_allocate_rtsig (int __high); -# if IS_IN (rtld) && !defined NO_RTLD_HIDDEN +# if IS_IN (rtld) extern __typeof (__sigaction) __sigaction attribute_hidden; extern __typeof (__libc_sigaction) __libc_sigaction attribute_hidden; # endif diff --git a/include/stdlib.h b/include/stdlib.h index ffcefd7b85..cdbdbf310d 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -310,7 +310,7 @@ struct abort_msg_s extern struct abort_msg_s *__abort_msg; libc_hidden_proto (__abort_msg) -# if IS_IN (rtld) && !defined NO_RTLD_HIDDEN +# if IS_IN (rtld) extern __typeof (unsetenv) unsetenv attribute_hidden; extern __typeof (__strtoul_internal) __strtoul_internal attribute_hidden; # endif diff --git a/include/string.h b/include/string.h index f4ce138622..7d344d77d4 100644 --- a/include/string.h +++ b/include/string.h @@ -150,7 +150,7 @@ libc_hidden_builtin_proto (strspn) libc_hidden_builtin_proto (strstr) libc_hidden_builtin_proto (ffs) -#if IS_IN (rtld) && !defined NO_RTLD_HIDDEN +#if IS_IN (rtld) extern __typeof (__stpcpy) __stpcpy attribute_hidden; extern __typeof (__strdup) __strdup attribute_hidden; extern __typeof (__strerror_r) __strerror_r attribute_hidden; diff --git a/include/sys/utsname.h b/include/sys/utsname.h index 9ed5fa2565..14f4247dd4 100644 --- a/include/sys/utsname.h +++ b/include/sys/utsname.h @@ -7,7 +7,7 @@ extern int __uname (struct utsname *__name); libc_hidden_proto (uname) libc_hidden_proto (__uname) -# if IS_IN (rtld) && !defined NO_RTLD_HIDDEN +# if IS_IN (rtld) extern __typeof (__uname) __uname attribute_hidden; # endif #endif diff --git a/include/unistd.h b/include/unistd.h index f48da2c7a3..54becbc9eb 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -4,7 +4,9 @@ # ifndef _ISOMAC libc_hidden_proto (_exit, __noreturn__) +# ifndef NO_RTLD_HIDDEN rtld_hidden_proto (_exit, __noreturn__) +# endif libc_hidden_proto (alarm) extern size_t __confstr (int name, char *buf, size_t len); libc_hidden_proto (__confstr) diff --git a/sysdeps/generic/_itoa.h b/sysdeps/generic/_itoa.h index 790f88a6d5..ef4de3af1b 100644 --- a/sysdeps/generic/_itoa.h +++ b/sysdeps/generic/_itoa.h @@ -46,7 +46,7 @@ extern char *_itoa (unsigned long long int value, char *buflim, extern const char _itoa_upper_digits[]; extern const char _itoa_lower_digits[]; -#if IS_IN (libc) || (IS_IN (rtld) && !defined NO_RTLD_HIDDEN) +#if IS_IN (libc) || IS_IN (rtld) hidden_proto (_itoa_upper_digits) hidden_proto (_itoa_lower_digits) #endif diff --git a/sysdeps/i386/dl-tlsdesc.S b/sysdeps/i386/dl-tlsdesc.S index 32383e3bad..6d57739515 100644 --- a/sysdeps/i386/dl-tlsdesc.S +++ b/sysdeps/i386/dl-tlsdesc.S @@ -129,11 +129,7 @@ _dl_tlsdesc_dynamic: .p2align 4,,7 .Lslow: cfi_adjust_cfa_offset (28) -#ifdef NO_RTLD_HIDDEN - call JUMPTARGET (___tls_get_addr) -#else call HIDDEN_JUMPTARGET (___tls_get_addr) -#endif jmp .Lret cfi_endproc .size _dl_tlsdesc_dynamic, .-_dl_tlsdesc_dynamic diff --git a/sysdeps/mach/hurd/_exit.c b/sysdeps/mach/hurd/_exit.c index 46db06db63..f04c5d2acf 100644 --- a/sysdeps/mach/hurd/_exit.c +++ b/sysdeps/mach/hurd/_exit.c @@ -51,5 +51,7 @@ _exit (int status) _hurd_exit (W_EXITCODE (status, 0)); } libc_hidden_def (_exit) +#ifndef NO_RTLD_HIDDEN rtld_hidden_def (_exit) +#endif weak_alias (_exit, _Exit) diff --git a/sysdeps/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c index 5c0bb3124d..6b32d41c76 100644 --- a/sysdeps/mach/hurd/dl-sysdep.c +++ b/sysdeps/mach/hurd/dl-sysdep.c @@ -641,7 +641,8 @@ __sbrk (intptr_t increment) return (void *) addr; } -check_no_hidden(__strtoul_internal); +/* This is only used by hurdlookup for the /dev/fd/nnn magic. + * We avoid pulling the whole libc implementation, and we can keep this hidden. */ unsigned long int weak_function __strtoul_internal (const char *nptr, char **endptr, int base, int group) { @@ -698,7 +699,6 @@ abort (void) /* We need this alias to satisfy references from libc_pic.a objects that were affected by the libc_hidden_proto declaration for abort. */ strong_alias (abort, __GI_abort) -strong_alias (abort, __GI___chk_fail) strong_alias (abort, __GI___fortify_fail) strong_alias (abort, __GI___assert_fail) strong_alias (abort, __GI___assert_perror_fail) diff --git a/sysdeps/mach/hurd/i386/ld.abilist b/sysdeps/mach/hurd/i386/ld.abilist index 2e9bf2811f..0eaea9f66d 100644 --- a/sysdeps/mach/hurd/i386/ld.abilist +++ b/sysdeps/mach/hurd/i386/ld.abilist @@ -9,7 +9,6 @@ GLIBC_2.2.6 __open64 F GLIBC_2.2.6 __pread64 F GLIBC_2.2.6 __read F GLIBC_2.2.6 __sbrk F -GLIBC_2.2.6 __strtoul_internal F GLIBC_2.2.6 __write F GLIBC_2.2.6 __writev F GLIBC_2.2.6 __xstat64 F diff --git a/sysdeps/mach/hurd/i386/localplt.data b/sysdeps/mach/hurd/i386/localplt.data index b199e14e7f..abd8f31fac 100644 --- a/sysdeps/mach/hurd/i386/localplt.data +++ b/sysdeps/mach/hurd/i386/localplt.data @@ -37,24 +37,11 @@ ld.so: __access_noerrno ld.so: __getpid ld.so: __getcwd ld.so: __sbrk -ld.so: __strtoul_internal -#ld.so: _exit +ld.so: _exit ? ld.so: abort ld.so: _hurd_intr_rpc_mach_msg ld.so: __errno_location -# rtld_hidden is currently disabled to avoid having to special-case the -# functions above which do need a PLT. These are thus currently expected. -ld.so: _dl_allocate_tls -ld.so: _dl_allocate_tls_init -ld.so: _dl_exception_create -ld.so: _dl_exception_create_format -ld.so: _dl_exception_free -ld.so: _dl_fatal_printf -ld.so: _dl_find_dso_for_object ld.so: _dl_init_first -ld.so: _dl_mcount -ld.so: ___tls_get_addr -ld.so: __tunable_get_val # # These should ideally be avoided, but is currently difficult libc.so: siglongjmp ? diff --git a/sysdeps/x86_64/dl-tlsdesc.S b/sysdeps/x86_64/dl-tlsdesc.S index 512a704fac..2535c88946 100644 --- a/sysdeps/x86_64/dl-tlsdesc.S +++ b/sysdeps/x86_64/dl-tlsdesc.S @@ -131,11 +131,7 @@ _dl_tlsdesc_dynamic: movq %r10, 40(%rsp) movq %r11, 48(%rsp) /* %rdi already points to the tlsinfo data structure. */ -#ifdef NO_RTLD_HIDDEN - call JUMPTARGET (__tls_get_addr) -#else call HIDDEN_JUMPTARGET (__tls_get_addr) -#endif movq 8(%rsp), %rdx movq 16(%rsp), %rcx movq 24(%rsp), %r8