Skip to content

Commit 293842a

Browse files
committed
[Backtracing] Update module maps.
Now that Darwin is provided by the system, we no longer need to disable the system module maps in favour of our own, which also resolves a few other problems that doing that was creating. rdar://137201928
1 parent 203f906 commit 293842a

16 files changed

+190
-61
lines changed

stdlib/public/Backtracing/Backtrace.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,22 @@
1616

1717
import Swift
1818

19-
@_implementationOnly import OS.Libc
19+
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
20+
internal import Darwin
21+
#elseif os(Windows)
22+
internal import ucrt
23+
#elseif canImport(Glibc)
24+
internal import Glibc
25+
#elseif canImport(Musl)
26+
internal import Musl
27+
#endif
2028

2129
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
22-
@_implementationOnly import OS.Darwin
30+
internal import BacktracingImpl.OS.Darwin
2331
#endif
2432

2533
#if os(Linux)
26-
@_implementationOnly import ImageFormats.Elf
34+
internal import BacktracingImpl.ImageFormats.Elf
2735
#endif
2836

2937
/// Holds a backtrace.

stdlib/public/Backtracing/BacktraceFormatter.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@
1717

1818
import Swift
1919

20-
@_implementationOnly import OS.Libc
20+
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
21+
internal import Darwin
22+
internal import BacktracingImpl.OS.Darwin
23+
#elseif os(Windows)
24+
internal import ucrt
25+
#elseif canImport(Glibc)
26+
internal import Glibc
27+
#elseif canImport(Musl)
28+
internal import Musl
29+
#endif
2130

2231
/// A backtrace formatting theme.
2332
@_spi(Formatting)

stdlib/public/Backtracing/CMakeLists.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ set(BACKTRACING_COMPILE_FLAGS
5050
"-Xfrontend;-experimental-spi-only-imports"
5151
"-Xcc;-I${SWIFT_SOURCE_DIR}/include"
5252
"-Xcc;-I${CMAKE_BINARY_DIR}/include"
53-
"-Xcc;-fno-implicit-module-maps"
54-
"-Xcc;-fbuiltin-module-map"
55-
"-Xcc;-fmodule-map-file=${SWIFT_STDLIB_SOURCE_DIR}/public/SwiftShims/swift/shims/module.modulemap"
56-
"-Xcc;-fmodule-map-file=${SWIFT_STDLIB_SOURCE_DIR}/public/Backtracing/modules/module.modulemap")
53+
"-Xcc;-I${SWIFT_STDLIB_SOURCE_DIR}/public/Backtracing/modules")
5754

5855
###TODO: Add these when we add static linking support
5956
#
@@ -79,6 +76,15 @@ add_swift_target_library(swift_Backtracing ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
7976

8077
SWIFT_MODULE_DEPENDS ${concurrency}
8178

79+
SWIFT_MODULE_DEPENDS_ANDROID Android
80+
SWIFT_MODULE_DEPENDS_LINUX Glibc
81+
SWIFT_MODULE_DEPENDS_LINUX_STATIC Musl
82+
SWIFT_MODULE_DEPENDS_FREEBSD Glibc
83+
SWIFT_MODULE_DEPENDS_OPENBSD Glibc
84+
SWIFT_MODULE_DEPENDS_CYGWIN Glibc
85+
SWIFT_MODULE_DEPENDS_HAIKU Glibc
86+
SWIFT_MODULE_DEPENDS_WINDOWS CRT
87+
8288
PRIVATE_LINK_LIBRARIES ${swift_backtracing_link_libraries}
8389

8490
SWIFT_COMPILE_FLAGS

stdlib/public/Backtracing/Compression.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,17 @@
2929

3030
import Swift
3131

32-
@_implementationOnly import OS.Libc
33-
@_implementationOnly import CompressionLibs
34-
@_implementationOnly import ImageFormats.Elf
32+
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
33+
internal import Darwin
34+
#elseif os(Windows)
35+
internal import ucrt
36+
#elseif canImport(Glibc)
37+
internal import Glibc
38+
#elseif canImport(Musl)
39+
internal import Musl
40+
#endif
41+
internal import BacktracingImpl.CompressionLibs
42+
internal import BacktracingImpl.ImageFormats.Elf
3543

3644
enum CompressedImageSourceError: Error {
3745
case unboundedImageSource

stdlib/public/Backtracing/Context.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020
import Swift
2121

2222
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
23-
@_implementationOnly import OS.Darwin
23+
internal import Darwin
24+
internal import BacktracingImpl.OS.Darwin
2425
#elseif os(Linux)
25-
@_implementationOnly import OS.Linux
26+
internal import BacktracingImpl.OS.Linux
2627
#endif
2728

28-
@_implementationOnly import FixedLayout
29+
internal import BacktracingImpl.FixedLayout
2930

3031
@_spi(Contexts) public enum ContextError: Error {
3132
case unableToFormTLSAddress

stdlib/public/Backtracing/CoreSymbolication.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
import Swift
2121

22-
@_implementationOnly import OS.Libc
23-
@_implementationOnly import OS.Darwin
22+
internal import Darwin
23+
internal import BacktracingImpl.OS.Darwin
2424

2525
// .. Dynamic binding ..........................................................
2626

stdlib/public/Backtracing/Dwarf.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
import Swift
2121

22-
@_implementationOnly import ImageFormats.Dwarf
23-
@_implementationOnly import Runtime
22+
internal import BacktracingImpl.ImageFormats.Dwarf
23+
internal import BacktracingImpl.Runtime
2424

2525
// .. Dwarf specific errors ....................................................
2626

stdlib/public/Backtracing/Elf.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,17 @@
2121

2222
import Swift
2323

24-
@_implementationOnly import OS.Libc
25-
@_implementationOnly import ImageFormats.Elf
26-
@_implementationOnly import Runtime
24+
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
25+
internal import Darwin
26+
#elseif os(Windows)
27+
internal import ucrt
28+
#elseif canImport(Glibc)
29+
internal import Glibc
30+
#elseif canImport(Musl)
31+
internal import Musl
32+
#endif
33+
internal import BacktracingImpl.ImageFormats.Elf
34+
internal import BacktracingImpl.Runtime
2735

2836
// .. Utilities ................................................................
2937

stdlib/public/Backtracing/FileImageSource.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@
1616

1717
import Swift
1818

19-
@_implementationOnly import OS.Libc
19+
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
20+
internal import Darwin
21+
#elseif os(Windows)
22+
internal import ucrt
23+
#elseif canImport(Glibc)
24+
internal import Glibc
25+
#elseif canImport(Musl)
26+
internal import Musl
27+
#endif
2028

2129
enum FileImageSourceError: Error {
2230
case posixError(Int32)
@@ -37,18 +45,18 @@ class FileImageSource: ImageSource {
3745

3846
public init(path: String) throws {
3947
_path = path
40-
let fd = _swift_open(path, O_RDONLY, 0)
48+
let fd = open(path, O_RDONLY, 0)
4149
if fd < 0 {
42-
throw FileImageSourceError.posixError(_swift_get_errno())
50+
throw FileImageSourceError.posixError(errno)
4351
}
4452
defer { close(fd) }
4553
let size = lseek(fd, 0, SEEK_END)
4654
if size < 0 {
47-
throw FileImageSourceError.posixError(_swift_get_errno())
55+
throw FileImageSourceError.posixError(errno)
4856
}
4957
let base = mmap(nil, Int(size), PROT_READ, MAP_FILE|MAP_PRIVATE, fd, 0)
5058
if base == nil || base! == UnsafeRawPointer(bitPattern: -1)! {
51-
throw FileImageSourceError.posixError(_swift_get_errno())
59+
throw FileImageSourceError.posixError(errno)
5260
}
5361
_mapping = UnsafeRawBufferPointer(start: base, count: Int(size))
5462
}

stdlib/public/Backtracing/MemoryReader.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,23 @@
1717

1818
import Swift
1919

20-
@_implementationOnly import OS.Libc
20+
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
21+
internal import Darwin
22+
#elseif os(Windows)
23+
internal import ucrt
24+
#elseif canImport(Glibc)
25+
internal import Glibc
26+
#elseif canImport(Musl)
27+
internal import Musl
28+
#endif
29+
2130
#if os(macOS)
22-
@_implementationOnly import OS.Darwin
31+
internal import BacktracingImpl.OS.Darwin
2332
#elseif os(Linux)
24-
@_implementationOnly import OS.Linux
33+
internal import BacktracingImpl.OS.Linux
2534
#endif
2635

27-
@_implementationOnly import Runtime
36+
internal import BacktracingImpl.Runtime
2837

2938
@_spi(MemoryReaders) public protocol MemoryReader {
3039
typealias Address = UInt64

stdlib/public/Backtracing/SymbolicatedBacktrace.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,19 @@
1818
import Swift
1919

2020
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
21-
@_implementationOnly import OS.Darwin
21+
internal import BacktracingImpl.OS.Darwin
2222
#endif
2323

24-
@_implementationOnly import OS.Libc
25-
@_implementationOnly import Runtime
26-
// Because we've turned off the OS/SDK modules, and we don't have a module for
27-
// stddef.h, and we sometimes build with -fbuiltin-headers-in-system-modules for
28-
// vfs reasons, stddef.h can be absorbed into a random module. Sometimes it's
29-
// SwiftOverlayShims.
30-
@_implementationOnly import SwiftOverlayShims
24+
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
25+
internal import Darwin
26+
#elseif os(Windows)
27+
internal import ucrt
28+
#elseif canImport(Glibc)
29+
internal import Glibc
30+
#elseif canImport(Musl)
31+
internal import Musl
32+
#endif
33+
internal import BacktracingImpl.Runtime
3134

3235
/// A symbolicated backtrace
3336
public struct SymbolicatedBacktrace: CustomStringConvertible {

stdlib/public/Backtracing/Utils.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@
1616

1717
import Swift
1818

19-
@_implementationOnly import OS.Libc
19+
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
20+
internal import Darwin
21+
#elseif os(Windows)
22+
internal import ucrt
23+
#elseif canImport(Glibc)
24+
internal import Glibc
25+
#elseif canImport(Musl)
26+
internal import Musl
27+
#endif
2028

2129
internal func hex<T: FixedWidthInteger>(_ value: T,
2230
prefix shouldPrefix: Bool = true,
@@ -53,7 +61,7 @@ func pad<T>(_ value: T, _ width: Int, align: PadAlignment = .left) -> String {
5361

5462
@_spi(Utils)
5563
public func readString(from file: String) -> String? {
56-
let fd = _swift_open(file, O_RDONLY, 0)
64+
let fd = open(file, O_RDONLY, 0)
5765
if fd < 0 {
5866
return nil
5967
}

stdlib/public/Backtracing/modules/OS/Darwin.h

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,15 @@
2222
#define SWIFT_BACKTRACING_DARWIN_H
2323
#ifdef __APPLE__
2424

25-
#ifdef __cplusplus
26-
extern "C" {
27-
#endif
28-
2925
#include <mach/mach.h>
3026
#include <mach/mach_vm.h>
3127

3228
#include <libproc.h>
3329
#include <stdint.h>
3430

35-
#include <CoreFoundation/CoreFoundation.h>
31+
#ifdef __cplusplus
32+
extern "C" {
33+
#endif
3634

3735
// .. Mach fixes ...............................................................
3836

@@ -141,6 +139,56 @@ extern void _dyld_process_info_for_each_segment(dyld_process_info info, uint64_t
141139
#define CS_PLATFORM_PATH 0x08000000
142140
extern int csops(int, unsigned int, void *, size_t);
143141

142+
// .. CoreFoundation ...........................................................
143+
144+
// We can't include <CoreFoundation/CoreFoundation.h> because that will create
145+
// a circular dependency. So declare some types directly.
146+
147+
typedef struct CFUUIDBytes {
148+
uint8_t byte0;
149+
uint8_t byte1;
150+
uint8_t byte2;
151+
uint8_t byte3;
152+
uint8_t byte4;
153+
uint8_t byte5;
154+
uint8_t byte6;
155+
uint8_t byte7;
156+
uint8_t byte8;
157+
uint8_t byte9;
158+
uint8_t byte10;
159+
uint8_t byte11;
160+
uint8_t byte12;
161+
uint8_t byte13;
162+
uint8_t byte14;
163+
uint8_t byte15;
164+
} CFUUIDBytes;
165+
166+
#define CF_BRIDGED_TYPE(T) __attribute__((objc_bridge(T)))
167+
168+
typedef const struct CF_BRIDGED_TYPE(NSString) __CFString *CFStringRef;
169+
typedef const struct CF_BRIDGED_TYPE(id) __CFAllocator *CFAllocatorRef;
170+
171+
#ifdef __LLP64__
172+
typedef signed long long CFIndex;
173+
#else
174+
typedef signed long CFIndex;
175+
#endif
176+
177+
typedef struct {
178+
CFIndex location;
179+
CFIndex length;
180+
} CFRange;
181+
182+
typedef uint32_t CFStringEncoding;
183+
184+
typedef enum __attribute__((enum_extensibility(open)))
185+
CFStringBuiltInEncodings : CFStringEncoding CFStringBuiltInEncodings;
186+
187+
enum CFStringBuiltInEncodings: CFStringEncoding {
188+
kCFStringEncodingASCII = 0x0600,
189+
kCFStringEncodingUTF8 = 0x08000100,
190+
};
191+
144192
// .. CoreSymbolication SPI ....................................................
145193

146194
typedef int32_t cpu_type_t;

stdlib/public/Backtracing/modules/OS/OS.modulemap

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
module OS {
2-
module Libc {
3-
header "Libc.h"
4-
}
5-
62
module Darwin {
73
header "Darwin.h"
84
}

0 commit comments

Comments
 (0)