From patchwork Thu Sep 5 20:56:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1158679 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-105063-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="KI7XIpsa"; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="PV5l0yWt"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46PXzr3G6wz9s00 for ; Fri, 6 Sep 2019 06:56:39 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; q=dns; s= default; b=Dl9PvW25WP36Wm+hmwYu5rRBmf9TE4XNEwQLMQD/NaaebUyuO4dDz seAPVloRNgJVwH/tTSdQln+vymtnpPm9Gq+J4EjxKSCqFP82Ws5ev1j8z3KhI+Cs UCmclFjeeWwUgIipi/RzC5ySvhPsEF/u8GJQRsmMeJjMGdaQwdzRTk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; s=default; bh=oRZJBGn6yZx6+gkyIl+/PRahUbY=; b=KI7XIpsaVR++HoohsJa8Zf0vNIJZ R9SrjjJ5vnAAdCfr16eecPE7/LYAI6kdTpkabnxjkNKGVtnwzNmQcEsQp5Dm+BVP jHoHd9cF5Y4B1Q+7UV9gCzDRttb2hy8waRj8nfIZl0L1m4hB1fDTkSJkuUY7gt23 ZoGx9RlNqT4EHc8= Received: (qmail 116523 invoked by alias); 5 Sep 2019 20:56:32 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 116513 invoked by uid 89); 5 Sep 2019 20:56:32 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=H*MI:4646, HX-Spam-Relays-External:209.85.222.194, H*RU:209.85.222.194 X-HELO: mail-qk1-f194.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id; bh=8uQvuZYeByzIBKvmR1ODMtf8YKFI8Ns4Sq2oLvKwtEI=; b=PV5l0yWtz0I7bk/LIiV1INFQ3yuVAm3u4uOzSoSogu22VwkrA/525F/uzmXUihLe/w gnRllBn47AsvATrp/7gX/ysI2LZXnUbDvdzlgpDOtJD66/Kik7NEk1NoIAljK+3C3W8q 1nQRkmM/9Y+DYHmT3Pd7vLQt9NEE19gARmafAdUGmLWRym2P2Db/VDyWTC1XL/hQuBqT d0ofEk3pp3uGKP7m6hW+3Tzwm3hh7MC0ozn7OF62kOGf0yRXc8HNhismViCAYvsVyd8p CyEOcW9TzhUrK2R5ZDhvz7ie/6F/AcqkXLMpdubzmNyNwA6sYG8mnZ5qBff8j5vMVTu+ NzNQ== From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 1/8] Remove PREPARE_VERSION and PREPARE_VERSION_KNOW Date: Thu, 5 Sep 2019 17:56:13 -0300 Message-Id: <20190905205620.4646-1-adhemerval.zanella@linaro.org> Changes from previous version: - Remove trailing whitespaces. --- This patch removes the PREPARE_VERSION and PREPARE_VERSION_KNOW macro and uses a static inline function instead, get_vdso_symbol. Each architecture that supports vDSO must define the Linux version and its hash for symbol resolution (VDSO_NAME and VDSO_HASH macro respectively). It also organizes the HAVE_*_VSYSCALL for mips, powerpc, and s390 to set them on a common header. The idea is to require less code to configure and enable vDSO support for newer ports. No semantic changes are expected. Checked with a build against all affected architectures. * sysdeps/unix/make-syscalls.sh: Make vDSO call use get_vdso_symbol. * sysdeps/unix/sysv/linux/aarch64/gettimeofday.c (__gettimeofday): Use get_vdso_symbol instead of _dl_vdso_vsym. * sysdeps/unix/sysv/linux/powerpc/time.c (time): Likewise. * sysdeps/unix/sysv/linux/riscv/flush-icache.c (__lookup_riscv_flush_icache): Likewise. * sysdeps/unix/sysv/linux/x86/gettimeofday.c (__gettimeofday): Likewise. * sysdeps/unix/sysv/linux/x86/time.c (time): Likewise. * sysdeps/unix/sysv/linux/powerpc/gettimeofday.c: Likewise. * sysdeps/unix/sysv/linux/aarch64/init-first.c: Likewise. * sysdeps/unix/sysv/linux/arm/init-first.c: Likewise. * sysdeps/unix/sysv/linux/i386/init-first.c: Likewise. * sysdeps/unix/sysv/linux/mips/init-first.c: Likewise. * sysdeps/unix/sysv/linux/powerpc/init-first.c: Likewise. * sysdeps/unix/sysv/linux/riscv/init-first.c: Likewise. * sysdeps/unix/sysv/linux/sparc/init-first.c: Likewise. * sysdeps/unix/sysv/linux/s390/init-first.c: Likewise. * sysdeps/unix/sysv/linux/x86_64/init-first.c: Likewise. * sysdeps/unix/sysv/linux/aarch64/sysdep.h (VDSO_NAME, VDSO_HASH): Define. * sysdeps/unix/sysv/linux/arm/sysdep.h (VDSO_NAME, VDSO_HASH): Likewise. * sysdeps/unix/sysv/linux/i386/sysdep.h (VDSO_NAME, VDSO_HASH): Likewise. * sysdeps/unix/sysv/linux/riscv/sysdep.h (VDSO_NAME, VDSO_HASH): Likewise. * sysdeps/unix/sysv/linux/sparc/sysdep.h (VDSO_NAME, VDSO_HASH): Likewise. * sysdeps/unix/sysv/linux/x86_64/sysdep.h (VDSO_NAME, VDSO_HASH): Likewise. * sysdeps/unix/sysv/linux/mips/mips32/sysdep.h (HAVE_CLOCK_GETTIME_VSYSCALL, HAVE_GETTIMEOFDAY_VSYSCALL): Remove definition. * sysdeps/unix/sysv/linux/mips/mips64/n32/sysdep.h (HAVE_CLOCK_GETTIME_VSYSCALL, HAVE_GETTIMEOFDAY_VSYSCALL): Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n64/sysdep.h (HAVE_CLOCK_GETTIME_VSYSCALL, HAVE_GETTIMEOFDAY_VSYSCALL): Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h (HAVE_CLOCK_GETTIME_VSYSCALL, HAVE_GETTIMEOFDAY_VSYSCALL): Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h (HAVE_CLOCK_GETTIME_VSYSCALL, HAVE_GETTIMEOFDAY_VSYSCALL): Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h (HAVE_CLOCK_GETRES_VSYSCALL, HAVE_CLOCK_GETTIME_VSYSCALL, HAVE_GETTIMEOFDAY_VSYSCALL, HAVE_GETCPU_VSYSCALL): Likewise. * sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h (HAVE_CLOCK_GETRES_VSYSCALL, HAVE_CLOCK_GETTIME_VSYSCALL, HAVE_GETTIMEOFDAY_VSYSCALL, HAVE_GETCPU_VSYSCALL): Likewise. * sysdeps/unix/sysv/linux/mips/sysdep.h: New file. * sysdeps/unix/sysv/linux/powerpc/sysdep.h: Likewise. * sysdeps/unix/sysv/linux/s390/sysdep.h: Likewise. * sysdeps/unix/sysv/linux/dl-vdso.h (PREPARE_VERSION, PREPARE_VERSION_KNOWN, VDSO_NAME_LINUX_2_6, VDSO_HASH_LINUX_2_6, VDSO_NAME_LINUX_2_6_15, VDSO_HASH_LINUX_2_6_15, VDSO_NAME_LINUX_2_6_29, VDSO_HASH_LINUX_2_6_29, VDSO_NAME_LINUX_4_15, VDSO_HASH_LINUX_4_15): Remove defines. (get_vdso_symbol): New function. --- sysdeps/unix/make-syscalls.sh | 5 +-- .../unix/sysv/linux/aarch64/gettimeofday.c | 27 ++++--------- sysdeps/unix/sysv/linux/aarch64/init-first.c | 12 ++---- sysdeps/unix/sysv/linux/aarch64/sysdep.h | 7 ++++ sysdeps/unix/sysv/linux/arm/init-first.c | 6 +-- sysdeps/unix/sysv/linux/arm/sysdep.h | 3 ++ sysdeps/unix/sysv/linux/dl-vdso.h | 38 ++++--------------- sysdeps/unix/sysv/linux/i386/init-first.c | 4 +- sysdeps/unix/sysv/linux/i386/sysdep.h | 3 ++ sysdeps/unix/sysv/linux/mips/init-first.c | 6 +-- sysdeps/unix/sysv/linux/mips/mips32/sysdep.h | 5 +-- .../unix/sysv/linux/mips/mips64/n32/sysdep.h | 5 +-- .../unix/sysv/linux/mips/mips64/n64/sysdep.h | 5 +-- sysdeps/unix/sysv/linux/mips/sysdep.h | 24 ++++++++++++ .../unix/sysv/linux/powerpc/gettimeofday.c | 7 ++-- sysdeps/unix/sysv/linux/powerpc/init-first.c | 22 +++++------ .../sysv/linux/powerpc/powerpc32/sysdep.h | 7 +--- .../sysv/linux/powerpc/powerpc64/sysdep.h | 6 +-- sysdeps/unix/sysv/linux/powerpc/sysdep.h | 26 +++++++++++++ sysdeps/unix/sysv/linux/powerpc/time.c | 5 +-- sysdeps/unix/sysv/linux/riscv/flush-icache.c | 4 +- sysdeps/unix/sysv/linux/riscv/init-first.c | 10 ++--- sysdeps/unix/sysv/linux/riscv/sysdep.h | 3 ++ sysdeps/unix/sysv/linux/s390/init-first.c | 10 ++--- sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h | 7 +--- sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h | 7 +--- sysdeps/unix/sysv/linux/s390/sysdep.h | 27 +++++++++++++ sysdeps/unix/sysv/linux/sparc/init-first.c | 6 +-- sysdeps/unix/sysv/linux/sparc/sysdep.h | 3 ++ sysdeps/unix/sysv/linux/x86/gettimeofday.c | 10 +++-- sysdeps/unix/sysv/linux/x86/time.c | 7 ++-- sysdeps/unix/sysv/linux/x86_64/init-first.c | 6 +-- sysdeps/unix/sysv/linux/x86_64/sysdep.h | 3 ++ 33 files changed, 168 insertions(+), 158 deletions(-) create mode 100644 sysdeps/unix/sysv/linux/mips/sysdep.h create mode 100644 sysdeps/unix/sysv/linux/powerpc/sysdep.h create mode 100644 sysdeps/unix/sysv/linux/s390/sysdep.h diff --git a/sysdeps/unix/make-syscalls.sh b/sysdeps/unix/make-syscalls.sh index 6a5c10d54e..b49e6b6305 100644 --- a/sysdeps/unix/make-syscalls.sh +++ b/sysdeps/unix/make-syscalls.sh @@ -283,10 +283,9 @@ while read file srcfile caller syscall args strong weak; do (echo '#define ${strong} __redirect_${strong}'; \\ echo '#include '; \\ echo '#undef ${strong}'; \\ - echo '#define vdso_ifunc_init() \\'; \\ - echo ' PREPARE_VERSION_KNOWN (symver, ${vdso_symver})'; \\ + echo '#define vdso_ifunc_init()'; \\ echo '__ifunc (__redirect_${strong}, ${strong},'; \\ - echo ' _dl_vdso_vsym ("${vdso_symbol}", &symver), void,'; \\ + echo ' get_vdso_symbol ("${vdso_symbol}"), void,'; \\ echo ' vdso_ifunc_init)'; \\ EOF # This is doing "hidden_def (${strong})", but the compiler diff --git a/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c b/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c index 9180b50bf7..9499a11fda 100644 --- a/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c +++ b/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c @@ -20,12 +20,10 @@ putting it into *tv and *tz. If tz is null, *tz is not filled. Returns 0 on success, -1 on errors. */ +#include + #ifdef SHARED -# define __gettimeofday __redirect___gettimeofday -# include -# undef __gettimeofday -# define HAVE_VSYSCALL # include # include @@ -38,25 +36,14 @@ __gettimeofday_vsyscall (struct timeval *tv, struct timezone *tz) return INLINE_VSYSCALL (gettimeofday, 2, tv, tz); } -/* PREPARE_VERSION_KNOWN will need an __LP64__ ifdef when ILP32 support - goes in. See _libc_vdso_platform_setup in - sysdeps/unix/sysv/linux/aarch64/init-first.c. */ - -# undef INIT_ARCH -# define INIT_ARCH() \ - PREPARE_VERSION_KNOWN (linux_version, LINUX_2_6_39); \ - void *vdso_gettimeofday = \ - _dl_vdso_vsym ("__kernel_gettimeofday", &linux_version); - -libc_ifunc_hidden (__redirect___gettimeofday, __gettimeofday, - vdso_gettimeofday ?: (void *) __gettimeofday_vsyscall) - -__hidden_ver1 (__gettimeofday_vsyscall, __GI___gettimeofday, - __gettimeofday_vsyscall); +# define INIT_ARCH() +libc_ifunc_hidden (__gettimeofday, __gettimeofday, + (get_vdso_symbol ("__vdso_gettimeofday") + ?: __gettimeofday_vsyscall)) +libc_hidden_def (__gettimeofday) #else -# include # include int __gettimeofday (struct timeval *tv, struct timezone *tz) diff --git a/sysdeps/unix/sysv/linux/aarch64/init-first.c b/sysdeps/unix/sysv/linux/aarch64/init-first.c index 80f7ed91ef..c3c27cfd4b 100644 --- a/sysdeps/unix/sysv/linux/aarch64/init-first.c +++ b/sysdeps/unix/sysv/linux/aarch64/init-first.c @@ -26,21 +26,15 @@ int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct timespec *); static inline void _libc_vdso_platform_setup (void) { -#ifdef __LP64__ - PREPARE_VERSION_KNOWN (linux_version, LINUX_2_6_39); -#else - PREPARE_VERSION_KNOWN (linux_version, LINUX_4_9); -#endif - - void *p = _dl_vdso_vsym ("__kernel_gettimeofday", &linux_version); + void *p = get_vdso_symbol ("__kernel_gettimeofday"); PTR_MANGLE (p); VDSO_SYMBOL(gettimeofday) = p; - p = _dl_vdso_vsym ("__kernel_clock_gettime", &linux_version); + p = get_vdso_symbol ("__kernel_clock_gettime"); PTR_MANGLE (p); VDSO_SYMBOL(clock_gettime) = p; - p = _dl_vdso_vsym ("__kernel_clock_getres", &linux_version); + p = get_vdso_symbol ("__kernel_clock_getres"); PTR_MANGLE (p); VDSO_SYMBOL(clock_getres) = p; } diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep.h b/sysdeps/unix/sysv/linux/aarch64/sysdep.h index a2f4061b58..662d321235 100644 --- a/sysdeps/unix/sysv/linux/aarch64/sysdep.h +++ b/sysdeps/unix/sysv/linux/aarch64/sysdep.h @@ -151,6 +151,13 @@ #else /* not __ASSEMBLER__ */ +# ifdef __LP64__ +# define VDSO_NAME "LINUX_2_6_39" +# define VDSO_HASH 123718537 +# else +# define VDSO_NAME "LINUX_4.9" +# define VDSO_HASH 61765625 +# endif /* List of system calls which are supported as vsyscalls. */ # define HAVE_CLOCK_GETRES_VSYSCALL 1 diff --git a/sysdeps/unix/sysv/linux/arm/init-first.c b/sysdeps/unix/sysv/linux/arm/init-first.c index e1846df661..2852ab135c 100644 --- a/sysdeps/unix/sysv/linux/arm/init-first.c +++ b/sysdeps/unix/sysv/linux/arm/init-first.c @@ -27,13 +27,11 @@ int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *); static inline void _libc_vdso_platform_setup (void) { - PREPARE_VERSION_KNOWN (linux26, LINUX_2_6); - - void *p = _dl_vdso_vsym ("__vdso_gettimeofday", &linux26); + void *p = get_vdso_symbol ("__vdso_gettimeofday"); PTR_MANGLE (p); VDSO_SYMBOL (gettimeofday) = p; - p = _dl_vdso_vsym ("__vdso_clock_gettime", &linux26); + p = get_vdso_symbol ("__vdso_clock_gettime"); PTR_MANGLE (p); VDSO_SYMBOL (clock_gettime) = p; } diff --git a/sysdeps/unix/sysv/linux/arm/sysdep.h b/sysdeps/unix/sysv/linux/arm/sysdep.h index 6d8d9a47f9..467ccf2631 100644 --- a/sysdeps/unix/sysv/linux/arm/sysdep.h +++ b/sysdeps/unix/sysv/linux/arm/sysdep.h @@ -388,6 +388,9 @@ __local_syscall_error: \ #undef INTERNAL_SYSCALL_ERRNO #define INTERNAL_SYSCALL_ERRNO(val, err) (-(val)) +#define VDSO_NAME "LINUX_2_6" +#define VDSO_HASH 61765110 + /* List of system calls which are supported as vsyscalls. */ #define HAVE_CLOCK_GETTIME_VSYSCALL 1 #define HAVE_GETTIMEOFDAY_VSYSCALL 1 diff --git a/sysdeps/unix/sysv/linux/dl-vdso.h b/sysdeps/unix/sysv/linux/dl-vdso.h index d83afe130e..bab3779615 100644 --- a/sysdeps/unix/sysv/linux/dl-vdso.h +++ b/sysdeps/unix/sysv/linux/dl-vdso.h @@ -22,40 +22,18 @@ #include #include #include - -/* Create version number record for lookup. */ -static inline struct r_found_version -prepare_version_base (const char *name, ElfW(Word) hash) -{ - assert (hash == _dl_elf_hash (name)); - return (struct r_found_version) { name, hash, 1, NULL }; -} -#define prepare_version(vname) \ - prepare_version_base (VDSO_NAME_##vname, VDSO_HASH_##vname) - -/* Use this for the known version sets defined below, where we - record their precomputed hash values only once, in this file. */ -#define PREPARE_VERSION_KNOWN(var, vname) \ - struct r_found_version var = prepare_version (vname); - -#define VDSO_NAME_LINUX_2_6 "LINUX_2.6" -#define VDSO_HASH_LINUX_2_6 61765110 -#define VDSO_NAME_LINUX_2_6_15 "LINUX_2.6.15" -#define VDSO_HASH_LINUX_2_6_15 123718565 -#define VDSO_NAME_LINUX_2_6_29 "LINUX_2.6.29" -#define VDSO_HASH_LINUX_2_6_29 123718585 -#define VDSO_NAME_LINUX_2_6_39 "LINUX_2.6.39" -#define VDSO_HASH_LINUX_2_6_39 123718537 -#define VDSO_NAME_LINUX_4 "LINUX_4" -#define VDSO_HASH_LINUX_4 14921332 -#define VDSO_NAME_LINUX_4_9 "LINUX_4.9" -#define VDSO_HASH_LINUX_4_9 61765625 -#define VDSO_NAME_LINUX_4_15 "LINUX_4.15" -#define VDSO_HASH_LINUX_4_15 182943605 +#include /* Functions for resolving symbols in the VDSO link map. */ extern void *_dl_vdso_vsym (const char *name, const struct r_found_version *version) attribute_hidden; +static inline void * +get_vdso_symbol (const char *symbol) +{ + struct r_found_version rfv = { VDSO_NAME, VDSO_HASH, 1, NULL }; + return _dl_vdso_vsym (symbol, &rfv); +} + #endif /* dl-vdso.h */ diff --git a/sysdeps/unix/sysv/linux/i386/init-first.c b/sysdeps/unix/sysv/linux/i386/init-first.c index 60d69777cd..9c03f87b67 100644 --- a/sysdeps/unix/sysv/linux/i386/init-first.c +++ b/sysdeps/unix/sysv/linux/i386/init-first.c @@ -34,9 +34,7 @@ clock_gettime_syscall (clockid_t id, struct timespec *tp) static inline void __vdso_platform_setup (void) { - PREPARE_VERSION_KNOWN (linux26, LINUX_2_6); - - void *p = _dl_vdso_vsym ("__vdso_clock_gettime", &linux26); + void *p = get_vdso_symbol ("__vdso_clock_gettime"); if (p == NULL) p = clock_gettime_syscall; PTR_MANGLE (p); diff --git a/sysdeps/unix/sysv/linux/i386/sysdep.h b/sysdeps/unix/sysv/linux/i386/sysdep.h index 77154b904a..278028f52e 100644 --- a/sysdeps/unix/sysv/linux/i386/sysdep.h +++ b/sysdeps/unix/sysv/linux/i386/sysdep.h @@ -309,6 +309,9 @@ struct libc_do_syscall_args #define INLINE_SYSCALL_ERROR_RETURN_VALUE(resultvar) \ __syscall_error (-(resultvar)) +# define VDSO_NAME "LINUX_2.6" +# define VDSO_HASH 61765110 + /* List of system calls which are supported as vsyscalls. */ # define HAVE_CLOCK_GETTIME_VSYSCALL 1 # define HAVE_GETTIMEOFDAY_VSYSCALL 1 diff --git a/sysdeps/unix/sysv/linux/mips/init-first.c b/sysdeps/unix/sysv/linux/mips/init-first.c index 25884ffd80..2a43bdc8b0 100644 --- a/sysdeps/unix/sysv/linux/mips/init-first.c +++ b/sysdeps/unix/sysv/linux/mips/init-first.c @@ -26,13 +26,11 @@ int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *); static inline void _libc_vdso_platform_setup (void) { - PREPARE_VERSION_KNOWN (linux26, LINUX_2_6); - - void *p = _dl_vdso_vsym ("__vdso_gettimeofday", &linux26); + void *p = get_vdso_symbol ("__vdso_gettimeofday"); PTR_MANGLE (p); VDSO_SYMBOL (gettimeofday) = p; - p = _dl_vdso_vsym ("__vdso_clock_gettime", &linux26); + p = get_vdso_symbol ("__vdso_clock_gettime"); PTR_MANGLE (p); VDSO_SYMBOL (clock_gettime) = p; } diff --git a/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h b/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h index a310a0acbc..ebe397b701 100644 --- a/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h +++ b/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h @@ -19,6 +19,7 @@ #define _LINUX_MIPS_MIPS32_SYSDEP_H 1 /* There is some commonality. */ +#include #include #include @@ -360,10 +361,6 @@ libc_hidden_proto (__mips_syscall7, nomips16) _ret; \ }) -/* List of system calls which are supported as vsyscalls. */ -#define HAVE_CLOCK_GETTIME_VSYSCALL 1 -#define HAVE_GETTIMEOFDAY_VSYSCALL 1 - #endif /* __ASSEMBLER__ */ /* Pointer mangling is not yet supported for MIPS. */ diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/sysdep.h b/sysdeps/unix/sysv/linux/mips/mips64/n32/sysdep.h index d83e08f96a..bb49429c30 100644 --- a/sysdeps/unix/sysv/linux/mips/mips64/n32/sysdep.h +++ b/sysdeps/unix/sysv/linux/mips/mips64/n32/sysdep.h @@ -19,6 +19,7 @@ #define _LINUX_MIPS_SYSDEP_H 1 /* There is some commonality. */ +#include #include #include @@ -308,10 +309,6 @@ _ret; \ }) -/* List of system calls which are supported as vsyscalls. */ -#define HAVE_CLOCK_GETTIME_VSYSCALL 1 -#define HAVE_GETTIMEOFDAY_VSYSCALL 1 - #endif /* __ASSEMBLER__ */ /* Pointer mangling is not yet supported for MIPS. */ diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n64/sysdep.h b/sysdeps/unix/sysv/linux/mips/mips64/n64/sysdep.h index bcfaf561a1..84a1ff186b 100644 --- a/sysdeps/unix/sysv/linux/mips/mips64/n64/sysdep.h +++ b/sysdeps/unix/sysv/linux/mips/mips64/n64/sysdep.h @@ -19,6 +19,7 @@ #define _LINUX_MIPS_SYSDEP_H 1 /* There is some commonality. */ +#include #include #include @@ -304,10 +305,6 @@ _ret; \ }) -/* List of system calls which are supported as vsyscalls. */ -#define HAVE_CLOCK_GETTIME_VSYSCALL 1 -#define HAVE_GETTIMEOFDAY_VSYSCALL 1 - #endif /* __ASSEMBLER__ */ /* Pointer mangling is not yet supported for MIPS. */ diff --git a/sysdeps/unix/sysv/linux/mips/sysdep.h b/sysdeps/unix/sysv/linux/mips/sysdep.h new file mode 100644 index 0000000000..cabc590961 --- /dev/null +++ b/sysdeps/unix/sysv/linux/mips/sysdep.h @@ -0,0 +1,24 @@ +/* Syscall definitions, Linux MIPS generic version. + Copyright (C) 2019 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#define VDSO_NAME "LINUX_2_6" +#define VDSO_HASH 61765110 + +/* List of system calls which are supported as vsyscalls. */ +#define HAVE_CLOCK_GETTIME_VSYSCALL 1 +#define HAVE_GETTIMEOFDAY_VSYSCALL 1 diff --git a/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c b/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c index 463b678ad9..c59d5ddc10 100644 --- a/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c +++ b/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c @@ -57,10 +57,9 @@ __gettimeofday_syscall (struct timeval *tv, struct timezone *tz) return INLINE_SYSCALL (gettimeofday, 2, tv, tz); } -# define INIT_ARCH() \ - PREPARE_VERSION_KNOWN (linux2615, LINUX_2_6_15); \ - void *vdso_gettimeofday = _dl_vdso_vsym ("__kernel_gettimeofday", &linux2615); - +# define INIT_ARCH() \ + void *vdso_gettimeofday = get_vdso_symbol ("__kernel_gettimeofday") + /* If the vDSO is not available we fall back syscall. */ libc_ifunc_hidden (__redirect___gettimeofday, __gettimeofday, vdso_gettimeofday diff --git a/sysdeps/unix/sysv/linux/powerpc/init-first.c b/sysdeps/unix/sysv/linux/powerpc/init-first.c index 831f910788..0d46563ce3 100644 --- a/sysdeps/unix/sysv/linux/powerpc/init-first.c +++ b/sysdeps/unix/sysv/linux/powerpc/init-first.c @@ -37,29 +37,27 @@ void *VDSO_SYMBOL(sigtramp_rt32); static inline void _libc_vdso_platform_setup (void) { - PREPARE_VERSION_KNOWN (linux2615, LINUX_2_6_15); - - void *p = _dl_vdso_vsym ("__kernel_gettimeofday", &linux2615); + void *p = get_vdso_symbol ("__kernel_gettimeofday"); PTR_MANGLE (p); VDSO_SYMBOL (gettimeofday) = p; - p = _dl_vdso_vsym ("__kernel_clock_gettime", &linux2615); + p = get_vdso_symbol ("__kernel_clock_gettime"); PTR_MANGLE (p); VDSO_SYMBOL (clock_gettime) = p; - p = _dl_vdso_vsym ("__kernel_clock_getres", &linux2615); + p = get_vdso_symbol ("__kernel_clock_getres"); PTR_MANGLE (p); VDSO_SYMBOL (clock_getres) = p; - p = _dl_vdso_vsym ("__kernel_get_tbfreq", &linux2615); + p = get_vdso_symbol ("__kernel_get_tbfreq"); PTR_MANGLE (p); VDSO_SYMBOL (get_tbfreq) = p; - p = _dl_vdso_vsym ("__kernel_getcpu", &linux2615); + p = get_vdso_symbol ("__kernel_getcpu"); PTR_MANGLE (p); VDSO_SYMBOL (getcpu) = p; - p = _dl_vdso_vsym ("__kernel_time", &linux2615); + p = get_vdso_symbol ("__kernel_time"); PTR_MANGLE (p); VDSO_SYMBOL (time) = p; @@ -69,12 +67,10 @@ _libc_vdso_platform_setup (void) There is no need to pointer mangle these symbol because they will used only for pointer comparison. */ #if defined(__PPC64__) || defined(__powerpc64__) - VDSO_SYMBOL(sigtramp_rt64) = _dl_vdso_vsym ("__kernel_sigtramp_rt64", - &linux2615); + VDSO_SYMBOL(sigtramp_rt64) = get_vdso_symbol ("__kernel_sigtramp_rt64"); #else - VDSO_SYMBOL(sigtramp32) = _dl_vdso_vsym ("__kernel_sigtramp32", &linux2615); - VDSO_SYMBOL(sigtramp_rt32) = _dl_vdso_vsym ("__kernel_sigtramp_rt32", - &linux2615); + VDSO_SYMBOL(sigtramp32) = get_vdso_symbol ("__kernel_sigtramp32"); + VDSO_SYMBOL(sigtramp_rt32) = get_vdso_symbol ("__kernel_sigtramp_rt32"); #endif } diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h b/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h index 62caa265d7..f459543fcd 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h @@ -18,6 +18,7 @@ #ifndef _LINUX_POWERPC_SYSDEP_H #define _LINUX_POWERPC_SYSDEP_H 1 +#include #include #include #include @@ -144,12 +145,6 @@ sc_ret; \ }) -/* List of system calls which are supported as vsyscalls. */ -# define HAVE_CLOCK_GETRES_VSYSCALL 1 -# define HAVE_CLOCK_GETTIME_VSYSCALL 1 -# define HAVE_GETCPU_VSYSCALL 1 - - # define LOADARGS_0(name, dummy) \ r0 = name # define LOADARGS_1(name, __arg1) \ diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h b/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h index 4122e5c4a9..06222f52e6 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h @@ -20,6 +20,7 @@ #ifndef _LINUX_POWERPC_SYSDEP_H #define _LINUX_POWERPC_SYSDEP_H 1 +#include #include #include #include @@ -60,11 +61,6 @@ sc_ret; \ }) -/* List of system calls which are supported as vsyscalls. */ -#define HAVE_CLOCK_GETRES_VSYSCALL 1 -#define HAVE_CLOCK_GETTIME_VSYSCALL 1 -#define HAVE_GETCPU_VSYSCALL 1 - /* Define a macro which expands inline into the wrapper code for a system call. This use is for internal calls that do not need to handle errors normally. It will never touch errno. This returns just what the kernel diff --git a/sysdeps/unix/sysv/linux/powerpc/sysdep.h b/sysdeps/unix/sysv/linux/powerpc/sysdep.h new file mode 100644 index 0000000000..5b411d0e8e --- /dev/null +++ b/sysdeps/unix/sysv/linux/powerpc/sysdep.h @@ -0,0 +1,26 @@ +/* Syscall definitions, Linux PowerPC generic version. + Copyright (C) 2019 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#define VDSO_NAME "LINUX_2.6.15" +#define VDSO_HASH 123718565 + +/* List of system calls which are supported as vsyscalls. */ +#define HAVE_CLOCK_GETRES_VSYSCALL 1 +#define HAVE_CLOCK_GETTIME_VSYSCALL 1 +#define HAVE_GETCPU_VSYSCALL 1 + diff --git a/sysdeps/unix/sysv/linux/powerpc/time.c b/sysdeps/unix/sysv/linux/powerpc/time.c index cb3e8b9a73..38477bce8b 100644 --- a/sysdeps/unix/sysv/linux/powerpc/time.c +++ b/sysdeps/unix/sysv/linux/powerpc/time.c @@ -66,9 +66,8 @@ time_syscall (time_t *t) return result; } -# define INIT_ARCH() \ - PREPARE_VERSION_KNOWN (linux2615, LINUX_2_6_15); \ - void *vdso_time = _dl_vdso_vsym ("__kernel_time", &linux2615); +# define INIT_ARCH() \ + void *vdso_time = get_vdso_symbol ("__kernel_time"); /* If the vDSO is not available we fall back to the syscall. */ libc_ifunc_hidden (__redirect_time, time, diff --git a/sysdeps/unix/sysv/linux/riscv/flush-icache.c b/sysdeps/unix/sysv/linux/riscv/flush-icache.c index f2dfcc50d0..6fbda9a088 100644 --- a/sysdeps/unix/sysv/linux/riscv/flush-icache.c +++ b/sysdeps/unix/sysv/linux/riscv/flush-icache.c @@ -38,9 +38,7 @@ __riscv_flush_icache_syscall (void *start, void *end, unsigned long int flags) static func_type __lookup_riscv_flush_icache (void) { - PREPARE_VERSION_KNOWN (linux_version, LINUX_4_15); - - func_type func = _dl_vdso_vsym ("__vdso_flush_icache", &linux_version); + func_type func = get_vdso_symbol ("__vdso_flush_icache"); /* If there is no vDSO entry then call the system call directly. All Linux versions provide the vDSO entry, but QEMU's user-mode emulation doesn't diff --git a/sysdeps/unix/sysv/linux/riscv/init-first.c b/sysdeps/unix/sysv/linux/riscv/init-first.c index 98a8ce33ad..f3d243a192 100644 --- a/sysdeps/unix/sysv/linux/riscv/init-first.c +++ b/sysdeps/unix/sysv/linux/riscv/init-first.c @@ -32,21 +32,19 @@ long int (*VDSO_SYMBOL (clock_getres)) (clockid_t, struct timespec *) static inline void _libc_vdso_platform_setup (void) { - PREPARE_VERSION_KNOWN (linux_version, LINUX_4_15); - - void *p = _dl_vdso_vsym ("__vdso_getcpu", &linux_version); + void *p = get_vdso_symbol ("__vdso_getcpu"); PTR_MANGLE (p); VDSO_SYMBOL (getcpu) = p; - p = _dl_vdso_vsym ("__vdso_gettimeofday", &linux_version); + p = get_vdso_symbol ("__vdso_gettimeofday"); PTR_MANGLE (p); VDSO_SYMBOL (gettimeofday) = p; - p = _dl_vdso_vsym ("__vdso_clock_gettime", &linux_version); + p = get_vdso_symbol ("__vdso_clock_gettime"); PTR_MANGLE (p); VDSO_SYMBOL (clock_gettime) = p; - p = _dl_vdso_vsym ("__vdso_clock_getres", &linux_version); + p = get_vdso_symbol ("__vdso_clock_getres"); PTR_MANGLE (p); VDSO_SYMBOL (clock_getres) = p; } diff --git a/sysdeps/unix/sysv/linux/riscv/sysdep.h b/sysdeps/unix/sysv/linux/riscv/sysdep.h index 5470ea3d2a..5de773744c 100644 --- a/sysdeps/unix/sysv/linux/riscv/sysdep.h +++ b/sysdeps/unix/sysv/linux/riscv/sysdep.h @@ -121,6 +121,9 @@ #ifndef __ASSEMBLER__ +# define VDSO_NAME "LINUX_4.15" +# define VDSO_HASH 182943605 + /* List of system calls which are supported as vsyscalls. */ # define HAVE_CLOCK_GETRES_VSYSCALL 1 # define HAVE_CLOCK_GETTIME_VSYSCALL 1 diff --git a/sysdeps/unix/sysv/linux/s390/init-first.c b/sysdeps/unix/sysv/linux/s390/init-first.c index a1ad9458e3..3e36270eac 100644 --- a/sysdeps/unix/sysv/linux/s390/init-first.c +++ b/sysdeps/unix/sysv/linux/s390/init-first.c @@ -34,21 +34,19 @@ long int (*VDSO_SYMBOL(getcpu)) (unsigned *, unsigned *, void *) static inline void _libc_vdso_platform_setup (void) { - PREPARE_VERSION_KNOWN (linux2629, LINUX_2_6_29); - - void *p = _dl_vdso_vsym ("__kernel_gettimeofday", &linux2629); + void *p = get_vdso_symbol ("__kernel_gettimeofday"); PTR_MANGLE (p); VDSO_SYMBOL (gettimeofday) = p; - p = _dl_vdso_vsym ("__kernel_clock_gettime", &linux2629); + p = get_vdso_symbol ("__kernel_clock_gettime"); PTR_MANGLE (p); VDSO_SYMBOL (clock_gettime) = p; - p = _dl_vdso_vsym ("__kernel_clock_getres", &linux2629); + p = get_vdso_symbol ("__kernel_clock_getres"); PTR_MANGLE (p); VDSO_SYMBOL (clock_getres) = p; - p = _dl_vdso_vsym ("__kernel_getcpu", &linux2629); + p = get_vdso_symbol ("__kernel_getcpu"); PTR_MANGLE (p); VDSO_SYMBOL (getcpu) = p; } diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h b/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h index 640fb52de1..b780d22d8f 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h +++ b/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h @@ -21,6 +21,7 @@ #include #include +#include #include #include /* For RTLD_PRIVATE_ERRNO. */ #include @@ -271,12 +272,6 @@ #define ASMFMT_5 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6) #define ASMFMT_6 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6), "d" (gpr7) -/* List of system calls which are supported as vsyscalls. */ -#define HAVE_CLOCK_GETRES_VSYSCALL 1 -#define HAVE_CLOCK_GETTIME_VSYSCALL 1 -#define HAVE_GETTIMEOFDAY_VSYSCALL 1 -#define HAVE_GETCPU_VSYSCALL 1 - /* Pointer mangling support. */ #if IS_IN (rtld) /* We cannot use the thread descriptor because in ld.so we use setjmp diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h b/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h index 9a9834c750..07cfa64cab 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h +++ b/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h @@ -22,6 +22,7 @@ #include #include +#include #include #include /* For RTLD_PRIVATE_ERRNO. */ #include @@ -277,12 +278,6 @@ #define ASMFMT_5 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6) #define ASMFMT_6 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6), "d" (gpr7) -/* List of system calls which are supported as vsyscalls. */ -#define HAVE_CLOCK_GETRES_VSYSCALL 1 -#define HAVE_CLOCK_GETTIME_VSYSCALL 1 -#define HAVE_GETTIMEOFDAY_VSYSCALL 1 -#define HAVE_GETCPU_VSYSCALL 1 - #define SINGLE_THREAD_BY_GLOBAL 1 /* Pointer mangling support. */ diff --git a/sysdeps/unix/sysv/linux/s390/sysdep.h b/sysdeps/unix/sysv/linux/s390/sysdep.h new file mode 100644 index 0000000000..eefbd8f007 --- /dev/null +++ b/sysdeps/unix/sysv/linux/s390/sysdep.h @@ -0,0 +1,27 @@ +/* Syscall definitions, Linux PowerPC generic version. + Copyright (C) 2000-2019 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#define VDSO_NAME "LINUX_2_6_29" +#define VDSO_HASH 123718585 + +/* List of system calls which are supported as vsyscalls. */ +#define HAVE_CLOCK_GETRES_VSYSCALL 1 +#define HAVE_CLOCK_GETTIME_VSYSCALL 1 +#define HAVE_GETTIMEOFDAY_VSYSCALL 1 +#define HAVE_GETCPU_VSYSCALL 1 + diff --git a/sysdeps/unix/sysv/linux/sparc/init-first.c b/sysdeps/unix/sysv/linux/sparc/init-first.c index 643d6c7c88..bdaa78fd32 100644 --- a/sysdeps/unix/sysv/linux/sparc/init-first.c +++ b/sysdeps/unix/sysv/linux/sparc/init-first.c @@ -28,13 +28,11 @@ long int (*VDSO_SYMBOL (clock_gettime)) (clockid_t, struct timespec *) static inline void _libc_vdso_platform_setup (void) { - PREPARE_VERSION_KNOWN (linux_version, LINUX_2_6); - - void *p = _dl_vdso_vsym ("__vdso_gettimeofday", &linux_version); + void *p = get_vdso_symbol ("__vdso_gettimeofday"); PTR_MANGLE (p); VDSO_SYMBOL (gettimeofday) = p; - p = _dl_vdso_vsym ("__vdso_clock_gettime", &linux_version); + p = get_vdso_symbol ("__vdso_clock_gettime"); PTR_MANGLE (p); VDSO_SYMBOL (clock_gettime) = p; } diff --git a/sysdeps/unix/sysv/linux/sparc/sysdep.h b/sysdeps/unix/sysv/linux/sparc/sysdep.h index 981b2a26b7..3bfb1fc60e 100644 --- a/sysdeps/unix/sysv/linux/sparc/sysdep.h +++ b/sysdeps/unix/sysv/linux/sparc/sysdep.h @@ -41,6 +41,9 @@ _ret; \ }) +# define VDSO_NAME "LINUX_2_6" +# define VDSO_HASH 61765110 + /* List of system calls which are supported as vsyscalls. */ # define HAVE_CLOCK_GETTIME_VSYSCALL 1 # define HAVE_GETTIMEOFDAY_VSYSCALL 1 diff --git a/sysdeps/unix/sysv/linux/x86/gettimeofday.c b/sysdeps/unix/sysv/linux/x86/gettimeofday.c index 8886ccd707..3ceab633e5 100644 --- a/sysdeps/unix/sysv/linux/x86/gettimeofday.c +++ b/sysdeps/unix/sysv/linux/x86/gettimeofday.c @@ -22,6 +22,8 @@ # include # include +# include +# include static int __gettimeofday_syscall (struct timeval *tv, struct timezone *tz) @@ -36,12 +38,12 @@ __gettimeofday_syscall (struct timeval *tv, struct timezone *tz) # define __gettimeofday_type __gettimeofday # endif -# undef INIT_ARCH -# define INIT_ARCH() PREPARE_VERSION_KNOWN (linux26, LINUX_2_6) +# define INIT_ARCH() + /* If the vDSO is not available we fall back to syscall. */ libc_ifunc_hidden (__gettimeofday_type, __gettimeofday, - (_dl_vdso_vsym ("__vdso_gettimeofday", &linux26) - ?: &__gettimeofday_syscall)) + (get_vdso_symbol ("__vdso_gettimeofday") + ?: __gettimeofday_syscall)); libc_hidden_def (__gettimeofday) #else diff --git a/sysdeps/unix/sysv/linux/x86/time.c b/sysdeps/unix/sysv/linux/x86/time.c index 3d72488500..60e6d1b7c0 100644 --- a/sysdeps/unix/sysv/linux/x86/time.c +++ b/sysdeps/unix/sysv/linux/x86/time.c @@ -22,6 +22,7 @@ #include #include +#include static time_t __time_syscall (time_t *t) @@ -38,11 +39,11 @@ __time_syscall (time_t *t) # endif #undef INIT_ARCH -#define INIT_ARCH() PREPARE_VERSION_KNOWN (linux26, LINUX_2_6); +#define INIT_ARCH() + /* If the vDSO is not available we fall back on the syscall. */ libc_ifunc_hidden (time_type, time, - (_dl_vdso_vsym ("__vdso_time", &linux26) - ?: &__time_syscall)) + (get_vdso_symbol ("__vdso_time") ?: __time_syscall)) libc_hidden_def (time) #else diff --git a/sysdeps/unix/sysv/linux/x86_64/init-first.c b/sysdeps/unix/sysv/linux/x86_64/init-first.c index 85333e5ff3..aede1c858d 100644 --- a/sysdeps/unix/sysv/linux/x86_64/init-first.c +++ b/sysdeps/unix/sysv/linux/x86_64/init-first.c @@ -32,15 +32,13 @@ extern __typeof (clock_gettime) __syscall_clock_gettime attribute_hidden; static inline void __vdso_platform_setup (void) { - PREPARE_VERSION_KNOWN (linux26, LINUX_2_6); - - void *p = _dl_vdso_vsym ("__vdso_clock_gettime", &linux26); + void *p = get_vdso_symbol ("__vdso_clock_gettime"); if (p == NULL) p = __syscall_clock_gettime; PTR_MANGLE (p); VDSO_SYMBOL(clock_gettime) = p; - p = _dl_vdso_vsym ("__vdso_getcpu", &linux26); + p = get_vdso_symbol ("__vdso_getcpu"); PTR_MANGLE (p); VDSO_SYMBOL(getcpu) = p; } diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/sysdep.h index 0a3ddd37e1..197329f4dc 100644 --- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h +++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h @@ -370,6 +370,9 @@ # undef INTERNAL_SYSCALL_ERRNO # define INTERNAL_SYSCALL_ERRNO(val, err) (-(val)) +# define VDSO_NAME "LINUX_2.6" +# define VDSO_HASH 61765110 + /* List of system calls which are supported as vsyscalls. */ # define HAVE_CLOCK_GETTIME_VSYSCALL 1 # define HAVE_GETTIMEOFDAY_VSYSCALL 1 From patchwork Thu Sep 5 20:56:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1158684 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-105068-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="WUEmAjDh"; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="aYz+eXes"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46PY0l26hsz9s7T for ; Fri, 6 Sep 2019 06:57:27 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=vWzOqCg47Wx3rUxVvO3TiZnSjLpjYSE AQluhgSS3aY09o2XuL2mEo0pjdk4tYE1iXbWW1ATYifuSqJr/w8UFiHOn1rWoF91 u3XPzTaSIPRVrNszxbpIez8g0roRzig119OIEuRYrGgj4Z8LemufAQ+DqwyDh4fi eCd/FHFZOxRg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; s=default; bh=oK1elsM6XmR4K7BTA2xEoPWXfRs=; b=WUEmA jDhimkf7pu8UYQ6tHKjAo6xJRKa+AWszjo3cMiUk+lxNewVTOWyLRME5cCGHW9wD T8aTkQHBpPgPoAokjdgn3MHzNrvwY8BHa4/GEVMGzQ+iOgHk5Wq3EIf1kLNpHd4B QI5hXgvfzbSaGHQ3IFA2YrgZAUDCaMekkuwmA4= Received: (qmail 117142 invoked by alias); 5 Sep 2019 20:56:36 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 117085 invoked by uid 89); 5 Sep 2019 20:56:36 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=consolidate, SA_SIGINFO, 1925, sa_siginfo X-HELO: mail-qk1-f196.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=m4V/odoMWHFq7AFTBvlA+pwuM7PHBUKe+qpE3nEttAE=; b=aYz+eXeseRvbojYSwBCrbMGZHWzuhKTA5Yrwh/MMbKy5M5jv4YlXVLsUZEetRlCnif OJrqlYbKkFgnNXPl9zhlL/iA34X7W1M+gHC6MGZ8Vl7DIT98ikG4OmeUYgTTGVwKsOOl CA3tW8SDWEljMOUd/keEhsJP09gQf9T6kHFqbgijx7kTggupYYsYtRfee1Xgyd3x2JYp Sg01sUlJNeOKZXz3EZ3BNh7ZHIyDL9ifUz0aLPyDN+UV7tBPfUao5tLnbVmpsfuvPgJx +oerdV9mV/SJl6jNk6su/P1Zyao0LZCCk0Q5Lb9DAyvBbPswC9Fn9svaYLTzf2P2ZsLI MhHQ== From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 2/8] Refactor vDSO initialization code Date: Thu, 5 Sep 2019 17:56:14 -0300 Message-Id: <20190905205620.4646-2-adhemerval.zanella@linaro.org> In-Reply-To: <20190905205620.4646-1-adhemerval.zanella@linaro.org> References: <20190905205620.4646-1-adhemerval.zanella@linaro.org> Linux vDSO initialization code the internal function pointers require a lot of duplicated boilerplate over different architectures. This patch aims to simplify not only the code but the required definition to enable a vDSO symbol. The changes are: 1. Consolidate all init-first.c on only one implementation and enable the symbol based on HAVE_*_VSYSCALL existence. 2. Set the HAVE_*_VSYSCALL to the architecture expected names string. 3. Add a new internal implementation, get_vdso_mangle_symbol, which returns a mangled function pointer. Currently the clock_gettime, clock_getres, gettimeofday, getcpu, and time are handled in an arch-independent way, powerpc still uses some arch-specific vDSO symbol handled in a specific init-first implementation. Checked on aarch64-linux-gnu, arm-linux-gnueabihf, i386-linux-gnu, mips64-linux-gnu, powerpc64le-linux-gnu, s390x-linux-gnu, sparc64-linux-gnu, and x86_64-linux-gnu. * sysdeps/powerpc/powerpc32/backtrace.c (is_sigtramp_address, is_sigtramp_address_rt): Use HAVE_SIGTRAMP_{RT}32 instead of SHARED. * sysdeps/powerpc/powerpc64/backtrace.c (is_sigtramp_address): Likewise. * sysdeps/unix/sysv/linux/aarch64/init-first.c: Remove file. * sysdeps/unix/sysv/linux/aarch64/libc-vdso.h: Likewise. * sysdeps/unix/sysv/linux/arm/init-first.c: Likewise. * sysdeps/unix/sysv/linux/arm/libc-vdso.h: Likewise. * sysdeps/unix/sysv/linux/mips/init-first.c: Likewise. * sysdeps/unix/sysv/linux/mips/libc-vdso.h: Likewise. * sysdeps/unix/sysv/linux/i386/init-first.c: Likewise. * sysdeps/unix/sysv/linux/riscv/init-first.c: Likewise. * sysdeps/unix/sysv/linux/riscv/libc-vdso.h: Likewise. * sysdeps/unix/sysv/linux/s390/init-first.c: Likewise. * sysdeps/unix/sysv/linux/s390/libc-vdso.h: Likewise. * sysdeps/unix/sysv/linux/sparc/init-first.c: Likewise. * sysdeps/unix/sysv/linux/sparc/libc-vdso.h: Likewise. * sysdeps/unix/sysv/linux/x86/libc-vdso.h: Likewise. * sysdeps/unix/sysv/linux/x86_64/init-first.c: Likewise. * sysdeps/unix/sysv/linux/aarch64/sysdep.h (HAVE_CLOCK_GETRES_VSYSCALL, HAVE_CLOCK_GETTIME_VSYSCALL, HAVE_GETTIMEOFDAY_VSYSCALL): Define value based on kernel exported name. * sysdeps/unix/sysv/linux/arm/sysdep.h (HAVE_CLOCK_GETTIME_VSYSCALL, HAVE_GETTIMEOFDAY_VSYSCALL): Likewise. * sysdeps/unix/sysv/linux/i386/sysdep.h (HAVE_CLOCK_GETTIME_VSYSCALL, HAVE_GETTIMEOFDAY_VSYSCALL): Likewise. * sysdeps/unix/sysv/linux/mips/sysdep.h (HAVE_CLOCK_GETTIME_VSYSCALL, HAVE_GETTIMEOFDAY_VSYSCALL): Likewise. * sysdeps/unix/sysv/linux/powerpc/sysdep.h (HAVE_CLOCK_GETRES_VSYSCALL, HAVE_CLOCK_GETTIME_VSYSCALL, HAVE_GETCPU_VSYSCALL, HAVE_TIME_VSYSCALL, HAVE_GET_TBFREQ, HAVE_SIGTRAMP_RT64, HAVE_SIGTRAMP_32, HAVE_SIGTRAMP_RT32): Likewise. * sysdeps/unix/sysv/linux/riscv/sysdep.h (HAVE_CLOCK_GETRES_VSYSCALL, HAVE_CLOCK_GETTIME_VSYSCALL, HAVE_GETTIMEOFDAY_VSYSCALL, HAVE_GETCPU_VSYSCALL): Likewise. * sysdeps/unix/sysv/linux/s390/sysdep.h (HAVE_CLOCK_GETRES_VSYSCALL, HAVE_CLOCK_GETTIME_VSYSCALL, HAVE_GETTIMEOFDAY_VSYSCALL, HAVE_GETCPU_VSYSCALL): Likewise. * sysdeps/unix/sysv/linux/sparc/sysdep.h (HAVE_CLOCK_GETTIME_VSYSCALL, HAVE_GETTIMEOFDAY_VSYSCALL): Likewise. * sysdeps/unix/sysv/linux/x86_64/sysdep.h (HAVE_CLOCK_GETTIME_VSYSCALL, HAVE_GETTIMEOFDAY_VSYSCALL, HAVE_GETCPU_VSYSCALL): Likewise. * sysdeps/unix/sysv/linux/dl-vdso.h (VDSO_NAME, VDSO_HASH): Define to invalid names if architecture does not define them. (get_vdso_mangle_symbol): New symbol. * sysdeps/unix/sysv/linux/init-first.c: New file. * sysdeps/unix/sysv/linux/libc-vdso.h: Likewise. * sysdeps/unix/sysv/linux/powerpc/init-first.c (gettimeofday, clock_gettime, clock_getres, getcpu, time): Remove declaration. (__libc_vdso_platform_setup_arch): Likewise and use get_vdso_mangle_symbol to setup vDSO symbols. (sigtramp_rt64, sigtramp32, sigtramp_rt32, get_tbfreq): Add attribute_hidden. * sysdeps/unix/sysv/linux/powerpc/libc-vdso.h: Likewise. * sysdeps/unix/sysv/linux/sysdep-vdso.h (VDSO_SYMBOL): Remove definition. --- sysdeps/powerpc/powerpc32/backtrace.c | 4 +- sysdeps/powerpc/powerpc64/backtrace.c | 2 +- sysdeps/unix/sysv/linux/aarch64/init-first.c | 44 ---------- sysdeps/unix/sysv/linux/aarch64/sysdep.h | 6 +- sysdeps/unix/sysv/linux/arm/init-first.c | 41 ---------- sysdeps/unix/sysv/linux/arm/libc-vdso.h | 29 ------- sysdeps/unix/sysv/linux/arm/sysdep.h | 4 +- sysdeps/unix/sysv/linux/dl-vdso.h | 21 ++++- sysdeps/unix/sysv/linux/i386/init-first.c | 46 ----------- sysdeps/unix/sysv/linux/i386/sysdep.h | 4 +- sysdeps/unix/sysv/linux/init-first.c | 80 +++++++++++++++++++ .../unix/sysv/linux/{aarch64 => }/libc-vdso.h | 18 ++++- sysdeps/unix/sysv/linux/mips/init-first.c | 40 ---------- sysdeps/unix/sysv/linux/mips/libc-vdso.h | 29 ------- sysdeps/unix/sysv/linux/mips/sysdep.h | 4 +- sysdeps/unix/sysv/linux/powerpc/init-first.c | 51 +++--------- sysdeps/unix/sysv/linux/powerpc/libc-vdso.h | 12 +-- sysdeps/unix/sysv/linux/powerpc/sysdep.h | 14 +++- sysdeps/unix/sysv/linux/riscv/init-first.c | 54 ------------- sysdeps/unix/sysv/linux/riscv/libc-vdso.h | 34 -------- sysdeps/unix/sysv/linux/riscv/sysdep.h | 8 +- sysdeps/unix/sysv/linux/s390/init-first.c | 56 ------------- sysdeps/unix/sysv/linux/s390/libc-vdso.h | 35 -------- sysdeps/unix/sysv/linux/s390/sysdep.h | 8 +- sysdeps/unix/sysv/linux/sparc/init-first.c | 42 ---------- sysdeps/unix/sysv/linux/sparc/libc-vdso.h | 29 ------- sysdeps/unix/sysv/linux/sparc/sysdep.h | 4 +- sysdeps/unix/sysv/linux/sysdep-vdso.h | 2 +- sysdeps/unix/sysv/linux/x86/libc-vdso.h | 33 -------- sysdeps/unix/sysv/linux/x86_64/init-first.c | 48 ----------- sysdeps/unix/sysv/linux/x86_64/sysdep.h | 6 +- 31 files changed, 164 insertions(+), 644 deletions(-) delete mode 100644 sysdeps/unix/sysv/linux/aarch64/init-first.c delete mode 100644 sysdeps/unix/sysv/linux/arm/init-first.c delete mode 100644 sysdeps/unix/sysv/linux/arm/libc-vdso.h delete mode 100644 sysdeps/unix/sysv/linux/i386/init-first.c create mode 100644 sysdeps/unix/sysv/linux/init-first.c rename sysdeps/unix/sysv/linux/{aarch64 => }/libc-vdso.h (70%) delete mode 100644 sysdeps/unix/sysv/linux/mips/init-first.c delete mode 100644 sysdeps/unix/sysv/linux/mips/libc-vdso.h delete mode 100644 sysdeps/unix/sysv/linux/riscv/init-first.c delete mode 100644 sysdeps/unix/sysv/linux/riscv/libc-vdso.h delete mode 100644 sysdeps/unix/sysv/linux/s390/init-first.c delete mode 100644 sysdeps/unix/sysv/linux/s390/libc-vdso.h delete mode 100644 sysdeps/unix/sysv/linux/sparc/init-first.c delete mode 100644 sysdeps/unix/sysv/linux/sparc/libc-vdso.h delete mode 100644 sysdeps/unix/sysv/linux/x86/libc-vdso.h delete mode 100644 sysdeps/unix/sysv/linux/x86_64/init-first.c diff --git a/sysdeps/powerpc/powerpc32/backtrace.c b/sysdeps/powerpc/powerpc32/backtrace.c index 857a8aad7b..2978632017 100644 --- a/sysdeps/powerpc/powerpc32/backtrace.c +++ b/sysdeps/powerpc/powerpc32/backtrace.c @@ -54,7 +54,7 @@ struct signal_frame_32 { static inline int is_sigtramp_address (void *nip) { -#ifdef SHARED +#ifdef HAVE_SIGTRAMP_RT32 if (nip == VDSO_SYMBOL (sigtramp32)) return 1; #endif @@ -71,7 +71,7 @@ struct rt_signal_frame_32 { static inline int is_sigtramp_address_rt (void * nip) { -#ifdef SHARED +#ifdef HAVE_SIGTRAMP_32 if (nip == VDSO_SYMBOL (sigtramp_rt32)) return 1; #endif diff --git a/sysdeps/powerpc/powerpc64/backtrace.c b/sysdeps/powerpc/powerpc64/backtrace.c index 7a167838d9..0fa7e9c403 100644 --- a/sysdeps/powerpc/powerpc64/backtrace.c +++ b/sysdeps/powerpc/powerpc64/backtrace.c @@ -57,7 +57,7 @@ struct signal_frame_64 { static inline int is_sigtramp_address (void *nip) { -#ifdef SHARED +#ifdef HAVE_SIGTRAMP_RT64 if (nip == VDSO_SYMBOL (sigtramp_rt64)) return 1; #endif diff --git a/sysdeps/unix/sysv/linux/aarch64/init-first.c b/sysdeps/unix/sysv/linux/aarch64/init-first.c deleted file mode 100644 index c3c27cfd4b..0000000000 --- a/sysdeps/unix/sysv/linux/aarch64/init-first.c +++ /dev/null @@ -1,44 +0,0 @@ -/* Copyright (C) 2007-2019 Free Software Foundation, Inc. - - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2.1 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include - -int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *) attribute_hidden; -int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *); -int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct timespec *); - -static inline void -_libc_vdso_platform_setup (void) -{ - void *p = get_vdso_symbol ("__kernel_gettimeofday"); - PTR_MANGLE (p); - VDSO_SYMBOL(gettimeofday) = p; - - p = get_vdso_symbol ("__kernel_clock_gettime"); - PTR_MANGLE (p); - VDSO_SYMBOL(clock_gettime) = p; - - p = get_vdso_symbol ("__kernel_clock_getres"); - PTR_MANGLE (p); - VDSO_SYMBOL(clock_getres) = p; -} - -#define VDSO_SETUP _libc_vdso_platform_setup - -#include diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep.h b/sysdeps/unix/sysv/linux/aarch64/sysdep.h index 662d321235..d57f7232e2 100644 --- a/sysdeps/unix/sysv/linux/aarch64/sysdep.h +++ b/sysdeps/unix/sysv/linux/aarch64/sysdep.h @@ -160,9 +160,9 @@ # endif /* List of system calls which are supported as vsyscalls. */ -# define HAVE_CLOCK_GETRES_VSYSCALL 1 -# define HAVE_CLOCK_GETTIME_VSYSCALL 1 -# define HAVE_GETTIMEOFDAY_VSYSCALL 1 +# define HAVE_CLOCK_GETRES_VSYSCALL "__kernel_clock_getres" +# define HAVE_CLOCK_GETTIME_VSYSCALL "__kernel_clock_gettime" +# define HAVE_GETTIMEOFDAY_VSYSCALL "__kernel_gettimeofday" /* Previously AArch64 used the generic version without the libc_hidden_def which lead in a non existent __send symbol in libc.so. */ diff --git a/sysdeps/unix/sysv/linux/arm/init-first.c b/sysdeps/unix/sysv/linux/arm/init-first.c deleted file mode 100644 index 2852ab135c..0000000000 --- a/sysdeps/unix/sysv/linux/arm/init-first.c +++ /dev/null @@ -1,41 +0,0 @@ -/* Initialization code run first thing by the ELF startup code. Linux/ARM. - Copyright (C) 2015-2019 Free Software Foundation, Inc. - - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2.1 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include - -int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *) attribute_hidden; -int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *); - -static inline void -_libc_vdso_platform_setup (void) -{ - void *p = get_vdso_symbol ("__vdso_gettimeofday"); - PTR_MANGLE (p); - VDSO_SYMBOL (gettimeofday) = p; - - p = get_vdso_symbol ("__vdso_clock_gettime"); - PTR_MANGLE (p); - VDSO_SYMBOL (clock_gettime) = p; -} - -#define VDSO_SETUP _libc_vdso_platform_setup - -#include diff --git a/sysdeps/unix/sysv/linux/arm/libc-vdso.h b/sysdeps/unix/sysv/linux/arm/libc-vdso.h deleted file mode 100644 index 8702165c6b..0000000000 --- a/sysdeps/unix/sysv/linux/arm/libc-vdso.h +++ /dev/null @@ -1,29 +0,0 @@ -/* VDSO function pointer declarations. Linux/ARM. - Copyright (C) 2015-2019 Free Software Foundation, Inc. - - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library. If not, see - . */ - -#ifndef _LIBC_VDSO_H -#define _LIBC_VDSO_H - -#include - -extern int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *) - attribute_hidden; -extern int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *); - -#endif /* _LIBC_VDSO_H */ diff --git a/sysdeps/unix/sysv/linux/arm/sysdep.h b/sysdeps/unix/sysv/linux/arm/sysdep.h index 467ccf2631..634aa2bc6b 100644 --- a/sysdeps/unix/sysv/linux/arm/sysdep.h +++ b/sysdeps/unix/sysv/linux/arm/sysdep.h @@ -392,8 +392,8 @@ __local_syscall_error: \ #define VDSO_HASH 61765110 /* List of system calls which are supported as vsyscalls. */ -#define HAVE_CLOCK_GETTIME_VSYSCALL 1 -#define HAVE_GETTIMEOFDAY_VSYSCALL 1 +#define HAVE_CLOCK_GETTIME_VSYSCALL "__vdso_gettimeofday" +#define HAVE_GETTIMEOFDAY_VSYSCALL "__vdso_clock_gettime" #define LOAD_ARGS_0() #define ASM_ARGS_0 diff --git a/sysdeps/unix/sysv/linux/dl-vdso.h b/sysdeps/unix/sysv/linux/dl-vdso.h index bab3779615..dcf065ef23 100644 --- a/sysdeps/unix/sysv/linux/dl-vdso.h +++ b/sysdeps/unix/sysv/linux/dl-vdso.h @@ -19,16 +19,25 @@ #ifndef _DL_VDSO_H #define _DL_VDSO_H 1 -#include #include #include -#include /* Functions for resolving symbols in the VDSO link map. */ extern void *_dl_vdso_vsym (const char *name, const struct r_found_version *version) attribute_hidden; +/* If the architecture support vDSO it should define which is the expected + kernel version and hash value through both VDSO_NAME and VDSO_HASH + (usually defined at architecture sysdep.h). */ + +#ifndef VDSO_NAME +# define VDSO_NAME "LINUX_0.0" +#endif +#ifndef VDSO_HASH +# define VDSO_HASH 0 +#endif + static inline void * get_vdso_symbol (const char *symbol) { @@ -36,4 +45,12 @@ get_vdso_symbol (const char *symbol) return _dl_vdso_vsym (symbol, &rfv); } +static inline void * +get_vdso_mangle_symbol (const char *symbol) +{ + void *vdsop = get_vdso_symbol (symbol); + PTR_MANGLE (vdsop); + return vdsop; +} + #endif /* dl-vdso.h */ diff --git a/sysdeps/unix/sysv/linux/i386/init-first.c b/sysdeps/unix/sysv/linux/i386/init-first.c deleted file mode 100644 index 9c03f87b67..0000000000 --- a/sysdeps/unix/sysv/linux/i386/init-first.c +++ /dev/null @@ -1,46 +0,0 @@ -/* Initialization code run first thing by the ELF startup code. Linux/i386. - Copyright (C) 2015-2019 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include -#include - -long int (*VDSO_SYMBOL (clock_gettime)) (clockid_t, struct timespec *) - attribute_hidden; - -static long int -clock_gettime_syscall (clockid_t id, struct timespec *tp) -{ - INTERNAL_SYSCALL_DECL (err); - return INTERNAL_SYSCALL (clock_gettime, err, 2, id, tp); -} - -static inline void -__vdso_platform_setup (void) -{ - void *p = get_vdso_symbol ("__vdso_clock_gettime"); - if (p == NULL) - p = clock_gettime_syscall; - PTR_MANGLE (p); - VDSO_SYMBOL (clock_gettime) = p; -} - -#define VDSO_SETUP __vdso_platform_setup - -#include diff --git a/sysdeps/unix/sysv/linux/i386/sysdep.h b/sysdeps/unix/sysv/linux/i386/sysdep.h index 278028f52e..e793fdc936 100644 --- a/sysdeps/unix/sysv/linux/i386/sysdep.h +++ b/sysdeps/unix/sysv/linux/i386/sysdep.h @@ -313,8 +313,8 @@ struct libc_do_syscall_args # define VDSO_HASH 61765110 /* List of system calls which are supported as vsyscalls. */ -# define HAVE_CLOCK_GETTIME_VSYSCALL 1 -# define HAVE_GETTIMEOFDAY_VSYSCALL 1 +# define HAVE_CLOCK_GETTIME_VSYSCALL "__vdso_clock_gettime" +# define HAVE_GETTIMEOFDAY_VSYSCALL "__vdso_gettimeofday" /* Define a macro which expands inline into the wrapper code for a system call. This use is for internal calls that do not need to handle errors diff --git a/sysdeps/unix/sysv/linux/init-first.c b/sysdeps/unix/sysv/linux/init-first.c new file mode 100644 index 0000000000..d90ca820be --- /dev/null +++ b/sysdeps/unix/sysv/linux/init-first.c @@ -0,0 +1,80 @@ +/* vDSO internal symbols. Linux generic version. + Copyright (C) 2019 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include + +/* vDSO symbol used on clock_gettime implementation. */ +#ifdef HAVE_CLOCK_GETTIME_VSYSCALL +int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *) + attribute_hidden; +#endif +/* vDSO symbol used on clock_getres implementation. */ +#ifdef HAVE_CLOCK_GETRES_VSYSCALL +int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct timespec *) + attribute_hidden; +#endif +/* vDSO symbol used on gettimeofday implementation. */ +#ifdef HAVE_GETTIMEOFDAY_VSYSCALL +int (*VDSO_SYMBOL (gettimeofday)) (struct timeval *, void *) + attribute_hidden; +#endif +/* vDSO symbol used on GNU extension getcpu implementation. */ +#ifdef HAVE_GETCPU_VSYSCALL +long int (*VDSO_SYMBOL(getcpu)) (unsigned *, unsigned *, void *) + attribute_hidden; +#endif +/* vDSO symbol used on time implementation. */ +#ifdef HAVE_TIME_VSYSCALL +time_t (*VDSO_SYMBOL(time)) (time_t *) attribute_hidden; +#endif + +static inline void +__libc_vdso_platform_setup (void) +{ +#ifdef HAVE_CLOCK_GETTIME_VSYSCALL + VDSO_SYMBOL(clock_gettime) + = get_vdso_mangle_symbol (HAVE_CLOCK_GETTIME_VSYSCALL); +#endif + +#ifdef HAVE_CLOCK_GETRES_VSYSCALL + VDSO_SYMBOL(clock_getres) + = get_vdso_mangle_symbol (HAVE_CLOCK_GETRES_VSYSCALL); +#endif + +#ifdef HAVE_GETTIMEOFDAY_VSYSCALL + VDSO_SYMBOL(gettimeofday) + = get_vdso_mangle_symbol (HAVE_GETTIMEOFDAY_VSYSCALL); +#endif + +#ifdef HAVE_GETCPU_VSYSCALL + VDSO_SYMBOL(getcpu) = get_vdso_mangle_symbol (HAVE_GETCPU_VSYSCALL); +#endif + +#ifdef HAVE_TIME_VSYSCALL + VDSO_SYMBOL(time) = get_vdso_mangle_symbol (HAVE_TIME_VSYSCALL); +#endif + +#ifdef VDSO_SETUP_ARCH + VDSO_SETUP_ARCH (); +#endif +} + +#define VDSO_SETUP __libc_vdso_platform_setup + +#include diff --git a/sysdeps/unix/sysv/linux/aarch64/libc-vdso.h b/sysdeps/unix/sysv/linux/libc-vdso.h similarity index 70% rename from sysdeps/unix/sysv/linux/aarch64/libc-vdso.h rename to sysdeps/unix/sysv/linux/libc-vdso.h index 3fcbaa9fce..f681868137 100644 --- a/sysdeps/unix/sysv/linux/aarch64/libc-vdso.h +++ b/sysdeps/unix/sysv/linux/libc-vdso.h @@ -19,12 +19,22 @@ #ifndef _LIBC_VDSO_H #define _LIBC_VDSO_H -#include -#include +#define VDSO_SYMBOL(__name) __vdso_##__name -extern int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *) - attribute_hidden; +#ifdef HAVE_CLOCK_GETTIME_VSYSCALL extern int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *); +#endif +#ifdef HAVE_CLOCK_GETRES_VSYSCALL extern int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct timespec *); +#endif +#ifdef HAVE_GETTIMEOFDAY_VSYSCALL +extern int (*VDSO_SYMBOL (gettimeofday)) (struct timeval *, void *); +#endif +#ifdef HAVE_GETCPU_VSYSCALL +extern long int (*VDSO_SYMBOL(getcpu)) (unsigned *, unsigned *, void *); +#endif +#ifdef HAVE_TIME_VSYSCALL +extern time_t (*VDSO_SYMBOL(time)) (time_t *); +#endif #endif /* _LIBC_VDSO_H */ diff --git a/sysdeps/unix/sysv/linux/mips/init-first.c b/sysdeps/unix/sysv/linux/mips/init-first.c deleted file mode 100644 index 2a43bdc8b0..0000000000 --- a/sysdeps/unix/sysv/linux/mips/init-first.c +++ /dev/null @@ -1,40 +0,0 @@ -/* Initialization code run first thing by the ELF startup code. - Copyright (C) 2016-2019 Free Software Foundation, Inc. - - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2.1 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include - -int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *) attribute_hidden; -int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *); - -static inline void -_libc_vdso_platform_setup (void) -{ - void *p = get_vdso_symbol ("__vdso_gettimeofday"); - PTR_MANGLE (p); - VDSO_SYMBOL (gettimeofday) = p; - - p = get_vdso_symbol ("__vdso_clock_gettime"); - PTR_MANGLE (p); - VDSO_SYMBOL (clock_gettime) = p; -} - -#define VDSO_SETUP _libc_vdso_platform_setup - -#include diff --git a/sysdeps/unix/sysv/linux/mips/libc-vdso.h b/sysdeps/unix/sysv/linux/mips/libc-vdso.h deleted file mode 100644 index 344ea2d750..0000000000 --- a/sysdeps/unix/sysv/linux/mips/libc-vdso.h +++ /dev/null @@ -1,29 +0,0 @@ -/* VDSO function pointer declarations. - Copyright (C) 2016-2019 Free Software Foundation, Inc. - - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library. If not, see - . */ - -#ifndef _LIBC_VDSO_H -#define _LIBC_VDSO_H - -#include - -extern int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *) - attribute_hidden; -extern int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *); - -#endif /* _LIBC_VDSO_H */ diff --git a/sysdeps/unix/sysv/linux/mips/sysdep.h b/sysdeps/unix/sysv/linux/mips/sysdep.h index cabc590961..58a7244581 100644 --- a/sysdeps/unix/sysv/linux/mips/sysdep.h +++ b/sysdeps/unix/sysv/linux/mips/sysdep.h @@ -20,5 +20,5 @@ #define VDSO_HASH 61765110 /* List of system calls which are supported as vsyscalls. */ -#define HAVE_CLOCK_GETTIME_VSYSCALL 1 -#define HAVE_GETTIMEOFDAY_VSYSCALL 1 +#define HAVE_CLOCK_GETTIME_VSYSCALL "__vdso_gettimeofday" +#define HAVE_GETTIMEOFDAY_VSYSCALL "__vdso_clock_gettime" diff --git a/sysdeps/unix/sysv/linux/powerpc/init-first.c b/sysdeps/unix/sysv/linux/powerpc/init-first.c index 0d46563ce3..6e72d9ca84 100644 --- a/sysdeps/unix/sysv/linux/powerpc/init-first.c +++ b/sysdeps/unix/sysv/linux/powerpc/init-first.c @@ -19,47 +19,18 @@ #include #include -int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *) - attribute_hidden; -int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *); -int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct timespec *); -unsigned long long (*VDSO_SYMBOL(get_tbfreq)) (void); -int (*VDSO_SYMBOL(getcpu)) (unsigned *, unsigned *); -time_t (*VDSO_SYMBOL(time)) (time_t *); - +unsigned long long (*VDSO_SYMBOL(get_tbfreq)) (void) attribute_hidden; #if defined(__PPC64__) || defined(__powerpc64__) -void *VDSO_SYMBOL(sigtramp_rt64); +void *VDSO_SYMBOL(sigtramp_rt64) attribute_hidden; #else -void *VDSO_SYMBOL(sigtramp32); -void *VDSO_SYMBOL(sigtramp_rt32); +void *VDSO_SYMBOL(sigtramp32) attribute_hidden; +void *VDSO_SYMBOL(sigtramp_rt32) attribute_hidden; #endif static inline void -_libc_vdso_platform_setup (void) +__libc_vdso_platform_setup_arch (void) { - void *p = get_vdso_symbol ("__kernel_gettimeofday"); - PTR_MANGLE (p); - VDSO_SYMBOL (gettimeofday) = p; - - p = get_vdso_symbol ("__kernel_clock_gettime"); - PTR_MANGLE (p); - VDSO_SYMBOL (clock_gettime) = p; - - p = get_vdso_symbol ("__kernel_clock_getres"); - PTR_MANGLE (p); - VDSO_SYMBOL (clock_getres) = p; - - p = get_vdso_symbol ("__kernel_get_tbfreq"); - PTR_MANGLE (p); - VDSO_SYMBOL (get_tbfreq) = p; - - p = get_vdso_symbol ("__kernel_getcpu"); - PTR_MANGLE (p); - VDSO_SYMBOL (getcpu) = p; - - p = get_vdso_symbol ("__kernel_time"); - PTR_MANGLE (p); - VDSO_SYMBOL (time) = p; + VDSO_SYMBOL (get_tbfreq) = get_vdso_mangle_symbol (HAVE_GET_TBFREQ); /* PPC64 uses only one signal trampoline symbol, while PPC32 will use two depending if SA_SIGINFO is used (__kernel_sigtramp_rt32) or not @@ -67,13 +38,13 @@ _libc_vdso_platform_setup (void) There is no need to pointer mangle these symbol because they will used only for pointer comparison. */ #if defined(__PPC64__) || defined(__powerpc64__) - VDSO_SYMBOL(sigtramp_rt64) = get_vdso_symbol ("__kernel_sigtramp_rt64"); + VDSO_SYMBOL(sigtramp_rt64) = get_vdso_symbol (HAVE_SIGTRAMP_RT64); #else - VDSO_SYMBOL(sigtramp32) = get_vdso_symbol ("__kernel_sigtramp32"); - VDSO_SYMBOL(sigtramp_rt32) = get_vdso_symbol ("__kernel_sigtramp_rt32"); + VDSO_SYMBOL(sigtramp32) = get_vdso_symbol (HAVE_SIGTRAMP_32); + VDSO_SYMBOL(sigtramp_rt32) = get_vdso_symbol (HAVE_SIGTRAMP_RT32); #endif } -#define VDSO_SETUP _libc_vdso_platform_setup +#define VDSO_SETUP_ARCH __libc_vdso_platform_setup_arch -#include +#include diff --git a/sysdeps/unix/sysv/linux/powerpc/libc-vdso.h b/sysdeps/unix/sysv/linux/powerpc/libc-vdso.h index f8184061c0..47e925493b 100644 --- a/sysdeps/unix/sysv/linux/powerpc/libc-vdso.h +++ b/sysdeps/unix/sysv/linux/powerpc/libc-vdso.h @@ -17,20 +17,14 @@ . */ -#ifndef _LIBC_VDSO_H -#define _LIBC_VDSO_H +#ifndef _LIBC_POWERPC_VDSO_H +#define _LIBC_POWERPC_VDSO_H #include #include +#include_next -extern int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *) - attribute_hidden; -extern int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *); -extern int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct timespec *); extern unsigned long long (*VDSO_SYMBOL(get_tbfreq)) (void); -extern int (*VDSO_SYMBOL(getcpu)) (unsigned *, unsigned *); -extern time_t (*VDSO_SYMBOL(time)) (time_t *); - #if defined(__PPC64__) || defined(__powerpc64__) extern void *VDSO_SYMBOL(sigtramp_rt64); #else diff --git a/sysdeps/unix/sysv/linux/powerpc/sysdep.h b/sysdeps/unix/sysv/linux/powerpc/sysdep.h index 5b411d0e8e..20167615c8 100644 --- a/sysdeps/unix/sysv/linux/powerpc/sysdep.h +++ b/sysdeps/unix/sysv/linux/powerpc/sysdep.h @@ -20,7 +20,15 @@ #define VDSO_HASH 123718565 /* List of system calls which are supported as vsyscalls. */ -#define HAVE_CLOCK_GETRES_VSYSCALL 1 -#define HAVE_CLOCK_GETTIME_VSYSCALL 1 -#define HAVE_GETCPU_VSYSCALL 1 +#define HAVE_CLOCK_GETRES_VSYSCALL "__kernel_clock_getres" +#define HAVE_CLOCK_GETTIME_VSYSCALL "__kernel_clock_gettime" +#define HAVE_GETCPU_VSYSCALL "__kernel_getcpu" +#define HAVE_TIME_VSYSCALL "__kernel_time" +#define HAVE_GET_TBFREQ "__kernel_get_tbfreq" +#if defined(__PPC64__) || defined(__powerpc64__) +# define HAVE_SIGTRAMP_RT64 "__kernel_sigtramp_rt64" +#else +# define HAVE_SIGTRAMP_32 "__kernel_sigtramp32" +# define HAVE_SIGTRAMP_RT32 "__kernel_sigtramp_rt32" +#endif diff --git a/sysdeps/unix/sysv/linux/riscv/init-first.c b/sysdeps/unix/sysv/linux/riscv/init-first.c deleted file mode 100644 index f3d243a192..0000000000 --- a/sysdeps/unix/sysv/linux/riscv/init-first.c +++ /dev/null @@ -1,54 +0,0 @@ -/* RISC-V VDSO initialization - Copyright (C) 2017-2019 Free Software Foundation, Inc. - - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2.1 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include - -long int (*VDSO_SYMBOL (getcpu)) (unsigned int *, unsigned int *, void *) - attribute_hidden; -long int (*VDSO_SYMBOL (gettimeofday)) (struct timeval *, void *) - attribute_hidden; -long int (*VDSO_SYMBOL (clock_gettime)) (clockid_t, struct timespec *) - attribute_hidden; -long int (*VDSO_SYMBOL (clock_getres)) (clockid_t, struct timespec *) - attribute_hidden; - -static inline void -_libc_vdso_platform_setup (void) -{ - void *p = get_vdso_symbol ("__vdso_getcpu"); - PTR_MANGLE (p); - VDSO_SYMBOL (getcpu) = p; - - p = get_vdso_symbol ("__vdso_gettimeofday"); - PTR_MANGLE (p); - VDSO_SYMBOL (gettimeofday) = p; - - p = get_vdso_symbol ("__vdso_clock_gettime"); - PTR_MANGLE (p); - VDSO_SYMBOL (clock_gettime) = p; - - p = get_vdso_symbol ("__vdso_clock_getres"); - PTR_MANGLE (p); - VDSO_SYMBOL (clock_getres) = p; -} - -#define VDSO_SETUP _libc_vdso_platform_setup - -#include diff --git a/sysdeps/unix/sysv/linux/riscv/libc-vdso.h b/sysdeps/unix/sysv/linux/riscv/libc-vdso.h deleted file mode 100644 index 2373292ab9..0000000000 --- a/sysdeps/unix/sysv/linux/riscv/libc-vdso.h +++ /dev/null @@ -1,34 +0,0 @@ -/* RISC-V VDSO function declarations - Copyright (C) 2017-2019 Free Software Foundation, Inc. - - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library. If not, see - . */ - -#ifndef _LIBC_VDSO_H -#define _LIBC_VDSO_H - -#include - -extern long int (*VDSO_SYMBOL (getcpu)) (unsigned int *, unsigned int *, void *) - attribute_hidden; -extern long int (*VDSO_SYMBOL (gettimeofday)) (struct timeval *, void *) - attribute_hidden; -extern long int (*VDSO_SYMBOL (clock_gettime)) (clockid_t, struct timespec *) - attribute_hidden; -extern long int (*VDSO_SYMBOL (clock_getres)) (clockid_t, struct timespec *) - attribute_hidden; - -#endif /* _LIBC_VDSO_H */ diff --git a/sysdeps/unix/sysv/linux/riscv/sysdep.h b/sysdeps/unix/sysv/linux/riscv/sysdep.h index 5de773744c..22835aa12f 100644 --- a/sysdeps/unix/sysv/linux/riscv/sysdep.h +++ b/sysdeps/unix/sysv/linux/riscv/sysdep.h @@ -125,10 +125,10 @@ # define VDSO_HASH 182943605 /* List of system calls which are supported as vsyscalls. */ -# define HAVE_CLOCK_GETRES_VSYSCALL 1 -# define HAVE_CLOCK_GETTIME_VSYSCALL 1 -# define HAVE_GETTIMEOFDAY_VSYSCALL 1 -# define HAVE_GETCPU_VSYSCALL 1 +# define HAVE_CLOCK_GETRES_VSYSCALL "__vdso_clock_getres" +# define HAVE_CLOCK_GETTIME_VSYSCALL "__vdso_clock_gettime" +# define HAVE_GETTIMEOFDAY_VSYSCALL "__vdso_gettimeofday" +# define HAVE_GETCPU_VSYSCALL "__vdso_getcpu" /* Define a macro which expands into the inline wrapper code for a system call. */ diff --git a/sysdeps/unix/sysv/linux/s390/init-first.c b/sysdeps/unix/sysv/linux/s390/init-first.c deleted file mode 100644 index 3e36270eac..0000000000 --- a/sysdeps/unix/sysv/linux/s390/init-first.c +++ /dev/null @@ -1,56 +0,0 @@ -/* Initialization code run first thing by the ELF startup code. Linux/s390. - Copyright (C) 2008-2019 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include - -long int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *) - attribute_hidden; - -long int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *) - __attribute__ ((nocommon)); - -long int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct timespec *) - __attribute__ ((nocommon)); - -long int (*VDSO_SYMBOL(getcpu)) (unsigned *, unsigned *, void *) - attribute_hidden; - -static inline void -_libc_vdso_platform_setup (void) -{ - void *p = get_vdso_symbol ("__kernel_gettimeofday"); - PTR_MANGLE (p); - VDSO_SYMBOL (gettimeofday) = p; - - p = get_vdso_symbol ("__kernel_clock_gettime"); - PTR_MANGLE (p); - VDSO_SYMBOL (clock_gettime) = p; - - p = get_vdso_symbol ("__kernel_clock_getres"); - PTR_MANGLE (p); - VDSO_SYMBOL (clock_getres) = p; - - p = get_vdso_symbol ("__kernel_getcpu"); - PTR_MANGLE (p); - VDSO_SYMBOL (getcpu) = p; -} - -#define VDSO_SETUP _libc_vdso_platform_setup - -#include diff --git a/sysdeps/unix/sysv/linux/s390/libc-vdso.h b/sysdeps/unix/sysv/linux/s390/libc-vdso.h deleted file mode 100644 index cc97601383..0000000000 --- a/sysdeps/unix/sysv/linux/s390/libc-vdso.h +++ /dev/null @@ -1,35 +0,0 @@ -/* Resolve function pointers to VDSO functions. - Copyright (C) 2008-2019 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - - -#ifndef _LIBC_VDSO_H -#define _LIBC_VDSO_H - -#include - -extern long int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *) - attribute_hidden; - -extern long int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *); - -extern long int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct timespec *); - -extern long int (*VDSO_SYMBOL(getcpu)) (unsigned *, unsigned *, void *) - attribute_hidden; - -#endif /* _LIBC_VDSO_H */ diff --git a/sysdeps/unix/sysv/linux/s390/sysdep.h b/sysdeps/unix/sysv/linux/s390/sysdep.h index eefbd8f007..386efb1896 100644 --- a/sysdeps/unix/sysv/linux/s390/sysdep.h +++ b/sysdeps/unix/sysv/linux/s390/sysdep.h @@ -20,8 +20,8 @@ #define VDSO_HASH 123718585 /* List of system calls which are supported as vsyscalls. */ -#define HAVE_CLOCK_GETRES_VSYSCALL 1 -#define HAVE_CLOCK_GETTIME_VSYSCALL 1 -#define HAVE_GETTIMEOFDAY_VSYSCALL 1 -#define HAVE_GETCPU_VSYSCALL 1 +#define HAVE_CLOCK_GETRES_VSYSCALL "__kernel_clock_getres" +#define HAVE_CLOCK_GETTIME_VSYSCALL "__kernel_clock_gettime" +#define HAVE_GETTIMEOFDAY_VSYSCALL "__kernel_gettimeofday" +#define HAVE_GETCPU_VSYSCALL "__kernel_getcpu" diff --git a/sysdeps/unix/sysv/linux/sparc/init-first.c b/sysdeps/unix/sysv/linux/sparc/init-first.c deleted file mode 100644 index bdaa78fd32..0000000000 --- a/sysdeps/unix/sysv/linux/sparc/init-first.c +++ /dev/null @@ -1,42 +0,0 @@ -/* SPARC VDSO initialization - Copyright (C) 2018-2019 Free Software Foundation, Inc. - - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2.1 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include - -long int (*VDSO_SYMBOL (gettimeofday)) (struct timeval *, void *) - attribute_hidden; -long int (*VDSO_SYMBOL (clock_gettime)) (clockid_t, struct timespec *) - attribute_hidden; - -static inline void -_libc_vdso_platform_setup (void) -{ - void *p = get_vdso_symbol ("__vdso_gettimeofday"); - PTR_MANGLE (p); - VDSO_SYMBOL (gettimeofday) = p; - - p = get_vdso_symbol ("__vdso_clock_gettime"); - PTR_MANGLE (p); - VDSO_SYMBOL (clock_gettime) = p; -} - -#define VDSO_SETUP _libc_vdso_platform_setup - -#include diff --git a/sysdeps/unix/sysv/linux/sparc/libc-vdso.h b/sysdeps/unix/sysv/linux/sparc/libc-vdso.h deleted file mode 100644 index d20afcdf04..0000000000 --- a/sysdeps/unix/sysv/linux/sparc/libc-vdso.h +++ /dev/null @@ -1,29 +0,0 @@ -/* VDSO function pointer declarations. - Copyright (C) 2018-2019 Free Software Foundation, Inc. - - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library. If not, see - . */ - -#ifndef _LIBC_VDSO_H -#define _LIBC_VDSO_H - -#include - -extern long int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *) - attribute_hidden; -extern long int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *); - -#endif /* _LIBC_VDSO_H */ diff --git a/sysdeps/unix/sysv/linux/sparc/sysdep.h b/sysdeps/unix/sysv/linux/sparc/sysdep.h index 3bfb1fc60e..925b57082d 100644 --- a/sysdeps/unix/sysv/linux/sparc/sysdep.h +++ b/sysdeps/unix/sysv/linux/sparc/sysdep.h @@ -45,8 +45,8 @@ # define VDSO_HASH 61765110 /* List of system calls which are supported as vsyscalls. */ -# define HAVE_CLOCK_GETTIME_VSYSCALL 1 -# define HAVE_GETTIMEOFDAY_VSYSCALL 1 +# define HAVE_CLOCK_GETTIME_VSYSCALL "__vdso_clock_gettime" +# define HAVE_GETTIMEOFDAY_VSYSCALL "__vdso_gettimeofday" #undef INLINE_SYSCALL #define INLINE_SYSCALL(name, nr, args...) \ diff --git a/sysdeps/unix/sysv/linux/sysdep-vdso.h b/sysdeps/unix/sysv/linux/sysdep-vdso.h index 5fec208380..3da5417fff 100644 --- a/sysdeps/unix/sysv/linux/sysdep-vdso.h +++ b/sysdeps/unix/sysv/linux/sysdep-vdso.h @@ -19,7 +19,7 @@ #ifndef SYSDEP_VDSO_LINUX_H # define SYSDEP_VDSO_LINUX_H -#define VDSO_SYMBOL(__name) __vdso_##__name +#include #ifndef INTERNAL_VSYSCALL_CALL # define INTERNAL_VSYSCALL_CALL(funcptr, err, nr, args...) \ diff --git a/sysdeps/unix/sysv/linux/x86/libc-vdso.h b/sysdeps/unix/sysv/linux/x86/libc-vdso.h deleted file mode 100644 index c9aa1c8a72..0000000000 --- a/sysdeps/unix/sysv/linux/x86/libc-vdso.h +++ /dev/null @@ -1,33 +0,0 @@ -/* Resolve function pointers to VDSO functions. - Copyright (C) 2005-2019 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#ifndef _LIBC_VDSO_H -#define _LIBC_VDSO_H - -#include -#include - -#include - -extern long int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *) - attribute_hidden; - -extern long int (*VDSO_SYMBOL(getcpu)) (unsigned *, unsigned *, void *) - attribute_hidden; - -#endif /* _LIBC_VDSO_H */ diff --git a/sysdeps/unix/sysv/linux/x86_64/init-first.c b/sysdeps/unix/sysv/linux/x86_64/init-first.c deleted file mode 100644 index aede1c858d..0000000000 --- a/sysdeps/unix/sysv/linux/x86_64/init-first.c +++ /dev/null @@ -1,48 +0,0 @@ -/* Initialization code run first thing by the ELF startup code. Linux/x86-64. - Copyright (C) 2007-2019 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include -#include - -long int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *) - attribute_hidden; -long int (*VDSO_SYMBOL(getcpu)) (unsigned *, unsigned *, void *) - attribute_hidden; - -extern __typeof (clock_gettime) __syscall_clock_gettime attribute_hidden; - - -static inline void -__vdso_platform_setup (void) -{ - void *p = get_vdso_symbol ("__vdso_clock_gettime"); - if (p == NULL) - p = __syscall_clock_gettime; - PTR_MANGLE (p); - VDSO_SYMBOL(clock_gettime) = p; - - p = get_vdso_symbol ("__vdso_getcpu"); - PTR_MANGLE (p); - VDSO_SYMBOL(getcpu) = p; -} - -#define VDSO_SETUP __vdso_platform_setup - -#include diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/sysdep.h index 197329f4dc..4541c0d492 100644 --- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h +++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h @@ -374,9 +374,9 @@ # define VDSO_HASH 61765110 /* List of system calls which are supported as vsyscalls. */ -# define HAVE_CLOCK_GETTIME_VSYSCALL 1 -# define HAVE_GETTIMEOFDAY_VSYSCALL 1 -# define HAVE_GETCPU_VSYSCALL 1 +# define HAVE_CLOCK_GETTIME_VSYSCALL "__vdso_clock_gettime" +# define HAVE_GETTIMEOFDAY_VSYSCALL "__vdso_gettimeofday" +# define HAVE_GETCPU_VSYSCALL "__vdso_getcpu" # define SINGLE_THREAD_BY_GLOBAL 1 From patchwork Thu Sep 5 20:56:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1158681 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-105065-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="kRtlFbee"; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="dc8kHJ2S"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46PY0F5YkVz9s00 for ; Fri, 6 Sep 2019 06:57:01 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=nL6TdTg7GtKc3oF8nkaG+FAIcX/ay8V whcHtRURlW5WVdDn6yS66rbKWrdAChXU1ZKBdUjsdtAq1HO2bKvV4NmTdhEwDQ3g NEXU9Rhez6G3ZQBVv55OmExafb2kRSVr2C5knleHirj+1qBzuMb18ScwkcMF6GCB 0mTFGYD18S/M= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; s=default; bh=nceBQ6hVKyP3HuZ9ZuQ8maw/wH4=; b=kRtlF beeghxZLcdBZyyoAazculvyjkv4nRmkvzBgHyXn1nMjkR0PW+hrD1LJAtoudy8q4 O4sfWV9Igm3fHDeic4MlpaPxsxR9soShwaxusGLrti5EvSeudB23QMcME8/t4Ays UFBPKq7nPhfcnhav7xzhxjnDznofvhYoHJdVuo= Received: (qmail 116697 invoked by alias); 5 Sep 2019 20:56:34 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 116618 invoked by uid 89); 5 Sep 2019 20:56:33 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mail-qt1-f182.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=uF6VWzgOgPXbytf1jDxQtnk29kzBnBa+AO2W3HtkS2U=; b=dc8kHJ2SRJagq5tVshhY/RHR72OMPlLa0PPHL0DpSK/p4xzaquRNZXls/ZxbU6vuR8 6uKKriJi9nzoP+7hB17neBkO7VEqvBtTQfNDJOhTQTKS3Njk4Q8EqgNqqMrr4ATK0lNH t8Iz77KVcFEe7MhLSSNfvNyK6eCduskWo9EdQTt83dwaH+UIXFdqdnQ+x7mYOoBCgUVl XWK7meltjhJcvQ4heX4HQ8xngcsY2eKLZky7/2NTKh60KTeggdH/oiJSkvRnovlGOVaE RjPzSALr7Tdi/mEVZy+/KnIVxI2ZGyKu0ACLbT9pC57fcT2QpLrcDYkI1SJSPE5BMiqu RHkg== From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 3/8] Enable vDSO on interposed malloc linked statically Date: Thu, 5 Sep 2019 17:56:15 -0300 Message-Id: <20190905205620.4646-3-adhemerval.zanella@linaro.org> In-Reply-To: <20190905205620.4646-1-adhemerval.zanella@linaro.org> References: <20190905205620.4646-1-adhemerval.zanella@linaro.org> For statically linked binaries, _dl_non_dynamic_init (csu/init-first.c:74) calls malloc before the vDSO is properly initialized (it will fully usable only after VDSO_SETUP call). The bug is triggered for the cases where an interposed malloc calls clock_gettime or any other implementation that may call a vDSO symbol. It is because PTR_DEMANDLE at {INLINE,INTERNAL}_VSYSCALL is called with uninitialized __vdso_* pointer value, which should be done by PTR_MANGLE (zero-initialized value in this case is invalid). The patch fixes by adding an extra hook before _dl_non_dynamic_init which setup the initial __vdso_* pointer symbol to an mangled NULL value. For NULL mangled values {INLINE,INTERNAL}_VSYSCALL issues the syscall directly in fallback code path. Once the __vdso_* is setup the vsyscall branches to vDSO. Checked on x86_64-linux-gnu. [BZ #24967] * sysdeps/unix/sysv/linux/init-first.c (libc_vdso_mangled_symbol): New symbol. (__libc_vdso_platform_setup): Add an option to call it to initialize the hooks to null values. (VDSO_PRE_SETUP): Define. * csu/init-first.c (_init): Add a pre-hook to initialize the vDSO internal pointer. * malloc/tst-interpose-aux.c (allocation_header): Add ts member. (malloc_internal): Call clock_gettime. --- csu/init-first.c | 8 ++++++ malloc/tst-interpose-aux.c | 5 ++++ sysdeps/unix/sysv/linux/init-first.c | 37 +++++++++++++++++++--------- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/csu/init-first.c b/csu/init-first.c index 10762b61f5..d984419554 100644 --- a/csu/init-first.c +++ b/csu/init-first.c @@ -69,6 +69,14 @@ _init (int argc, char **argv, char **envp) __environ = envp; #ifndef SHARED + /* Initialize the vDSO internal pointers to mangled zero value. It makes + the {INTERNAL,INLINE}_VSYSCALL macro to fallback to direct syscall + and allows call the symbol that might the vDSO on _dl_non_dynamic_init + (for instance clock_gettime on an interposed malloc). */ +# ifdef VDSO_PRE_SETUP + VDSO_PRE_SETUP (); +# endif + /* First the initialization which normally would be done by the dynamic linker. */ _dl_non_dynamic_init (); diff --git a/malloc/tst-interpose-aux.c b/malloc/tst-interpose-aux.c index bf86224401..de62d436bc 100644 --- a/malloc/tst-interpose-aux.c +++ b/malloc/tst-interpose-aux.c @@ -28,6 +28,7 @@ #include #include #include +#include #if INTERPOSE_THREADS #include @@ -96,6 +97,7 @@ struct __attribute__ ((aligned (__alignof__ (max_align_t)))) allocation_header { size_t allocation_index; size_t allocation_size; + struct timespec ts; }; /* Array of known allocations, to track invalid frees. */ @@ -166,6 +168,9 @@ malloc_internal (size_t size) .allocation_index = index, .allocation_size = allocation_size }; + /* Check if calling a symbol which may use the vDSO does not fail. + The CLOCK_REALTIME should be supported on all systems. */ + clock_gettime (CLOCK_REALTIME, &allocations[index]->ts); return allocations[index] + 1; } diff --git a/sysdeps/unix/sysv/linux/init-first.c b/sysdeps/unix/sysv/linux/init-first.c index d90ca820be..a23e5d9f6e 100644 --- a/sysdeps/unix/sysv/linux/init-first.c +++ b/sysdeps/unix/sysv/linux/init-first.c @@ -44,37 +44,52 @@ long int (*VDSO_SYMBOL(getcpu)) (unsigned *, unsigned *, void *) time_t (*VDSO_SYMBOL(time)) (time_t *) attribute_hidden; #endif +static inline void * +__libc_vdso_mangled_symbol (const char *symbol) +{ + void *vdsop = NULL; + if (symbol != NULL) + vdsop = get_vdso_mangle_symbol (symbol); + else + PTR_MANGLE (vdsop); + return vdsop; +} + static inline void -__libc_vdso_platform_setup (void) +__libc_vdso_platform_setup (bool initial) { #ifdef HAVE_CLOCK_GETTIME_VSYSCALL - VDSO_SYMBOL(clock_gettime) - = get_vdso_mangle_symbol (HAVE_CLOCK_GETTIME_VSYSCALL); + VDSO_SYMBOL(clock_gettime) = + __libc_vdso_mangled_symbol (initial ? NULL : HAVE_CLOCK_GETTIME_VSYSCALL); #endif #ifdef HAVE_CLOCK_GETRES_VSYSCALL - VDSO_SYMBOL(clock_getres) - = get_vdso_mangle_symbol (HAVE_CLOCK_GETRES_VSYSCALL); + VDSO_SYMBOL(clock_getres) = + __libc_vdso_mangled_symbol (initial ? NULL : HAVE_CLOCK_GETRES_VSYSCALL); #endif #ifdef HAVE_GETTIMEOFDAY_VSYSCALL - VDSO_SYMBOL(gettimeofday) - = get_vdso_mangle_symbol (HAVE_GETTIMEOFDAY_VSYSCALL); + VDSO_SYMBOL(gettimeofday) = + __libc_vdso_mangled_symbol (initial ? NULL : HAVE_GETTIMEOFDAY_VSYSCALL); #endif #ifdef HAVE_GETCPU_VSYSCALL - VDSO_SYMBOL(getcpu) = get_vdso_mangle_symbol (HAVE_GETCPU_VSYSCALL); + VDSO_SYMBOL(getcpu) = + __libc_vdso_mangled_symbol (initial ? NULL : HAVE_GETCPU_VSYSCALL); #endif #ifdef HAVE_TIME_VSYSCALL - VDSO_SYMBOL(time) = get_vdso_mangle_symbol (HAVE_TIME_VSYSCALL); + VDSO_SYMBOL(time) = + __libc_vdso_mangled_symbol (initial ? NULL : HAVE_TIME_VSYSCALL); #endif #ifdef VDSO_SETUP_ARCH - VDSO_SETUP_ARCH (); + if (!initial) + VDSO_SETUP_ARCH (); #endif } -#define VDSO_SETUP __libc_vdso_platform_setup +#define VDSO_PRE_SETUP() ({ __libc_vdso_platform_setup (true); }) +#define VDSO_SETUP() ({ __libc_vdso_platform_setup (false); }) #include From patchwork Thu Sep 5 20:56:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1158680 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-105064-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="wbT7oGf7"; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="jr6x+4ga"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46PY0518PPz9s00 for ; Fri, 6 Sep 2019 06:56:52 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=wd10v/8g3flZcOjIuRnX8RKyOoppXlE 5XqfHRMfiDmBwstm3SW1Q2JtpnjCUiX91LTZVFdI/15n5WyOIreJhkJid2qXISK+ 1TGRAdKeUOV3Y4suUM3C78WrBySTXVCjZXhoyiqxwXMPRtjQIiON6o9DH7qCu81J b/xKFnLoldfA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; s=default; bh=GS14GPDkZkTkOM6it7Jp3TXtUWw=; b=wbT7o Gf7FxqkONLDYdwHA4dnTI/L911+DM9v5De0B0aAEW58CNzelS36+pBEUcEauMjaR 7+AVtJDfWzxmPKGo2mxdeIRty3/BdnN3Mj46eQfchqsiwMcyvHX27QyyyZkCDG8C VYigWALYt/DgYanhKVsoCulaiAC2hrfU6UQSK0= Received: (qmail 116679 invoked by alias); 5 Sep 2019 20:56:34 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 116616 invoked by uid 89); 5 Sep 2019 20:56:33 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=HX-Spam-Relays-External:209.85.160.195, H*RU:209.85.160.195, HX-Received:60a, simplifies X-HELO: mail-qt1-f195.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=lKtwSvhpuwDh8vRnSPAaaDI5N0Z1HZNrZLhpf0iPV7w=; b=jr6x+4gaQj+FRHx2Ni2vSg3EV3q8lSRa3K28MnS50JP0D7bLf+edeAbkWisB4+p1DX uGauFUqIlFgX6dfuFhtzrCyRoZsnO+s6+S0QzjdXr56Nr8mbEqCHhbPqR4ATuqmRnKm3 2drP4JqfKV36NKJqyPdF0BFbv5jna+VRgmFhbJj+lyW4YrjdkU/YzuvsuDNBhqFtFX3d jVAhWM++F6p8qItcWb7MeJ98qIKCX/CYRLg3k1UWVfGCDkkpM81za73ZvETiR8Oug/v9 Kxzkro/DYttwf5IDfvSsxyM1mvS23+zxLoKDCcwykJQMuAaDe+YWHT/k/Ti/M+TBl8Rm umnA== From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 4/8] powerpc: Simplify vsyscall internal macros Date: Thu, 5 Sep 2019 17:56:16 -0300 Message-Id: <20190905205620.4646-4-adhemerval.zanella@linaro.org> In-Reply-To: <20190905205620.4646-1-adhemerval.zanella@linaro.org> References: <20190905205620.4646-1-adhemerval.zanella@linaro.org> Changes from previous version: - Fixed the issue with the removal of the CR0.SO check on INTERNAL_VSYSCALL_CALL. --- This patch simplifies the powerpc internal macros for vDSO calls by: - Removing INTERNAL_VSYSCALL_NO_SYSCALL_FALLBACK, used solely on get_timebase_freq. - Adjust INTERNAL_VSYSCALL_CALL_TYPE powerpc32 to follow powerpc64 argument ordering. - Use HAVE_*_VSYSCALL instead of explicit strings. - Make powerpc libc-vdso.h include generic implementation. No semantic change expected, checked on powerpc-linux-gnu-power4, powerpc64-linux-gnu, and powerpc64le-linux-gnu. * sysdeps/unix/sysv/linux/libc-vdso.h (VDSO_IFUNC_RET): Define if not defined. * sysdeps/unix/sysv/linux/powerpc/get_timebase_freq.c (__get_timebase_freq): Remove use of INTERNAL_VSYSCALL_NO_SYSCALL_FALLBACK. (get_timebase_freq_fallback): New symbol. * sysdeps/unix/sysv/linux/powerpc/gettimeofday.c (time): Use HAVE_GETTIMEOFDAY_VSYSCALL. * sysdeps/unix/sysv/linux/powerpc/time.c (gettimeofday): Use HAVE_TIME_VSYSCALL. * sysdeps/unix/sysv/linux/powerpc/libc-vdso.h: Include generic implementation. * sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h (INTERNAL_VSYSCALL_CALL_TYPE): Make calling convention similar to powerpc64. (INTERNAL_VSYSCALL_NO_SYSCALL_FALLBACK): Remove macro. * .../sysv/linux/powerpc/powerpc64/sysdep.h (INTERNAL_VSYSCALL_NO_SYSCALL_FALLBACK): Likewise. * sysdeps/unix/sysv/linux/powerpc/sysdep.h (HAVE_GETTIMEOFDAY_VSYSCALL): Define. --- sysdeps/unix/sysv/linux/libc-vdso.h | 7 ++++++ .../sysv/linux/powerpc/get_timebase_freq.c | 24 ++++++++++++------- .../unix/sysv/linux/powerpc/gettimeofday.c | 2 +- sysdeps/unix/sysv/linux/powerpc/libc-vdso.h | 24 ++++++++++--------- .../sysv/linux/powerpc/powerpc32/sysdep.h | 18 ++------------ .../sysv/linux/powerpc/powerpc64/sysdep.h | 19 +-------------- sysdeps/unix/sysv/linux/powerpc/sysdep.h | 1 + sysdeps/unix/sysv/linux/powerpc/time.c | 2 +- 8 files changed, 41 insertions(+), 56 deletions(-) diff --git a/sysdeps/unix/sysv/linux/libc-vdso.h b/sysdeps/unix/sysv/linux/libc-vdso.h index f681868137..199ae9a033 100644 --- a/sysdeps/unix/sysv/linux/libc-vdso.h +++ b/sysdeps/unix/sysv/linux/libc-vdso.h @@ -21,6 +21,13 @@ #define VDSO_SYMBOL(__name) __vdso_##__name +/* Adjust the return IFUNC value from a vDSO symbol accordingly required + architecture ABI. It is used for powerpc64 elfv1 to create a ODP + entry since kernvel vDSO does not provide it. */ +#ifndef VDSO_IFUNC_RET +# define VDSO_IFUNC_RET(__value) (__value) +#endif + #ifdef HAVE_CLOCK_GETTIME_VSYSCALL extern int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *); #endif diff --git a/sysdeps/unix/sysv/linux/powerpc/get_timebase_freq.c b/sysdeps/unix/sysv/linux/powerpc/get_timebase_freq.c index c245e97526..61ff6e2b2a 100644 --- a/sysdeps/unix/sysv/linux/powerpc/get_timebase_freq.c +++ b/sysdeps/unix/sysv/linux/powerpc/get_timebase_freq.c @@ -23,17 +23,11 @@ #include #include -uint64_t -__get_timebase_freq (void) +static uint64_t +get_timebase_freq_fallback (void) { hp_timing_t result = 0L; -#ifdef SHARED - /* The vDSO does not return an error (it clear cr0.so on returning). */ - INTERNAL_SYSCALL_DECL (err); - result = - INTERNAL_VSYSCALL_NO_SYSCALL_FALLBACK (get_tbfreq, err, uint64_t, 0); -#else /* We read the information from the /proc filesystem. /proc/cpuinfo contains at least one line like: timebase : 33333333 @@ -99,8 +93,20 @@ __get_timebase_freq (void) } } } -#endif return result; } + +uint64_t +__get_timebase_freq (void) +{ + /* The vDSO does not have a fallback mechanism (such calling a syscall). */ + __typeof (VDSO_SYMBOL (get_tbfreq)) vdsop = VDSO_SYMBOL (get_tbfreq); + PTR_DEMANGLE (vdsop); + if (vdsop == NULL) + return get_timebase_freq_fallback (); + + INTERNAL_SYSCALL_DECL (err); + return INTERNAL_VSYSCALL_CALL_TYPE (vdsop, err, uint64_t, 0); +} weak_alias (__get_timebase_freq, __ppc_get_timebase_freq) diff --git a/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c b/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c index c59d5ddc10..e046594d40 100644 --- a/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c +++ b/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c @@ -58,7 +58,7 @@ __gettimeofday_syscall (struct timeval *tv, struct timezone *tz) } # define INIT_ARCH() \ - void *vdso_gettimeofday = get_vdso_symbol ("__kernel_gettimeofday") + void *vdso_gettimeofday = get_vdso_symbol (HAVE_GETTIMEOFDAY_VSYSCALL) /* If the vDSO is not available we fall back syscall. */ libc_ifunc_hidden (__redirect___gettimeofday, __gettimeofday, diff --git a/sysdeps/unix/sysv/linux/powerpc/libc-vdso.h b/sysdeps/unix/sysv/linux/powerpc/libc-vdso.h index 47e925493b..170adcc964 100644 --- a/sysdeps/unix/sysv/linux/powerpc/libc-vdso.h +++ b/sysdeps/unix/sysv/linux/powerpc/libc-vdso.h @@ -22,17 +22,9 @@ #include #include -#include_next - -extern unsigned long long (*VDSO_SYMBOL(get_tbfreq)) (void); -#if defined(__PPC64__) || defined(__powerpc64__) -extern void *VDSO_SYMBOL(sigtramp_rt64); -#else -extern void *VDSO_SYMBOL(sigtramp32); -extern void *VDSO_SYMBOL(sigtramp_rt32); -#endif #if (defined(__PPC64__) || defined(__powerpc64__)) && _CALL_ELF != 2 +# include /* The correct solution is for _dl_vdso_vsym to return the address of the OPD for the kernel VDSO function. That address would then be stored in the __vdso_* variables and returned as the result of the IFUNC resolver function. @@ -51,7 +43,7 @@ extern void *VDSO_SYMBOL(sigtramp_rt32); are processed immediately at startup the resolver functions and this code need not be thread-safe, but if the caller writes to a PLT slot it must do so in a thread-safe manner with all the required barriers. */ -#define VDSO_IFUNC_RET(value) \ +# define VDSO_IFUNC_RET(value) \ ({ \ static Elf64_FuncDesc vdso_opd = { .fd_toc = ~0x0 }; \ vdso_opd.fd_func = (Elf64_Addr)value; \ @@ -59,7 +51,17 @@ extern void *VDSO_SYMBOL(sigtramp_rt32); }) #else -#define VDSO_IFUNC_RET(value) ((void *) (value)) +# define VDSO_IFUNC_RET(value) ((void *) (value)) +#endif + +#include_next + +extern unsigned long long (*VDSO_SYMBOL(get_tbfreq)) (void); +#if defined(__PPC64__) || defined(__powerpc64__) +extern void *VDSO_SYMBOL(sigtramp_rt64); +#else +extern void *VDSO_SYMBOL(sigtramp32); +extern void *VDSO_SYMBOL(sigtramp_rt32); #endif #endif /* _LIBC_VDSO_H */ diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h b/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h index f459543fcd..703c668a92 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h @@ -41,7 +41,7 @@ function call, with the exception of LR (which is needed for the "sc; bnslr+" sequence) and CR (where only CR0.SO is clobbered to signal an error return status). */ -# define INTERNAL_VSYSCALL_CALL_TYPE(funcptr, err, nr, type, args...) \ +# define INTERNAL_VSYSCALL_CALL_TYPE(funcptr, err, type, nr, args...) \ ({ \ register void *r0 __asm__ ("r0"); \ register long int r3 __asm__ ("r3"); \ @@ -69,7 +69,7 @@ }) #define INTERNAL_VSYSCALL_CALL(funcptr, err, nr, args...) \ - INTERNAL_VSYSCALL_CALL_TYPE(funcptr, err, nr, long int, args) + INTERNAL_VSYSCALL_CALL_TYPE(funcptr, err, long int, nr, args) # undef INLINE_SYSCALL # define INLINE_SYSCALL(name, nr, args...) \ @@ -131,20 +131,6 @@ # undef INTERNAL_SYSCALL_ERRNO # define INTERNAL_SYSCALL_ERRNO(val, err) (val) -# define INTERNAL_VSYSCALL_NO_SYSCALL_FALLBACK(name, err, type, nr, args...) \ - ({ \ - type sc_ret = ENOSYS; \ - \ - __typeof (__vdso_##name) vdsop = __vdso_##name; \ - PTR_DEMANGLE (vdsop); \ - if (vdsop != NULL) \ - sc_ret = \ - INTERNAL_VSYSCALL_CALL_TYPE (vdsop, err, nr, type, ##args); \ - else \ - err = 1 << 28; \ - sc_ret; \ - }) - # define LOADARGS_0(name, dummy) \ r0 = name # define LOADARGS_1(name, __arg1) \ diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h b/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h index 06222f52e6..e7b2fce05f 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h @@ -45,22 +45,6 @@ #endif /* __ASSEMBLER__ */ -/* This version is for internal uses when there is no desire - to set errno */ -#define INTERNAL_VSYSCALL_NO_SYSCALL_FALLBACK(name, err, type, nr, args...) \ - ({ \ - type sc_ret = ENOSYS; \ - \ - __typeof (__vdso_##name) vdsop = __vdso_##name; \ - PTR_DEMANGLE (vdsop); \ - if (vdsop != NULL) \ - sc_ret = \ - INTERNAL_VSYSCALL_CALL_TYPE (vdsop, err, type, nr, ##args); \ - else \ - err = 1 << 28; \ - sc_ret; \ - }) - /* Define a macro which expands inline into the wrapper code for a system call. This use is for internal calls that do not need to handle errors normally. It will never touch errno. This returns just what the kernel @@ -94,10 +78,9 @@ #define INTERNAL_VSYSCALL_CALL(funcptr, err, nr, args...) \ INTERNAL_VSYSCALL_CALL_TYPE(funcptr, err, long int, nr, args) -#undef INLINE_SYSCALL - /* This version is for kernels that implement system calls that behave like function calls as far as register saving. */ +#undef INLINE_SYSCALL #define INLINE_SYSCALL(name, nr, args...) \ ({ \ INTERNAL_SYSCALL_DECL (sc_err); \ diff --git a/sysdeps/unix/sysv/linux/powerpc/sysdep.h b/sysdeps/unix/sysv/linux/powerpc/sysdep.h index 20167615c8..357d1b5243 100644 --- a/sysdeps/unix/sysv/linux/powerpc/sysdep.h +++ b/sysdeps/unix/sysv/linux/powerpc/sysdep.h @@ -24,6 +24,7 @@ #define HAVE_CLOCK_GETTIME_VSYSCALL "__kernel_clock_gettime" #define HAVE_GETCPU_VSYSCALL "__kernel_getcpu" #define HAVE_TIME_VSYSCALL "__kernel_time" +#define HAVE_GETTIMEOFDAY_VSYSCALL "__kernel_gettimeofday" #define HAVE_GET_TBFREQ "__kernel_get_tbfreq" #if defined(__PPC64__) || defined(__powerpc64__) diff --git a/sysdeps/unix/sysv/linux/powerpc/time.c b/sysdeps/unix/sysv/linux/powerpc/time.c index 38477bce8b..f0537a2307 100644 --- a/sysdeps/unix/sysv/linux/powerpc/time.c +++ b/sysdeps/unix/sysv/linux/powerpc/time.c @@ -67,7 +67,7 @@ time_syscall (time_t *t) } # define INIT_ARCH() \ - void *vdso_time = get_vdso_symbol ("__kernel_time"); + void *vdso_time = get_vdso_symbol (HAVE_TIME_VSYSCALL); /* If the vDSO is not available we fall back to the syscall. */ libc_ifunc_hidden (__redirect_time, time, From patchwork Thu Sep 5 20:56:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1158682 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-105066-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="cMFhYFR9"; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="cr++hD3x"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46PY0Q3rPvz9s00 for ; Fri, 6 Sep 2019 06:57:10 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=vZJ5Sle3Dvx2RTQpBL/kISHpKGeOEnr 9UoZT8g6ZJMkvsTUgLrqG9qQ5tdVDJ+PgWcVbX8OtrLtIUSNSqWYbcr+JL/abKBZ u092e+2RaGVNizljXN7HE9O0UYZVGHNbXUkF34jGs6hQa4qmchf175hr9kvVOK2U ulCjGKI3pY5Y= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; s=default; bh=pQspx06S0kWLVMl73gnYpOIwKe4=; b=cMFhY FR9XFXO1M2E39SriWa8m8OidxqXBj7A/HHSs20mlxBhThFfI++up8omphzEuhUMd lJLc0+3hgEW2fzXOY7IkXpWpDO6nC4nqLQp8VNU4Zqn86IwLRTQI6BjI0WTZmBMm VIg7TGCz9OHHUormQfgFpuaHj8KYHJ0bewvE2o= Received: (qmail 116801 invoked by alias); 5 Sep 2019 20:56:34 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 116690 invoked by uid 89); 5 Sep 2019 20:56:34 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=consolidate X-HELO: mail-qt1-f194.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=gwUlLK9DTxZpgKw8a8M/qTuEBhoxxCH3anBUMULq41c=; b=cr++hD3xymsBhGS3WaFeyLJuBdM23u5Xd57OXHlkDYIO5LPBKLrjv03NUUWtmEeag7 K4Ij+KfHlczjVr4mgE9Yc6gdq0S+U4Q3/ZqaFys1wGEhUtDfA6k7gV92kSjQN+8c5asL 0qCLDtSRIR7HAgJMPm/fUpgZy6dov6ezI0RCqfaYdRLsC3dMKdDsI5YY3k6jGom/K9qH KxaEdcAam2mBvh9N4tDBOu4jcqZt4MLtxy0e0s/oiB6UTGzyc8rsDx9FWpyElWd3f0gE 1GFyjD8Rw9vbU9w1FeMg2LwswuEm3i0o+jf8gryzgKbmZN8pMvWaLqDBO2I+lFTcnmy/ tvOg== From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 5/8] mips: Consolidate INTERNAL_VSYSCALL_CALL Date: Thu, 5 Sep 2019 17:56:17 -0300 Message-Id: <20190905205620.4646-5-adhemerval.zanella@linaro.org> In-Reply-To: <20190905205620.4646-1-adhemerval.zanella@linaro.org> References: <20190905205620.4646-1-adhemerval.zanella@linaro.org> This patch consolidates the mips, mips64, and mips64-n32 INTERNAL_VSYSCALL_CALL on a single implementation. No semantic changes. I checked against a build for mips-linux-gnu, mips64-linux-gnu, and mips64-n32-linux-gnu. * sysdeps/unix/sysv/linux/mips/mips32/sysdep.h (INTERNAL_VSYSCALL_CALL): Remove. * sysdeps/unix/sysv/linux/mips/mips64/n32/sysdep.h (INTERNAL_VSYSCALL_CALL): Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n64/sysdep.h (INTERNAL_VSYSCALL_CALL): Likewise. * sysdeps/unix/sysv/linux/mips/sysdep.h (INTERNAL_VSYSCALL_CALL): New macro. --- sysdeps/unix/sysv/linux/mips/mips32/sysdep.h | 12 ------------ sysdeps/unix/sysv/linux/mips/mips64/n32/sysdep.h | 12 ------------ sysdeps/unix/sysv/linux/mips/mips64/n64/sysdep.h | 12 ------------ sysdeps/unix/sysv/linux/mips/sysdep.h | 16 ++++++++++++++++ 4 files changed, 16 insertions(+), 36 deletions(-) diff --git a/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h b/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h index ebe397b701..bfcb916f15 100644 --- a/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h +++ b/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h @@ -349,18 +349,6 @@ libc_hidden_proto (__mips_syscall7, nomips16) #define __SYSCALL_CLOBBERS "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13", \ "$14", "$15", "$24", "$25", "hi", "lo", "memory" -/* Standard MIPS syscalls have an error flag, and return a positive errno - when the error flag is set. Emulate this behaviour for vsyscalls so that - the INTERNAL_SYSCALL_{ERROR_P,ERRNO} macros work correctly. */ -#define INTERNAL_VSYSCALL_CALL(funcptr, err, nr, args...) \ - ({ \ - long _ret = funcptr (args); \ - err = ((unsigned long) (_ret) >= (unsigned long) -4095L); \ - if (err) \ - _ret = -_ret; \ - _ret; \ - }) - #endif /* __ASSEMBLER__ */ /* Pointer mangling is not yet supported for MIPS. */ diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/sysdep.h b/sysdeps/unix/sysv/linux/mips/mips64/n32/sysdep.h index bb49429c30..49e94a1706 100644 --- a/sysdeps/unix/sysv/linux/mips/mips64/n32/sysdep.h +++ b/sysdeps/unix/sysv/linux/mips/mips64/n32/sysdep.h @@ -297,18 +297,6 @@ #define __SYSCALL_CLOBBERS "$1", "$3", "$10", "$11", "$12", "$13", \ "$14", "$15", "$24", "$25", "hi", "lo", "memory" -/* Standard MIPS syscalls have an error flag, and return a positive errno - when the error flag is set. Emulate this behaviour for vsyscalls so that - the INTERNAL_SYSCALL_{ERROR_P,ERRNO} macros work correctly. */ -#define INTERNAL_VSYSCALL_CALL(funcptr, err, nr, args...) \ - ({ \ - long _ret = funcptr (args); \ - err = ((unsigned long) (_ret) >= (unsigned long) -4095L); \ - if (err) \ - _ret = -_ret; \ - _ret; \ - }) - #endif /* __ASSEMBLER__ */ /* Pointer mangling is not yet supported for MIPS. */ diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n64/sysdep.h b/sysdeps/unix/sysv/linux/mips/mips64/n64/sysdep.h index 84a1ff186b..5911a62e5b 100644 --- a/sysdeps/unix/sysv/linux/mips/mips64/n64/sysdep.h +++ b/sysdeps/unix/sysv/linux/mips/mips64/n64/sysdep.h @@ -293,18 +293,6 @@ #define __SYSCALL_CLOBBERS "$1", "$3", "$10", "$11", "$12", "$13", \ "$14", "$15", "$24", "$25", "hi", "lo", "memory" -/* Standard MIPS syscalls have an error flag, and return a positive errno - when the error flag is set. Emulate this behaviour for vsyscalls so that - the INTERNAL_SYSCALL_{ERROR_P,ERRNO} macros work correctly. */ -#define INTERNAL_VSYSCALL_CALL(funcptr, err, nr, args...) \ - ({ \ - long _ret = funcptr (args); \ - err = ((unsigned long) (_ret) >= (unsigned long) -4095L); \ - if (err) \ - _ret = -_ret; \ - _ret; \ - }) - #endif /* __ASSEMBLER__ */ /* Pointer mangling is not yet supported for MIPS. */ diff --git a/sysdeps/unix/sysv/linux/mips/sysdep.h b/sysdeps/unix/sysv/linux/mips/sysdep.h index 58a7244581..77b1f9c2fb 100644 --- a/sysdeps/unix/sysv/linux/mips/sysdep.h +++ b/sysdeps/unix/sysv/linux/mips/sysdep.h @@ -22,3 +22,19 @@ /* List of system calls which are supported as vsyscalls. */ #define HAVE_CLOCK_GETTIME_VSYSCALL "__vdso_gettimeofday" #define HAVE_GETTIMEOFDAY_VSYSCALL "__vdso_clock_gettime" + +#ifndef __ASSEMBLER__ + +/* Standard MIPS syscalls have an error flag, and return a positive errno + when the error flag is set. Emulate this behaviour for vsyscalls so that + the INTERNAL_SYSCALL_{ERROR_P,ERRNO} macros work correctly. */ +#define INTERNAL_VSYSCALL_CALL(funcptr, err, nr, args...) \ + ({ \ + long _ret = funcptr (args); \ + err = ((unsigned long) (_ret) >= (unsigned long) -4095L); \ + if (err) \ + _ret = -_ret; \ + _ret; \ + }) + +#endif /* __ASSEMBLER__ */ From patchwork Thu Sep 5 20:56:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1158683 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-105067-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="gojoXM1B"; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="AW7yKBkI"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46PY0Z4cBsz9s00 for ; Fri, 6 Sep 2019 06:57:18 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=a5v15SNDtObBgA7eFYAAgTz5FuTejdH K3tO5Bn2dUL9SZum/nKba8qPd8n17/8pW9Pnc70BaX4ktq9iipMVwHwJtHCWIdRF tRqVcZaPAGXhvYkTqYrmnwTciGdexk3UDxPAoH0LsRW4lshNVmHjb6XTvTRYvwTo JOFcKEJQ99Dc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; s=default; bh=sib1OYOaMtWG8J+/DLpEq6OsYLE=; b=gojoX M1B3qHzSrd9GGPI7QtDrqCyOVsKHnV4W/ZYCPnAmfyRFmej92V268foM9VBucdRO +NhC6Whzsf02lfVtYBHa/q/d9VAs97KB6WddkaNUDj5IF0y/GtUK5XqHPsJ83xz0 2fxxX5/TSHnY+6Z0Sf4DKIta7psbArZOV4wjSg= Received: (qmail 116978 invoked by alias); 5 Sep 2019 20:56:35 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 116867 invoked by uid 89); 5 Sep 2019 20:56:34 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mail-qk1-f194.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=a2hhNon9R39tQEg3zKHZ8tICMNEpxzwjxLO9GgnyuHc=; b=AW7yKBkILYogkDa0k/JMr7AknjEAozKgBIU1XZ8sR4mUbIX7BXl8VQBdbcyPai8s9K XDkoCFniddevbT3qET6+zvIcqg8p8+JOg1MiyJFE0AVsVXilIb97lURpNi3WMzVtYcC7 uPzbIVN4CYJTlNsCfFKYhy1Z+TVn9W21En3mFFBBrdl1Qo9bCPVyeERkMUI/G/pDFP6G xnvIDirBFr3Hl2np9UfbRUqj0K7dGVjjwi97gj2jD1viW7/7wKwJSbp0sMQiUhKV+uqg 07pgdnjYPs6cQI1u6UaYi0N7SMpXCnf96qNZLoQ0V5BmgntMKK2sxaehvS2knbvCAbiV MVqQ== From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 6/8] sparc64: Use linux generic time implementation Date: Thu, 5 Sep 2019 17:56:18 -0300 Message-Id: <20190905205620.4646-6-adhemerval.zanella@linaro.org> In-Reply-To: <20190905205620.4646-1-adhemerval.zanella@linaro.org> References: <20190905205620.4646-1-adhemerval.zanella@linaro.org> There is no need to sparc64 provide an arch-specific implementation to route to POSIX one (which uses gettimeofday). Linux one already handles the case for architecture that does not have __NR_time. No semantic changes, checked against a build for sparc64-linux-gnu. * sysdeps/unix/sysv/linux/sparc/sparc64/time.c: Remove file. --- sysdeps/unix/sysv/linux/sparc/sparc64/time.c | 1 - 1 file changed, 1 deletion(-) delete mode 100644 sysdeps/unix/sysv/linux/sparc/sparc64/time.c diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/time.c b/sysdeps/unix/sysv/linux/sparc/sparc64/time.c deleted file mode 100644 index 509b580c55..0000000000 --- a/sysdeps/unix/sysv/linux/sparc/sparc64/time.c +++ /dev/null @@ -1 +0,0 @@ -#include From patchwork Thu Sep 5 20:56:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1158685 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-105069-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="ByM1NhIU"; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Z1IDfjiH"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46PY114fpqz9s00 for ; Fri, 6 Sep 2019 06:57:41 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=qVEq7FZqyQ3yVpNBfIGrZhV9tVJZAx5 AqzwQJQSmK3Xee4nIomF/m/wqcldpN5mRk6u9gHQ9iTKhhwMrO+WHbHPWrR88WhB PpK2BIxHEPQn29vr3iHwqmwtSbaRf2dlXXfxoD136IvXpXJIHzneX6HzDEhjTfO5 nc8R5B9SnDsw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; s=default; bh=uP+DErUe9aAoSvdNrl7u4Q66VTQ=; b=ByM1N hIUXqMIBUMWntG7F5fB75H/U01CsHeT/P37Meol8ybB1lQ/ymn4I2FF6dsd42AWs /lBWWaObl7qTSkVpk5qaBpWrujylfvB0F6IHSWvJqokI/09wrOl8GWIBqFi/yfXC MDQykkfcs+1L/iEVTFoLkhWxNoIHKLK49T4m6w= Received: (qmail 117476 invoked by alias); 5 Sep 2019 20:56:39 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 117411 invoked by uid 89); 5 Sep 2019 20:56:39 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS, T_FILL_THIS_FORM_SHORT autolearn=ham version=3.3.1 spammy= X-HELO: mail-qt1-f194.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=3IOo+BI80Erhf+jc53R3uhJBUadI14E1Pzz1NLp8/W8=; b=Z1IDfjiHgKdMsZWSO0xNw0e2IU5b07VghOXdXCBQLNgUMjIwIEsUIDRaPAbzvshat9 OeDrQaRA/9hKb+kN/5ZW1uIV01FefVzzt384HXAlSL/yN6QGNIOLR7h+BoZjSJrYWlKg rzWItHIRbWaW+P3bycj29++m2uvotAsnCXcmA9BUGkjgUW4ShgjF9Y854mC+S0MDd0kk gLscUuFW+oAVu7FRbjxGCtqPrfn2ia13GI9uf6Ao37LwmzDXgxEY9t6l3Kbf3IvpAGt5 PlZIj+6q0plRH2mpNuR+WvMNg4Whl+XaLQiUrasdGrwRoid8yUjEnZxnj6CRWMVGWVgW ErJw== From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 7/8] linux: Consolidate time implementation Date: Thu, 5 Sep 2019 17:56:19 -0300 Message-Id: <20190905205620.4646-7-adhemerval.zanella@linaro.org> In-Reply-To: <20190905205620.4646-1-adhemerval.zanella@linaro.org> References: <20190905205620.4646-1-adhemerval.zanella@linaro.org> Changes from previous version: - Improve comment about hidden_def_redir. - Update due powerpc64 fixes. --- The time syscall has currently 3 possible implementations: 1. Wire-up __NR_time with a vDSO implementation (currently only x86 and powerpc). 2. Wire-up __NR_time (hppa, i686, m68k, microblaze, mips, powerpc, powerpc64, s390, sh4, sparcv9, x86_64). 3. Using internal gettimeofday (aarch64, alpha, arm, mips64, mips64-n32, nios2, s390x, sparc64). This patch consolidates all implementation on Linux generic sysdeps/unix/sysv/linux/time.c. To simplify the code, some changes are made: * The wire-up with vDSO implementation route external calls directly to vDSO through IFUNC. To enable it the architecture need to explicit define USE_TIME_VSYSCALL_IFUNC. * Also, powerpc and x86 tries to route internal time usages to IFUNC mechanism, which is problematic since powerpc32 and i686 does not really support it. Instead, all internal calls are routed to a default internal symbol which in turn calls INTERNAL_VSYSCALL. * Static linking also uses the fallback mechanism which calls INTERNAL_VSYSCALL, so vDSO is used for this case as well. The generic implementation issues a syscall as default, calls the vDSO if the architecture defines HAVE_TIME_VSYSCALL, and route the external calls to iFUNC if the architecture also defines USE_TIME_VSYSCALL_IFUNC. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc-linux-gnu, powerpc64-linux-gnu, powerpc64le-linux-gnu, and aarch64-linux-gnu. * include/libc-symbols.h (hidden_def_redir): New macro. * sysdeps/unix/sysv/linux/i386/sysdep.h (HAVE_TIME_VSYSCALL, USE_TIME_VSYSCALL_IFUNC): Define. * sysdeps/unix/sysv/linux/x86_64/sysdep.h (HAVE_TIME_VSYSCALL, USE_TIME_VSYSCALL_IFUNC): Likewise. * sysdeps/unix/sysv/linux/powerpc/sysdep.h (USE_TIME_VSYSCALL_IFUNC): Likewise. * sysdeps/unix/sysv/linux/i386/time.c: Remove file. * sysdeps/unix/sysv/linux/x86/time.c: Likewise. * sysdeps/unix/sysv/linux/powerpc/time.c: Likewise. * sysdeps/unix/sysv/linux/time.c (time): Handle all possible Linux implementations (wire-up syscall, vDSO implementation, iFUNC). (time_syscall): New function. --- include/libc-symbols.h | 11 ++++ sysdeps/unix/sysv/linux/i386/sysdep.h | 2 + sysdeps/unix/sysv/linux/i386/time.c | 34 ---------- sysdeps/unix/sysv/linux/powerpc/sysdep.h | 1 + sysdeps/unix/sysv/linux/powerpc/time.c | 83 ------------------------ sysdeps/unix/sysv/linux/time.c | 57 +++++++++++++--- sysdeps/unix/sysv/linux/x86/time.c | 60 ----------------- sysdeps/unix/sysv/linux/x86_64/sysdep.h | 2 + 8 files changed, 65 insertions(+), 185 deletions(-) delete mode 100644 sysdeps/unix/sysv/linux/i386/time.c delete mode 100644 sysdeps/unix/sysv/linux/powerpc/time.c delete mode 100644 sysdeps/unix/sysv/linux/x86/time.c diff --git a/include/libc-symbols.h b/include/libc-symbols.h index b68ec4b7f5..a585a04e63 100644 --- a/include/libc-symbols.h +++ b/include/libc-symbols.h @@ -491,6 +491,12 @@ for linking") int foo = INITIAL_FOO_VALUE; libc_hidden_data_weak (foo) + If the internal foo should use a different internal symbol (for instance + if the symbol is exported as an IFUNC, but internal calls should use a + default version) then you may use: + + libc_hidden_def_redir (foo_internal, foo) + If foo is normally just an alias (strong or weak) to some other function, you should use the normal strong_alias first, then add libc_hidden_def or libc_hidden_weak: @@ -548,6 +554,7 @@ for linking") # define hidden_ver(local, name) __hidden_ver1(local, __GI_##name, name); # define hidden_data_ver(local, name) hidden_ver(local, name) # define hidden_def(name) __hidden_ver1(__GI_##name, name, name); +# define hidden_def_redir(redir, name) __hidden_ver1(redir, __GI_##name, redir); # define hidden_data_def(name) hidden_def(name) # define hidden_tls_def(name) \ __hidden_ver2 (__thread, __GI_##name, name, name); @@ -575,6 +582,7 @@ for linking") hidden_proto doesn't make sense for assembly but the equivalent is to call via the HIDDEN_JUMPTARGET macro instead of JUMPTARGET. */ # define hidden_def(name) strong_alias (name, __GI_##name) +# define hidden_def_redir(redir, name) strong_alias(redir, __GI_##name); # define hidden_weak(name) hidden_def (name) # define hidden_ver(local, name) strong_alias (local, __GI_##name) # define hidden_data_def(name) strong_data_alias (name, __GI_##name) @@ -605,6 +613,7 @@ for linking") # endif /* Not __ASSEMBLER__ */ # define hidden_weak(name) # define hidden_def(name) +# define hidden_def_redir(redir, name) # define hidden_ver(local, name) # define hidden_data_weak(name) # define hidden_data_def(name) @@ -617,6 +626,7 @@ for linking") # define libc_hidden_proto(name, attrs...) hidden_proto (name, ##attrs) # define libc_hidden_tls_proto(name, attrs...) hidden_tls_proto (name, ##attrs) # define libc_hidden_def(name) hidden_def (name) +# define libc_hidden_def_redir(redir, name) hidden_def_redir (redir, name) # define libc_hidden_weak(name) hidden_weak (name) # ifdef LINK_OBSOLETE_RPC /* libc_hidden_nolink_sunrpc should only get used in sunrpc code. */ @@ -633,6 +643,7 @@ for linking") # define libc_hidden_proto(name, attrs...) # define libc_hidden_tls_proto(name, attrs...) # define libc_hidden_def(name) +# define libc_hidden_def_redir(redir, name) # define libc_hidden_weak(name) # define libc_hidden_ver(local, name) # define libc_hidden_data_def(name) diff --git a/sysdeps/unix/sysv/linux/i386/sysdep.h b/sysdeps/unix/sysv/linux/i386/sysdep.h index e793fdc936..4f79f25989 100644 --- a/sysdeps/unix/sysv/linux/i386/sysdep.h +++ b/sysdeps/unix/sysv/linux/i386/sysdep.h @@ -315,6 +315,8 @@ struct libc_do_syscall_args /* List of system calls which are supported as vsyscalls. */ # define HAVE_CLOCK_GETTIME_VSYSCALL "__vdso_clock_gettime" # define HAVE_GETTIMEOFDAY_VSYSCALL "__vdso_gettimeofday" +# define HAVE_TIME_VSYSCALL "__vdso_time" +# define USE_TIME_VSYSCALL_IFUNC 1 /* Define a macro which expands inline into the wrapper code for a system call. This use is for internal calls that do not need to handle errors diff --git a/sysdeps/unix/sysv/linux/i386/time.c b/sysdeps/unix/sysv/linux/i386/time.c deleted file mode 100644 index 440e3e6ab4..0000000000 --- a/sysdeps/unix/sysv/linux/i386/time.c +++ /dev/null @@ -1,34 +0,0 @@ -/* time -- Get number of seconds since Epoch. Linux/i386 version. - Copyright (C) 2015-2019 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#ifdef SHARED -# define time __redirect_time -#endif - -#include - -#ifdef SHARED -# undef time -# define time_type __redirect_time - -# undef libc_hidden_def -# define libc_hidden_def(name) \ - __hidden_ver1 (__time_syscall, __GI_time, __time_syscall); -#endif - -#include diff --git a/sysdeps/unix/sysv/linux/powerpc/sysdep.h b/sysdeps/unix/sysv/linux/powerpc/sysdep.h index 357d1b5243..084b6525ca 100644 --- a/sysdeps/unix/sysv/linux/powerpc/sysdep.h +++ b/sysdeps/unix/sysv/linux/powerpc/sysdep.h @@ -24,6 +24,7 @@ #define HAVE_CLOCK_GETTIME_VSYSCALL "__kernel_clock_gettime" #define HAVE_GETCPU_VSYSCALL "__kernel_getcpu" #define HAVE_TIME_VSYSCALL "__kernel_time" +#define USE_TIME_VSYSCALL_IFUNC 1 #define HAVE_GETTIMEOFDAY_VSYSCALL "__kernel_gettimeofday" #define HAVE_GET_TBFREQ "__kernel_get_tbfreq" diff --git a/sysdeps/unix/sysv/linux/powerpc/time.c b/sysdeps/unix/sysv/linux/powerpc/time.c deleted file mode 100644 index f0537a2307..0000000000 --- a/sysdeps/unix/sysv/linux/powerpc/time.c +++ /dev/null @@ -1,83 +0,0 @@ -/* time system call for Linux/PowerPC. - Copyright (C) 2013-2019 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#ifdef SHARED -# ifndef __powerpc64__ -# define time __redirect_time -# else -# define __redirect_time time -# endif - -# include -# include -# include -# include -# include - -# ifndef __powerpc64__ -# undef time - -time_t -__time_vsyscall (time_t *t) -{ - return INLINE_VSYSCALL (time, 1, t); -} - -/* __GI_time is defined as hidden and for ppc32 it enables the - compiler make a local call (symbol@local) for internal GLIBC usage. It - means the PLT won't be used and the ifunc resolver will be called directly. - For ppc64 a call to a function in another translation unit might use a - different toc pointer thus disallowing direct branchess and making internal - ifuncs calls safe. */ -# undef libc_hidden_def -# define libc_hidden_def(name) \ - __hidden_ver1 (__time_vsyscall, __GI_time, __time_vsyscall); - -# endif /* !__powerpc64__ */ - -static time_t -time_syscall (time_t *t) -{ - struct timeval tv; - time_t result; - - if (INLINE_VSYSCALL (gettimeofday, 2, &tv, NULL) < 0) - result = (time_t) -1; - else - result = (time_t) tv.tv_sec; - - if (t != NULL) - *t = result; - return result; -} - -# define INIT_ARCH() \ - void *vdso_time = get_vdso_symbol (HAVE_TIME_VSYSCALL); - -/* If the vDSO is not available we fall back to the syscall. */ -libc_ifunc_hidden (__redirect_time, time, - vdso_time - ? VDSO_IFUNC_RET (vdso_time) - : (void *) time_syscall); -libc_hidden_def (time) - -#else - -#include - -#endif /* !SHARED */ diff --git a/sysdeps/unix/sysv/linux/time.c b/sysdeps/unix/sysv/linux/time.c index 1978f6d817..9176fe6ed7 100644 --- a/sysdeps/unix/sysv/linux/time.c +++ b/sysdeps/unix/sysv/linux/time.c @@ -15,27 +15,68 @@ License along with the GNU C Library; if not, see . */ -#include +/* Currently we have 3 possible time implementations, which is also selected + in the order: + + 1. Wire-up __NR_time with a vDSO implementation (currently only x86 and + powerpc). + 2. Only wire-up __NR_time (usually old kABIs). + 3. Using internal gettimeofday (which may call a vDSO as well). */ + +#define time __redirect_time #include +#undef time +#include #include +#ifdef HAVE_TIME_VSYSCALL +# define HAVE_VSYSCALL +#endif +#include +#include -#ifdef __NR_time - -time_t -time (time_t *t) +static time_t +time_syscall (time_t *t) { + time_t res; +#ifdef __NR_time INTERNAL_SYSCALL_DECL (err); - time_t res = INTERNAL_SYSCALL (time, err, 1, NULL); + res = INTERNAL_VSYSCALL (time, err, 1, NULL); /* There cannot be any error. */ +#else + struct timeval tv; + /* gettimeofday does not fail with valid 'tv' and null timezone. */ + __gettimeofday (&tv, NULL); + res = tv.tv_sec; +#endif if (t != NULL) *t = res; return res; } -libc_hidden_def (time) +#if HAVE_IFUNC && defined USE_TIME_VSYSCALL_IFUNC +/* Route externals calls direct to vDSO and static and internal calls to + fallback implementation (which also might call the vDSO). */ +# ifdef SHARED +# undef INIT_ARCH +# define INIT_ARCH() \ + void *vdso_time = get_vdso_symbol (HAVE_TIME_VSYSCALL); + +libc_ifunc_redirected (__redirect_time, time, + vdso_time + ? VDSO_IFUNC_RET (vdso_time) + : (void *) time_syscall); +libc_hidden_def_redir (time_syscall, time) +# else +strong_alias (time_syscall, time) +# endif /* SHARED */ #else -# include +time_t +time (time_t *t) +{ + return time_syscall (t); +} +libc_hidden_def_redir (time, time) #endif diff --git a/sysdeps/unix/sysv/linux/x86/time.c b/sysdeps/unix/sysv/linux/x86/time.c deleted file mode 100644 index 60e6d1b7c0..0000000000 --- a/sysdeps/unix/sysv/linux/x86/time.c +++ /dev/null @@ -1,60 +0,0 @@ -/* time -- Get number of seconds since Epoch. Linux/x86 version. - Copyright (C) 2015-2019 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include - -#ifdef SHARED - -#include -#include -#include - -static time_t -__time_syscall (time_t *t) -{ - INTERNAL_SYSCALL_DECL (err); - return INTERNAL_SYSCALL (time, err, 1, t); -} - -# ifndef time_type -/* The i386 time.c includes this file with a defined time_type macro. - For x86_64 we have to define it to time as the internal symbol is the - ifunc'ed one. */ -# define time_type time -# endif - -#undef INIT_ARCH -#define INIT_ARCH() - -/* If the vDSO is not available we fall back on the syscall. */ -libc_ifunc_hidden (time_type, time, - (get_vdso_symbol ("__vdso_time") ?: __time_syscall)) -libc_hidden_def (time) - -#else - -# include - -time_t -time (time_t *t) -{ - INTERNAL_SYSCALL_DECL (err); - return INTERNAL_SYSCALL (time, err, 1, t); -} - -#endif diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/sysdep.h index 4541c0d492..c64fbd1e26 100644 --- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h +++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h @@ -376,6 +376,8 @@ /* List of system calls which are supported as vsyscalls. */ # define HAVE_CLOCK_GETTIME_VSYSCALL "__vdso_clock_gettime" # define HAVE_GETTIMEOFDAY_VSYSCALL "__vdso_gettimeofday" +# define HAVE_TIME_VSYSCALL "__vdso_time" +# define USE_TIME_VSYSCALL_IFUNC 1 # define HAVE_GETCPU_VSYSCALL "__vdso_getcpu" # define SINGLE_THREAD_BY_GLOBAL 1 From patchwork Thu Sep 5 20:56:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1158686 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-105070-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="eG3yATdb"; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="a5J40TiB"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46PY1B6L01z9s00 for ; Fri, 6 Sep 2019 06:57:50 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=DE6aV9Y3WPDjWyF3Y3i0WApXoqwT6W3 /zbkIKgd6B+3RXfA7EZTzXllFlIJzKH3ZBPO9oD9adN2PO+NjE2a/Lx8C+n3yKZm GCFSVSAICF76WDgdkJBE0OCvTm4h3YlsNWcpmxNpiFYQGDBAAeNtex0To91ClFBI I3bO07edjc2s= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; s=default; bh=EJCqriYsbr/8oST/OE+TWeB5Cno=; b=eG3yA Tdb6JWcLpxpb3y0ZeD4brrs80Lcp+ATnpaICAN1vSzZH1VUtPERbIWH2Xdmbh/t8 OspvHQ798GDuCej730+aYekebGw5mNl3aJAgCqjOU1BIVPEXk1H5fnyWOWJji9R1 pM1w69ahq2UkVcAWXpDzUlo/7QnHhi8gbUwQEU= Received: (qmail 117720 invoked by alias); 5 Sep 2019 20:56:41 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 117651 invoked by uid 89); 5 Sep 2019 20:56:41 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=H*RU:209.85.160.196, HX-Spam-Relays-External:209.85.160.196 X-HELO: mail-qt1-f196.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=MWQuXfMf3IWTXs8matr+lGt67d/nvAusyTdZyVJFT8o=; b=a5J40TiB79uImJIioqez3S1jVGtx6bjCVrUX2V+eLiEbBlbdJp6heIBK5wh2VTEQsj 41iVOUHoqwi4ZivFUolHJJ4KoCdSadPlNh/zH57wK4fN7YWQ84IYF+46alqKZw6D34N+ idAhzYVaj7DalDQnDq1gBRBU0aRKWoF6nLh0ycDTiJnV8ybosNPaulYqIpNn17KgP61G QKwCNbAFPeqov1Q9NmXH/6Suz0vcqTU/zWiUMMIzdypFh+xkPgxRPdGmF6+qag2t6FCu odrMjBkyFHoN1xiOgxYa3Z5VqWrISn5SxflzypcKYSBGiSV754lq9ATPWqNUFgZudL+d F5oQ== From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 8/8] linux: Consolidate gettimeofday implementation Date: Thu, 5 Sep 2019 17:56:20 -0300 Message-Id: <20190905205620.4646-8-adhemerval.zanella@linaro.org> In-Reply-To: <20190905205620.4646-1-adhemerval.zanella@linaro.org> References: <20190905205620.4646-1-adhemerval.zanella@linaro.org> Changes from previous version: - Update due powerpc64 fixes. --- The gettimeofday syscall has currently 3 possible implementations: 1. Wire-up __NR_gettimeofday with a VDSO implementation accessed directly through IFUNC (aarch64, x86, and powerpc*). 2. vDSO gettimeofday (arm, mips*, riscv*, s390, and sparc). 3. Wire-up __NR_gettimeofday (alpha, hppa, ia64, m68k, microblaze, nios, sh4). This patch consolidates all implementation on Linux generic sysdeps/unix/sysv/linux/gettimeofday.c. To simplify the code, some changes are made: * The wire-up with vDSO implementation may route external calls directly to vDSO through IFUNC. To enable it the architecture need to explicit define USE_GETTIMEOFDAY_VSYSCALL_IFUNC. * Also, powerpc and x86 tries to route internal time usages to IFUNC mechanism, which is problematic since powerpc32 and i686 does not really support it. Instead, all internal calls are routed to a default internal symbol which in turn calls INTERNAL_VSYSCALL. * Static linking also uses the fallback mechanism which calls INTERNAL_VSYSCALL, so vDSO is used for this case as well. The generic implementation issues a syscall as default, calls the vDSO if the architecture defines HAVE_GETTIMEOFDAY_VSYSCALL, and route the external calls to iFUNC if the architecture also defines USE_GETTIMEOFDAY_VSYSCALL_IFUNC. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc-linux-gnu, powerpc64-linux-gnu, powerpc64le-linux-gnu, and aarch64-linux-gnu. * sysdeps/unix/sysv/linux/aarch64/gettimeofday.c: Remove file. * sysdeps/unix/sysv/linux/i386/gettimeofday.c: Likewise. * sysdeps/unix/sysv/linux/powerpc/gettimeofday.c: Likewise. * sysdeps/unix/sysv/linux/x86/gettimeofday.c: Likewise. * sysdeps/unix/sysv/linux/aarch64/sysdep.h (USE_GETTIMEOFDAY_VSYSCALL_IFUNC): Define. * sysdeps/unix/sysv/linux/i386/sysdep.h (USE_GETTIMEOFDAY_VSYSCALL_IFUNC): Likewise. * sysdeps/unix/sysv/linux/x86_64/sysdep.h (USE_GETTIMEOFDAY_VSYSCALL_IFUNC): Likewise. * sysdeps/unix/sysv/linux/powerpc/sysdep.h (USE_GETTIMEOFDAY_VSYSCALL_IFUNC): Likewise. * sysdeps/unix/sysv/linux/gettimeofday.c (gettimeofday): Handle all possible Linux implementations (wire-up syscall, vDSO implementation, and iFUNC). (gettimeofday_syscall): New function. --- .../unix/sysv/linux/aarch64/gettimeofday.c | 58 ------------- sysdeps/unix/sysv/linux/aarch64/sysdep.h | 1 + sysdeps/unix/sysv/linux/gettimeofday.c | 51 +++++++++-- sysdeps/unix/sysv/linux/i386/gettimeofday.c | 35 -------- sysdeps/unix/sysv/linux/i386/sysdep.h | 1 + .../unix/sysv/linux/powerpc/gettimeofday.c | 84 ------------------- sysdeps/unix/sysv/linux/powerpc/sysdep.h | 1 + sysdeps/unix/sysv/linux/x86/gettimeofday.c | 63 -------------- sysdeps/unix/sysv/linux/x86_64/sysdep.h | 1 + 9 files changed, 48 insertions(+), 247 deletions(-) delete mode 100644 sysdeps/unix/sysv/linux/aarch64/gettimeofday.c delete mode 100644 sysdeps/unix/sysv/linux/i386/gettimeofday.c delete mode 100644 sysdeps/unix/sysv/linux/powerpc/gettimeofday.c delete mode 100644 sysdeps/unix/sysv/linux/x86/gettimeofday.c diff --git a/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c b/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c deleted file mode 100644 index 9499a11fda..0000000000 --- a/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c +++ /dev/null @@ -1,58 +0,0 @@ -/* Copyright (C) 2018-2019 Free Software Foundation, Inc. - - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2.1 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -/* Get the current time of day and timezone information, - putting it into *tv and *tz. If tz is null, *tz is not filled. - Returns 0 on success, -1 on errors. */ - -#include - -#ifdef SHARED - -# include -# include - -/* Used as a fallback in the ifunc resolver if VDSO is not available - and for libc.so internal __gettimeofday calls. */ - -static int -__gettimeofday_vsyscall (struct timeval *tv, struct timezone *tz) -{ - return INLINE_VSYSCALL (gettimeofday, 2, tv, tz); -} - -# define INIT_ARCH() -libc_ifunc_hidden (__gettimeofday, __gettimeofday, - (get_vdso_symbol ("__vdso_gettimeofday") - ?: __gettimeofday_vsyscall)) -libc_hidden_def (__gettimeofday) - -#else - -# include -int -__gettimeofday (struct timeval *tv, struct timezone *tz) -{ - return INLINE_SYSCALL (gettimeofday, 2, tv, tz); -} -libc_hidden_def (__gettimeofday) - -#endif - -weak_alias (__gettimeofday, gettimeofday) -libc_hidden_weak (gettimeofday) diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep.h b/sysdeps/unix/sysv/linux/aarch64/sysdep.h index d57f7232e2..526741ed82 100644 --- a/sysdeps/unix/sysv/linux/aarch64/sysdep.h +++ b/sysdeps/unix/sysv/linux/aarch64/sysdep.h @@ -163,6 +163,7 @@ # define HAVE_CLOCK_GETRES_VSYSCALL "__kernel_clock_getres" # define HAVE_CLOCK_GETTIME_VSYSCALL "__kernel_clock_gettime" # define HAVE_GETTIMEOFDAY_VSYSCALL "__kernel_gettimeofday" +# define USE_GETTIMEOFDAY_VSYSCALL_IFUNC 1 /* Previously AArch64 used the generic version without the libc_hidden_def which lead in a non existent __send symbol in libc.so. */ diff --git a/sysdeps/unix/sysv/linux/gettimeofday.c b/sysdeps/unix/sysv/linux/gettimeofday.c index a74f03825a..833e97ca7d 100644 --- a/sysdeps/unix/sysv/linux/gettimeofday.c +++ b/sysdeps/unix/sysv/linux/gettimeofday.c @@ -16,24 +16,61 @@ License along with the GNU C Library; if not, see . */ -#include -#include +/* Currently we have 3 possible gettimeofday implementations, which is also + selected in the order: + + 1. Wire-up __NR_gettimeofday with a vDSO implementation (currently aarch64, + x86, and powerpc). + + 2. vDSO gettimeofday (arm, mips*, riscv*, s390, and sparc). + + 3. Wire-up __NR_gettimeofday (alpha, hppa, ia64, m68k, microblaze, + nios, sh4). */ +#define __gettimeofday __redirect___gettimeofday +#include #undef __gettimeofday +#include #ifdef HAVE_GETTIMEOFDAY_VSYSCALL # define HAVE_VSYSCALL #endif #include +#include + +/* Get the current time of day and timezone information, putting it into *tv + and *tz. If tz is null, *tz is not filled. Returns 0 on success, -1 on + errors. */ +static int +gettimeofday_syscall (struct timeval *tv, struct timezone *tz) +{ + return INLINE_VSYSCALL (gettimeofday, 2, tv, tz); +} + +#if HAVE_IFUNC && defined USE_GETTIMEOFDAY_VSYSCALL_IFUNC +/* Route externals calls direct to vDSO and static and internal calls to + fallback implementation (which also might call the vDSO). */ +# ifdef SHARED +# undef INIT_ARCH +# define INIT_ARCH() \ + void *vdso_gettimeofday = get_vdso_symbol (HAVE_GETTIMEOFDAY_VSYSCALL) + +libc_ifunc_redirected (__redirect___gettimeofday, __gettimeofday, + vdso_gettimeofday + ? VDSO_IFUNC_RET (vdso_gettimeofday) + : (void *) gettimeofday_syscall); +libc_hidden_def_redir (gettimeofday_syscall, __gettimeofday) +# else +strong_alias (gettimeofday_syscall, __gettimeofday) +# endif /* SHARED */ +#else -/* Get the current time of day and timezone information, - putting it into *tv and *tz. If tz is null, *tz is not filled. - Returns 0 on success, -1 on errors. */ int __gettimeofday (struct timeval *tv, struct timezone *tz) { - return INLINE_VSYSCALL (gettimeofday, 2, tv, tz); + return gettimeofday_syscall (tv, tz); } -libc_hidden_def (__gettimeofday) +libc_hidden_def_redir (__gettimeofday, __gettimeofday) +#endif weak_alias (__gettimeofday, gettimeofday) libc_hidden_weak (gettimeofday) diff --git a/sysdeps/unix/sysv/linux/i386/gettimeofday.c b/sysdeps/unix/sysv/linux/i386/gettimeofday.c deleted file mode 100644 index 185450ece6..0000000000 --- a/sysdeps/unix/sysv/linux/i386/gettimeofday.c +++ /dev/null @@ -1,35 +0,0 @@ -/* gettimeofday - get the time. Linux/i386 version. - Copyright (C) 2015-2019 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#ifdef SHARED -# define __gettimeofday __redirect___gettimeofday -#endif - -#include - -#ifdef SHARED -# undef __gettimeofday -# define __gettimeofday_type __redirect___gettimeofday - -# undef libc_hidden_def -# define libc_hidden_def(name) \ - __hidden_ver1 (__gettimeofday_syscall, __GI___gettimeofday, \ - __gettimeofday_syscall); -#endif - -#include diff --git a/sysdeps/unix/sysv/linux/i386/sysdep.h b/sysdeps/unix/sysv/linux/i386/sysdep.h index 4f79f25989..076e4393d3 100644 --- a/sysdeps/unix/sysv/linux/i386/sysdep.h +++ b/sysdeps/unix/sysv/linux/i386/sysdep.h @@ -315,6 +315,7 @@ struct libc_do_syscall_args /* List of system calls which are supported as vsyscalls. */ # define HAVE_CLOCK_GETTIME_VSYSCALL "__vdso_clock_gettime" # define HAVE_GETTIMEOFDAY_VSYSCALL "__vdso_gettimeofday" +# define USE_GETTIMEOFDAY_VSYSCALL_IFUNC 1 # define HAVE_TIME_VSYSCALL "__vdso_time" # define USE_TIME_VSYSCALL_IFUNC 1 diff --git a/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c b/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c deleted file mode 100644 index e046594d40..0000000000 --- a/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c +++ /dev/null @@ -1,84 +0,0 @@ -/* Copyright (C) 2005-2019 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#if defined SHARED && !defined __powerpc64__ -# define __gettimeofday __redirect___gettimeofday -#else -# define __redirect___gettimeofday __gettimeofday -#endif - -#include - -#ifdef SHARED - -# include -# include -# include - -# ifndef __powerpc64__ -# undef __gettimeofday - -int -__gettimeofday_vsyscall (struct timeval *tv, struct timezone *tz) -{ - return INLINE_VSYSCALL (gettimeofday, 2, tv, tz); -} - -/* __GI___gettimeofday is defined as hidden and for ppc32 it enables the - compiler make a local call (symbol@local) for internal GLIBC usage. It - means the PLT won't be used and the ifunc resolver will be called directly. - For ppc64 a call to a function in another translation unit might use a - different toc pointer thus disallowing direct branchess and making internal - ifuncs calls safe. */ -# undef libc_hidden_def -# define libc_hidden_def(name) \ - __hidden_ver1 (__gettimeofday_vsyscall, __GI___gettimeofday, \ - __gettimeofday_vsyscall); - -# endif /* !__powerpc64__ */ - -static int -__gettimeofday_syscall (struct timeval *tv, struct timezone *tz) -{ - return INLINE_SYSCALL (gettimeofday, 2, tv, tz); -} - -# define INIT_ARCH() \ - void *vdso_gettimeofday = get_vdso_symbol (HAVE_GETTIMEOFDAY_VSYSCALL) - -/* If the vDSO is not available we fall back syscall. */ -libc_ifunc_hidden (__redirect___gettimeofday, __gettimeofday, - vdso_gettimeofday - ? VDSO_IFUNC_RET (vdso_gettimeofday) - : (void *) __gettimeofday_syscall); -libc_hidden_def (__gettimeofday) - -#else - -# include -# include - -int -__gettimeofday (struct timeval *tv, struct timezone *tz) -{ - return INLINE_SYSCALL (gettimeofday, 2, tv, tz); -} -libc_hidden_def (__gettimeofday) - -#endif -weak_alias (__gettimeofday, gettimeofday) -libc_hidden_weak (gettimeofday) diff --git a/sysdeps/unix/sysv/linux/powerpc/sysdep.h b/sysdeps/unix/sysv/linux/powerpc/sysdep.h index 084b6525ca..743eb67557 100644 --- a/sysdeps/unix/sysv/linux/powerpc/sysdep.h +++ b/sysdeps/unix/sysv/linux/powerpc/sysdep.h @@ -26,6 +26,7 @@ #define HAVE_TIME_VSYSCALL "__kernel_time" #define USE_TIME_VSYSCALL_IFUNC 1 #define HAVE_GETTIMEOFDAY_VSYSCALL "__kernel_gettimeofday" +#define USE_GETTIMEOFDAY_VSYSCALL_IFUNC 1 #define HAVE_GET_TBFREQ "__kernel_get_tbfreq" #if defined(__PPC64__) || defined(__powerpc64__) diff --git a/sysdeps/unix/sysv/linux/x86/gettimeofday.c b/sysdeps/unix/sysv/linux/x86/gettimeofday.c deleted file mode 100644 index 3ceab633e5..0000000000 --- a/sysdeps/unix/sysv/linux/x86/gettimeofday.c +++ /dev/null @@ -1,63 +0,0 @@ -/* gettimeofday - get the time. Linux/x86 version. - Copyright (C) 2015-2019 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include - -#ifdef SHARED - -# include -# include -# include -# include - -static int -__gettimeofday_syscall (struct timeval *tv, struct timezone *tz) -{ - return INLINE_SYSCALL (gettimeofday, 2, tv, tz); -} - -# ifndef __gettimeofday_type -/* The i386 gettimeofday.c includes this file with a defined - __gettimeofday_type macro. For x86_64 we have to define it to __gettimeofday - as the internal symbol is the ifunc'ed one. */ -# define __gettimeofday_type __gettimeofday -# endif - -# define INIT_ARCH() - -/* If the vDSO is not available we fall back to syscall. */ -libc_ifunc_hidden (__gettimeofday_type, __gettimeofday, - (get_vdso_symbol ("__vdso_gettimeofday") - ?: __gettimeofday_syscall)); -libc_hidden_def (__gettimeofday) - -#else - -# include -# include - -int -__gettimeofday (struct timeval *tv, struct timezone *tz) -{ - return INLINE_SYSCALL (gettimeofday, 2, tv, tz); -} -libc_hidden_def (__gettimeofday) - -#endif -weak_alias (__gettimeofday, gettimeofday) -libc_hidden_weak (gettimeofday) diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/sysdep.h index c64fbd1e26..4ea9c4fa31 100644 --- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h +++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h @@ -376,6 +376,7 @@ /* List of system calls which are supported as vsyscalls. */ # define HAVE_CLOCK_GETTIME_VSYSCALL "__vdso_clock_gettime" # define HAVE_GETTIMEOFDAY_VSYSCALL "__vdso_gettimeofday" +# define USE_GETTIMEOFDAY_VSYSCALL_IFUNC 1 # define HAVE_TIME_VSYSCALL "__vdso_time" # define USE_TIME_VSYSCALL_IFUNC 1 # define HAVE_GETCPU_VSYSCALL "__vdso_getcpu"