Skip to content

Commit 2dfd3d5

Browse files
author
Davide Italiano
committed
[Runtime] Remove dependency on Compiler.h from Config.h.
The runtime doesn't really need Compiler.h. It just needs some visibility macros which can be inlined here instead of pulling the whole heavyweight header (including its transitive closure, llvm-config.h). This is becoming more important now that Compiler.h includes C++ headers (namely, <new>), and swift/Runtime/Config.h can be included from C or Objective-C files (causing build failures). <rdar://problem/35860874>
1 parent 55eb35c commit 2dfd3d5

File tree

5 files changed

+33
-7
lines changed

5 files changed

+33
-7
lines changed

include/swift/Runtime/Config.h

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,34 @@
1717
#ifndef SWIFT_RUNTIME_CONFIG_H
1818
#define SWIFT_RUNTIME_CONFIG_H
1919

20-
// Bring in visibility attribute macros for library visibility.
21-
#include "llvm/Support/Compiler.h"
20+
/// \macro SWIFT_RUNTIME_GNUC_PREREQ
21+
/// Extend the default __GNUC_PREREQ even if glibc's features.h isn't
22+
/// available.
23+
#ifndef SWIFT_RUNTIME_GNUC_PREREQ
24+
# if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
25+
# define SWIFT_RUNTIME_GNUC_PREREQ(maj, min, patch) \
26+
((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) + __GNUC_PATCHLEVEL__ >= \
27+
((maj) << 20) + ((min) << 10) + (patch))
28+
# elif defined(__GNUC__) && defined(__GNUC_MINOR__)
29+
# define SWIFT_RUNTIME_GNUC_PREREQ(maj, min, patch) \
30+
((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) >= ((maj) << 20) + ((min) << 10))
31+
# else
32+
# define SWIFT_RUNTIME_GNUC_PREREQ(maj, min, patch) 0
33+
# endif
34+
#endif
35+
36+
/// SWIFT_RUNTIME_LIBRARY_VISIBILITY - If a class marked with this attribute is
37+
/// linked into a shared library, then the class should be private to the
38+
/// library and not accessible from outside it. Can also be used to mark
39+
/// variables and functions, making them private to any shared library they are
40+
/// linked into.
41+
/// On PE/COFF targets, library visibility is the default, so this isn't needed.
42+
#if (__has_attribute(visibility) || SWIFT_RUNTIME_GNUC_PREREQ(4, 0, 0)) && \
43+
!defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(_WIN32)
44+
#define SWIFT_RUNTIME_LIBRARY_VISIBILITY __attribute__ ((visibility("hidden")))
45+
#else
46+
#define SWIFT_RUNTIME_LIBRARY_VISIBILITY
47+
#endif
2248

2349
/// Does the current Swift platform support "unbridged" interoperation
2450
/// with Objective-C? If so, the implementations of various types must

stdlib/private/StdlibUnittest/GetOSVersion.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#include "swift/Runtime/Config.h"
1717

18-
SWIFT_CC(swift) LLVM_LIBRARY_VISIBILITY extern "C"
18+
SWIFT_CC(swift) SWIFT_RUNTIME_LIBRARY_VISIBILITY extern "C"
1919
const char *
2020
getSystemVersionPlistProperty(const char *PropertyName) {
2121
// This function is implemented in Objective-C because Swift does not support

stdlib/private/StdlibUnittest/InterceptTraps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static void CrashCatcher(int Sig) {
3333
_exit(0);
3434
}
3535

36-
SWIFT_CC(swift) LLVM_LIBRARY_VISIBILITY extern "C"
36+
SWIFT_CC(swift) SWIFT_RUNTIME_LIBRARY_VISIBILITY extern "C"
3737
void installTrapInterceptor() {
3838
// Disable buffering on stdout so that everything is printed before crashing.
3939
setbuf(stdout, 0);

stdlib/private/StdlibUnittest/OpaqueIdentityFunctions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212

1313
#include "swift/Runtime/Config.h"
1414

15-
SWIFT_CC(swift) LLVM_LIBRARY_VISIBILITY extern "C"
15+
SWIFT_CC(swift) SWIFT_RUNTIME_LIBRARY_VISIBILITY extern "C"
1616
void *getPointer(void *x) { return x; }
1717

stdlib/private/StdlibUnittestFoundationExtras/UnavailableFoundationMethodThunks.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <Foundation/Foundation.h>
1414
#include "swift/Runtime/Config.h"
1515

16-
SWIFT_CC(swift) LLVM_LIBRARY_VISIBILITY
16+
SWIFT_CC(swift) SWIFT_RUNTIME_LIBRARY_VISIBILITY
1717
extern "C" void
1818
NSArray_getObjects(NSArray SWIFT_NS_RELEASES_ARGUMENT *_Nonnull nsArray,
1919
id *objects, NSUInteger rangeLocation,
@@ -22,7 +22,7 @@
2222
SWIFT_CC_PLUSONE_GUARD([nsArray release]);
2323
}
2424

25-
SWIFT_CC(swift) LLVM_LIBRARY_VISIBILITY
25+
SWIFT_CC(swift) SWIFT_RUNTIME_LIBRARY_VISIBILITY
2626
extern "C" void
2727
NSDictionary_getObjects(NSDictionary *_Nonnull nsDictionary,
2828
id *objects, id *keys) {

0 commit comments

Comments
 (0)