Skip to content

[Backtracing] Update module maps. #78514

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 5 commits into from
Jan 16, 2025
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
2 changes: 0 additions & 2 deletions include/swift/Runtime/CrashInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
namespace swift {
namespace runtime {
namespace backtrace {
extern "C" {
#endif

// Note: The "pointers" below are pointers in a different process's address
Expand Down Expand Up @@ -89,7 +88,6 @@ struct thread {
#endif

#ifdef __cplusplus
} // extern "C"
} // namespace backtrace
} // namespace runtime
} // namespace swift
Expand Down
14 changes: 11 additions & 3 deletions stdlib/public/Backtracing/Backtrace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,22 @@

import Swift

@_implementationOnly import OS.Libc
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
internal import Darwin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Darwin is pretty heavy, is it possible to import one of the modules under it like errno_h or stdio_h if they're available?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe. That might involve importing a number of modules, mind, and it'll only really affect the compile time of the backtracing library (since we aren't exporting anything from them). So it's worth experimenting with, for sure, but we can probably defer that for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking more like pulling in dependencies you don't want rather than compile time. i.e. do you really want bsm and nurses and all the other bs that Darwin gives you? Or do you just need a few cstdlib things?

#elseif os(Windows)
internal import ucrt
#elseif canImport(Glibc)
internal import Glibc
#elseif canImport(Musl)
internal import Musl
#endif

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
@_implementationOnly import OS.Darwin
internal import BacktracingImpl.OS.Darwin
#endif

#if os(Linux)
@_implementationOnly import ImageFormats.Elf
internal import BacktracingImpl.ImageFormats.Elf
#endif

/// Holds a backtrace.
Expand Down
11 changes: 10 additions & 1 deletion stdlib/public/Backtracing/BacktraceFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@

import Swift

@_implementationOnly import OS.Libc
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
internal import Darwin
internal import BacktracingImpl.OS.Darwin
#elseif os(Windows)
internal import ucrt
#elseif canImport(Glibc)
internal import Glibc
#elseif canImport(Musl)
internal import Musl
#endif

/// A backtrace formatting theme.
@_spi(Formatting)
Expand Down
18 changes: 14 additions & 4 deletions stdlib/public/Backtracing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ set(BACKTRACING_SOURCES
Image.swift
ImageSource.swift
MemoryImageSource.swift
Libc.swift
MemoryReader.swift
ProcMapsScanner.swift
Registers.swift
Runtime.swift
SymbolicatedBacktrace.swift
Utils.swift
Win32Extras.cpp
Expand All @@ -47,13 +49,12 @@ set(BACKTRACING_SOURCES
)

set(BACKTRACING_COMPILE_FLAGS
"-cxx-interoperability-mode=default"
"-Xfrontend;-experimental-spi-only-imports"
"-Xcc;-I${SWIFT_SOURCE_DIR}/include"
"-Xcc;-I${CMAKE_BINARY_DIR}/include"
"-Xcc;-fno-implicit-module-maps"
"-Xcc;-fbuiltin-module-map"
"-Xcc;-fmodule-map-file=${SWIFT_STDLIB_SOURCE_DIR}/public/SwiftShims/swift/shims/module.modulemap"
"-Xcc;-fmodule-map-file=${SWIFT_STDLIB_SOURCE_DIR}/public/Backtracing/modules/module.modulemap")
"-Xcc;-I${SWIFT_STDLIB_SOURCE_DIR}/public/Backtracing/modules"
"-disable-upcoming-feature;MemberImportVisibility")

###TODO: Add these when we add static linking support
#
Expand All @@ -79,6 +80,15 @@ add_swift_target_library(swift_Backtracing ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I

SWIFT_MODULE_DEPENDS ${concurrency}

SWIFT_MODULE_DEPENDS_ANDROID Android
SWIFT_MODULE_DEPENDS_LINUX Glibc
SWIFT_MODULE_DEPENDS_LINUX_STATIC Musl
SWIFT_MODULE_DEPENDS_FREEBSD Glibc
SWIFT_MODULE_DEPENDS_OPENBSD Glibc
SWIFT_MODULE_DEPENDS_CYGWIN Glibc
SWIFT_MODULE_DEPENDS_HAIKU Glibc
SWIFT_MODULE_DEPENDS_WINDOWS CRT

PRIVATE_LINK_LIBRARIES ${swift_backtracing_link_libraries}

SWIFT_COMPILE_FLAGS
Expand Down
17 changes: 14 additions & 3 deletions stdlib/public/Backtracing/Compression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,17 @@

import Swift

@_implementationOnly import OS.Libc
@_implementationOnly import CompressionLibs
@_implementationOnly import ImageFormats.Elf
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
internal import Darwin
#elseif os(Windows)
internal import ucrt
#elseif canImport(Glibc)
internal import Glibc
#elseif canImport(Musl)
internal import Musl
#endif
internal import BacktracingImpl.CompressionLibs
internal import BacktracingImpl.ImageFormats.Elf

enum CompressedImageSourceError: Error {
case unboundedImageSource
Expand All @@ -42,6 +50,9 @@ enum CompressedImageSourceError: Error {
case outputOverrun
}

let zlib_stream_init = swift.runtime.zlib_stream_init
let lzma_stream_init = swift.runtime.lzma_stream_init

// .. CompressedStream .........................................................

protocol CompressedStream {
Expand Down
21 changes: 17 additions & 4 deletions stdlib/public/Backtracing/Context.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,26 @@

import Swift

#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
internal import Darwin
#elseif os(Windows)
internal import ucrt
#elseif canImport(Glibc)
internal import Glibc
#elseif canImport(Musl)
internal import Musl
#endif

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
@_implementationOnly import OS.Darwin
#elseif os(Linux)
@_implementationOnly import OS.Linux
internal import BacktracingImpl.OS.Darwin
#endif

@_implementationOnly import FixedLayout
internal import BacktracingImpl.FixedLayout

typealias x86_64_gprs = swift.runtime.backtrace.x86_64_gprs
typealias i386_gprs = swift.runtime.backtrace.i386_gprs
typealias arm64_gprs = swift.runtime.backtrace.arm64_gprs
typealias arm_gprs = swift.runtime.backtrace.arm_gprs

@_spi(Contexts) public enum ContextError: Error {
case unableToFormTLSAddress
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/Backtracing/CoreSymbolication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import Swift

@_implementationOnly import OS.Libc
@_implementationOnly import OS.Darwin
internal import Darwin
internal import BacktracingImpl.OS.Darwin

// .. Dynamic binding ..........................................................

Expand Down
Loading