mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
These should hopefully all be uncontroversial, minimal changes to deal with progressing the build to completion on OpenBSD or addressing minor portability issues. This is not the full set of changes to get a successful build; other portability issues will be addressed in future commits. Most of this is just adding the relevant clauses to the ifdefs, but of note in this commit: * StdlibUnittest.swift: the default conditional in _getOSVersion assumes an Apple platform, therefore the explicit conditional and the relevant enums need filling out. The default conditional should be #error, but we'll fix this in a different commit. * tgmath.swift.gyb: inexplicably, OpenBSD is missing just lgammal_r. Tests are updated correspondingly. * ThreadLocalStorage.h: we use the pthread implementation, so it seems we should typedef __swift_thread_key_t as pthread_key_t. However, that's also a tweak for another commit.
54 lines
1.8 KiB
Swift
54 lines
1.8 KiB
Swift
//===--- SymbolLookup.swift -----------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
|
|
import Darwin
|
|
#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI)
|
|
import Glibc
|
|
#elseif os(Windows)
|
|
import MSVCRT
|
|
import WinSDK
|
|
#else
|
|
#error("Unsupported platform")
|
|
#endif
|
|
|
|
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(OpenBSD)
|
|
let RTLD_DEFAULT = UnsafeMutableRawPointer(bitPattern: -2)
|
|
#elseif os(Linux)
|
|
let RTLD_DEFAULT = UnsafeMutableRawPointer(bitPattern: 0)
|
|
#elseif os(Android)
|
|
#if arch(arm) || arch(i386)
|
|
let RTLD_DEFAULT = UnsafeMutableRawPointer(bitPattern: 0xffffffff as UInt)
|
|
#elseif arch(arm64) || arch(x86_64)
|
|
let RTLD_DEFAULT = UnsafeMutableRawPointer(bitPattern: 0)
|
|
#else
|
|
#error("Unsupported platform")
|
|
#endif
|
|
#elseif os(Windows)
|
|
let hStdlibCore: HMODULE = GetModuleHandleA("swiftCore.dll")!
|
|
#elseif os(WASI)
|
|
// WASI doesn't support dynamic linking yet.
|
|
#else
|
|
#error("Unsupported platform")
|
|
#endif
|
|
|
|
public func pointerToSwiftCoreSymbol(name: String) -> UnsafeMutableRawPointer? {
|
|
#if os(Windows)
|
|
return unsafeBitCast(GetProcAddress(hStdlibCore, name),
|
|
to: UnsafeMutableRawPointer?.self)
|
|
#elseif os(WASI)
|
|
fatalError("\(#function) is not supported on WebAssembly/WASI")
|
|
#else
|
|
return dlsym(RTLD_DEFAULT, name)
|
|
#endif
|
|
}
|