Skip to content

Commit d546222

Browse files
committed
[CMake] Use separate namespace for demangling symbols used by runtime
This matches the behavior introduced with swiftlang#30733 -- quoting the explanation here for the sake of convenience: > Since libDemangling is included in the Swift standard library, > ODR violations can occur on platforms that allow statically > linking stdlib if Swift code is linked with other compiler > libraries that also transitively pull in libDemangling, and if > the stdlib version and compiler version do not match exactly > (even down to commit drift between releases). This lets the > runtime conditionally segregate its copies of the libDemangling > symbols from those in the compiler using an inline namespace > without affecting usage throughout source. Addresses rdar://142550635
1 parent bc405c5 commit d546222

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Runtimes/Core/Demangling/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ target_compile_definitions(swiftDemangling PRIVATE
1616
$<$<BOOL:${SwiftCore_ENABLE_CRASH_REPORTER_CLIENT}>:-DSWIFT_HAVE_CRASHREPORTERCLIENT>
1717
$<$<BOOL:${SwiftCore_HAS_ASL}>:-DSWIFT_STDLIB_HAS_ASL>)
1818

19+
# Target libraries that include libDemangling must define the name to use for
20+
# the inline namespace to distinguish symbols from those built for the
21+
# compiler, in order to avoid possible ODR violations if both are statically
22+
# linked into the same binary. (see also commit message for 5b1daa9055c99904c84862ecc313641fd9b26e63)
23+
target_compile_definitions(swiftDemangling PUBLIC
24+
$<$<COMPILE_LANGUAGE:C,CXX>:-DSWIFT_INLINE_NAMESPACE=__runtime>)
25+
1926
target_include_directories(swiftDemangling
2027
PRIVATE
2128
"${SwiftCore_SWIFTC_SOURCE_DIR}/include"

Runtimes/Core/runtime/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ target_include_directories(swiftRuntime PRIVATE
9595

9696
target_link_libraries(swiftRuntime PRIVATE
9797
$<$<PLATFORM_ID:Windows>:User32>
98-
swiftShims)
98+
swiftShims
99+
swiftDemangling)
99100

100101
# FIXME: Refactor so that we're not pulling sources from the compiler files
101102
target_sources(swiftRuntime PRIVATE

0 commit comments

Comments
 (0)