]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Enable --enable-fortify-source with clang
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 8 Feb 2024 13:56:30 +0000 (10:56 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 28 Oct 2025 16:45:21 +0000 (13:45 -0300)
clang generates internal calls for some _chk symbol, so add internal
aliases for them, and stub some with rtld-stubbed-symbols to avoid
ld.so linker issues.

20 files changed:
debug/vasprintf_chk.c
debug/vfprintf_chk.c
elf/Makefile
include/arpa/inet.h
include/bits/inet-fortified-decl.h
include/bits/stdio2-decl.h
include/bits/string_fortified.h
include/bits/syslog-decl.h
include/bits/unistd-decl.h
include/bits/wchar2-decl.h
include/stdio.h
include/unistd.h
include/wchar.h
inet/bits/inet-fortified.h
libio/Makefile
misc/syslog.c
string/Makefile
sysdeps/generic/symbol-hacks.h
sysdeps/ieee754/ldbl-128ibm-compat/ieee128-snprintf.c
sysdeps/ieee754/ldbl-128ibm-compat/ieee128-syslog.c

index 41c15689eeb271022e75bbdd6227afafe9604171..f86320cadb0ecaf1125b80d44d625252c10e1e49 100644 (file)
@@ -35,3 +35,4 @@ __vasprintf_chk (char **result_ptr, int flag, const char *format, va_list ap)
 
   return __vasprintf_internal (result_ptr, format, ap, mode);
 }
+libc_hidden_def (__vasprintf_chk)
index 74b7c86add248c51302df0306340d397272517f9..999b6aa3934b7269d9711990754faf6906535c09 100644 (file)
@@ -29,3 +29,4 @@ ___vfprintf_chk (FILE *fp, int flag, const char *format, va_list ap)
   return __vfprintf_internal (fp, format, ap, mode);
 }
 ldbl_strong_alias (___vfprintf_chk, __vfprintf_chk)
+ldbl_hidden_def (___vfprintf_chk, __vfprintf_chk)
index 5a676f858d63a408d08d77a1cffe9aa1c947f6e2..dd21fe6241105c5a9c102ae3efb1e6816cf95bde 100644 (file)
@@ -1487,6 +1487,14 @@ rtld-stubbed-symbols = \
   realloc \
   # rtld-stubbed-symbols
 
+# These symbols might be emitted by the compiler when fortify is enabled
+# (through builtins).
+rtld-stubbed-symbols += \
+  __GI___vfprintf_chk \
+  __GI___vsprintf_chk \
+  __GI___vsyslog_chk \
+  # rtld-stubbed-symbols
+
 ifeq ($(have-ssp),yes)
 # rtld is not built with the stack protector, so these references will
 # go away in the rebuilds.
index 3db8f1a96fdbd6fd7a36d68ef2a83a399cb01ef2..7650e1acb5e8aa270fe1b1140be39b8544c97b63 100644 (file)
@@ -14,12 +14,10 @@ libc_hidden_proto (__inet_aton_exact)
 
 extern __typeof (inet_ntop) __inet_ntop;
 libc_hidden_proto (__inet_ntop)
-libc_hidden_proto (__inet_ntop_chk)
 
 libc_hidden_proto (inet_pton)
 extern __typeof (inet_pton) __inet_pton;
 libc_hidden_proto (__inet_pton)
-libc_hidden_proto (__inet_pton_chk)
 
 extern __typeof (inet_makeaddr) __inet_makeaddr;
 libc_hidden_proto (__inet_makeaddr)
index e6ad4d4663c61a0d3ea9542ff9146bfb0d2ad62f..1110ce49f2cca5195eee66d8ea578bfe99d54873 100644 (file)
@@ -1 +1,6 @@
 #include <inet/bits/inet-fortified-decl.h>
+
+#ifndef _ISOMAC
+libc_hidden_proto (__inet_ntop_chk)
+libc_hidden_proto (__inet_pton_chk)
+#endif
index bbb052f192218219eb1b924191382911a28a0982..9758bf4b557e77ab97386ae5f1802b5c76f1d906 100644 (file)
@@ -1 +1,8 @@
 #include <libio/bits/stdio2-decl.h>
+
+#ifndef _ISOMAC
+libc_hidden_proto (__fgets_unlocked_chk)
+libc_hidden_ldbl_proto (vfprintf)
+libc_hidden_ldbl_proto (__vasprintf_chk)
+libc_hidden_ldbl_proto (__vfprintf_chk)
+#endif
index 88bf073c9cf32e8e9b4bf7d6f486abcc7f9d291e..0cf0e76db1dd9ba169ada59e817d84ed9eb8c8db 100644 (file)
@@ -1 +1,16 @@
+#ifndef _ISOMAC
+# if IS_IN(libc) && defined SHARED
+/* Redirect calls from __builtin_stpcpy_chk to internal __stpcpy when building
+   with fortify enable.  */
+__asm__ ("stpcpy = __GI___stpcpy");
+# endif
+
+/* Add the internal aliass attribute to symbol before they first usage on the
+   fortify wrappers.  */
+libc_hidden_builtin_proto (memcpy)
+libc_hidden_builtin_proto (mempcpy)
+libc_hidden_builtin_proto (memmove)
+libc_hidden_builtin_proto (memset)
+#endif
+
 #include <string/bits/string_fortified.h>
index 491a263777a84b207aa4039e242b8d9f8eee7a2e..762b289184242e24f2c6b69cd38b6ee3c9564199 100644 (file)
@@ -1 +1,5 @@
 #include <misc/bits/syslog-decl.h>
+
+#ifndef _ISOMAC
+libc_hidden_ldbl_proto (__vsyslog_chk)
+#endif
index 7fcbd272acb78f449e89db7322e922d4798e200a..dd6af7e4c8da8212124d556aa2d63a8d84a8968f 100644 (file)
@@ -1 +1,7 @@
 #include <posix/bits/unistd-decl.h>
+
+#ifndef _ISOMAC
+libc_hidden_proto (__read_chk)
+libc_hidden_proto (__getdomainname_chk)
+libc_hidden_proto (__getlogin_r_chk)
+#endif
index 00b1b93342ef28ff43d3aaa7b29f6ec8910f5a3f..f3b8a8cf8794ed705bfb78cfcc5ced7ed592edb4 100644 (file)
@@ -1 +1,6 @@
 #include <wcsmbs/bits/wchar2-decl.h>
+
+#ifndef _ISOMAC
+libc_hidden_builtin_proto (__wmemset_chk)
+libc_hidden_proto (__wcrtomb_chk)
+#endif
index 181a746949ca1bde104670e3799da69473fb2fe3..67a38d8c34106012e5bc156bce6985a5ba22b261 100644 (file)
     redirecting ldouble to _Float128 variants.  We can therefore safely
     directly alias them to their internal name.  */
 # if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1 && IS_IN (libc)
-#  define stdio_hidden_ldbl_proto(p, f) \
-  extern __typeof (p ## f) p ## f __asm (__ASMNAME ("___ieee128_" #f));
+#  ifdef SHARED
+#   define stdio_hidden_ldbl_proto(p, f) __LDBL_REDIR2_DECL (f)
+#  else
+#   define stdio_hidden_ldbl_proto(p, f) \
+  extern __typeof (p ## f) p ## f __asm (#p __ASMNAME (#f "ieee128"));
+#  endif
 # elif __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
 #  define stdio_hidden_ldbl_proto(p,f) __LDBL_REDIR1_DECL (p ## f, p ## f ## ieee128)
 # else
@@ -70,10 +74,12 @@ extern int __printf_chk (int, const char *, ...);
 extern int __fprintf_chk (FILE *, int, const char *, ...);
 extern int __vprintf_chk (int, const char *, __gnuc_va_list);
 extern int __vfprintf_chk (FILE *, int, const char *, __gnuc_va_list);
+stdio_hidden_ldbl_proto (__, vfprintf_chk)
 extern char *__fgets_unlocked_chk (char *buf, size_t size, int n, FILE *fp);
 extern char *__fgets_chk (char *buf, size_t size, int n, FILE *fp);
 extern int __asprintf_chk (char **, int, const char *, ...) __THROW;
 extern int __vasprintf_chk (char **, int, const char *, __gnuc_va_list) __THROW;
+stdio_hidden_ldbl_proto (__, vasprintf_chk)
 extern int __dprintf_chk (int, int, const char *, ...);
 extern int __vdprintf_chk (int, int, const char *, __gnuc_va_list);
 extern int __obstack_printf_chk (struct obstack *, int, const char *, ...)
index 376ab5a93688c39544251c68cf19c9f6a6734a03..c1a4736951b484c38b3ab6d6152abe933b22d657 100644 (file)
@@ -32,10 +32,6 @@ libc_hidden_proto (readlinkat)
 libc_hidden_proto (fsync)
 libc_hidden_proto (fdatasync)
 
-libc_hidden_proto (__read_chk)
-libc_hidden_proto (__getdomainname_chk)
-libc_hidden_proto (__getlogin_r_chk)
-
 /* Now define the internal interfaces.  */
 extern int __access (const char *__name, int __type);
 libc_hidden_proto (__access)
index bf3262573642f00b8236b06a3715df186764681c..6abb0d26972a194d80da4d6a044d2b623661dcd7 100644 (file)
@@ -166,7 +166,6 @@ libc_hidden_proto (putwc)
 
 libc_hidden_proto (mbrtowc)
 libc_hidden_proto (wcrtomb)
-libc_hidden_proto (__wcrtomb_chk)
 
 extern int __wcscmp (const wchar_t *__s1, const wchar_t *__s2)
      __THROW __attribute_pure__;
index cc476ebcfdefb8919fe42e6934a22c442ee3369a..0919bc9779fe5169bf0dd12efd70fc929d84b749 100644 (file)
@@ -45,6 +45,7 @@ __NTH (inet_pton (int __af,
     __fortify_clang_warning_only_if_bos0_lt
        (4, __dst, "inet_pton called with destination buffer size less than 4")
 {
+#if !__fortify_use_clang
   size_t __sz = 0;
   if (__af == AF_INET)
     __sz = sizeof (struct in_addr);
@@ -52,6 +53,7 @@ __NTH (inet_pton (int __af,
     __sz = sizeof (struct in6_addr);
   else
     return __inet_pton_alias (__af, __src, __dst);
+#endif
 
   return __glibc_fortify (inet_pton, __sz, sizeof (char),
                          __glibc_objsize (__dst),
index 2bc98365225ed42563c6ef7a7e3948ee15c13f34..f946cd311b444eeb174d9163471c626f607edbeb 100644 (file)
@@ -60,6 +60,7 @@ routines_no_fortify += \
   iofgets_u \
   iofgetws \
   iofgetws_u \
+  iovdprintf \
   swprintf \
   vasprintf \
   vsnprintf \
index 53bb33425918d10d68e21e3787a8bc27ee873f57..b7414e7b43a510342273bece335b4258e8754905 100644 (file)
@@ -114,10 +114,12 @@ ldbl_hidden_def (___syslog_chk, __syslog_chk)
 ldbl_strong_alias (___syslog_chk, __syslog_chk)
 
 void
-__vsyslog_chk (int pri, int flag, const char *fmt, va_list ap)
+___vsyslog_chk (int pri, int flag, const char *fmt, va_list ap)
 {
   __vsyslog_internal (pri, fmt, ap, (flag > 0) ? PRINTF_FORTIFY : 0);
 }
+ldbl_hidden_def (___vsyslog_chk, __vsyslog_chk)
+ldbl_strong_alias (___vsyslog_chk, __vsyslog_chk)
 
 void
 __vsyslog_internal (int pri, const char *fmt, va_list ap,
index 2f30e66df581713750eaab7ba07a4d92720f0bc3..7c0245452b2b8061247a70b12ac6cb035f544dca 100644 (file)
@@ -121,6 +121,7 @@ routines := \
 
 # Exclude fortified routines from being built with _FORTIFY_SOURCE
 routines_no_fortify += \
+  bzero \
   explicit_bzero \
   memcpy \
   memmove \
index 1115e4c0a7af113e21eefb99fb04ca794470e68a..58398d33a5f81001c8cb6b7180b33d3fdb07cad9 100644 (file)
@@ -6,6 +6,21 @@ asm ("memmove = __GI_memmove");
 asm ("memset = __GI_memset");
 asm ("memcpy = __GI_memcpy");
 
+/* clang might generate the internal fortfify calls when it is enabled,
+   through the buitintin.  */
+asm ("__vfprintf_chk = __GI___vfprintf_chk");
+asm ("__vsprintf_chk = __GI___vsprintf_chk");
+asm ("__vsyslog_chk = __GI___vsyslog_chk");
+asm ("__memcpy_chk = __GI___memcpy_chk");
+asm ("__memmove_chk = __GI___memmove_chk");
+asm ("__memset_chk = __GI___memset_chk");
+asm ("__mempcpy_chk = __GI___mempcpy_chk");
+asm ("__stpcpy_chk = __GI___stpcpy_chk");
+asm ("__strcpy_chk = __GI___strcpy_chk");
+asm ("strcpy = __GI_strcpy");
+asm ("strncpy = __GI_strncpy");
+asm ("strcat = __GI_strcat");
+
 /* Some targets do not use __stack_chk_fail_local.  In libc.so,
    redirect __stack_chk_fail to a hidden reference
    __stack_chk_fail_local, to avoid the PLT reference.
index d458da7903c24b8cb8c4c8afa878b281c301d062..f880a55e0b9e909b31a7af9307910d0ec7b8e360 100644 (file)
@@ -33,3 +33,7 @@ ___ieee128_snprintf (char *s, size_t maxlen, const char *format, ...)
   return done;
 }
 strong_alias (___ieee128_snprintf, __snprintfieee128)
+ldbl_hidden_def (___ieee128_snprintf, ___ieee128_snprintf)
+#ifdef SHARED
+strong_alias (___ieee128_snprintf, __GI____ieee128___snprintf)
+#endif
index 197b149d0f2936172f4ab47173bf70aa2883d881..e08ae3aa280c55feb569693e39f3d8a8f634e4ba 100644 (file)
@@ -56,7 +56,7 @@ hidden_def (___ieee128___syslog_chk)
 strong_alias (___ieee128___syslog_chk, __syslog_chkieee128)
 
 void
-___ieee128___vsyslog_chk (int pri, int flag, const char *fmt, va_list ap)
+____ieee128___vsyslog_chk (int pri, int flag, const char *fmt, va_list ap)
 {
   unsigned int mode = PRINTF_LDBL_USES_FLOAT128;
   if (flag > 0)
@@ -64,4 +64,5 @@ ___ieee128___vsyslog_chk (int pri, int flag, const char *fmt, va_list ap)
 
   __vsyslog_internal (pri, fmt, ap, mode);
 }
-strong_alias (___ieee128___vsyslog_chk, __vsyslog_chkieee128)
+strong_alias (____ieee128___vsyslog_chk, ___ieee128___vsyslog_chk)
+strong_alias (____ieee128___vsyslog_chk, __vsyslog_chkieee128)