Skip to content

Commit 2489fc4

Browse files
committed
swift-testing: fix _FORTIFY_SOURCE build
`limits.h` must be included before `stdlib.h` when building with glibc and having `_FORTIFY_SOURCE` set to a non-zero value. When building with `_FORTIFY_SOURCE`, `realpath()` is inlined, and its definition depends on whether `limits.h` has been included or not (clearly, this is a terrible idea in terms of interacting with Clang modules and should probably be fixed upstream). If the definition differs from the one in SwiftGlibc, then _TestingInternals will not build. swiftlang/swift-testing#1184
1 parent 390ff01 commit 2489fc4

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

recipes-devtools/swift/swift-testing.bb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ SRCREV_FORMAT = "swift_testing"
1313

1414
SRC_URI = "git://github.com/swiftlang/swift-testing.git;protocol=https;tag=swift-${SWIFT_VERSION}-RELEASE;nobranch=1"
1515
SRC_URI += "file://0001-build-as-dynamic-library.patch;striplevel=1;"
16+
SRC_URI += "file://0002-order-limits.h-before-stdlib.h-to-workaround-for-gli.patch;striplevel=1;"
1617

1718
S = "${WORKDIR}/git"
1819
B = "${WORKDIR}/build"
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
From 2ee53c692f781dff38dcbabe819ecfe841841588 Mon Sep 17 00:00:00 2001
2+
From: Luke Howard <[email protected]>
3+
Date: Sat, 28 Jun 2025 16:00:04 +1000
4+
Subject: [PATCH] order limits.h before stdlib.h to workaround for glibc
5+
fortify source issue
6+
7+
limits.h must be included before stdlib.h with glibc, otherwise the fortified
8+
realpath() in this module's stdlib will differ from the one in SwiftGlibc.
9+
---
10+
Sources/_TestingInternals/include/Includes.h | 9 +++++----
11+
1 file changed, 5 insertions(+), 4 deletions(-)
12+
13+
diff --git a/Sources/_TestingInternals/include/Includes.h b/Sources/_TestingInternals/include/Includes.h
14+
index 1b95151..acc38df 100644
15+
--- a/Sources/_TestingInternals/include/Includes.h
16+
+++ b/Sources/_TestingInternals/include/Includes.h
17+
@@ -39,6 +39,11 @@
18+
#include <stdbool.h>
19+
#include <stdint.h>
20+
#include <stdio.h>
21+
+#if __has_include(<limits.h>)
22+
+/// limits.h must be included before stdlib.h with glibc, otherwise the
23+
+/// fortified realpath() in this module will differ from the one in SwiftGlibc.
24+
+#include <limits.h>
25+
+#endif
26+
#include <stdlib.h>
27+
#include <string.h>
28+
#include <time.h>
29+
@@ -97,10 +102,6 @@
30+
#include <pwd.h>
31+
#endif
32+
33+
-#if __has_include(<limits.h>)
34+
-#include <limits.h>
35+
-#endif
36+
-
37+
#if __has_include(<spawn.h>)
38+
#include <spawn.h>
39+
#endif
40+
--
41+
2.39.5 (Apple Git-154)
42+

0 commit comments

Comments
 (0)