Skip to content

Commit 42678c1

Browse files
committed
stdlib: tweak import declarations
Ensure that the functions which are declared with @_silgen_name for importing from external libraries are described with the correct linkage. If the declared functions are marked with internal or no linkage, the declaration for the import will be given internal linkage. However, this is incorrect if the definition is not part of the image. The remaining uses were filtered on the assumption that the swift standard library is statically linked and provides the definitions for those symbols and thus will be part of the image. This was noticed by manual inspection of the IR generated. Thanks to Dmitri Gribenko for the hint about the trampoline construction.
1 parent 991fc1a commit 42678c1

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

stdlib/public/SDK/Darwin/Misc.mm

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
#include <fcntl.h>
1414
#include <semaphore.h>
1515

16+
#define _REENTRANT
17+
#include <math.h>
18+
1619
extern "C" int
1720
_swift_Darwin_open(const char *path, int oflag, mode_t mode) {
1821
return open(path, oflag, mode);
@@ -42,3 +45,17 @@
4245
return fcntl(fd, cmd, ptr);
4346
}
4447

48+
extern "C" float
49+
_swift_Darwin_lgammaf_r(float x, int *psigngam) {
50+
return lgammaf_r(x, psigngam);
51+
}
52+
53+
extern "C" double
54+
_swift_Darwin_lgamma_r(double x, int *psigngam) {
55+
return lgamma_r(x, psigngam);
56+
}
57+
58+
extern "C" long double
59+
_swift_Darwin_lgammal_r(long double x, int *psigngam) {
60+
return lgammal_r(x, psigngam);
61+
}

stdlib/public/SDK/Darwin/tgmath.swift.gyb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,10 @@ public func scalbn(x: ${T}, _ n: Int) -> ${T} {
259259
% for T, CT, f in AllFloatTypes():
260260
% # The real lgamma_r is not imported because it hides behind macro _REENTRANT.
261261
@warn_unused_result
262-
@_silgen_name("lgamma${f}_r")
262+
@_silgen_name("_swift_Darwin_lgamma${f}_r")
263263
func _swift_Darwin_lgamma${f}_r(_: ${CT},
264264
_: UnsafeMutablePointer<CInt>) -> ${CT}
265+
265266
@_transparent
266267
@warn_unused_result
267268
public func lgamma(x: ${T}) -> (${T}, Int) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
add_swift_library(swiftObjectiveC IS_SDK_OVERLAY
2+
ObjectiveC.mm
23
ObjectiveC.swift
34
SWIFT_MODULE_DEPENDS Darwin)
45

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include <objc/objc-api.h>
14+
15+
OBJC_EXPORT
16+
void *objc_autoreleasePoolPush(void);
17+
18+
OBJC_EXPORT
19+
void objc_autoreleasePoolPop(void *);
20+
21+
extern "C" void *_swift_objc_autoreleasePoolPush(void) {
22+
return objc_autoreleasePoolPush();
23+
}
24+
25+
extern "C" void _swift_objc_autoreleasePoolPop(void *context) {
26+
return objc_autoreleasePoolPop(context);
27+
}
28+

stdlib/public/SDK/ObjectiveC/ObjectiveC.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,10 @@ typealias Zone = NSZone
196196
//===----------------------------------------------------------------------===//
197197

198198
@warn_unused_result
199-
@_silgen_name("objc_autoreleasePoolPush")
199+
@_silgen_name("_swift_objc_autoreleasePoolPush")
200200
func __pushAutoreleasePool() -> OpaquePointer
201201

202-
@_silgen_name("objc_autoreleasePoolPop")
202+
@_silgen_name("_swift_objc_autoreleasePoolPop")
203203
func __popAutoreleasePool(pool: OpaquePointer)
204204

205205
public func autoreleasepool(@noescape code: () -> Void) {

0 commit comments

Comments
 (0)