[PATCH] Declare __warn_memset_zero_len internally for newer gcc [bz #25399]
Siddhesh Poyarekar
siddhesh@sourceware.org
Tue Nov 3 11:15:34 GMT 2020
The __warn_memset_zero_len symbol, used to issue a linker warning
about zero length memset calls, is included in warning-nop.o only when
glibc is built with an older gcc, which is incorrect. When a program
calling memset with zero length is built with either gcc < 5.0 or with
clang (which advertises __GNUC__ as 4), it results in a link failure
due to not finding the symbol in libc_nonshared.a.
Fill in this gap by declaring __warn_memset_zero_len for newer gcc as
well so that it is always available in libc_nonshared.a for any
compiler to link against.
---
debug/warning-nop.c | 10 ++++++++++
string/bits/string_fortified.h | 6 ++++--
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/debug/warning-nop.c b/debug/warning-nop.c
index 4ab7e182b7..8df7b0d098 100644
--- a/debug/warning-nop.c
+++ b/debug/warning-nop.c
@@ -68,3 +68,13 @@ nop (void)
#define __builtin_object_size(bos, level) 0
#include <string.h>
+
+/* The public string_fortify.h header (included via string.h above) declares
+ __warn_memset_zero_len only when it is built with GCC < 5.0 or a non-gcc
+ compiler where compiler support for zero length memset warning may not be
+ available. Internally however we need to ensure that __warn_memset_zero_len
+ is always available when using older gcc or other compilers to link against
+ glibc. */
+#if __GNUC_PREREQ (5,0)
+__warndecl (__warn_memset_zero_len, __WARN_MEMSET_ZERO_LEN_MSG);
+#endif
diff --git a/string/bits/string_fortified.h b/string/bits/string_fortified.h
index 309d0f39b2..be88291f62 100644
--- a/string/bits/string_fortified.h
+++ b/string/bits/string_fortified.h
@@ -22,9 +22,11 @@
# error "Never use <bits/string_fortified.h> directly; include <string.h> instead."
#endif
+#define __WARN_MEMSET_ZERO_LEN_MSG \
+ "memset used with constant zero length parameter; this could be due to transposed parameters"
+
#if !__GNUC_PREREQ (5,0)
-__warndecl (__warn_memset_zero_len,
- "memset used with constant zero length parameter; this could be due to transposed parameters");
+__warndecl (__warn_memset_zero_len, __WARN_MEMSET_ZERO_LEN_MSG);
#endif
__fortify_function void *
--
2.26.2
More information about the Libc-alpha
mailing list