Skip to content

Commit

Permalink
Merge branch 'main' into swiftlang#78960-swift-stdlib-cross-compile
Browse files Browse the repository at this point in the history
  • Loading branch information
xtremekforever committed Jan 28, 2025
2 parents 66c3a13 + 76243a2 commit 7a5d265
Show file tree
Hide file tree
Showing 173 changed files with 7,546 additions and 3,034 deletions.
18 changes: 9 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -695,10 +695,6 @@ option(SWIFT_IMPLICIT_CONCURRENCY_IMPORT
"Implicitly import the Swift concurrency module"
TRUE)

option(SWIFT_IMPLICIT_BACKTRACING_IMPORT
"Implicitly import the Swift backtracing module"
FALSE)

option(SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY
"Enable build of the Swift concurrency module"
FALSE)
Expand Down Expand Up @@ -731,6 +727,10 @@ option(SWIFT_ENABLE_SYNCHRONIZATION
"Enable build of the Swift Synchronization module"
FALSE)

option(SWIFT_ENABLE_RUNTIME_MODULE
"Build the Swift Runtime module"
FALSE)

option(SWIFT_ENABLE_VOLATILE
"Enable build of the Swift Volatile module"
FALSE)
Expand Down Expand Up @@ -865,11 +865,6 @@ if (CMAKE_Swift_COMPILER)
SWIFT_SUPPORTS_DISABLE_IMPLICIT_STRING_PROCESSING_MODULE_IMPORT)
message(STATUS " Implicit 'string-processing' import: ${SWIFT_SUPPORTS_DISABLE_IMPLICIT_STRING_PROCESSING_MODULE_IMPORT}")

# Same for _Backtracing.
swift_supports_implicit_module("backtracing"
SWIFT_SUPPORTS_DISABLE_IMPLICIT_BACKTRACING_MODULE_IMPORT)
message(STATUS " Implicit 'backtracing' import: ${SWIFT_SUPPORTS_DISABLE_IMPLICIT_BACKTRACING_MODULE_IMPORT}")

swift_get_package_cmo_support(
Swift_COMPILER_PACKAGE_CMO_SUPPORT)
message(STATUS " Package CMO: ${Swift_COMPILER_PACKAGE_CMO_SUPPORT}")
Expand Down Expand Up @@ -1087,6 +1082,9 @@ endif()
#
swift_common_cxx_warnings()

# Set sanitizer options for Swift compiler.
swift_common_sanitizer_config()

# Check if we're build with MSVC or Clang-cl, as these compilers have similar command line arguments.
if("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
set(SWIFT_COMPILER_IS_MSVC_LIKE TRUE)
Expand Down Expand Up @@ -1393,6 +1391,8 @@ if(SWIFT_BUILD_STDLIB OR SWIFT_BUILD_SDK_OVERLAY)
message(STATUS "Observation Support: ${SWIFT_ENABLE_EXPERIMENTAL_OBSERVATION}")
message(STATUS "Synchronization Support: ${SWIFT_ENABLE_SYNCHRONIZATION}")
message(STATUS "Volatile Support: ${SWIFT_ENABLE_VOLATILE}")
message(STATUS "Pointer Bounds Support: ${SWIFT_ENABLE_EXPERIMENTAL_POINTER_BOUNDS}")
message(STATUS "Runtime Support: ${SWIFT_ENABLE_RUNTIME_MODULE}")
message(STATUS "")
else()
message(STATUS "Not building Swift standard library, SDK overlays, and runtime")
Expand Down
4 changes: 2 additions & 2 deletions Runtimes/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ defaulted_option(SwiftCore_ENABLE_RUNTIME_FUNCTION_COUNTERS "Enable runtime func
defaulted_option(SwiftCore_ENABLE_STDIN "Enable functions that use stdin support")
defaulted_option(SwiftCore_ENABLE_ENVIRONMENT "Enable environment variable support")
defaulted_option(SwiftCore_ENABLE_OVERRIDABLE_RETAIN_RELEASE "Enable override hooks for retain/release")
defaulted_option(SwiftCore_ENABLE_MALLOC_TYPE "Enable malloc type information")
defaulted_option(SwiftCore_ENABLE_RUNTIME_OS_VERSIONING "Enable runtime OS version detection")
defaulted_option(SwiftCore_ENABLE_STATIC_PRINT "Disable full print")
defaulted_option(SwiftCore_ENABLE_COMPACT_ABSOLUTE_FUNCTION_POINTERS "Resolve absolute function pointer as identity")
Expand All @@ -102,6 +101,7 @@ option(SwiftCore_ENABLE_UNICODE_DATA "Include unicode data in Swift runtimes" ON
option(SwiftCore_ENABLE_SHORT_MANGLING_LOOKUPS "Build with fast-path context descriptor lookups based on well-known short manglings." ON)
option(SwiftCore_ENABLE_FILESYSTEM_SUPPORT "Build for systems that have a filesystem" ON)
option(SwiftCore_ENABLE_OS_TRACE_LAZY_INIT "Use os_trace call to check if lazy init has been completed before making os_signpost calls." ${SwiftCore_HAS_OS_TRACE})
option(SwiftCore_HAS_DARWIN_LIBMALLOC "Use Darwin malloc features" ${APPLE})

defaulted_option(SwiftCore_ENABLE_BACKTRACING "Enable backtracing runtime support")
defaulted_set(SwiftCore_BACKTRACER_PATH STRING "Set a fixed path to the Swift backtracer")
Expand Down Expand Up @@ -135,6 +135,7 @@ add_compile_definitions(
$<$<BOOL:${SwiftCore_ENABLE_UNICODE_DATA}>:-DSWIFT_STDLIB_ENABLE_UNICODE_DATA> # Stubs
$<$<BOOL:${SwiftCore_ENABLE_ENVIRONMENT}>:-DSWIFT_STDLIB_HAS_ENVIRON> # Concurrency, runtime, shims, platform overlay
$<$<BOOL:${SwiftCore_ENABLE_BACKDEPLOYMENT_SUPPORT}>:-DSWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT> # Concurrency, Compatibility override, magic symbols
$<$<BOOL:${SwiftCore_HAS_DARWIN_LIBMALLOC}>:-DSWIFT_STDLIB_HAS_DARWIN_LIBMALLOC> # Anything that includes include/swift/Runtime/Config.h
$<$<COMPILE_LANGUAGE:C,CXX>:-DSWIFT_THREADING_${SwiftCore_THREADING_PACKAGE}>
$<$<COMPILE_LANGUAGE:C,CXX>:-DSWIFT_RUNTIME_ENABLE_LEAK_CHECKER=$<BOOL:${SwiftCore_ENABLE_RUNTIME_LEAK_CHECKER}>>
$<$<COMPILE_LANGUAGE:C,CXX>:-DSWIFT_RUNTIME_CLOBBER_FREED_OBJECTS=$<BOOL:${SwiftCore_ENABLE_CLOBBER_FREED_OBJECTS}>>)
Expand Down Expand Up @@ -173,7 +174,6 @@ add_compile_options(
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -enable-experimental-concise-pound-file>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -enable-lexical-lifetimes=false>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-implicit-concurrency-module-import>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-implicit-backtracing-module-import>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-implicit-string-processing-module-import>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -enforce-exclusivity=unchecked>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -enable-ossa-modules>"
Expand Down
3 changes: 1 addition & 2 deletions Runtimes/Core/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,10 @@ endif()
target_compile_definitions(swiftRuntime
PRIVATE
-DSWIFT_RUNTIME
-DSWIFT_TARGET_LIBRARY_NAME=swiftRuntime
-DSWIFT_TARGET_LIBRARY_NAME=swiftRuntimeCore
$<$<BOOL:${BUILD_SHARED_LIBS}>:-DswiftCore_EXPORTS>
$<$<BOOL:${SwiftCore_ENABLE_BACKTRACING}>:-DSWIFT_ENABLE_BACKTRACING>
$<$<BOOL:${SwiftCore_ENABLE_OVERRIDABLE_RETAIN_RELEASE}>:-DSWIFT_STDLIB_OVERRIDABLE_RETAIN_RELEASE>
$<$<BOOL:${SwiftCore_ENABLE_MALLOC_TYPE}>:-DSWIFT_STDLIB_HAS_MALLOC_TYPE>
$<$<BOOL:${SwiftCore_BACKTRACER_PATH}>:-DSWIFT_RUNTIME_FIXED_BACKTRACER_PATH="${SwiftCore_BACKTRACER_PATH}">
$<$<BOOL:${SwiftCore_ENABLE_STDLIB_TRACING}>:-DSWIFT_STDLIB_TRACING>
$<$<BOOL:${SwiftCore_ENABLE_SHORT_MANGLING_LOOKUPS}>:-DSWIFT_STDLIB_SHORT_MANGLING_LOOKUPS>
Expand Down
17 changes: 0 additions & 17 deletions cmake/caches/Windows-aarch64.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,6 @@ set(LLVM_DEFAULT_TARGET_TRIPLE aarch64-unknown-windows-msvc CACHE STRING "")
set(LLVM_APPEND_VC_REV NO CACHE BOOL "")
set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR YES CACHE BOOL "")
set(LLVM_ENABLE_PYTHON YES CACHE BOOL "")
set(LLVM_RUNTIME_TARGETS
aarch64-unknown-windows-msvc
CACHE STRING "")
foreach(target ${LLVM_RUNTIME_TARGETS})
set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES
compiler-rt
CACHE STRING "")
set(RUNTIMES_${target}_CMAKE_MT mt CACHE STRING "")
set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Windows CACHE STRING "")
set(RUNTIMES_${target}_CMAKE_BUILD_TYPE Release CACHE STRING "")
set(RUNTIMES_${target}_COMPILER_RT_BUILD_CRT NO CACHE BOOL "")
set(RUNTIMES_${target}_COMPILER_RT_BUILD_LIBFUZZER NO CACHE BOOL "")
set(RUNTIMES_${target}_COMPILER_RT_BUILD_PROFILE YES CACHE BOOL "")
set(RUNTIMES_${target}_COMPILER_RT_BUILD_SANITIZERS NO CACHE BOOL "")
set(RUNTIMES_${target}_COMPILER_RT_BUILD_XRAY NO CACHE BOOL "")
endforeach()

set(LLVM_TARGETS_TO_BUILD AArch64 ARM WebAssembly X86 CACHE STRING "")

Expand Down Expand Up @@ -167,7 +151,6 @@ set(LLVM_DISTRIBUTION_COMPONENTS
libclang
libclang-headers
LTO
runtimes
${LLVM_TOOLCHAIN_TOOLS}
${CLANG_TOOLS}
${LLD_TOOLS}
Expand Down
58 changes: 0 additions & 58 deletions cmake/caches/Windows-x86_64.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,62 +27,6 @@ set(LLVM_APPEND_VC_REV NO CACHE BOOL "")
set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR YES CACHE BOOL "")
set(LLVM_ENABLE_PYTHON YES CACHE BOOL "")

set(DEFAULT_BUILTIN_TARGETS
x86_64-unknown-windows-msvc
aarch64-unknown-windows-msvc)
# Build the android builtins if NDK path is provided.
if(NOT "$ENV{NDKPATH}" STREQUAL "")
list(APPEND DEFAULT_BUILTIN_TARGETS
aarch64-unknown-linux-android
x86_64-unknown-linux-android)
endif()

# The builtin targets are used to build the compiler-rt builtins.
set(LLVM_BUILTIN_TARGETS ${DEFAULT_BUILTIN_TARGETS} CACHE STRING "")

# The runtime targets are used to build the compiler-rt profile library.
set(LLVM_RUNTIME_TARGETS
x86_64-unknown-windows-msvc
aarch64-unknown-windows-msvc
CACHE STRING "")

foreach(target ${LLVM_RUNTIME_TARGETS})
set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES
compiler-rt
CACHE STRING "")
set(RUNTIMES_${target}_CMAKE_MT mt CACHE STRING "")
set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Windows CACHE STRING "")
set(RUNTIMES_${target}_CMAKE_BUILD_TYPE Release CACHE STRING "")
set(RUNTIMES_${target}_COMPILER_RT_BUILD_BUILTINS NO CACHE BOOL "")
set(RUNTIMES_${target}_COMPILER_RT_BUILD_CRT NO CACHE BOOL "")
set(RUNTIMES_${target}_COMPILER_RT_BUILD_LIBFUZZER NO CACHE BOOL "")
set(RUNTIMES_${target}_COMPILER_RT_BUILD_ORC NO CACHE BOOL "")
set(RUNTIMES_${target}_COMPILER_RT_BUILD_PROFILE YES CACHE BOOL "")
set(RUNTIMES_${target}_COMPILER_RT_BUILD_SANITIZERS NO CACHE BOOL "")
set(RUNTIMES_${target}_COMPILER_RT_BUILD_XRAY NO CACHE BOOL "")
endforeach()

foreach(target ${LLVM_BUILTIN_TARGETS})
set(BUILTINS_${target}_CMAKE_MT mt CACHE STRING "")
if(${target} MATCHES windows-msvc)
set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Windows CACHE STRING "")
elseif(${target} MATCHES linux-android)
# Use a single 'linux' directory and arch-based lib names on Android.
set(BUILTINS_${target}_LLVM_ENABLE_PER_TARGET_RUNTIME_DIR NO CACHE BOOL "")
set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Android CACHE STRING "")
if(${target} MATCHES aarch64)
set(BUILTINS_${target}_CMAKE_ANDROID_ARCH_ABI arm64-v8a CACHE STRING "")
else()
set(BUILTINS_${target}_CMAKE_ANDROID_ARCH_ABI x86_64 CACHE STRING "")
endif()
set(BUILTINS_${target}_CMAKE_ANDROID_NDK $ENV{NDKPATH} CACHE PATH "")
set(BUILTINS_${target}_CMAKE_ANDROID_API 21 CACHE STRING "")
set(BUILTINS_${target}_CMAKE_C_COMPILER_TARGET "${target}21" CACHE STRING "")
set(BUILTINS_${target}_CMAKE_CXX_COMPILER_TARGET "${target}21" CACHE STRING "")
endif()
set(BUILTINS_${target}_CMAKE_BUILD_TYPE Release CACHE STRING "")
endforeach()

set(LLVM_TARGETS_TO_BUILD AArch64 ARM WebAssembly X86 CACHE STRING "")

# Disable certain targets to reduce the configure time or to avoid configuration
Expand Down Expand Up @@ -207,8 +151,6 @@ set(LLVM_DISTRIBUTION_COMPONENTS
libclang
libclang-headers
LTO
builtins
runtimes
${LLVM_TOOLCHAIN_TOOLS}
${CLANG_TOOLS}
${LLD_TOOLS}
Expand Down
9 changes: 1 addition & 8 deletions cmake/modules/AddPureSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,7 @@ function(_add_host_swift_compile_options name)
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-implicit-string-processing-module-import>")
endif()

# Same for backtracing
if (SWIFT_SUPPORTS_DISABLE_IMPLICIT_BACKTRACING_MODULE_IMPORT)
target_compile_options(${name} PRIVATE
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-implicit-backtracing-module-import>")
endif()

if(SWIFT_ANALYZE_CODE_COVERAGE)
if(SWIFT_ANALYZE_CODE_COVERAGE)
set(_cov_flags $<$<COMPILE_LANGUAGE:Swift>:-profile-generate -profile-coverage-mapping>)
target_compile_options(${name} PRIVATE ${_cov_flags})
target_link_options(${name} PRIVATE ${_cov_flags})
Expand Down Expand Up @@ -69,7 +63,6 @@ function(_add_host_swift_compile_options name)
target_compile_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:Swift>:-tools-directory;${tools_path};>)
endif()
endif()
_add_host_variant_swift_sanitizer_flags(${name})

target_compile_options(${name} PRIVATE
$<$<COMPILE_LANGUAGE:Swift>:-color-diagnostics>
Expand Down
32 changes: 0 additions & 32 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -82,36 +82,6 @@ function(_set_target_prefix_and_suffix target kind sdk)
endif()
endfunction()

function(_add_host_variant_swift_sanitizer_flags target)
if(LLVM_USE_SANITIZER)
if(LLVM_USE_SANITIZER STREQUAL "Address")
set(_Swift_SANITIZER_FLAGS "-sanitize=address" "-Xclang-linker" "-fsanitize=address")
elseif(LLVM_USE_SANITIZER STREQUAL "HWAddress")
# Not supported?
elseif(LLVM_USE_SANITIZER MATCHES "Memory(WithOrigins)?")
# Not supported
if(LLVM_USE_SANITIZER STREQUAL "MemoryWithOrigins")
# Not supported
endif()
elseif(LLVM_USE_SANITIZER STREQUAL "Undefined")
set(_Swift_SANITIZER_FLAGS "-sanitize=undefined" "-Xclang-linker" "-fsanitize=undefined")
elseif(LLVM_USE_SANITIZER STREQUAL "Thread")
set(_Swift_SANITIZER_FLAGS "-sanitize=thread" "-Xclang-linker" "-fsanitize=thread")
elseif(LLVM_USE_SANITIZER STREQUAL "DataFlow")
# Not supported
elseif(LLVM_USE_SANITIZER STREQUAL "Address;Undefined" OR
LLVM_USE_SANITIZER STREQUAL "Undefined;Address")
set(_Swift_SANITIZER_FLAGS "-sanitize=address" "-sanitize=undefined" "-Xclang-linker" "-fsanitize=address" "-Xclang-linker" "-fsanitize=undefined")
elseif(LLVM_USE_SANITIZER STREQUAL "Leaks")
# Not supported
else()
message(SEND_ERROR "unsupported value for LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}")
endif()

target_compile_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:Swift>:${_Swift_SANITIZER_FLAGS}>)
endif()
endfunction()

function(swift_get_host_triple out_var)
if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
set(DEPLOYMENT_VERSION "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_DEPLOYMENT_VERSION}")
Expand Down Expand Up @@ -145,8 +115,6 @@ function(_add_host_variant_c_compile_link_flags name)

if (CMAKE_Swift_COMPILER)
target_compile_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:Swift>:-target;${SWIFT_HOST_TRIPLE}>)

_add_host_variant_swift_sanitizer_flags(${name})
endif()

set(_sysroot
Expand Down
32 changes: 32 additions & 0 deletions cmake/modules/SwiftSharedCMakeConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,35 @@ function(swift_common_llvm_config target)
llvm_config("${target}" ${ARGN})
endif()
endfunction()

# Set sanitizer options to all Swift compiler flags. Similar options are added to C/CXX compiler in 'HandleLLVMOptions'
macro(swift_common_sanitizer_config)
if(LLVM_USE_SANITIZER)
if(LLVM_USE_SANITIZER STREQUAL "Address")
set(_Swift_SANITIZER_FLAGS "-sanitize=address -Xclang-linker -fsanitize=address")
elseif(LLVM_USE_SANITIZER STREQUAL "HWAddress")
# Not supported?
elseif(LLVM_USE_SANITIZER MATCHES "Memory(WithOrigins)?")
# Not supported
if(LLVM_USE_SANITIZER STREQUAL "MemoryWithOrigins")
# Not supported
endif()
elseif(LLVM_USE_SANITIZER STREQUAL "Undefined")
set(_Swift_SANITIZER_FLAGS "-sanitize=undefined -Xclang-linker -fsanitize=undefined")
elseif(LLVM_USE_SANITIZER STREQUAL "Thread")
set(_Swift_SANITIZER_FLAGS "-sanitize=thread -Xclang-linker -fsanitize=thread")
elseif(LLVM_USE_SANITIZER STREQUAL "DataFlow")
# Not supported
elseif(LLVM_USE_SANITIZER STREQUAL "Address;Undefined" OR
LLVM_USE_SANITIZER STREQUAL "Undefined;Address")
set(_Swift_SANITIZER_FLAGS "-sanitize=address -sanitize=undefined -Xclang-linker -fsanitize=address -Xclang-linker -fsanitize=undefined")
elseif(LLVM_USE_SANITIZER STREQUAL "Leaks")
# Not supported
else()
message(SEND_ERROR "unsupported value for LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}")
endif()

set(CMAKE_Swift_FLAGS "${CMAKE_Swift_FLAGS} ${_Swift_SANITIZER_FLAGS}")

endif()
endmacro()
11 changes: 11 additions & 0 deletions docs/Backtracing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,14 @@ of the backtracer using

If the runtime is unable to locate the backtracer, it will allow your program to
crash as it would have done anyway.

Backtrace Storage
-----------------

Backtraces are stored internally in a format called :download:`Compact Backtrace
Format <CompactBacktraceFormat.md>`. This provides us with a way to store a
large number of frames in a much smaller space than would otherwise be possible.

Similarly, where we need to store address to image mappings, we
use :download:`Compact ImageMap Format <CompactImageMapFormat.md>` to minimise
storage requirements.
Loading

0 comments on commit 7a5d265

Please sign in to comment.