]> Savannah Git Hosting - gnulib.git/commitdiff
string: fix build failure on BSD/OSX with FORTIFY_SOURCE
authorPádraig Brady <P@draigBrady.com>
Wed, 27 May 2015 11:59:05 +0000 (12:59 +0100)
committerPádraig Brady <P@draigBrady.com>
Wed, 27 May 2015 12:25:51 +0000 (13:25 +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
lib/string.in.h

index a5f6bd07298a028be5a900fef8a14b7e167df775..a64a2df9c44b668594463c6be15d1603fa82c555 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2015-05-27  Pádraig Brady  <P@draigBrady.com>
+
+       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  <eblake@redhat.com>
 
        stdio: limit __gnu_printf__ witness to gcc 4.4+
index 0b5e738c184cb928f1176bd5523b01b6070bfb2c..b3356bbc7bf8c92951d6fafffc5f8102547ef384 100644 (file)
    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 _@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> -> <strings.h> -> "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