Skip to content

Commit

Permalink
Redirect mempcpy and stpcpy only in libc.a
Browse files Browse the repository at this point in the history
The mempcpy and stpcpy redirections to __mempcpy and __stpcpy were added
by

commit 939da41
Author: Joseph Myers <joseph@codesourcery.com>
Date:   Wed Nov 12 22:36:34 2014 +0000

    Fix stpcpy / mempcpy namespace (bug 17573).

to fix the namespace bug since __mempcpy and __stpcpy were defined as
macros in <bits/string2.h>.  These macros call __builtin_mempcpy and
__builtin_stpcpy which may end up calling the C functions mempcpy
and stpcpy.  In libc.so, libc_hidden_builtin_proto ensures that calls
to mempcpy and stpcpy are in turn mapped to call __GI_mempcpy and
__GI_stpcpy.  The redirections were applied outside of libc.so, including
libc.a, to map mempcpy and stpcpy to __mempcpy and __stpcpy.  Since

commit 18b10de
Author: Wilco Dijkstra <wdijkstr@arm.com>
Date:   Mon Jun 12 15:19:38 2017 +0100

    2017-06-12  Wilco Dijkstra  <wdijkstr@arm.com>

    There is no longer a need for string2.h, so remove it and all mention of it.
    Move the redirect for __stpcpy to include/string.h since it is
still required
    until all internal uses have been renamed.
    This fixes several linknamespace/localplt failures when building with -Os.

removed the __mempcpy and __stpcpy macros from the public header file,
limit these redirections to libc.a to avoid Clang error:

In file included from tst-iconv-sticky-input-error.c:22:
In file included from ./gconv_int.h:24:
../include/string.h:182:44: error: attribute declaration must precede definition [-Werror,-Wignored-attributes]
  182 | extern __typeof (mempcpy) mempcpy __asm__ ("__mempcpy");
      |                                            ^
../string/bits/string_fortified.h:42:8: note: previous definition is here
   42 | __NTH (mempcpy (void *__restrict __dest, const void *__restrict __src,
      |        ^

when testing with Clang for fortify build.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Sam James <sam@gentoo.org>
  • Loading branch information
hjl-tools committed Jan 2, 2025
1 parent ed97ef7 commit e9eea05
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion include/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ extern __typeof (strnlen) strnlen attribute_hidden;
extern __typeof (strsep) strsep attribute_hidden;
#endif

#if (!IS_IN (libc) || !defined SHARED) \
#if IS_IN (libc) && !defined SHARED \
&& !defined NO_MEMPCPY_STPCPY_REDIRECT
/* Redirect calls to __builtin_mempcpy and __builtin_stpcpy to call
__mempcpy and __stpcpy if not inlined. */
Expand Down

0 comments on commit e9eea05

Please sign in to comment.