From 1769608794096c835095826559c0ba1555f43fc0 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Tue, 2 Jun 2015 20:24:25 +0000 Subject: [PATCH] Use libc_hidden_proto / libc_hidden_def with __strnlen. Various code in glibc uses __strnlen instead of strnlen for namespace reasons. However, __strnlen does not use libc_hidden_proto / libc_hidden_def (as is normally done for any function defined and called within the same library, whether or not exported from the library and whatever namespace it is in), so the compiler does not know that those calls are to a function within libc. This patch uses libc_hidden_proto / libc_hidden_def with __strnlen. On x86_64, it makes no difference to the installed stripped shared libraries. On 32-bit x86, it causes __strnlen calls to go to the same place as strnlen calls (the fallback strnlen implementation), rather than through a PLT entry for the strnlen IFUNC; I'm not sure of the logic behind when calls from within libc should use IFUNCs versus when they should go direct to a particular function implementation, but clearly it doesn't make sense for strnlen and __strnlen to be handled differently in this regard. Tested for x86_64 and x86 (testsuite, and comparison of installed shared libraries as described above). * string/strnlen.c [!STRNLEN] (__strnlen): Use libc_hidden_def. * include/string.h (__strnlen): Use libc_hidden_proto. * sysdeps/aarch64/strnlen.S (__strnlen): Use libc_hidden_def. * sysdeps/i386/i686/multiarch/strnlen-c.c [SHARED] (libc_hidden_def): Define __GI___strnlen as well as __GI_strnlen. * sysdeps/powerpc/powerpc32/power4/multiarch/strnlen-power7.S (libc_hidden_def): Undefine and redefine. * sysdeps/powerpc/powerpc32/power4/multiarch/strnlen-ppc32.c [SHARED] (libc_hidden_def): Define __GI___strnlen as well as __GI_strnlen. * sysdeps/powerpc/powerpc32/power7/strnlen.S (__strnlen): Use libc_hidden_def. * sysdeps/tile/tilegx/strnlen.c (__strnlen): Likewise. --- ChangeLog | 14 ++++++++++++++ include/string.h | 1 + string/strnlen.c | 1 + sysdeps/aarch64/strnlen.S | 1 + sysdeps/i386/i686/multiarch/strnlen-c.c | 4 +++- .../powerpc32/power4/multiarch/strnlen-power7.S | 3 +++ .../powerpc32/power4/multiarch/strnlen-ppc32.c | 4 +++- sysdeps/powerpc/powerpc32/power7/strnlen.S | 1 + sysdeps/tile/tilegx/strnlen.c | 1 + 9 files changed, 28 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9182ed9adae..1c67d9977eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,19 @@ 2015-06-02 Joseph Myers + * string/strnlen.c [!STRNLEN] (__strnlen): Use libc_hidden_def. + * include/string.h (__strnlen): Use libc_hidden_proto. + * sysdeps/aarch64/strnlen.S (__strnlen): Use libc_hidden_def. + * sysdeps/i386/i686/multiarch/strnlen-c.c [SHARED] + (libc_hidden_def): Define __GI___strnlen as well as __GI_strnlen. + * sysdeps/powerpc/powerpc32/power4/multiarch/strnlen-power7.S + (libc_hidden_def): Undefine and redefine. + * sysdeps/powerpc/powerpc32/power4/multiarch/strnlen-ppc32.c + [SHARED] (libc_hidden_def): Define __GI___strnlen as well as + __GI_strnlen. + * sysdeps/powerpc/powerpc32/power7/strnlen.S (__strnlen): Use + libc_hidden_def. + * sysdeps/tile/tilegx/strnlen.c (__strnlen): Likewise. + [BZ #18469] * wctype/wcfuncs.c (towlower): Rename to __towlower and define as weak alias of __towlower. Use libc_hidden_weak. diff --git a/include/string.h b/include/string.h index 89f00fda4ed..c57671ea631 100644 --- a/include/string.h +++ b/include/string.h @@ -91,6 +91,7 @@ libc_hidden_proto (__strtok_r) extern char *__strsep_g (char **__stringp, const char *__delim); libc_hidden_proto (__strsep_g) libc_hidden_proto (strnlen) +libc_hidden_proto (__strnlen) libc_hidden_proto (memmem) extern __typeof (memmem) __memmem; libc_hidden_proto (__memmem) diff --git a/string/strnlen.c b/string/strnlen.c index 803d78b7d56..d2bb843fddb 100644 --- a/string/strnlen.c +++ b/string/strnlen.c @@ -160,6 +160,7 @@ __strnlen (const char *str, size_t maxlen) return char_ptr - str; } #ifndef STRNLEN +libc_hidden_def (__strnlen) weak_alias (__strnlen, strnlen) #endif libc_hidden_def (strnlen) diff --git a/sysdeps/aarch64/strnlen.S b/sysdeps/aarch64/strnlen.S index 743172cb475..9d6b19f6857 100644 --- a/sysdeps/aarch64/strnlen.S +++ b/sysdeps/aarch64/strnlen.S @@ -157,5 +157,6 @@ L(hit_limit): mov len, limit RET END (__strnlen) +libc_hidden_def (__strnlen) weak_alias (__strnlen, strnlen) libc_hidden_def (strnlen) diff --git a/sysdeps/i386/i686/multiarch/strnlen-c.c b/sysdeps/i386/i686/multiarch/strnlen-c.c index f02465d6a47..351e939a934 100644 --- a/sysdeps/i386/i686/multiarch/strnlen-c.c +++ b/sysdeps/i386/i686/multiarch/strnlen-c.c @@ -2,7 +2,9 @@ #ifdef SHARED # undef libc_hidden_def # define libc_hidden_def(name) \ - __hidden_ver1 (__strnlen_ia32, __GI_strnlen, __strnlen_ia32); + __hidden_ver1 (__strnlen_ia32, __GI_strnlen, __strnlen_ia32); \ + strong_alias (__strnlen_ia32, __strnlen_ia32_1); \ + __hidden_ver1 (__strnlen_ia32_1, __GI___strnlen, __strnlen_ia32_1); #endif #include "string/strnlen.c" diff --git a/sysdeps/powerpc/powerpc32/power4/multiarch/strnlen-power7.S b/sysdeps/powerpc/powerpc32/power4/multiarch/strnlen-power7.S index 32fba1b5f39..e8577545deb 100644 --- a/sysdeps/powerpc/powerpc32/power4/multiarch/strnlen-power7.S +++ b/sysdeps/powerpc/powerpc32/power4/multiarch/strnlen-power7.S @@ -31,6 +31,9 @@ cfi_endproc; \ ASM_SIZE_DIRECTIVE(__strnlen_power7) +#undef libc_hidden_def +#define libc_hidden_def(name) + #undef libc_hidden_builtin_def #define libc_hidden_builtin_def(name) diff --git a/sysdeps/powerpc/powerpc32/power4/multiarch/strnlen-ppc32.c b/sysdeps/powerpc/powerpc32/power4/multiarch/strnlen-ppc32.c index 6eaed608db9..a5f75160c23 100644 --- a/sysdeps/powerpc/powerpc32/power4/multiarch/strnlen-ppc32.c +++ b/sysdeps/powerpc/powerpc32/power4/multiarch/strnlen-ppc32.c @@ -20,7 +20,9 @@ #ifdef SHARED # undef libc_hidden_def # define libc_hidden_def(name) \ - __hidden_ver1 (__strnlen_ppc, __GI_strnlen, __strnlen_ppc); + __hidden_ver1 (__strnlen_ppc, __GI_strnlen, __strnlen_ppc); \ + strong_alias (__strnlen_ppc, __strnlen_ppc_1); \ + __hidden_ver1 (__strnlen_ppc_1, __GI___strnlen, __strnlen_ppc_1); #endif #include diff --git a/sysdeps/powerpc/powerpc32/power7/strnlen.S b/sysdeps/powerpc/powerpc32/power7/strnlen.S index be169c6ab53..de1001cfa38 100644 --- a/sysdeps/powerpc/powerpc32/power7/strnlen.S +++ b/sysdeps/powerpc/powerpc32/power7/strnlen.S @@ -171,5 +171,6 @@ L(loop_small): blr END (__strnlen) +libc_hidden_def (__strnlen) weak_alias (__strnlen, strnlen) libc_hidden_builtin_def (strnlen) diff --git a/sysdeps/tile/tilegx/strnlen.c b/sysdeps/tile/tilegx/strnlen.c index 575f8f55c71..d1f212b72f7 100644 --- a/sysdeps/tile/tilegx/strnlen.c +++ b/sysdeps/tile/tilegx/strnlen.c @@ -52,5 +52,6 @@ __strnlen (const char *s, size_t maxlen) size_t len = ((const char *) p) + (CFZ (bits) >> 3) - s; return (len < maxlen ? len : maxlen); } +libc_hidden_def (__strnlen) weak_alias (__strnlen, strnlen) libc_hidden_def (strnlen) -- 2.47.2