Skip to content

Commit c2a9272

Browse files
authored
Split the NO_DYLD CMake flag into separate HAS_DLADDR and STATIC_IMAGE_INSPECTION flags (swiftlang#39339)
1 parent 5a85c12 commit c2a9272

File tree

8 files changed

+30
-14
lines changed

8 files changed

+30
-14
lines changed

stdlib/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,12 @@ option(SWIFT_ENABLE_COMPATIBILITY_OVERRIDES
7171
"Support back-deploying compatibility fixes for newer apps running on older runtimes."
7272
TRUE)
7373

74-
option(SWIFT_RUNTIME_MACHO_NO_DYLD
75-
"Build stdlib assuming the runtime environment uses Mach-O but does not support dynamic modules."
74+
option(SWIFT_STDLIB_HAS_DLADDR
75+
"Build stdlib assuming the runtime environment runtime environment provides dladdr API."
76+
TRUE)
77+
78+
option(SWIFT_RUNTIME_STATIC_IMAGE_INSPECTION
79+
"Build stdlib assuming the runtime environment runtime environment only supports a single runtime image with Swift code."
7680
FALSE)
7781

7882
option(SWIFT_STDLIB_HAS_DARWIN_LIBMALLOC

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,12 @@ function(_add_target_variant_c_compile_flags)
321321
list(APPEND result "-DSWIFT_ENABLE_REFLECTION")
322322
endif()
323323

324-
if(SWIFT_RUNTIME_MACHO_NO_DYLD)
325-
list(APPEND result "-DSWIFT_RUNTIME_MACHO_NO_DYLD")
324+
if(SWIFT_STDLIB_HAS_DLADDR)
325+
list(APPEND result "-DSWIFT_STDLIB_HAS_DLADDR")
326+
endif()
327+
328+
if(SWIFT_RUNTIME_STATIC_IMAGE_INSPECTION)
329+
list(APPEND result "-DSWIFT_RUNTIME_STATIC_IMAGE_INSPECTION")
326330
endif()
327331

328332
if(SWIFT_STDLIB_HAS_DARWIN_LIBMALLOC)

stdlib/public/runtime/Errors.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ enum: uint32_t {
7373

7474
using namespace swift;
7575

76-
#if SWIFT_SUPPORTS_BACKTRACE_REPORTING
76+
#if SWIFT_SUPPORTS_BACKTRACE_REPORTING && SWIFT_STDLIB_HAS_DLADDR
7777
static bool getSymbolNameAddr(llvm::StringRef libraryName,
7878
const SymbolInfo &syminfo,
7979
std::string &symbolName, uintptr_t &addrOut) {
@@ -136,7 +136,7 @@ static bool getSymbolNameAddr(llvm::StringRef libraryName,
136136

137137
void swift::dumpStackTraceEntry(unsigned index, void *framePC,
138138
bool shortOutput) {
139-
#if SWIFT_SUPPORTS_BACKTRACE_REPORTING && !defined(SWIFT_RUNTIME_MACHO_NO_DYLD)
139+
#if SWIFT_SUPPORTS_BACKTRACE_REPORTING && SWIFT_STDLIB_HAS_DLADDR
140140
SymbolInfo syminfo;
141141

142142
// 0 is failure for lookupSymbol

stdlib/public/runtime/ImageInspectionMachO.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
//===----------------------------------------------------------------------===//
2020

2121
#if defined(__APPLE__) && defined(__MACH__) && \
22-
!defined(SWIFT_RUNTIME_MACHO_NO_DYLD)
22+
!defined(SWIFT_RUNTIME_STATIC_IMAGE_INSPECTION)
2323

2424
#include "ImageInspection.h"
2525
#include "ImageInspectionCommon.h"
@@ -159,6 +159,7 @@ void swift::initializeDynamicReplacementLookup() {
159159
addImageDynamicReplacementBlockCallback>);
160160
}
161161

162+
#if SWIFT_STDLIB_HAS_DLADDR
162163
int swift::lookupSymbol(const void *address, SymbolInfo *info) {
163164
Dl_info dlinfo;
164165
if (dladdr(address, &dlinfo) == 0) {
@@ -171,6 +172,7 @@ int swift::lookupSymbol(const void *address, SymbolInfo *info) {
171172
info->symbolAddress = dlinfo.dli_saddr;
172173
return 1;
173174
}
175+
#endif
174176

175177
#endif // defined(__APPLE__) && defined(__MACH__) &&
176-
// !defined(SWIFT_RUNTIME_MACHO_NO_DYLD)
178+
// !defined(SWIFT_RUNTIME_STATIC_IMAGE_INSPECTION)

stdlib/public/runtime/ImageInspectionStatic.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
///
1818
//===----------------------------------------------------------------------===//
1919

20-
#if defined(__MACH__) && defined(SWIFT_RUNTIME_MACHO_NO_DYLD)
20+
#if defined(__MACH__) && defined(SWIFT_RUNTIME_STATIC_IMAGE_INSPECTION)
2121

2222
#include "ImageInspection.h"
2323
#include "ImageInspectionCommon.h"
@@ -75,4 +75,4 @@ void swift::initializeDynamicReplacementLookup() {
7575
addImageDynamicReplacementBlockCallback(start1, size1, start2, size2);
7676
}
7777

78-
#endif // defined(__MACH__) && defined(SWIFT_RUNTIME_MACHO_NO_DYLD)
78+
#endif // defined(__MACH__) && defined(SWIFT_RUNTIME_STATIC_IMAGE_INSPECTION)

stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ _gatherGenericParameters(const ContextDescriptor *context,
10341034

10351035
str += "_gatherGenericParameters: context: ";
10361036

1037-
#if !defined(SWIFT_RUNTIME_MACHO_NO_DYLD)
1037+
#if SWIFT_STDLIB_HAS_DLADDR
10381038
SymbolInfo contextInfo;
10391039
if (lookupSymbol(context, &contextInfo)) {
10401040
str += contextInfo.symbolName.get();

utils/build-presets.ini

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2453,9 +2453,10 @@ build-swift-static-stdlib=1
24532453
swift-objc-interop=0
24542454
swift-enable-compatibility-overrides=0
24552455
swift-enable-reflection=0
2456-
swift-runtime-macho-no-dyld=1
2456+
swift-stdlib-has-dladdr=0
24572457
swift-stdlib-has-darwin-libmalloc=0
24582458
swift-stdlib-has-stdin=0
2459+
swift-runtime-static-image-inspection=1
24592460
swift-stdlib-single-threaded-runtime=1
24602461
swift-stdlib-os-versioning=0
24612462
extra-cmake-options=
@@ -2478,6 +2479,9 @@ swift-freestanding-triple-name=macosx11.0
24782479
swift-freestanding-module-name=macos
24792480
swift-freestanding-archs=x86_64
24802481

2482+
# For lit tests, we are producing dynamic executables with statically linked stdlib into the executable.
2483+
swift-runtime-static-image-inspection=0
2484+
24812485
[preset: stdlib_S_standalone_minimal_macho_x86_64,build,test]
24822486
mixin-preset=stdlib_S_standalone_minimal_macho_x86_64,build
24832487

utils/build-script-impl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ KNOWN_SETTINGS=(
205205
swift-objc-interop "" "whether to enable interoperability with Objective-C, default is 1 on Apple platfors, 0 otherwise"
206206
swift-enable-compatibility-overrides "1" "whether to support back-deploying compatibility fixes for newer apps running on older runtimes"
207207
swift-enable-reflection "1" "whether to support reflection and mirrors"
208-
swift-runtime-macho-no-dyld "0" "whether to build stdlib assuming the runtime environment does not support dynamic modules"
208+
swift-stdlib-has-dladdr "1" "whether to build stdlib assuming the runtime environment provides dladdr API"
209+
swift-runtime-static-image-inspection "0" "whether to build stdlib assuming the runtime environment only supports a single runtime image with Swift code"
209210
swift-stdlib-single-threaded-runtime "0" "whether to build stdlib as a single-threaded runtime only"
210211
swift-stdlib-os-versioning "1" "whether to build stdlib with availability based on OS versions (Darwin only)"
211212
swift-stdlib-stable-abi "" "should stdlib be built with stable ABI, if not set defaults to true on Darwin, false otherwise"
@@ -1981,7 +1982,8 @@ for host in "${ALL_HOSTS[@]}"; do
19811982
-DSWIFT_ENABLE_COMPATIBILITY_OVERRIDES:BOOL=$(true_false "${SWIFT_ENABLE_COMPATIBILITY_OVERRIDES}")
19821983
-DSWIFT_STDLIB_SINGLE_THREADED_RUNTIME:BOOL=$(true_false "${SWIFT_STDLIB_SINGLE_THREADED_RUNTIME}")
19831984
-DSWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS:BOOL=$(true_false "${SWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS}")
1984-
-DSWIFT_RUNTIME_MACHO_NO_DYLD:BOOL=$(true_false "${SWIFT_RUNTIME_MACHO_NO_DYLD}")
1985+
-DSWIFT_STDLIB_HAS_DLADDR:BOOL=$(true_false "${SWIFT_STDLIB_HAS_DLADDR}")
1986+
-DSWIFT_RUNTIME_STATIC_IMAGE_INSPECTION:BOOL=$(true_false "${SWIFT_RUNTIME_STATIC_IMAGE_INSPECTION}")
19851987
-DSWIFT_STDLIB_OS_VERSIONING:BOOL=$(true_false "${SWIFT_STDLIB_OS_VERSIONING}")
19861988
-DSWIFT_STDLIB_HAS_DARWIN_LIBMALLOC:BOOL=$(true_false "${SWIFT_STDLIB_HAS_DARWIN_LIBMALLOC}")
19871989
-DSWIFT_STDLIB_HAS_STDIN:BOOL=$(true_false "${SWIFT_STDLIB_HAS_STDIN}")

0 commit comments

Comments
 (0)