Skip to content

Commit 61f16a6

Browse files
committed
toolchain: fortify-headers: Fix build of some packages
Fix some warnings and compile errors generated by the new fortify-headers when compiling some applications like strace. Fixes: 6268692 ("toolchain: fortify-headers: Update to version 2.3.3") Link: openwrt/openwrt#20561 Signed-off-by: Hauke Mehrtens <[email protected]>
1 parent 6de9691 commit 61f16a6

File tree

3 files changed

+373
-0
lines changed

3 files changed

+373
-0
lines changed
Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Hauke Mehrtens <[email protected]>
3+
Date: Sun, 26 Oct 2025 17:38:41 +0100
4+
Subject: Check if FORTIFY_USE_NATIVE_CHK is defined
5+
6+
The previews code tried to get the value defined for
7+
FORTIFY_USE_NATIVE_CHK and this resulted in some build errors like
8+
this:
9+
```
10+
/include/fortify/stdio.h: In function 'vsnprintf':
11+
/include/fortify/stdio.h:155:49: error: "FORTIFY_USE_NATIVE_CHK" is not defined, evaluates to 0 [-Werror=undef]
12+
155 | #if __has_builtin(__builtin___vsnprintf_chk) && FORTIFY_USE_NATIVE_CHK
13+
| ^~~~~~~~~~~~~~~~~~~~~~
14+
```
15+
16+
Check if it is defined instead.
17+
18+
Signed-off-by: Hauke Mehrtens <[email protected]>
19+
---
20+
include/stdio.h | 20 ++++++++++----------
21+
include/string.h | 32 ++++++++++++++++----------------
22+
2 files changed, 26 insertions(+), 26 deletions(-)
23+
24+
--- a/include/stdio.h
25+
+++ b/include/stdio.h
26+
@@ -152,7 +152,7 @@ __diagnose_as_builtin(__builtin_vsnprint
27+
_FORTIFY_FN(vsnprintf) int vsnprintf(char * _FORTIFY_POS0 __s, size_t __n,
28+
const char *__f, __builtin_va_list __v)
29+
{
30+
-#if __has_builtin(__builtin___vsnprintf_chk) && FORTIFY_USE_NATIVE_CHK
31+
+#if __has_builtin(__builtin___vsnprintf_chk) && defined(FORTIFY_USE_NATIVE_CHK)
32+
return __builtin___vsnprintf_chk(__s, __n, _FORTIFY_SOURCE, __fh_bos(__s, 0), __f, __v);
33+
#else
34+
__fh_size_t __b = __fh_bos(__s, 0);
35+
@@ -172,7 +172,7 @@ __diagnose_as_builtin(__builtin_vsprintf
36+
_FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f,
37+
__builtin_va_list __v)
38+
{
39+
-#if __has_builtin(__builtin___vsprintf_chk) && FORTIFY_USE_NATIVE_CHK
40+
+#if __has_builtin(__builtin___vsprintf_chk) && defined(FORTIFY_USE_NATIVE_CHK)
41+
return __builtin___vsprintf_chk(__s, _FORTIFY_SOURCE, __fh_bos(__s, 0), __f, __v);
42+
#else
43+
__fh_size_t __b = __fh_bos(__s, 0);
44+
@@ -200,7 +200,7 @@ __diagnose_as_builtin(__builtin_vfprintf
45+
#endif
46+
_FORTIFY_FN(vfprintf) int vfprintf(FILE * __s, const char *__f, __builtin_va_list __v)
47+
{
48+
-#if __has_builtin(__builtin___vfprintf_chk) && FORTIFY_USE_NATIVE_CHK
49+
+#if __has_builtin(__builtin___vfprintf_chk) && defined(FORTIFY_USE_NATIVE_CHK)
50+
return __builtin___vfprintf_chk(__s, _FORTIFY_SOURCE, __f, __v);
51+
#else
52+
return __orig_vfprintf(__s, __f, __v);
53+
@@ -214,7 +214,7 @@ __diagnose_as_builtin(__builtin_vprintf,
54+
#endif
55+
_FORTIFY_FN(vprintf) int vprintf(const char *__f, __builtin_va_list __v)
56+
{
57+
-#if __has_builtin(__builtin___vprintf_chk) && FORTIFY_USE_NATIVE_CHK
58+
+#if __has_builtin(__builtin___vprintf_chk) && defined(FORTIFY_USE_NATIVE_CHK)
59+
return __builtin___vprintf_chk(_FORTIFY_SOURCE, __f, __v);
60+
#else
61+
return __orig_vprintf(__f, __v);
62+
@@ -228,7 +228,7 @@ __diagnose_as_builtin(__builtin_vasprint
63+
#endif
64+
_FORTIFY_FN(vasprintf) int vasprintf(char **strp, const char *fmt, __builtin_va_list ap)
65+
{
66+
-#if __has_builtin(__builtin___vasprintf_chk) && FORTIFY_USE_NATIVE_CHK
67+
+#if __has_builtin(__builtin___vasprintf_chk) && defined(FORTIFY_USE_NATIVE_CHK)
68+
return __builtin___vasprintf_chk(_FORTIFY_SOURCE, strp, fmt, ap);
69+
#else
70+
int ret = __orig_vasprintf(strp, fmt, ap);
71+
@@ -275,7 +275,7 @@ __fh_format(printf, 3, 4)
72+
_FORTIFY_FN(snprintf) int snprintf(char *__s, size_t __n,
73+
const char *__f, ...)
74+
{
75+
-#if __has_builtin(__builtin___snprintf_chk) && FORTIFY_USE_NATIVE_CHK
76+
+#if __has_builtin(__builtin___snprintf_chk) && defined(FORTIFY_USE_NATIVE_CHK)
77+
return __builtin___snprintf_chk(__s, __n, _FORTIFY_SOURCE, __fh_bos(__s, 0), __f, __builtin_va_arg_pack());
78+
#else
79+
__fh_size_t __b = __fh_bos(__s, 0);
80+
@@ -291,7 +291,7 @@ __fh_format(printf, 2, 3)
81+
__fh_access(read_only, 2)
82+
_FORTIFY_FN(sprintf) int sprintf(char *__s, const char *__f, ...)
83+
{
84+
-#if __has_builtin(__builtin___sprintf_chk) && FORTIFY_USE_NATIVE_CHK
85+
+#if __has_builtin(__builtin___sprintf_chk) && defined(FORTIFY_USE_NATIVE_CHK)
86+
return __builtin___sprintf_chk(__s, _FORTIFY_SOURCE, __fh_bos(__s, 0), __f, __builtin_va_arg_pack());
87+
#else
88+
__fh_size_t __b = __fh_bos(__s, 0);
89+
@@ -312,7 +312,7 @@ __fh_format(printf, 1, 2)
90+
__fh_access(read_only, 1)
91+
_FORTIFY_FN(printf) int printf(const char *__f, ...)
92+
{
93+
-#if __has_builtin(__builtin___printf_chk) && FORTIFY_USE_NATIVE_CHK
94+
+#if __has_builtin(__builtin___printf_chk) && defined(FORTIFY_USE_NATIVE_CHK)
95+
return __builtin___printf_chk(_FORTIFY_SOURCE, __f, __builtin_va_arg_pack());
96+
#else
97+
return __orig_printf(__f, __builtin_va_arg_pack());
98+
@@ -326,7 +326,7 @@ __diagnose_as_builtin(__builtin_fprintf,
99+
#endif
100+
_FORTIFY_FN(fprintf) int fprintf(FILE *__s, const char *__f, ...)
101+
{
102+
-#if __has_builtin(__builtin___fprintf_chk) && FORTIFY_USE_NATIVE_CHK
103+
+#if __has_builtin(__builtin___fprintf_chk) && defined(FORTIFY_USE_NATIVE_CHK)
104+
return __builtin___fprintf_chk(_FORTIFY_SOURCE, __s, __f, __builtin_va_arg_pack());
105+
#else
106+
return __orig_fprintf(__s, __f, __builtin_va_arg_pack());
107+
@@ -343,7 +343,7 @@ __diagnose_as_builtin(__builtin_asprintf
108+
#endif
109+
_FORTIFY_FN(asprintf) int asprintf(char **strp, const char *fmt, ...)
110+
{
111+
-#if __has_builtin(__builtin___asprintf_chk) && FORTIFY_USE_NATIVE_CHK
112+
+#if __has_builtin(__builtin___asprintf_chk) && defined(FORTIFY_USE_NATIVE_CHK)
113+
return __builtin___asprintf_chk(_FORTIFY_SOURCE, strp, fmt, __builtin_va_arg_pack());
114+
#else
115+
int ret = __orig_asprintf(strp, fmt, __builtin_va_arg_pack());
116+
--- a/include/string.h
117+
+++ b/include/string.h
118+
@@ -48,7 +48,7 @@ _FORTIFY_FN(memcpy) void *memcpy(void *
119+
const void * _FORTIFY_POS0 __os, size_t __n)
120+
__error_if((__fh_bos(__od, 0) < __n), "'memcpy' called with `n` bigger than the size of `d`.")
121+
{
122+
-#if __has_builtin(__builtin___memcpy_chk) && FORTIFY_USE_NATIVE_CHK
123+
+#if __has_builtin(__builtin___memcpy_chk) && defined(FORTIFY_USE_NATIVE_CHK)
124+
return __builtin___memcpy_chk(__od, __os, __n, __fh_bos(__od, 0));
125+
#else
126+
#if defined FORTIFY_PEDANTIC_CHECKS
127+
@@ -75,7 +75,7 @@ __diagnose_as_builtin(__builtin_memmove,
128+
_FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d,
129+
const void * _FORTIFY_POS0 __s, size_t __n)
130+
{
131+
-#if __has_builtin(__builtin___memmove_chk) && FORTIFY_USE_NATIVE_CHK
132+
+#if __has_builtin(__builtin___memmove_chk) && defined(FORTIFY_USE_NATIVE_CHK)
133+
return __builtin___memmove_chk(__d, __s, __n, __fh_bos(__d, 0));
134+
#else
135+
#if defined FORTIFY_PEDANTIC_CHECKS
136+
@@ -99,7 +99,7 @@ __diagnose_as_builtin(__builtin_memset,
137+
_FORTIFY_FN(memset) void *memset(void * _FORTIFY_POS0 __d, int __c, size_t __n)
138+
__warning_if(__c != 0 && __n == 0, "'memset' will set `0` bytes; did you invert the arguments?")
139+
{
140+
-#if __has_builtin(__builtin___memset_chk) && FORTIFY_USE_NATIVE_CHK
141+
+#if __has_builtin(__builtin___memset_chk) && defined(FORTIFY_USE_NATIVE_CHK)
142+
return __builtin___memset_chk(__d, __c, __n, __fh_bos(__d, 0));
143+
#else
144+
#if defined FORTIFY_PEDANTIC_CHECKS
145+
@@ -121,7 +121,7 @@ __diagnose_as_builtin(__builtin_memchr,
146+
#endif
147+
_FORTIFY_FN(memchr) void *memchr(const void * _FORTIFY_POS0 __d, int __c, size_t __n)
148+
{
149+
-#if __has_builtin(__builtin___memchr_chk) && FORTIFY_USE_NATIVE_CHK
150+
+#if __has_builtin(__builtin___memchr_chk) && defined(FORTIFY_USE_NATIVE_CHK)
151+
return __builtin___memchr_chk(__d, __c, __n, __fh_bos(__d, 0));
152+
#else
153+
#if defined FORTIFY_PEDANTIC_CHECKS
154+
@@ -142,7 +142,7 @@ _FORTIFY_FN(memchr) void *memchr(const v
155+
__fh_access(read_only, 1, 2)
156+
_FORTIFY_FN(strchr) char *strchr(const char * _FORTIFY_POS0 __s, int __c)
157+
{
158+
-#if __has_builtin(__builtin___strchr_chk) && FORTIFY_USE_NATIVE_CHK
159+
+#if __has_builtin(__builtin___strchr_chk) && defined(FORTIFY_USE_NATIVE_CHK)
160+
return __builtin___strchr_chk(__s, __c, __fh_bos(__s, 0));
161+
#else
162+
__fh_size_t __b = __fh_bos(__s, 0);
163+
@@ -157,7 +157,7 @@ _FORTIFY_FN(strchr) char *strchr(const c
164+
__fh_access(read_only, 1, 2)
165+
_FORTIFY_FN(strrchr) char *strrchr(const char * _FORTIFY_POS0 __s, int __c)
166+
{
167+
-#if __has_builtin(__builtin___strrchr_chk) && FORTIFY_USE_NATIVE_CHK
168+
+#if __has_builtin(__builtin___strrchr_chk) && defined(FORTIFY_USE_NATIVE_CHK)
169+
return __builtin___strrchr_chk(__s, __c, __fh_bos(__s, 0));
170+
#else
171+
__fh_size_t __b = __fh_bos(__s, 0);
172+
@@ -181,7 +181,7 @@ __diagnose_as_builtin(__builtin_stpcpy,
173+
#endif
174+
_FORTIFY_FN(stpcpy) char *stpcpy(char * _FORTIFY_POS0 __d, const char *__s)
175+
{
176+
-#if __has_builtin(__builtin___stpcpy_chk) && FORTIFY_USE_NATIVE_CHK
177+
+#if __has_builtin(__builtin___stpcpy_chk) && defined(FORTIFY_USE_NATIVE_CHK)
178+
return __builtin___stpcpy_chk(__d, __s, __fh_bos(__d, 0));
179+
#else
180+
__fh_size_t __n = strlen(__s) + 1;
181+
@@ -205,7 +205,7 @@ __diagnose_as_builtin(__builtin_stpncpy,
182+
_FORTIFY_FN(stpncpy) char *stpncpy(char * _FORTIFY_POS0 __d, const char *__s,
183+
size_t __n)
184+
{
185+
-#if __has_builtin(__builtin___stpncpy_chk) && FORTIFY_USE_NATIVE_CHK
186+
+#if __has_builtin(__builtin___stpncpy_chk) && defined(FORTIFY_USE_NATIVE_CHK)
187+
return __builtin___stpncpy_chk(__d, __s, __n, __fh_bos(__d, 0));
188+
#else
189+
// If the length strlen(src) is smaller than n, the remaining
190+
@@ -227,7 +227,7 @@ __diagnose_as_builtin(__builtin_strcat,
191+
#endif
192+
_FORTIFY_FN(strcat) char *strcat(char * _FORTIFY_POS0 __d, const char *__s)
193+
{
194+
-#if __has_builtin(__builtin___strcat_chk) && FORTIFY_USE_NATIVE_CHK
195+
+#if __has_builtin(__builtin___strcat_chk) && defined(FORTIFY_USE_NATIVE_CHK)
196+
return __builtin___strcat_chk(__d, __s, __fh_bos(__d, 0));
197+
#else
198+
__fh_size_t __b = __fh_bos(__d, 0);
199+
@@ -245,7 +245,7 @@ __diagnose_as_builtin(__builtin_strcpy,
200+
#endif
201+
_FORTIFY_FN(strcpy) char *strcpy(char * _FORTIFY_POS0 __d, const char *__s)
202+
{
203+
-#if __has_builtin(__builtin___strcpy_chk) && FORTIFY_USE_NATIVE_CHK
204+
+#if __has_builtin(__builtin___strcpy_chk) && defined(FORTIFY_USE_NATIVE_CHK)
205+
return __builtin___strcpy_chk(__d, __s, __fh_bos(__d, 0));
206+
#else
207+
__fh_size_t __n = strlen(__s) + 1;
208+
@@ -266,7 +266,7 @@ __diagnose_as_builtin(__builtin_strlen,
209+
#endif
210+
_FORTIFY_FN(strlen) size_t strlen(const char * _FORTIFY_POS0 __s)
211+
{
212+
-#if __has_builtin(__builtin___strlen_chk) && FORTIFY_USE_NATIVE_CHK
213+
+#if __has_builtin(__builtin___strlen_chk) && defined(FORTIFY_USE_NATIVE_CHK)
214+
return __builtin___strlen_chk(__s, __fh_bos(__s, 0));
215+
#else
216+
__fh_size_t ret = __orig_strlen(__s);
217+
@@ -284,7 +284,7 @@ __diagnose_as_builtin(__builtin_strncat,
218+
_FORTIFY_FN(strncat) char *strncat(char * _FORTIFY_POS0 __d, const char *__s,
219+
size_t __n)
220+
{
221+
-#if __has_builtin(__builtin___strncat_chk) && FORTIFY_USE_NATIVE_CHK
222+
+#if __has_builtin(__builtin___strncat_chk) && defined(FORTIFY_USE_NATIVE_CHK)
223+
return __builtin___strncat_chk(__d, __s, __n, __fh_bos(__d, 0));
224+
#else
225+
#if 0 // strlen(__s) isn't guaranteed to be valid.
226+
@@ -311,7 +311,7 @@ __diagnose_as_builtin(__builtin_strncpy,
227+
_FORTIFY_FN(strncpy) char *strncpy(char * _FORTIFY_POS0 __d,
228+
const char *__s, size_t __n)
229+
{
230+
-#if __has_builtin(__builtin___strncpy_chk) && FORTIFY_USE_NATIVE_CHK
231+
+#if __has_builtin(__builtin___strncpy_chk) && defined(FORTIFY_USE_NATIVE_CHK)
232+
return __builtin___strncpy_chk(__d, __s, __n, __fh_bos(__d, 0));
233+
#else
234+
// If the length of src is less than n, strncpy() writes additional
235+
@@ -334,7 +334,7 @@ __diagnose_as_builtin(__builtin_mempcpy,
236+
_FORTIFY_FN(mempcpy) void *mempcpy(void * _FORTIFY_POS0 __d,
237+
const void * _FORTIFY_POS0 __s, size_t __n)
238+
{
239+
-#if __has_builtin(__builtin___mempcpy_chk) && FORTIFY_USE_NATIVE_CHK
240+
+#if __has_builtin(__builtin___mempcpy_chk) && defined(FORTIFY_USE_NATIVE_CHK)
241+
return __builtin___mempcpy_chk(__d, __s, __n, __fh_bos(__d, 0));
242+
#else
243+
if (!__d || !__s)
244+
@@ -361,7 +361,7 @@ __diagnose_as_builtin(__builtin_strlcat,
245+
_FORTIFY_FN(strlcat) size_t strlcat(char * _FORTIFY_POS0 __d,
246+
const char *__s, size_t __n)
247+
{
248+
-#if __has_builtin(__builtin___strlcat_chk) && FORTIFY_USE_NATIVE_CHK
249+
+#if __has_builtin(__builtin___strlcat_chk) && defined(FORTIFY_USE_NATIVE_CHK)
250+
return __builtin___strlcat_chk(__d, __s, __n, __fh_bos(__d, 0));
251+
#else
252+
__fh_size_t __b = __fh_bos(__d, 0);
253+
@@ -380,7 +380,7 @@ __diagnose_as_builtin(__builtin_strlcpy,
254+
_FORTIFY_FN(strlcpy) size_t strlcpy(char * _FORTIFY_POS0 __d,
255+
const char *__s, size_t __n)
256+
{
257+
-#if __has_builtin(__builtin___strlcpy_chk) && FORTIFY_USE_NATIVE_CHK
258+
+#if __has_builtin(__builtin___strlcpy_chk) && defined(FORTIFY_USE_NATIVE_CHK)
259+
return __builtin___strlcpy_chk(__d, __s, __n, __fh_bos(__d, 0));
260+
#else
261+
__fh_size_t __b = __fh_bos(__d, 0);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Hauke Mehrtens <[email protected]>
3+
Date: Sun, 26 Oct 2025 23:15:30 +0100
4+
Subject: poll: Check if _REDIR_TIME64 is defined
5+
6+
Treat _REDIR_TIME64 being undefined like being set to 0.
7+
8+
This fixes the following compile error in strace:
9+
```
10+
In file included from pathtrace.c:12:
11+
/include/fortify/poll.h:46:30: error: "_REDIR_TIME64" is not defined, evaluates to 0 [-Werror=undef]
12+
46 | #if defined(_GNU_SOURCE) && !_REDIR_TIME64
13+
| ^~~~~~~~~~~~~
14+
cc1: all warnings being treated as errors
15+
```
16+
17+
Signed-off-by: Hauke Mehrtens <[email protected]>
18+
---
19+
include/poll.h | 2 +-
20+
1 file changed, 1 insertion(+), 1 deletion(-)
21+
22+
--- a/include/poll.h
23+
+++ b/include/poll.h
24+
@@ -43,7 +43,7 @@ _FORTIFY_FN(poll) int poll(struct pollfd
25+
return __orig_poll(__f, __n, __s);
26+
}
27+
28+
-#if defined(_GNU_SOURCE) && !_REDIR_TIME64
29+
+#if defined(_GNU_SOURCE) && (!defined(_REDIR_TIME64) || !_REDIR_TIME64)
30+
#undef ppoll
31+
#if __has_builtin(__builtin_ppoll)
32+
__diagnose_as_builtin(__builtin_ppoll, 1, 2, 3, 4)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Hauke Mehrtens <[email protected]>
3+
Date: Sun, 26 Oct 2025 23:16:01 +0100
4+
Subject: fortify-headers: Remove __fh_has_builtin()
5+
6+
GCC complains about the `defined` usage here. Just call `__has_builtin` directly.
7+
8+
This fixes the following compile error when compiling strace:
9+
```
10+
In file included from /home/hauke/openwrt/openwrt/staging_dir/toolchain-aarch64_generic_gcc-14.3.0_musl/include/fortify/stdlib.h:27,
11+
from number_set.c:14:
12+
/home/hauke/openwrt/openwrt/staging_dir/toolchain-aarch64_generic_gcc-14.3.0_musl/include/fortify/fortify-headers.h:26:30: error: this use of "defined" may not be portable [-Werror=expansion-to-defined]
13+
26 | #define __fh_has_builtin(x) (__has_builtin(x) || defined(x))
14+
| ^~~~~~~~~~~~~
15+
/home/hauke/openwrt/openwrt/staging_dir/toolchain-aarch64_generic_gcc-14.3.0_musl/include/fortify/fortify-headers.h:28:7: note: in expansion of macro '__fh_has_builtin'
16+
28 | #if ! __fh_has_builtin(__builtin_trap)
17+
| ^~~~~~~~~~~~~~~~
18+
/home/hauke/openwrt/openwrt/staging_dir/toolchain-aarch64_generic_gcc-14.3.0_musl/include/fortify/fortify-headers.h:26:30: error: this use of "defined" may not be portable [-Werror=expansion-to-defined]
19+
26 | #define __fh_has_builtin(x) (__has_builtin(x) || defined(x))
20+
| ^~~~~~~~~~~~~
21+
/home/hauke/openwrt/openwrt/staging_dir/toolchain-aarch64_generic_gcc-14.3.0_musl/include/fortify/fortify-headers.h:73:29: note: in expansion of macro '__fh_has_builtin'
22+
73 | #if _FORTIFY_SOURCE > 2 && __fh_has_builtin (__builtin_dynamic_object_size)
23+
| ^~~~~~~~~~~~~~~~
24+
/home/hauke/openwrt/openwrt/staging_dir/toolchain-aarch64_generic_gcc-14.3.0_musl/include/fortify/fortify-headers.h:26:30: error: this use of "defined" may not be portable [-Werror=expansion-to-defined]
25+
26 | #define __fh_has_builtin(x) (__has_builtin(x) || defined(x))
26+
| ^~~~~~~~~~~~~
27+
/home/hauke/openwrt/openwrt/staging_dir/toolchain-aarch64_generic_gcc-14.3.0_musl/include/fortify/fortify-headers.h:158:5: note: in expansion of macro '__fh_has_builtin'
28+
158 | #if __fh_has_builtin (__builtin_mul_overflow_p)
29+
| ^~~~~~~~~~~~~~~~
30+
cc1: all warnings being treated as errors
31+
```
32+
33+
Signed-off-by: Hauke Mehrtens <[email protected]>
34+
---
35+
include/fortify-headers.h | 14 +++-----------
36+
1 file changed, 3 insertions(+), 11 deletions(-)
37+
38+
--- a/include/fortify-headers.h
39+
+++ b/include/fortify-headers.h
40+
@@ -21,21 +21,13 @@
41+
#error a compiler with __has_builtin support is required
42+
#endif
43+
44+
-// https://clang.llvm.org/docs/LanguageExtensions.html#has-builtin
45+
-// > __has_builtin should not be used to detect support for a builtin macro; use #ifdef instead.
46+
-#define __fh_has_builtin(x) (__has_builtin(x) || defined(x))
47+
-
48+
-#if ! __fh_has_builtin(__builtin_trap)
49+
-#define __builtin_trap abort
50+
-#endif
51+
-
52+
#if _FORTIFY_SOURCE > 3
53+
#warning _FORTIFY_SOURCE > 3 is treated as 3
54+
#endif
55+
56+
#ifdef __clang__
57+
58+
-#if _FORTIFY_SOURCE > 2 && __fh_has_builtin (__builtin_dynamic_object_size) && __has_attribute(pass_dynamic_object_size)
59+
+#if _FORTIFY_SOURCE > 2 && __has_builtin (__builtin_dynamic_object_size) && __has_attribute(pass_dynamic_object_size)
60+
#define _FORTIFY_POSN(n) const __attribute__((pass_dynamic_object_size(n)))
61+
#else
62+
#define _FORTIFY_POSN(n) const __attribute__((pass_object_size(n)))
63+
@@ -70,7 +62,7 @@
64+
#define _FORTIFY_FN(fn) _FORTIFY_FNB(fn); _FORTIFY_INLINE
65+
66+
/* Use __builtin_dynamic_object_size with _FORTIFY_SOURCE>2, if available. */
67+
-#if _FORTIFY_SOURCE > 2 && __fh_has_builtin (__builtin_dynamic_object_size)
68+
+#if _FORTIFY_SOURCE > 2 && __has_builtin (__builtin_dynamic_object_size)
69+
/*
70+
* See:
71+
* - https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
72+
@@ -155,7 +147,7 @@
73+
* - https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html
74+
* - https://clang.llvm.org/docs/LanguageExtensions.html#checked-arithmetic-builtins
75+
*/
76+
-#if __fh_has_builtin (__builtin_mul_overflow_p)
77+
+#if __has_builtin (__builtin_mul_overflow_p)
78+
#define __bmo(x, y) (x != 0 && __builtin_mul_overflow_p(x, y, (__typeof__ ((x) + (y))) 0))
79+
#else /* !__builtin_mul_overflow_p */
80+
#define __bmo(x, y) (x != 0 && (x * y) / x != y)

0 commit comments

Comments
 (0)