From f023bdeee9ed8d31cfdd4c0d4db4f0a1ed26122b Mon Sep 17 00:00:00 2001 From: Evan Wilde Date: Wed, 15 Feb 2023 19:39:26 -0800 Subject: [PATCH 1/2] Base override section names on swift version This patch automates maintaining the right compatibility override section names so we don't need to remember to update them by hand with each version. The expansions look like '"__swift" "5" "9" "_hooks"' and '"__s" "5" "9" "async_hook"'. Note: The section names can only grow to be 16 characters long. If we see explosions regarding these names, that could be why. --- CMakeLists.txt | 4 +++- include/swift/Runtime/CMakeConfig.h.in | 3 +++ .../CompatibilityOverride/CompatibilityOverride.h | 14 ++++++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c8e4e521ae70..6dad918106814 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -268,7 +268,9 @@ set(SWIFT_ANALYZE_CODE_COVERAGE FALSE CACHE STRING # SWIFT_VERSION is deliberately /not/ cached so that an existing build directory # can be reused when a new version of Swift comes out (assuming the user hasn't # manually set it as part of their own CMake configuration). -set(SWIFT_VERSION "5.9") +set(SWIFT_VERSION_MAJOR 5) +set(SWIFT_VERSION_MINOR 9) +set(SWIFT_VERSION "${SWIFT_VERSION_MAJOR}.${SWIFT_VERSION_MINOR}") set(SWIFT_VENDOR "" CACHE STRING "The vendor name of the Swift compiler") diff --git a/include/swift/Runtime/CMakeConfig.h.in b/include/swift/Runtime/CMakeConfig.h.in index e24e5c3fe7db8..4f31705582890 100644 --- a/include/swift/Runtime/CMakeConfig.h.in +++ b/include/swift/Runtime/CMakeConfig.h.in @@ -7,4 +7,7 @@ #cmakedefine01 SWIFT_BNI_OS_BUILD #cmakedefine01 SWIFT_BNI_XCODE_BUILD +#cmakedefine SWIFT_VERSION_MAJOR "@SWIFT_VERSION_MAJOR@" +#cmakedefine SWIFT_VERSION_MINOR "@SWIFT_VERSION_MINOR@" + #endif diff --git a/stdlib/public/CompatibilityOverride/CompatibilityOverride.h b/stdlib/public/CompatibilityOverride/CompatibilityOverride.h index 527a3586de7f8..e56eb37d15327 100644 --- a/stdlib/public/CompatibilityOverride/CompatibilityOverride.h +++ b/stdlib/public/CompatibilityOverride/CompatibilityOverride.h @@ -85,6 +85,7 @@ #include "swift/Runtime/Concurrency.h" #include "swift/Runtime/Metadata.h" #include "swift/Runtime/Once.h" +#include "swift/Runtime/CMakeConfig.h" #include namespace swift { @@ -153,8 +154,17 @@ namespace swift { // Override section name computation. `COMPATIBILITY_OVERRIDE_SECTION_NAME` will // resolve to string literal containing the appropriate section name for the // current library. -#define COMPATIBILITY_OVERRIDE_SECTION_NAME_swiftRuntime "__swift58_hooks" -#define COMPATIBILITY_OVERRIDE_SECTION_NAME_swift_Concurrency "__s58async_hook" +// Turns into '__swift_hooks' +#define COMPATIBILITY_OVERRIDE_SECTION_NAME_swiftRuntime "__swift" \ + SWIFT_VERSION_MAJOR \ + SWIFT_VERSION_MINOR \ + "_hooks" + +// Turns into '__sasync_hook' +#define COMPATIBILITY_OVERRIDE_SECTION_NAME_swift_Concurrency "__s" \ + SWIFT_VERSION_MAJOR \ + SWIFT_VERSION_MINOR \ + "async_hook" #define COMPATIBILITY_OVERRIDE_SECTION_NAME \ COMPATIBILITY_CONCAT(COMPATIBILITY_OVERRIDE_SECTION_NAME_, \ From aa34d98e26bcb00622ede8e35356a3a877b357ba Mon Sep 17 00:00:00 2001 From: Evan Wilde Date: Thu, 16 Feb 2023 10:25:43 -0800 Subject: [PATCH 2/2] Update tests to use macro section names Automatically update the section names in the runtime and concurrency runtime tests. --- unittests/runtime/CompatibilityOverrideConcurrency.cpp | 2 +- unittests/runtime/CompatibilityOverrideRuntime.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/unittests/runtime/CompatibilityOverrideConcurrency.cpp b/unittests/runtime/CompatibilityOverrideConcurrency.cpp index b6fc271ab27c1..51c283e8e93f9 100644 --- a/unittests/runtime/CompatibilityOverrideConcurrency.cpp +++ b/unittests/runtime/CompatibilityOverrideConcurrency.cpp @@ -55,7 +55,7 @@ struct OverrideSection { }; OverrideSection ConcurrencyOverrides - __attribute__((section("__DATA,__s58async_hook"))) = { + __attribute__((section("__DATA," COMPATIBILITY_OVERRIDE_SECTION_NAME_swift_Concurrency))) = { 0, #define OVERRIDE(name, ret, attrs, ccAttrs, namespace, typedArgs, namedArgs) \ name##Override, diff --git a/unittests/runtime/CompatibilityOverrideRuntime.cpp b/unittests/runtime/CompatibilityOverrideRuntime.cpp index 070b5b5b2fb32..90a1bafbc6b16 100644 --- a/unittests/runtime/CompatibilityOverrideRuntime.cpp +++ b/unittests/runtime/CompatibilityOverrideRuntime.cpp @@ -62,7 +62,7 @@ struct OverrideSection { }; OverrideSection RuntimeOverrides - __attribute__((section("__DATA,__swift58_hooks"))) = { + __attribute__((section("__DATA," COMPATIBILITY_OVERRIDE_SECTION_NAME_swiftRuntime))) = { 0, #define OVERRIDE(name, ret, attrs, ccAttrs, namespace, typedArgs, namedArgs) \ name ## Override,