This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Fix stpcpy / mempcpy namespace (bug 17573)
- From: Joseph Myers <joseph at codesourcery dot com>
- To: <libc-alpha at sourceware dot org>
- Cc: Siddhesh Poyarekar <siddhesh at redhat dot com>
- Date: Mon, 10 Nov 2014 18:18:35 +0000
- Subject: Fix stpcpy / mempcpy namespace (bug 17573)
- Authentication-results: sourceware.org; auth=none
Various glibc functions call __stpcpy and __mempcpy for namespace
reasons instead of plain stpcpy and mempcpy. But __stpcpy and
__mempcpy are macros that call __builtin_stpcpy and __builtin_mempcpy,
and unless GCC optimizes the calls, they end up calling the C
functions stpcpy and mempcpy.
For calls from within shared libc, libc_hidden_builtin_proto ensures
that calls to those C functions are in turn mapped to call __GI_stpcpy
and __GI_mempcpy. However, for static libc, and for calls from shared
libraries other than libc, the ELF symbols stpcpy and mempcpy end up
getting called, breaking the ISO C namespace (in the case of stpcpy)
or glibc conventions about not relying on the "future library
directions" reservations (in the case of mempcpy).
This patch fixes this by adding declarations of these functions to
include/string.h, under an appropriate condition, with __asm__ used to
change the assembler name used for calls; this fixes one of the bugs
shown in the sample output of my proposed tests for such namespace
issues <https://sourceware.org/ml/libc-alpha/2014-11/msg00157.html>
(the mempcpy case was previously discussed, and the approach for the
fix is as I suggested in
<https://sourceware.org/ml/libc-alpha/2013-02/msg00063.html>).
(Siddhesh, the new NOT_IN_libc conditional will I expect need updating
as part of your overhaul of such conditionals.)
Tested for x86_64 with the testsuite; also checked that dcigettext.o
(an example previously noted of undesired calls to stpcpy and mempcpy)
now calls __stpcpy and __mempcpy instead, as do non-libc shared
libraries (__stpcpy and __mempcpy were already exported from shared
libc). Disassembly of installed shared libraries isn't easy to
compare because of reordered PLT entries resulting from the change in
functions called (libnsl, libnss_compat, libnss_dns, libnss_files,
libnss_hesiod, libnss_nis, libnss_nisplus, libpthread, librt all have
such changes).
2014-11-10 Joseph Myers <joseph@codesourcery.com>
[BZ #17573]
* include/string.h [NOT_IN_libc || !SHARED] (mempcpy): Declare
with asm name __mempcpy.
[NOT_IN_libc || !SHARED] (stpcpy): Declare with asm name __stpcpy.
diff --git a/include/string.h b/include/string.h
index 8323412..2603e9c 100644
--- a/include/string.h
+++ b/include/string.h
@@ -113,6 +113,13 @@ libc_hidden_builtin_proto (strspn)
libc_hidden_builtin_proto (strstr)
libc_hidden_builtin_proto (ffs)
+#if defined NOT_IN_libc || !defined SHARED
+/* Redirect calls to __builtin_mempcpy and __builtin_stpcpy to call
+ __mempcpy and __stpcpy if not inlined. */
+extern __typeof (mempcpy) mempcpy __asm__ ("__mempcpy");
+extern __typeof (stpcpy) stpcpy __asm__ ("__stpcpy");
+#endif
+
# ifndef _ISOMAC
# ifndef index
# define index(s, c) (strchr ((s), (c)))
--
Joseph S. Myers
joseph@codesourcery.com