public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/azanella/clang] Enable --enable-fortify-source with clang
@ 2024-02-09 17:39 Adhemerval Zanella
0 siblings, 0 replies; 3+ messages in thread
From: Adhemerval Zanella @ 2024-02-09 17:39 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=fe177b6733842a617ce6dc9de15194447ecb6be1
commit fe177b6733842a617ce6dc9de15194447ecb6be1
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Thu Feb 8 10:56:30 2024 -0300
Enable --enable-fortify-source with clang
Diff:
---
debug/vasprintf_chk.c | 1 +
debug/vfprintf_chk.c | 1 +
elf/Makefile | 8 ++++++++
include/bits/stdio2-decl.h | 7 +++++++
include/bits/string_fortified.h | 15 +++++++++++++++
include/bits/syslog-decl.h | 4 ++++
include/bits/unistd-decl.h | 6 ++++++
include/bits/wchar2-decl.h | 5 +++++
include/stdio.h | 2 ++
include/string.h | 1 +
include/unistd.h | 4 ----
include/wchar.h | 1 -
libio/Makefile | 1 +
misc/syslog.c | 4 +++-
string/Makefile | 1 +
sysdeps/generic/symbol-hacks.h | 15 +++++++++++++++
sysdeps/unix/sysv/linux/not-cancel.h | 8 ++++----
17 files changed, 74 insertions(+), 10 deletions(-)
diff --git a/debug/vasprintf_chk.c b/debug/vasprintf_chk.c
index 2d6bf8ebba..693bac0432 100644
--- a/debug/vasprintf_chk.c
+++ b/debug/vasprintf_chk.c
@@ -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)
diff --git a/debug/vfprintf_chk.c b/debug/vfprintf_chk.c
index 62c34a965e..7ee34d57a7 100644
--- a/debug/vfprintf_chk.c
+++ b/debug/vfprintf_chk.c
@@ -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)
diff --git a/elf/Makefile b/elf/Makefile
index 49e205b38d..88fe44ebed 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -1289,6 +1289,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.
diff --git a/include/bits/stdio2-decl.h b/include/bits/stdio2-decl.h
index bbb052f192..d4e094a9ce 100644
--- a/include/bits/stdio2-decl.h
+++ b/include/bits/stdio2-decl.h
@@ -1 +1,8 @@
#include <libio/bits/stdio2-decl.h>
+
+#ifndef _ISOMAC
+libc_hidden_ldbl_proto (vfprintf)
+libc_hidden_proto (__fgets_unlocked_chk)
+libc_hidden_proto (__vasprintf_chk)
+libc_hidden_proto (__vfprintf_chk)
+#endif
diff --git a/include/bits/string_fortified.h b/include/bits/string_fortified.h
index 88bf073c9c..0cf0e76db1 100644
--- a/include/bits/string_fortified.h
+++ b/include/bits/string_fortified.h
@@ -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>
diff --git a/include/bits/syslog-decl.h b/include/bits/syslog-decl.h
index 491a263777..762b289184 100644
--- a/include/bits/syslog-decl.h
+++ b/include/bits/syslog-decl.h
@@ -1 +1,5 @@
#include <misc/bits/syslog-decl.h>
+
+#ifndef _ISOMAC
+libc_hidden_ldbl_proto (__vsyslog_chk)
+#endif
diff --git a/include/bits/unistd-decl.h b/include/bits/unistd-decl.h
index 7fcbd272ac..dd6af7e4c8 100644
--- a/include/bits/unistd-decl.h
+++ b/include/bits/unistd-decl.h
@@ -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
diff --git a/include/bits/wchar2-decl.h b/include/bits/wchar2-decl.h
index 00b1b93342..f3b8a8cf87 100644
--- a/include/bits/wchar2-decl.h
+++ b/include/bits/wchar2-decl.h
@@ -1 +1,6 @@
#include <wcsmbs/bits/wchar2-decl.h>
+
+#ifndef _ISOMAC
+libc_hidden_builtin_proto (__wmemset_chk)
+libc_hidden_proto (__wcrtomb_chk)
+#endif
diff --git a/include/stdio.h b/include/stdio.h
index 24f1652f19..3de3674b16 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -70,10 +70,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);
+libc_hidden_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;
+libc_hidden_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 *, ...)
diff --git a/include/string.h b/include/string.h
index 2a4788e8c2..b5c8d7cb3d 100644
--- a/include/string.h
+++ b/include/string.h
@@ -84,6 +84,7 @@ libc_hidden_proto (__mempcpy)
# define __mempcpy(dest, src, n) __builtin_mempcpy (dest, src, n)
#endif
libc_hidden_proto (__stpcpy)
+//#if !defined __NO_STRING_INLINES && !defined __clang__
#ifndef __NO_STRING_INLINES
# define __stpcpy(dest, src) __builtin_stpcpy (dest, src)
#endif
diff --git a/include/unistd.h b/include/unistd.h
index e241603b81..b042a485f9 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -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)
diff --git a/include/wchar.h b/include/wchar.h
index bf32625736..6abb0d2697 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -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__;
diff --git a/libio/Makefile b/libio/Makefile
index 385bee9b7d..b5d1eafe6b 100644
--- a/libio/Makefile
+++ b/libio/Makefile
@@ -66,6 +66,7 @@ routines_no_fortify += \
vswprintf \
vwprintf \
wprintf \
+ iovdprintf \
# routines_no_fortify
tests = tst_swprintf tst_wprintf tst_swscanf tst_wscanf tst_getwc tst_putwc \
diff --git a/misc/syslog.c b/misc/syslog.c
index 4186292b24..9578dd7307 100644
--- a/misc/syslog.c
+++ b/misc/syslog.c
@@ -115,10 +115,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,
diff --git a/string/Makefile b/string/Makefile
index cbdcff3706..dd44febc39 100644
--- a/string/Makefile
+++ b/string/Makefile
@@ -133,6 +133,7 @@ routines_no_fortify += \
strlcpy \
strncat \
strncpy \
+ bzero \
# routines_no_fortify
tests := \
diff --git a/sysdeps/generic/symbol-hacks.h b/sysdeps/generic/symbol-hacks.h
index 560116d575..e262a5c153 100644
--- a/sysdeps/generic/symbol-hacks.h
+++ b/sysdeps/generic/symbol-hacks.h
@@ -13,6 +13,21 @@ asm ("memcpy = __GI_memcpy");
callbacks (for instance pthread_once). */
asm ("abort = __GI_abort");
+/* 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.
diff --git a/sysdeps/unix/sysv/linux/not-cancel.h b/sysdeps/unix/sysv/linux/not-cancel.h
index 2a7585b73f..7a5af5275a 100644
--- a/sysdeps/unix/sysv/linux/not-cancel.h
+++ b/sysdeps/unix/sysv/linux/not-cancel.h
@@ -29,16 +29,16 @@
#include <time.h>
/* Non cancellable open syscall. */
-__typeof (open) __open_nocancel;
+extern int __open_nocancel (const char *, int, ...);
/* Non cancellable open syscall (LFS version). */
-__typeof (open64) __open64_nocancel;
+extern int __open64_nocancel (const char *, int, ...);
/* Non cancellable openat syscall. */
-__typeof (openat) __openat_nocancel;
+extern int __openat_nocancel (int fd, const char *, int, ...);
/* Non cacellable openat syscall (LFS version). */
-__typeof (openat64) __openat64_nocancel;
+extern int __openat64_nocancel (int fd, const char *, int, ...);
/* Non cancellable read syscall. */
__typeof (__read) __read_nocancel;
^ permalink raw reply [flat|nested] 3+ messages in thread
* [glibc/azanella/clang] Enable --enable-fortify-source with clang
@ 2024-04-17 20:15 Adhemerval Zanella
0 siblings, 0 replies; 3+ messages in thread
From: Adhemerval Zanella @ 2024-04-17 20:15 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=db7a80b30f1972456fde5a0db1e1047b048fdf28
commit db7a80b30f1972456fde5a0db1e1047b048fdf28
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Thu Feb 8 10:56:30 2024 -0300
Enable --enable-fortify-source with clang
Diff:
---
debug/vasprintf_chk.c | 1 +
debug/vfprintf_chk.c | 1 +
elf/Makefile | 8 ++++++++
include/bits/stdio2-decl.h | 7 +++++++
include/bits/string_fortified.h | 15 +++++++++++++++
include/bits/syslog-decl.h | 4 ++++
include/bits/unistd-decl.h | 6 ++++++
include/bits/wchar2-decl.h | 5 +++++
include/stdio.h | 12 ++++++++++--
include/unistd.h | 4 ----
include/wchar.h | 1 -
libio/Makefile | 1 +
misc/syslog.c | 4 +++-
string/Makefile | 1 +
sysdeps/generic/symbol-hacks.h | 15 +++++++++++++++
sysdeps/ieee754/ldbl-128ibm-compat/ieee128-snprintf.c | 4 ++++
sysdeps/ieee754/ldbl-128ibm-compat/ieee128-syslog.c | 5 +++--
sysdeps/unix/sysv/linux/not-cancel.h | 8 ++++----
18 files changed, 88 insertions(+), 14 deletions(-)
diff --git a/debug/vasprintf_chk.c b/debug/vasprintf_chk.c
index 2d6bf8ebba..693bac0432 100644
--- a/debug/vasprintf_chk.c
+++ b/debug/vasprintf_chk.c
@@ -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)
diff --git a/debug/vfprintf_chk.c b/debug/vfprintf_chk.c
index 62c34a965e..7ee34d57a7 100644
--- a/debug/vfprintf_chk.c
+++ b/debug/vfprintf_chk.c
@@ -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)
diff --git a/elf/Makefile b/elf/Makefile
index 9c91e8bed1..835600575f 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -1303,6 +1303,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.
diff --git a/include/bits/stdio2-decl.h b/include/bits/stdio2-decl.h
index bbb052f192..9758bf4b55 100644
--- a/include/bits/stdio2-decl.h
+++ b/include/bits/stdio2-decl.h
@@ -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
diff --git a/include/bits/string_fortified.h b/include/bits/string_fortified.h
index 88bf073c9c..0cf0e76db1 100644
--- a/include/bits/string_fortified.h
+++ b/include/bits/string_fortified.h
@@ -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>
diff --git a/include/bits/syslog-decl.h b/include/bits/syslog-decl.h
index 491a263777..762b289184 100644
--- a/include/bits/syslog-decl.h
+++ b/include/bits/syslog-decl.h
@@ -1 +1,5 @@
#include <misc/bits/syslog-decl.h>
+
+#ifndef _ISOMAC
+libc_hidden_ldbl_proto (__vsyslog_chk)
+#endif
diff --git a/include/bits/unistd-decl.h b/include/bits/unistd-decl.h
index 7fcbd272ac..dd6af7e4c8 100644
--- a/include/bits/unistd-decl.h
+++ b/include/bits/unistd-decl.h
@@ -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
diff --git a/include/bits/wchar2-decl.h b/include/bits/wchar2-decl.h
index 00b1b93342..f3b8a8cf87 100644
--- a/include/bits/wchar2-decl.h
+++ b/include/bits/wchar2-decl.h
@@ -1 +1,6 @@
#include <wcsmbs/bits/wchar2-decl.h>
+
+#ifndef _ISOMAC
+libc_hidden_builtin_proto (__wmemset_chk)
+libc_hidden_proto (__wcrtomb_chk)
+#endif
diff --git a/include/stdio.h b/include/stdio.h
index e48d709919..63cd59da90 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -23,8 +23,12 @@
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,14 @@ 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);
+//libc_hidden_proto (__vfprintf_chk)
+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;
+//libc_hidden_proto (__vasprintf_chk)
+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 *, ...)
diff --git a/include/unistd.h b/include/unistd.h
index e241603b81..b042a485f9 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -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)
diff --git a/include/wchar.h b/include/wchar.h
index bf32625736..6abb0d2697 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -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__;
diff --git a/libio/Makefile b/libio/Makefile
index 385bee9b7d..70d39c752e 100644
--- a/libio/Makefile
+++ b/libio/Makefile
@@ -60,6 +60,7 @@ routines_no_fortify += \
iofgets_u \
iofgetws \
iofgetws_u \
+ iovdprintf \
swprintf \
vasprintf \
vsnprintf \
diff --git a/misc/syslog.c b/misc/syslog.c
index 4186292b24..9578dd7307 100644
--- a/misc/syslog.c
+++ b/misc/syslog.c
@@ -115,10 +115,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,
diff --git a/string/Makefile b/string/Makefile
index cbdcff3706..f630b4ea63 100644
--- a/string/Makefile
+++ b/string/Makefile
@@ -120,6 +120,7 @@ routines := \
# Exclude fortified routines from being built with _FORTIFY_SOURCE
routines_no_fortify += \
+ bzero \
explicit_bzero \
memcpy \
memmove \
diff --git a/sysdeps/generic/symbol-hacks.h b/sysdeps/generic/symbol-hacks.h
index 560116d575..e262a5c153 100644
--- a/sysdeps/generic/symbol-hacks.h
+++ b/sysdeps/generic/symbol-hacks.h
@@ -13,6 +13,21 @@ asm ("memcpy = __GI_memcpy");
callbacks (for instance pthread_once). */
asm ("abort = __GI_abort");
+/* 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.
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-snprintf.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-snprintf.c
index 80ca498095..27c7c87960 100644
--- a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-snprintf.c
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-snprintf.c
@@ -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
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-syslog.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-syslog.c
index 187e861847..39adc7e61c 100644
--- a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-syslog.c
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-syslog.c
@@ -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)
diff --git a/sysdeps/unix/sysv/linux/not-cancel.h b/sysdeps/unix/sysv/linux/not-cancel.h
index 2a7585b73f..7a5af5275a 100644
--- a/sysdeps/unix/sysv/linux/not-cancel.h
+++ b/sysdeps/unix/sysv/linux/not-cancel.h
@@ -29,16 +29,16 @@
#include <time.h>
/* Non cancellable open syscall. */
-__typeof (open) __open_nocancel;
+extern int __open_nocancel (const char *, int, ...);
/* Non cancellable open syscall (LFS version). */
-__typeof (open64) __open64_nocancel;
+extern int __open64_nocancel (const char *, int, ...);
/* Non cancellable openat syscall. */
-__typeof (openat) __openat_nocancel;
+extern int __openat_nocancel (int fd, const char *, int, ...);
/* Non cacellable openat syscall (LFS version). */
-__typeof (openat64) __openat64_nocancel;
+extern int __openat64_nocancel (int fd, const char *, int, ...);
/* Non cancellable read syscall. */
__typeof (__read) __read_nocancel;
^ permalink raw reply [flat|nested] 3+ messages in thread
* [glibc/azanella/clang] Enable --enable-fortify-source with clang
@ 2024-04-02 16:01 Adhemerval Zanella
0 siblings, 0 replies; 3+ messages in thread
From: Adhemerval Zanella @ 2024-04-02 16:01 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=cbf9eeb0b0be6661d87e984e0753d0165b2f1113
commit cbf9eeb0b0be6661d87e984e0753d0165b2f1113
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Thu Feb 8 10:56:30 2024 -0300
Enable --enable-fortify-source with clang
Diff:
---
debug/vasprintf_chk.c | 1 +
debug/vfprintf_chk.c | 1 +
elf/Makefile | 8 ++++++++
include/bits/stdio2-decl.h | 7 +++++++
include/bits/string_fortified.h | 15 +++++++++++++++
include/bits/syslog-decl.h | 4 ++++
include/bits/unistd-decl.h | 6 ++++++
include/bits/wchar2-decl.h | 5 +++++
include/stdio.h | 12 ++++++++++--
include/unistd.h | 4 ----
include/wchar.h | 1 -
libio/Makefile | 1 +
misc/syslog.c | 4 +++-
string/Makefile | 1 +
sysdeps/generic/symbol-hacks.h | 15 +++++++++++++++
sysdeps/ieee754/ldbl-128ibm-compat/ieee128-snprintf.c | 4 ++++
sysdeps/ieee754/ldbl-128ibm-compat/ieee128-syslog.c | 5 +++--
sysdeps/unix/sysv/linux/not-cancel.h | 8 ++++----
18 files changed, 88 insertions(+), 14 deletions(-)
diff --git a/debug/vasprintf_chk.c b/debug/vasprintf_chk.c
index 2d6bf8ebba..693bac0432 100644
--- a/debug/vasprintf_chk.c
+++ b/debug/vasprintf_chk.c
@@ -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)
diff --git a/debug/vfprintf_chk.c b/debug/vfprintf_chk.c
index 62c34a965e..7ee34d57a7 100644
--- a/debug/vfprintf_chk.c
+++ b/debug/vfprintf_chk.c
@@ -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)
diff --git a/elf/Makefile b/elf/Makefile
index c271095eb7..20cc569151 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -1295,6 +1295,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.
diff --git a/include/bits/stdio2-decl.h b/include/bits/stdio2-decl.h
index bbb052f192..9758bf4b55 100644
--- a/include/bits/stdio2-decl.h
+++ b/include/bits/stdio2-decl.h
@@ -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
diff --git a/include/bits/string_fortified.h b/include/bits/string_fortified.h
index 88bf073c9c..0cf0e76db1 100644
--- a/include/bits/string_fortified.h
+++ b/include/bits/string_fortified.h
@@ -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>
diff --git a/include/bits/syslog-decl.h b/include/bits/syslog-decl.h
index 491a263777..762b289184 100644
--- a/include/bits/syslog-decl.h
+++ b/include/bits/syslog-decl.h
@@ -1 +1,5 @@
#include <misc/bits/syslog-decl.h>
+
+#ifndef _ISOMAC
+libc_hidden_ldbl_proto (__vsyslog_chk)
+#endif
diff --git a/include/bits/unistd-decl.h b/include/bits/unistd-decl.h
index 7fcbd272ac..dd6af7e4c8 100644
--- a/include/bits/unistd-decl.h
+++ b/include/bits/unistd-decl.h
@@ -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
diff --git a/include/bits/wchar2-decl.h b/include/bits/wchar2-decl.h
index 00b1b93342..f3b8a8cf87 100644
--- a/include/bits/wchar2-decl.h
+++ b/include/bits/wchar2-decl.h
@@ -1 +1,6 @@
#include <wcsmbs/bits/wchar2-decl.h>
+
+#ifndef _ISOMAC
+libc_hidden_builtin_proto (__wmemset_chk)
+libc_hidden_proto (__wcrtomb_chk)
+#endif
diff --git a/include/stdio.h b/include/stdio.h
index 24f1652f19..5a22f8bff2 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -23,8 +23,12 @@
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,14 @@ 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);
+//libc_hidden_proto (__vfprintf_chk)
+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;
+//libc_hidden_proto (__vasprintf_chk)
+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 *, ...)
diff --git a/include/unistd.h b/include/unistd.h
index e241603b81..b042a485f9 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -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)
diff --git a/include/wchar.h b/include/wchar.h
index bf32625736..6abb0d2697 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -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__;
diff --git a/libio/Makefile b/libio/Makefile
index 385bee9b7d..70d39c752e 100644
--- a/libio/Makefile
+++ b/libio/Makefile
@@ -60,6 +60,7 @@ routines_no_fortify += \
iofgets_u \
iofgetws \
iofgetws_u \
+ iovdprintf \
swprintf \
vasprintf \
vsnprintf \
diff --git a/misc/syslog.c b/misc/syslog.c
index 4186292b24..9578dd7307 100644
--- a/misc/syslog.c
+++ b/misc/syslog.c
@@ -115,10 +115,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,
diff --git a/string/Makefile b/string/Makefile
index cbdcff3706..f630b4ea63 100644
--- a/string/Makefile
+++ b/string/Makefile
@@ -120,6 +120,7 @@ routines := \
# Exclude fortified routines from being built with _FORTIFY_SOURCE
routines_no_fortify += \
+ bzero \
explicit_bzero \
memcpy \
memmove \
diff --git a/sysdeps/generic/symbol-hacks.h b/sysdeps/generic/symbol-hacks.h
index 560116d575..e262a5c153 100644
--- a/sysdeps/generic/symbol-hacks.h
+++ b/sysdeps/generic/symbol-hacks.h
@@ -13,6 +13,21 @@ asm ("memcpy = __GI_memcpy");
callbacks (for instance pthread_once). */
asm ("abort = __GI_abort");
+/* 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.
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-snprintf.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-snprintf.c
index 80ca498095..27c7c87960 100644
--- a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-snprintf.c
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-snprintf.c
@@ -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
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-syslog.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-syslog.c
index 187e861847..39adc7e61c 100644
--- a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-syslog.c
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-syslog.c
@@ -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)
diff --git a/sysdeps/unix/sysv/linux/not-cancel.h b/sysdeps/unix/sysv/linux/not-cancel.h
index 2a7585b73f..7a5af5275a 100644
--- a/sysdeps/unix/sysv/linux/not-cancel.h
+++ b/sysdeps/unix/sysv/linux/not-cancel.h
@@ -29,16 +29,16 @@
#include <time.h>
/* Non cancellable open syscall. */
-__typeof (open) __open_nocancel;
+extern int __open_nocancel (const char *, int, ...);
/* Non cancellable open syscall (LFS version). */
-__typeof (open64) __open64_nocancel;
+extern int __open64_nocancel (const char *, int, ...);
/* Non cancellable openat syscall. */
-__typeof (openat) __openat_nocancel;
+extern int __openat_nocancel (int fd, const char *, int, ...);
/* Non cacellable openat syscall (LFS version). */
-__typeof (openat64) __openat64_nocancel;
+extern int __openat64_nocancel (int fd, const char *, int, ...);
/* Non cancellable read syscall. */
__typeof (__read) __read_nocancel;
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-04-17 20:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-09 17:39 [glibc/azanella/clang] Enable --enable-fortify-source with clang Adhemerval Zanella
2024-04-02 16:01 Adhemerval Zanella
2024-04-17 20:15 Adhemerval Zanella
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).