Skip to content

Commit ca54f1a

Browse files
committed
Hide more symbols
Apparently `-fvisibility=hidden` is not sufficient to hide some of the symbols in this library. I've explicitly marked the symbols that were flagged as being incorrectly exported as "hidden" so hopefully no one drags them out again. This is a statically linked library, so the symbols shouldn't need to be exported for this work work. To ensure that this is the case and that we're still hitting the overridden API with all of the hidden symbols, I added a debug log line to the fixed `AsyncTask::waitFuture` implementation and have verified that we see the compat56 log message emitted from executables that need the compat56 library.
1 parent d427c7a commit ca54f1a

File tree

9 files changed

+59
-0
lines changed

9 files changed

+59
-0
lines changed

stdlib/toolchain/Compatibility56/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ set(library_name "swiftCompatibility56")
22

33
include_directories("include/" "${SWIFT_STDLIB_SOURCE_DIR}")
44

5+
set(CMAKE_C_VISIBILITY_PRESET hidden)
6+
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
7+
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
8+
59
add_compile_definitions(SWIFT_COMPATIBILITY56)
610
add_swift_target_library("${library_name}" STATIC
711
Overrides.cpp

stdlib/toolchain/Compatibility56/Concurrency/Task.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ FutureFragment::Status AsyncTask::waitFuture(AsyncTask *waitingTask,
1515
TaskContinuationFunction *resumeFn,
1616
AsyncContext *callerContext,
1717
OpaqueValue *result) {
18+
SWIFT_TASK_DEBUG_LOG("compat 56 task task %p", this);
1819
using Status = FutureFragment::Status;
1920
using WaitQueueItem = FutureFragment::WaitQueueItem;
2021

stdlib/toolchain/Compatibility56/Overrides.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ struct ConcurrencyOverrideSection {
3939

4040
#undef OVERRIDE
4141

42+
__attribute__((visibility("hidden")))
4243
ConcurrencyOverrideSection Swift56ConcurrencyOverrides
4344
__attribute__((used, section("__DATA,__s_async_hook"))) = {
4445
.version = 0,
4546
.task_future_wait = swift56override_swift_task_future_wait,
4647
.task_future_wait_throwing = swift56override_swift_task_future_wait_throwing,
4748
};
4849

50+
__attribute__((visibility("hidden")))
4951
RuntimeOverrideSection Swift56RuntimeOverrides
5052
__attribute__((used, section("__DATA,__swift56_hooks"))) = {
5153
.version = 0,

stdlib/toolchain/Compatibility56/include/Concurrency/Error.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
namespace swift {
2525

26+
__attribute__((visibility("hidden")))
2627
SWIFT_NORETURN void swift_Concurrency_fatalError(uint32_t flags, const char *format, ...);
2728

2829
} // namespace swift

stdlib/toolchain/Compatibility56/include/Concurrency/Task.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,9 @@ class AsyncTask : public Job {
307307
///
308308
/// Generally this should be done immediately after updating
309309
/// ActiveTask.
310+
__attribute__((visibility("hidden")))
310311
void flagAsRunning();
312+
__attribute__((visibility("hidden")))
311313
void flagAsRunning_slow();
312314

313315
/// Flag that this task is now suspended. This can update the
@@ -316,26 +318,33 @@ class AsyncTask : public Job {
316318
/// clearing ActiveTask and immediately before enqueuing the task
317319
/// somewhere. TODO: record where the task is enqueued if
318320
/// possible.
321+
__attribute__((visibility("hidden")))
319322
void flagAsSuspended();
323+
__attribute__((visibility("hidden")))
320324
void flagAsSuspended_slow();
321325

322326
/// Flag that this task is now completed. This normally does not do anything
323327
/// but can be used to locally insert logging.
328+
__attribute__((visibility("hidden")))
324329
void flagAsCompleted();
325330

326331
/// Check whether this task has been cancelled.
327332
/// Checking this is, of course, inherently race-prone on its own.
333+
__attribute__((visibility("hidden")))
328334
bool isCancelled() const;
329335

330336
// ==== Task Local Values ----------------------------------------------------
331337

338+
__attribute__((visibility("hidden")))
332339
void localValuePush(const HeapObject *key,
333340
/* +1 */ OpaqueValue *value,
334341
const Metadata *valueType);
335342

343+
__attribute__((visibility("hidden")))
336344
OpaqueValue *localValueGet(const HeapObject *key);
337345

338346
/// Returns true if storage has still more bindings.
347+
__attribute__((visibility("hidden")))
339348
bool localValuePop();
340349

341350
// ==== Child Fragment -------------------------------------------------------
@@ -563,6 +572,7 @@ class AsyncTask : public Job {
563572
/// the future has completed and can be queried.
564573
/// The waiting task's async context will be intialized with the parameters if
565574
/// the current's task state is executing.
575+
__attribute__((visibility("hidden")))
566576
FutureFragment::Status waitFuture(AsyncTask *waitingTask,
567577
AsyncContext *waitingTaskContext,
568578
TaskContinuationFunction *resumeFn,

stdlib/toolchain/Compatibility56/include/Concurrency/TaskPrivate.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,23 @@ class TaskFutureWaitAsyncContext : public AsyncContext {
106106

107107
/// Adopt the voucher stored in `task`. This removes the voucher from the task
108108
/// and adopts it on the current thread.
109+
__attribute__((visibility("hidden")))
109110
void adoptTaskVoucher(AsyncTask *task);
110111

111112
/// Restore the voucher for `task`. This un-adopts the current thread's voucher
112113
/// and stores it back into the task again.
114+
__attribute__((visibility("hidden")))
113115
void restoreTaskVoucher(AsyncTask *task);
114116

115117
/// release() establishes a happens-before relation with a preceding acquire()
116118
/// on the same address.
119+
__attribute__((visibility("hidden")))
117120
void _swift_tsan_acquire(void *addr);
121+
__attribute__((visibility("hidden")))
118122
void _swift_tsan_release(void *addr);
119123

120124
/// Clear the active task reference for the current thread.
125+
__attribute__((visibility("hidden")))
121126
AsyncTask *_swift_task_clearCurrent();
122127

123128
/// The current state of a task's status records.

stdlib/toolchain/Compatibility56/include/Concurrency/TaskStatus.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ class CancellationNotificationStatusRecord : public TaskStatusRecord {
159159
};
160160

161161
/// Return the current thread's active task reference.
162+
__attribute__((visibility("hidden")))
162163
SWIFT_CC(swift)
163164
AsyncTask *swift_task_getCurrent(void);
164165
} // namespace swift

stdlib/toolchain/Compatibility56/include/Concurrency/Threading/MutexPThread.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ typedef pthread_mutex_t MutexHandle;
5656
///
5757
/// See ConditionVariable
5858
struct ConditionPlatformHelper {
59+
__attribute__((visibility("hidden")))
5960
#if SWIFT_CONDITION_SUPPORTS_CONSTEXPR
6061
static constexpr
6162
#else
@@ -65,10 +66,15 @@ struct ConditionPlatformHelper {
6566
staticInit() {
6667
return PTHREAD_COND_INITIALIZER;
6768
};
69+
__attribute__((visibility("hidden")))
6870
static void init(ConditionHandle &condition);
71+
__attribute__((visibility("hidden")))
6972
static void destroy(ConditionHandle &condition);
73+
__attribute__((visibility("hidden")))
7074
static void notifyOne(ConditionHandle &condition);
75+
__attribute__((visibility("hidden")))
7176
static void notifyAll(ConditionHandle &condition);
77+
__attribute__((visibility("hidden")))
7278
static void wait(ConditionHandle &condition, ConditionMutexHandle &mutex);
7379
};
7480

@@ -77,6 +83,7 @@ struct ConditionPlatformHelper {
7783
///
7884
/// See Mutex
7985
struct MutexPlatformHelper {
86+
__attribute__((visibility("hidden")))
8087
#if SWIFT_MUTEX_SUPPORTS_CONSTEXPR
8188
static constexpr
8289
#else
@@ -86,6 +93,7 @@ struct MutexPlatformHelper {
8693
conditionStaticInit() {
8794
return PTHREAD_MUTEX_INITIALIZER;
8895
};
96+
__attribute__((visibility("hidden")))
8997
#if SWIFT_MUTEX_SUPPORTS_CONSTEXPR
9098
static constexpr
9199
#else
@@ -99,30 +107,46 @@ struct MutexPlatformHelper {
99107
return PTHREAD_MUTEX_INITIALIZER;
100108
#endif
101109
}
110+
111+
__attribute__((visibility("hidden")))
102112
static void init(ConditionMutexHandle &mutex, bool checked = false);
113+
114+
__attribute__((visibility("hidden")))
103115
static void destroy(ConditionMutexHandle &mutex);
116+
__attribute__((visibility("hidden")))
104117
static void lock(ConditionMutexHandle &mutex);
118+
__attribute__((visibility("hidden")))
105119
static void unlock(ConditionMutexHandle &mutex);
120+
__attribute__((visibility("hidden")))
106121
static bool try_lock(ConditionMutexHandle &mutex);
107122

108123
// The ConditionMutexHandle versions handle everything on-Apple platforms.
109124
#if HAS_OS_UNFAIR_LOCK
110125

126+
__attribute__((visibility("hidden")))
111127
static void init(MutexHandle &mutex, bool checked = false);
128+
__attribute__((visibility("hidden")))
112129
static void destroy(MutexHandle &mutex);
130+
__attribute__((visibility("hidden")))
113131
static void lock(MutexHandle &mutex);
132+
__attribute__((visibility("hidden")))
114133
static void unlock(MutexHandle &mutex);
134+
__attribute__((visibility("hidden")))
115135
static bool try_lock(MutexHandle &mutex);
116136

117137
// os_unfair_lock always checks for errors, so just call through.
138+
__attribute__((visibility("hidden")))
118139
static void unsafeLock(MutexHandle &mutex) { lock(mutex); }
140+
__attribute__((visibility("hidden")))
119141
static void unsafeUnlock(MutexHandle &mutex) { unlock(mutex); }
120142
#endif
121143

122144
// The unsafe versions don't do error checking.
145+
__attribute__((visibility("hidden")))
123146
static void unsafeLock(ConditionMutexHandle &mutex) {
124147
(void)pthread_mutex_lock(&mutex);
125148
}
149+
__attribute__((visibility("hidden")))
126150
static void unsafeUnlock(ConditionMutexHandle &mutex) {
127151
(void)pthread_mutex_unlock(&mutex);
128152
}
@@ -133,6 +157,8 @@ struct MutexPlatformHelper {
133157
///
134158
/// See ReadWriteLock
135159
struct ReadWriteLockPlatformHelper {
160+
161+
__attribute__((visibility("hidden")))
136162
#if SWIFT_READWRITELOCK_SUPPORTS_CONSTEXPR
137163
static constexpr
138164
#else
@@ -143,13 +169,21 @@ struct ReadWriteLockPlatformHelper {
143169
return PTHREAD_RWLOCK_INITIALIZER;
144170
};
145171

172+
__attribute__((visibility("hidden")))
146173
static void init(ReadWriteLockHandle &rwlock);
174+
__attribute__((visibility("hidden")))
147175
static void destroy(ReadWriteLockHandle &rwlock);
176+
__attribute__((visibility("hidden")))
148177
static void readLock(ReadWriteLockHandle &rwlock);
178+
__attribute__((visibility("hidden")))
149179
static bool try_readLock(ReadWriteLockHandle &rwlock);
180+
__attribute__((visibility("hidden")))
150181
static void readUnlock(ReadWriteLockHandle &rwlock);
182+
__attribute__((visibility("hidden")))
151183
static void writeLock(ReadWriteLockHandle &rwlock);
184+
__attribute__((visibility("hidden")))
152185
static bool try_writeLock(ReadWriteLockHandle &rwlock);
186+
__attribute__((visibility("hidden")))
153187
static void writeUnlock(ReadWriteLockHandle &rwlock);
154188
};
155189
}

stdlib/toolchain/Compatibility56/include/Runtime/Concurrency.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ using FutureAsyncSignature =
8282
/// This has no effect if the task already has at least the given priority.
8383
/// Returns the priority of the task.
8484
SWIFT_CC(swift)
85+
__attribute__((visibility("hidden")))
8586
JobPriority swift_task_escalateBackdeploy56(AsyncTask *task,
8687
JobPriority newPriority);
8788
} // namespace swift

0 commit comments

Comments
 (0)