Skip to content

Don't include support for old mangling in runtimes without ObjC interop #39675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,6 @@ option(SWIFT_REPORT_STATISTICS
"Create json files which contain internal compilation statistics"
FALSE)

option(SWIFT_DISABLE_OBJC_INTEROP
"Disable Objective-C interoperability even on platforms what would normally have it"
FALSE)

#
# User-configurable experimental options. Do not use in production builds.
#
Expand Down
3 changes: 2 additions & 1 deletion lib/Demangling/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ add_swift_host_library(swiftDemangling STATIC
Punycode.cpp
Remangler.cpp)
target_compile_definitions(swiftDemangling PRIVATE
LLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING=1)
LLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING=1
SWIFT_SUPPORT_OLD_MANGLING=1)

# NOTE: Runtime libraries that depend on swiftDemangling should define
# SWIFT_INLINE_NAMESPACE to specify the identifier that will be used for an
Expand Down
4 changes: 4 additions & 0 deletions lib/Demangling/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ void Context::clear() {
}

NodePointer Context::demangleSymbolAsNode(llvm::StringRef MangledName) {
#if SWIFT_SUPPORT_OLD_MANGLING
if (isMangledName(MangledName)) {
return D->demangleSymbol(MangledName);
}
return demangleOldSymbolAsNode(MangledName, *D);
#else
return D->demangleSymbol(MangledName);
#endif
}

NodePointer Context::demangleTypeAsNode(llvm::StringRef MangledName) {
Expand Down
2 changes: 2 additions & 0 deletions lib/Demangling/Demangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,10 +542,12 @@ NodePointer Demangler::demangleSymbol(StringRef MangledName,
DemangleInitRAII state(*this, MangledName,
std::move(SymbolicReferenceResolver));

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

unsigned PrefixLength = getManglingPrefixLength(MangledName);
if (PrefixLength == 0)
Expand Down
11 changes: 11 additions & 0 deletions stdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ else()
set(SWIFT_STDLIB_HAS_ASL_default FALSE)
endif()

# Only Darwin platforms enable ObjC interop by default.
if("${SWIFT_HOST_VARIANT_SDK}" MATCHES "(OSX|IOS*|TVOS*|WATCHOS*)")
set(SWIFT_STDLIB_ENABLE_OBJC_INTEROP_default TRUE)
else()
set(SWIFT_STDLIB_ENABLE_OBJC_INTEROP_default FALSE)
endif()

#
# User-configurable options for the standard library.
#
Expand All @@ -79,6 +86,10 @@ option(SWIFT_STDLIB_STABLE_ABI
"Should stdlib be built with stable ABI (library evolution, resilience)."
"${SWIFT_STDLIB_STABLE_ABI_default}")

option(SWIFT_STDLIB_ENABLE_OBJC_INTEROP
"Should stdlib be built with Obj-C interop."
"${SWIFT_STDLIB_ENABLE_OBJC_INTEROP_default}")

option(SWIFT_ENABLE_MODULE_INTERFACES
"Generate .swiftinterface files alongside .swiftmodule files"
"${SWIFT_STDLIB_STABLE_ABI}")
Expand Down
2 changes: 1 addition & 1 deletion stdlib/cmake/modules/AddSwiftStdlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ function(_add_target_variant_c_compile_flags)
list(APPEND result "-D_WASI_EMULATED_MMAN")
endif()

if(SWIFT_DISABLE_OBJC_INTEROP)
if(NOT SWIFT_STDLIB_ENABLE_OBJC_INTEROP)
list(APPEND result "-DSWIFT_OBJC_INTEROP=0")
endif()

Expand Down
2 changes: 1 addition & 1 deletion stdlib/cmake/modules/SwiftSource.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ function(_compile_swift_files
list(APPEND swift_flags "-warn-swift3-objc-inference-complete")
endif()

if(SWIFT_DISABLE_OBJC_INTEROP)
if(NOT SWIFT_STDLIB_ENABLE_OBJC_INTEROP)
list(APPEND swift_flags "-Xfrontend" "-disable-objc-interop")
endif()

Expand Down
15 changes: 12 additions & 3 deletions stdlib/public/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,24 @@ if(SWIFT_BUILD_STDLIB OR SWIFT_BUILD_REMOTE_MIRROR)
"${SWIFT_SOURCE_DIR}/lib/Demangling/Demangler.cpp"
"${SWIFT_SOURCE_DIR}/lib/Demangling/ManglingUtils.cpp"
"${SWIFT_SOURCE_DIR}/lib/Demangling/NodePrinter.cpp"
"${SWIFT_SOURCE_DIR}/lib/Demangling/OldDemangler.cpp"
"${SWIFT_SOURCE_DIR}/lib/Demangling/OldRemangler.cpp"
"${SWIFT_SOURCE_DIR}/lib/Demangling/Punycode.cpp"
"${SWIFT_SOURCE_DIR}/lib/Demangling/Remangler.cpp"
"${SWIFT_SOURCE_DIR}/lib/Demangling/NodeDumper.cpp")

# The old mangling support is only needed on platforms with ObjC.
if(SWIFT_STDLIB_ENABLE_OBJC_INTEROP)
list(APPEND swiftDemanglingSources
"${SWIFT_SOURCE_DIR}/lib/Demangling/OldDemangler.cpp"
"${SWIFT_SOURCE_DIR}/lib/Demangling/OldRemangler.cpp"
)
set(swift_demangling_cflags -DSWIFT_SUPPORT_OLD_MANGLING=1)
else()
set(swift_demangling_cflags -DSWIFT_SUPPORT_OLD_MANGLING=0)
endif()

add_swift_target_library(swiftDemangling OBJECT_LIBRARY
${swiftDemanglingSources}
C_COMPILE_FLAGS -DswiftCore_EXPORTS
C_COMPILE_FLAGS -DswiftCore_EXPORTS ${swift_demangling_cflags}
INSTALL_IN_COMPONENT never_install)
endif()

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

if [[ "${SWIFT_OBJC_INTEROP}" == "0" ]] ; then
if [[ "${SWIFT_OBJC_INTEROP}" ]] ; then
cmake_options=(
"${cmake_options[@]}"
-DSWIFT_DISABLE_OBJC_INTEROP:BOOL=True
-DSWIFT_STDLIB_ENABLE_OBJC_INTEROP:BOOL=$(true_false "${SWIFT_OBJC_INTEROP}")
)
fi

Expand Down