Skip to content

Commit be19535

Browse files
authored
Merge pull request #14831 from jckarter/protected-runtime-visibility
Visibility fixes for ELF.
2 parents ac54fec + 8656807 commit be19535

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

stdlib/public/SwiftShims/Visibility.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,37 @@
7272
// SWIFT_RUNTIME_EXPORT on the library it's exported from.
7373

7474
/// Attribute used to export symbols from the runtime.
75-
#if defined(__MACH__) || defined(__ELF__)
75+
#if defined(__MACH__)
76+
7677
# define SWIFT_EXPORT_ATTRIBUTE __attribute__((__visibility__("default")))
7778

78-
#else // FIXME: this #else should be some sort of #elif Windows
79+
#elif defined(__ELF__)
80+
81+
// We make assumptions that the runtime and standard library can refer to each
82+
// other's symbols as DSO-local, which means we can't allow the dynamic linker
83+
// to relocate these symbols. We must give them protected visibility while
84+
// building the standard library and runtime.
85+
# if defined(swiftCore_EXPORTS)
86+
# define SWIFT_EXPORT_ATTRIBUTE __attribute__((__visibility__("protected")))
87+
# else
88+
# define SWIFT_EXPORT_ATTRIBUTE __attribute__((__visibility__("default")))
89+
# endif
90+
91+
// FIXME: this #else should be some sort of #elif Windows
92+
#else // !__MACH__ && !__ELF__
93+
7994
# if defined(__CYGWIN__)
8095
# define SWIFT_EXPORT_ATTRIBUTE
8196
# else
97+
8298
# if defined(swiftCore_EXPORTS)
8399
# define SWIFT_EXPORT_ATTRIBUTE __declspec(dllexport)
84100
# else
85101
# define SWIFT_EXPORT_ATTRIBUTE __declspec(dllimport)
86102
# endif
103+
87104
# endif
105+
88106
#endif
89107

90108
#if defined(__cplusplus)

stdlib/public/stubs/GlobalObjects.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ SWIFT_RUNTIME_STDLIB_INTERFACE
3737
ClassMetadata CLASS_METADATA_SYM(s20_RawNativeSetStorage);
3838
} // namespace swift
3939

40+
SWIFT_RUNTIME_STDLIB_INTERFACE
4041
swift::_SwiftEmptyArrayStorage swift::_swiftEmptyArrayStorage = {
4142
// HeapObject header;
4243
{
@@ -50,8 +51,7 @@ swift::_SwiftEmptyArrayStorage swift::_swiftEmptyArrayStorage = {
5051
}
5152
};
5253

53-
54-
54+
SWIFT_RUNTIME_STDLIB_INTERFACE
5555
swift::_SwiftEmptyDictionaryStorage swift::_swiftEmptyDictionaryStorage = {
5656
// HeapObject header;
5757
{
@@ -79,7 +79,7 @@ swift::_SwiftEmptyDictionaryStorage swift::_swiftEmptyDictionaryStorage = {
7979
0 // int entries; (zero'd bits)
8080
};
8181

82-
82+
SWIFT_RUNTIME_STDLIB_INTERFACE
8383
swift::_SwiftEmptySetStorage swift::_swiftEmptySetStorage = {
8484
// HeapObject header;
8585
{

0 commit comments

Comments
 (0)