Skip to content

Commit 720eb89

Browse files
kateinoigakukunrunner
authored andcommitted
[stdlib] Fix calling convention mismatch for runtime function tracking
Runtime function tracking APIs are defined with the C calling convention but they are called from Swift through `@_silgen_name`, so they are called with the Swift calling convention. This patch fixes the mismatch by adding `SWIFT_CC(swift)` to the definitions, but ideally we should be able to call these APIs with the C calling convention with `@_cdecl`. `@cdecl` without body is not supported yet but discussed in https://forums.swift.org/t/formalizing-cdecl/40677
1 parent dbb97bc commit 720eb89

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

stdlib/public/runtime/RuntimeInvocationsTracking.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static std::uint16_t RuntimeFunctionCountersOffsets[] = {
130130
/// Public APIs
131131

132132
/// Get the runtime object state associated with an object.
133-
void _swift_getObjectRuntimeFunctionCounters(
133+
SWIFT_CC(swift) void _swift_getObjectRuntimeFunctionCounters(
134134
HeapObject *object, RuntimeFunctionCountersState *result) {
135135
auto &theSentinel = RuntimeObjectStateCache.get();
136136
Mutex::ScopedLock lock(theSentinel.Lock);
@@ -139,7 +139,7 @@ void _swift_getObjectRuntimeFunctionCounters(
139139

140140
/// Set the runtime object state associated with an object from a provided
141141
/// state.
142-
void _swift_setObjectRuntimeFunctionCounters(
142+
SWIFT_CC(swift) void _swift_setObjectRuntimeFunctionCounters(
143143
HeapObject *object, RuntimeFunctionCountersState *state) {
144144
auto &theSentinel = RuntimeObjectStateCache.get();
145145
Mutex::ScopedLock lock(theSentinel.Lock);
@@ -148,14 +148,14 @@ void _swift_setObjectRuntimeFunctionCounters(
148148

149149
/// Get the global runtime state containing the total numbers of invocations for
150150
/// each runtime function of interest.
151-
void _swift_getGlobalRuntimeFunctionCounters(
151+
SWIFT_CC(swift) void _swift_getGlobalRuntimeFunctionCounters(
152152
RuntimeFunctionCountersState *result) {
153153
LazyMutex::ScopedLock lock(RuntimeGlobalFunctionCountersState.Lock);
154154
*result = RuntimeGlobalFunctionCountersState.State;
155155
}
156156

157157
/// Set the global runtime state of function pointers from a provided state.
158-
void _swift_setGlobalRuntimeFunctionCounters(
158+
SWIFT_CC(swift) void _swift_setGlobalRuntimeFunctionCounters(
159159
RuntimeFunctionCountersState *state) {
160160
LazyMutex::ScopedLock lock(RuntimeGlobalFunctionCountersState.Lock);
161161
RuntimeGlobalFunctionCountersState.State = *state;
@@ -164,18 +164,20 @@ void _swift_setGlobalRuntimeFunctionCounters(
164164
/// Return the names of the runtime functions being tracked.
165165
/// Their order is the same as the order of the counters in the
166166
/// RuntimeObjectState structure. All these strings are null terminated.
167-
const char **_swift_getRuntimeFunctionNames() {
167+
SWIFT_CC(swift) const char **_swift_getRuntimeFunctionNames() {
168168
return RuntimeFunctionNames;
169169
}
170170

171171
/// Return the offsets of the runtime function counters being tracked.
172172
/// Their order is the same as the order of the counters in the
173173
/// RuntimeObjectState structure.
174+
SWIFT_CC(swift)
174175
const std::uint16_t *_swift_getRuntimeFunctionCountersOffsets() {
175176
return RuntimeFunctionCountersOffsets;
176177
}
177178

178179
/// Return the number of runtime functions being tracked.
180+
SWIFT_CC(swift)
179181
std::uint64_t _swift_getNumRuntimeFunctionCounters() {
180182
return ID_LastRuntimeFunctionName;
181183
}
@@ -204,15 +206,15 @@ void _swift_dumpObjectsRuntimeFunctionPointers() {
204206

205207
/// Set mode for global runtime function counters.
206208
/// Return the old value of this flag.
207-
int _swift_setGlobalRuntimeFunctionCountersMode(int mode) {
209+
SWIFT_CC(swift) int _swift_setGlobalRuntimeFunctionCountersMode(int mode) {
208210
int oldMode = UpdateGlobalRuntimeFunctionCounters;
209211
UpdateGlobalRuntimeFunctionCounters = mode ? 1 : 0;
210212
return oldMode;
211213
}
212214

213215
/// Set mode for per object runtime function counters.
214216
/// Return the old value of this flag.
215-
int _swift_setPerObjectRuntimeFunctionCountersMode(int mode) {
217+
SWIFT_CC(swift) int _swift_setPerObjectRuntimeFunctionCountersMode(int mode) {
216218
int oldMode = UpdatePerObjectRuntimeFunctionCounters;
217219
UpdatePerObjectRuntimeFunctionCounters = mode ? 1 : 0;
218220
return oldMode;

stdlib/public/runtime/RuntimeInvocationsTracking.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,47 +61,47 @@ using RuntimeFunctionCountersUpdateHandler =
6161

6262
/// Get the runtime object state associated with an object and store it
6363
/// into the result.
64-
SWIFT_RUNTIME_EXPORT void
64+
SWIFT_CC(swift) SWIFT_RUNTIME_EXPORT void
6565
_swift_getObjectRuntimeFunctionCounters(HeapObject *object,
6666
RuntimeFunctionCountersState *result);
6767

6868
/// Get the global runtime state containing the total numbers of invocations for
6969
/// each runtime function of interest and store it into the result.
70-
SWIFT_RUNTIME_EXPORT void _swift_getGlobalRuntimeFunctionCounters(
70+
SWIFT_CC(swift) SWIFT_RUNTIME_EXPORT void _swift_getGlobalRuntimeFunctionCounters(
7171
swift::RuntimeFunctionCountersState *result);
7272

7373
/// Return the names of the runtime functions being tracked.
7474
/// Their order is the same as the order of the counters in the
7575
/// RuntimeObjectState structure.
76-
SWIFT_RUNTIME_EXPORT const char **_swift_getRuntimeFunctionNames();
76+
SWIFT_CC(swift) SWIFT_RUNTIME_EXPORT const char **_swift_getRuntimeFunctionNames();
7777

7878
/// Return the offsets of the runtime function counters being tracked.
7979
/// Their order is the same as the order of the counters in the
8080
/// RuntimeFunctionCountersState structure.
81-
SWIFT_RUNTIME_EXPORT const uint16_t *_swift_getRuntimeFunctionCountersOffsets();
81+
SWIFT_CC(swift) SWIFT_RUNTIME_EXPORT const uint16_t *_swift_getRuntimeFunctionCountersOffsets();
8282

8383
/// Return the number of runtime functions being tracked.
84-
SWIFT_RUNTIME_EXPORT uint64_t _swift_getNumRuntimeFunctionCounters();
84+
SWIFT_CC(swift) SWIFT_RUNTIME_EXPORT uint64_t _swift_getNumRuntimeFunctionCounters();
8585

8686
/// Dump all per-object runtime function pointers.
8787
SWIFT_RUNTIME_EXPORT void _swift_dumpObjectsRuntimeFunctionPointers();
8888

8989
/// Set mode for global runtime function counters.
9090
/// Return the old value of this flag.
91-
SWIFT_RUNTIME_EXPORT int
91+
SWIFT_CC(swift) SWIFT_RUNTIME_EXPORT int
9292
_swift_setPerObjectRuntimeFunctionCountersMode(int mode);
9393

9494
/// Set mode for per object runtime function counters.
9595
/// Return the old value of this flag.
96-
SWIFT_RUNTIME_EXPORT int _swift_setGlobalRuntimeFunctionCountersMode(int mode);
96+
SWIFT_CC(swift) SWIFT_RUNTIME_EXPORT int _swift_setGlobalRuntimeFunctionCountersMode(int mode);
9797

9898
/// Set the global runtime state of function pointers from a provided state.
99-
SWIFT_RUNTIME_EXPORT void _swift_setGlobalRuntimeFunctionCounters(
99+
SWIFT_CC(swift) SWIFT_RUNTIME_EXPORT void _swift_setGlobalRuntimeFunctionCounters(
100100
swift::RuntimeFunctionCountersState *state);
101101

102102
/// Set the runtime object state associated with an object from a provided
103103
/// state.
104-
SWIFT_RUNTIME_EXPORT void
104+
SWIFT_CC(swift) SWIFT_RUNTIME_EXPORT void
105105
_swift_setObjectRuntimeFunctionCounters(HeapObject *object,
106106
RuntimeFunctionCountersState *state);
107107

0 commit comments

Comments
 (0)