From: Pádraig Brady
Date: Wed, 27 May 2015 11:59:05 +0000 (+0100)
Subject: string: fix build failure on BSD/OSX with FORTIFY_SOURCE
X-Git-Tag: v1.0~7069
X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=70e0e9ed738ddc514b09fa486421fc86c31c7e25;p=gnulib.git
string: fix build failure on BSD/OSX with FORTIFY_SOURCE
This avoids a conflict with "FORTIFY_SOURCE" variants
of the string functions when they're replaced on NetBSD-6.0.1
and Darwin-14.3.0 at least. On these platforms, the system
re-includes "string.h" through , before
going on to redefine the "FORTIFY_SOURCE" _chk variants.
For example rpl_strncat is redefined to __builtin___strncat_chk.
Note strncat is being replaced as the configure check is failing
with GCC 4.5.0, due to the builtin strncat failing the check.
I.E. when compiled with -O2 the test fails, but passes when
-fno-builtin-strncat is also specified. -D_FORTIFY_SOURCE has
no impact on the configure test result.
* lib/string.in.h: Avoid including our "lib/string.h" while
including the system .
---
diff --git a/ChangeLog b/ChangeLog
index a5f6bd0729..a64a2df9c4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2015-05-27 Pádraig Brady
+
+ string: fix build failure on BSD/OSX with FORTIFY_SOURCE
+ This avoids a conflict with "FORTIFY_SOURCE" variants
+ of the string functions when they're replaced on NetBSD-6.0.1
+ and Darwin-14.3.0 at least.
+ * lib/string.in.h: Avoid including our "lib/string.h" while
+ including the system .
+
2015-05-26 Eric Blake
stdio: limit __gnu_printf__ witness to gcc 4.4+
diff --git a/lib/string.in.h b/lib/string.in.h
index 0b5e738c18..b3356bbc7b 100644
--- a/lib/string.in.h
+++ b/lib/string.in.h
@@ -15,16 +15,32 @@
You should have received a copy of the GNU General Public License
along with this program; if not, see . */
-#ifndef _@GUARD_PREFIX@_STRING_H
-
#if __GNUC__ >= 3
@PRAGMA_SYSTEM_HEADER@
#endif
@PRAGMA_COLUMNS@
+#if defined _GL_ALREADY_INCLUDING_STRING_H
+/* Special invocation convention:
+ - On OS X/NetBSD we have a sequence of nested includes
+ -> -> "string.h"
+ In this situation system _chk variants due to -D_FORTIFY_SOURCE
+ might be used after any replacements defined here. */
+
+#@INCLUDE_NEXT@ @NEXT_STRING_H@
+
+#else
+/* Normal invocation convention. */
+
+#ifndef _@GUARD_PREFIX@_STRING_H
+
+#define _GL_ALREADY_INCLUDING_STRING_H
+
/* The include_next requires a split double-inclusion guard. */
#@INCLUDE_NEXT@ @NEXT_STRING_H@
+#undef _GL_ALREADY_INCLUDING_STRING_H
+
#ifndef _@GUARD_PREFIX@_STRING_H
#define _@GUARD_PREFIX@_STRING_H
@@ -1027,3 +1043,4 @@ _GL_WARN_ON_USE (strverscmp, "strverscmp is unportable - "
#endif /* _@GUARD_PREFIX@_STRING_H */
#endif /* _@GUARD_PREFIX@_STRING_H */
+#endif