Skip to content

Commit 557bf68

Browse files
authored
Don't include support for old mangling in runtimes without ObjC interop (#39675)
1 parent ff7de78 commit 557bf68

File tree

9 files changed

+36
-13
lines changed

9 files changed

+36
-13
lines changed

CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,6 @@ option(SWIFT_REPORT_STATISTICS
405405
"Create json files which contain internal compilation statistics"
406406
FALSE)
407407

408-
option(SWIFT_DISABLE_OBJC_INTEROP
409-
"Disable Objective-C interoperability even on platforms what would normally have it"
410-
FALSE)
411-
412408
#
413409
# User-configurable experimental options. Do not use in production builds.
414410
#

lib/Demangling/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ add_swift_host_library(swiftDemangling STATIC
99
Punycode.cpp
1010
Remangler.cpp)
1111
target_compile_definitions(swiftDemangling PRIVATE
12-
LLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING=1)
12+
LLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING=1
13+
SWIFT_SUPPORT_OLD_MANGLING=1)
1314

1415
# NOTE: Runtime libraries that depend on swiftDemangling should define
1516
# SWIFT_INLINE_NAMESPACE to specify the identifier that will be used for an

lib/Demangling/Context.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,14 @@ void Context::clear() {
3939
}
4040

4141
NodePointer Context::demangleSymbolAsNode(llvm::StringRef MangledName) {
42+
#if SWIFT_SUPPORT_OLD_MANGLING
4243
if (isMangledName(MangledName)) {
4344
return D->demangleSymbol(MangledName);
4445
}
4546
return demangleOldSymbolAsNode(MangledName, *D);
47+
#else
48+
return D->demangleSymbol(MangledName);
49+
#endif
4650
}
4751

4852
NodePointer Context::demangleTypeAsNode(llvm::StringRef MangledName) {

lib/Demangling/Demangler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,10 +542,12 @@ NodePointer Demangler::demangleSymbol(StringRef MangledName,
542542
DemangleInitRAII state(*this, MangledName,
543543
std::move(SymbolicReferenceResolver));
544544

545+
#if SWIFT_SUPPORT_OLD_MANGLING
545546
// Demangle old-style class and protocol names, which are still used in the
546547
// ObjC metadata.
547548
if (nextIf("_Tt"))
548549
return demangleOldSymbolAsNode(Text, *this);
550+
#endif
549551

550552
unsigned PrefixLength = getManglingPrefixLength(MangledName);
551553
if (PrefixLength == 0)

stdlib/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ else()
6868
set(SWIFT_STDLIB_HAS_ASL_default FALSE)
6969
endif()
7070

71+
# Only Darwin platforms enable ObjC interop by default.
72+
if("${SWIFT_HOST_VARIANT_SDK}" MATCHES "(OSX|IOS*|TVOS*|WATCHOS*)")
73+
set(SWIFT_STDLIB_ENABLE_OBJC_INTEROP_default TRUE)
74+
else()
75+
set(SWIFT_STDLIB_ENABLE_OBJC_INTEROP_default FALSE)
76+
endif()
77+
7178
#
7279
# User-configurable options for the standard library.
7380
#
@@ -79,6 +86,10 @@ option(SWIFT_STDLIB_STABLE_ABI
7986
"Should stdlib be built with stable ABI (library evolution, resilience)."
8087
"${SWIFT_STDLIB_STABLE_ABI_default}")
8188

89+
option(SWIFT_STDLIB_ENABLE_OBJC_INTEROP
90+
"Should stdlib be built with Obj-C interop."
91+
"${SWIFT_STDLIB_ENABLE_OBJC_INTEROP_default}")
92+
8293
option(SWIFT_ENABLE_MODULE_INTERFACES
8394
"Generate .swiftinterface files alongside .swiftmodule files"
8495
"${SWIFT_STDLIB_STABLE_ABI}")

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ function(_add_target_variant_c_compile_flags)
303303
list(APPEND result "-D_WASI_EMULATED_MMAN")
304304
endif()
305305

306-
if(SWIFT_DISABLE_OBJC_INTEROP)
306+
if(NOT SWIFT_STDLIB_ENABLE_OBJC_INTEROP)
307307
list(APPEND result "-DSWIFT_OBJC_INTEROP=0")
308308
endif()
309309

stdlib/cmake/modules/SwiftSource.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ function(_compile_swift_files
498498
list(APPEND swift_flags "-warn-swift3-objc-inference-complete")
499499
endif()
500500

501-
if(SWIFT_DISABLE_OBJC_INTEROP)
501+
if(NOT SWIFT_STDLIB_ENABLE_OBJC_INTEROP)
502502
list(APPEND swift_flags "-Xfrontend" "-disable-objc-interop")
503503
endif()
504504

stdlib/public/CMakeLists.txt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,24 @@ if(SWIFT_BUILD_STDLIB OR SWIFT_BUILD_REMOTE_MIRROR)
6767
"${SWIFT_SOURCE_DIR}/lib/Demangling/Demangler.cpp"
6868
"${SWIFT_SOURCE_DIR}/lib/Demangling/ManglingUtils.cpp"
6969
"${SWIFT_SOURCE_DIR}/lib/Demangling/NodePrinter.cpp"
70-
"${SWIFT_SOURCE_DIR}/lib/Demangling/OldDemangler.cpp"
71-
"${SWIFT_SOURCE_DIR}/lib/Demangling/OldRemangler.cpp"
7270
"${SWIFT_SOURCE_DIR}/lib/Demangling/Punycode.cpp"
7371
"${SWIFT_SOURCE_DIR}/lib/Demangling/Remangler.cpp"
7472
"${SWIFT_SOURCE_DIR}/lib/Demangling/NodeDumper.cpp")
7573

74+
# The old mangling support is only needed on platforms with ObjC.
75+
if(SWIFT_STDLIB_ENABLE_OBJC_INTEROP)
76+
list(APPEND swiftDemanglingSources
77+
"${SWIFT_SOURCE_DIR}/lib/Demangling/OldDemangler.cpp"
78+
"${SWIFT_SOURCE_DIR}/lib/Demangling/OldRemangler.cpp"
79+
)
80+
set(swift_demangling_cflags -DSWIFT_SUPPORT_OLD_MANGLING=1)
81+
else()
82+
set(swift_demangling_cflags -DSWIFT_SUPPORT_OLD_MANGLING=0)
83+
endif()
84+
7685
add_swift_target_library(swiftDemangling OBJECT_LIBRARY
7786
${swiftDemanglingSources}
78-
C_COMPILE_FLAGS -DswiftCore_EXPORTS
87+
C_COMPILE_FLAGS -DswiftCore_EXPORTS ${swift_demangling_cflags}
7988
INSTALL_IN_COMPONENT never_install)
8089
endif()
8190

utils/build-script-impl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ KNOWN_SETTINGS=(
203203
report-statistics "0" "set to 1 to generate compilation statistics files for swift libraries"
204204
sil-verify-all "0" "If enabled, run the SIL verifier after each transform when building Swift files during this build process"
205205
stdlib-deployment-targets "" "space-separated list of targets to configure the Swift standard library to be compiled or cross-compiled for"
206-
swift-objc-interop "" "whether to enable interoperability with Objective-C, default is 1 on Apple platfors, 0 otherwise"
206+
swift-objc-interop "" "whether to enable interoperability with Objective-C, default is 1 on Darwin platforms, 0 otherwise"
207207
swift-enable-compatibility-overrides "1" "whether to support back-deploying compatibility fixes for newer apps running on older runtimes"
208208
swift-enable-reflection "1" "whether to support reflection and mirrors"
209209
swift-stdlib-has-dladdr "1" "whether to build stdlib assuming the runtime environment provides dladdr API"
@@ -2074,10 +2074,10 @@ for host in "${ALL_HOSTS[@]}"; do
20742074
)
20752075
fi
20762076

2077-
if [[ "${SWIFT_OBJC_INTEROP}" == "0" ]] ; then
2077+
if [[ "${SWIFT_OBJC_INTEROP}" ]] ; then
20782078
cmake_options=(
20792079
"${cmake_options[@]}"
2080-
-DSWIFT_DISABLE_OBJC_INTEROP:BOOL=True
2080+
-DSWIFT_STDLIB_ENABLE_OBJC_INTEROP:BOOL=$(true_false "${SWIFT_OBJC_INTEROP}")
20812081
)
20822082
fi
20832083

0 commit comments

Comments
 (0)