bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] string: fix build failure on BSD/OSX with FORTIFY_SOURCE


From: Pádraig Brady
Subject: [PATCH] string: fix build failure on BSD/OSX with FORTIFY_SOURCE
Date: Wed, 27 May 2015 13:27:40 +0100

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
<string.h> re-includes "string.h" through <strings.h>, 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 <string.h>.
---
 ChangeLog       |  9 +++++++++
 lib/string.in.h | 21 +++++++++++++++++++--
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a5f6bd0..a64a2df 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2015-05-27  Pádraig Brady  <address@hidden>
+
+       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 <string.h>.
+
 2015-05-26  Eric Blake  <address@hidden>
 
        stdio: limit __gnu_printf__ witness to gcc 4.4+
diff --git a/lib/string.in.h b/lib/string.in.h
index 0b5e738..b3356bb 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 <http://www.gnu.org/licenses/>.  */
 
-#ifndef address@hidden@_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> -> <strings.h> -> "string.h"
+     In this situation system _chk variants due to -D_FORTIFY_SOURCE
+     might be used after any replacements defined here.  */
+
address@hidden@ @NEXT_STRING_H@
+
+#else
+/* Normal invocation convention.  */
+
+#ifndef address@hidden@_STRING_H
+
+#define _GL_ALREADY_INCLUDING_STRING_H
+
 /* The include_next requires a split double-inclusion guard.  */
 address@hidden@ @NEXT_STRING_H@
 
+#undef _GL_ALREADY_INCLUDING_STRING_H
+
 #ifndef address@hidden@_STRING_H
 #define address@hidden@_STRING_H
 
@@ -1027,3 +1043,4 @@ _GL_WARN_ON_USE (strverscmp, "strverscmp is unportable - "
 
 #endif /* address@hidden@_STRING_H */
 #endif /* address@hidden@_STRING_H */
+#endif
-- 
2.4.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]