Skip to content

Commit c889270

Browse files
authored
Remove lookupSymbol() and have all callers use SymbolInfo::lookup() instead (#62552)
1 parent 9cebd69 commit c889270

File tree

7 files changed

+29
-53
lines changed

7 files changed

+29
-53
lines changed

stdlib/public/SwiftShims/swift/shims/MetadataSections.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ struct MetadataSections {
5353
/// reported when the section was registered with the Swift runtime.
5454
///
5555
/// The value of this field is equivalent to the value of
56-
/// \c SymbolInfo::baseAddress as returned from \c lookupSymbol() for a symbol
57-
/// in the image that contains these sections.
56+
/// \c SymbolInfo::baseAddress as returned from \c SymbolInfo::lookup() for a
57+
/// symbol in the image that contains these sections.
5858
///
5959
/// For Mach-O images, set this field to \c __dso_handle (i.e. the Mach header
6060
/// for the image.) For ELF images, set it to \c __dso_handle (the runtime

stdlib/public/runtime/Errors.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,16 @@ static bool getSymbolNameAddr(llvm::StringRef libraryName,
144144
void swift::dumpStackTraceEntry(unsigned index, void *framePC,
145145
bool shortOutput) {
146146
#if SWIFT_STDLIB_SUPPORTS_BACKTRACE_REPORTING && SWIFT_STDLIB_HAS_DLADDR
147-
SymbolInfo syminfo;
148-
149-
// 0 is failure for lookupSymbol
150-
if (0 == lookupSymbol(framePC, &syminfo)) {
147+
auto syminfo = SymbolInfo::lookup(framePC);
148+
if (!syminfo.has_value()) {
151149
return;
152150
}
153151

154-
// If lookupSymbol succeeded then fileName is non-null. Thus, we find the
152+
// If SymbolInfo:lookup succeeded then fileName is non-null. Thus, we find the
155153
// library name here. Avoid using StringRef::rsplit because its definition
156154
// is not provided in the header so that it requires linking with
157155
// libSupport.a.
158-
llvm::StringRef libraryName{syminfo.getFilename()};
156+
llvm::StringRef libraryName{syminfo->getFilename()};
159157
libraryName = libraryName.substr(libraryName.rfind('/')).substr(1);
160158

161159
// Next we get the symbol name that we are going to use in our backtrace.
@@ -165,12 +163,12 @@ void swift::dumpStackTraceEntry(unsigned index, void *framePC,
165163
// we just get HexAddr + 0.
166164
uintptr_t symbolAddr = uintptr_t(framePC);
167165
bool foundSymbol =
168-
getSymbolNameAddr(libraryName, syminfo, symbolName, symbolAddr);
166+
getSymbolNameAddr(libraryName, syminfo.value(), symbolName, symbolAddr);
169167
ptrdiff_t offset = 0;
170168
if (foundSymbol) {
171169
offset = ptrdiff_t(uintptr_t(framePC) - symbolAddr);
172170
} else {
173-
auto baseAddress = syminfo.getBaseAddress();
171+
auto baseAddress = syminfo->getBaseAddress();
174172
offset = ptrdiff_t(uintptr_t(framePC) - uintptr_t(baseAddress));
175173
symbolAddr = uintptr_t(framePC);
176174
symbolName = "<unavailable>";

stdlib/public/runtime/ImageInspectionCommon.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ static void fixupMetadataSectionBaseAddress(swift::MetadataSections *sections) {
6464
if (fixupNeeded) {
6565
// We need to fix up the base address. We'll need a known-good address in
6666
// the same image: `sections` itself will work nicely.
67-
swift::SymbolInfo symbolInfo;
68-
if (lookupSymbol(sections, &symbolInfo) && symbolInfo.getBaseAddress()) {
69-
sections->baseAddress.store(symbolInfo.getBaseAddress(),
67+
auto symbolInfo = SymbolInfo::lookup(sections);
68+
if (symbolInfo.has_value() && symbolInfo->getBaseAddress()) {
69+
sections->baseAddress.store(symbolInfo->getBaseAddress(),
7070
std::memory_order_relaxed);
7171
}
7272
}
@@ -190,10 +190,9 @@ const swift::MetadataSections *swift_getMetadataSection(size_t index) {
190190
SWIFT_RUNTIME_EXPORT
191191
const char *
192192
swift_getMetadataSectionName(const swift::MetadataSections *section) {
193-
swift::SymbolInfo info;
194-
if (lookupSymbol(section, &info)) {
195-
if (info.getFilename()) {
196-
return info.getFilename();
193+
if (auto info = SymbolInfo::lookup(section)) {
194+
if (info->getFilename()) {
195+
return info->getFilename();
197196
}
198197
}
199198
return "";
@@ -203,9 +202,8 @@ SWIFT_RUNTIME_EXPORT
203202
void swift_getMetadataSectionBaseAddress(const swift::MetadataSections *section,
204203
void const **out_actual,
205204
void const **out_expected) {
206-
swift::SymbolInfo info;
207-
if (lookupSymbol(section, &info)) {
208-
*out_actual = info.getBaseAddress();
205+
if (auto info = SymbolInfo::lookup(section)) {
206+
*out_actual = info->getBaseAddress();
209207
} else {
210208
*out_actual = nullptr;
211209
}

stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,9 +1105,8 @@ _gatherGenericParameters(const ContextDescriptor *context,
11051105

11061106
str += "_gatherGenericParameters: context: ";
11071107

1108-
SymbolInfo contextInfo;
1109-
if (lookupSymbol(context, &contextInfo)) {
1110-
str += contextInfo.getSymbolName();
1108+
if (auto contextInfo = SymbolInfo::lookup(context)) {
1109+
str += contextInfo->getSymbolName();
11111110
str += " ";
11121111
}
11131112

stdlib/public/runtime/ProtocolConformance.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,13 @@ static const char *class_getName(const ClassMetadata* type) {
124124
}
125125

126126
template<> void ProtocolConformanceDescriptor::dump() const {
127-
SymbolInfo info;
127+
llvm::Optional<SymbolInfo> info;
128128
auto symbolName = [&](const void *addr) -> const char * {
129-
int ok = lookupSymbol(addr, &info);
130-
if (!ok || !info.getSymbolName())
131-
return "<unknown addr>";
132-
return info.getSymbolName();
129+
info = SymbolInfo::lookup(addr);
130+
if (info.has_value() && info->getSymbolName()) {
131+
return info->getSymbolName();
132+
}
133+
return "<unknown addr>";
133134
};
134135

135136
switch (auto kind = getTypeKind()) {

stdlib/public/runtime/ReflectionMirror.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,11 +1116,12 @@ id swift_reflectionMirror_quickLookObject(OpaqueValue *value, const Metadata *T)
11161116

11171117
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERNAL
11181118
const char *swift_keyPath_copySymbolName(void *address) {
1119-
SymbolInfo info;
1120-
if (lookupSymbol(address, &info) && info.getSymbolName()) {
1121-
return strdup(info.getSymbolName());
1119+
if (auto info = SymbolInfo::lookup(address)) {
1120+
if (info->getSymbolName()) {
1121+
return strdup(info->getSymbolName());
1122+
}
11221123
}
1123-
return 0;
1124+
return nullptr;
11241125
}
11251126

11261127
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERNAL

stdlib/public/runtime/SymbolInfo.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,27 +76,6 @@ struct SymbolInfo {
7676
static llvm::Optional<SymbolInfo> lookup(const void *address);
7777
};
7878

79-
/// Look up a symbol by address and store the result in a locally-declared
80-
/// \c SymbolInfo value.
81-
///
82-
/// \param address The address where the symbol is located.
83-
/// \param outInfo On successful return, populated with information about the
84-
/// symbol at \a address. On failure, unspecified.
85-
///
86-
/// \returns On success, a non-zero integer. On failure, zero.
87-
///
88-
/// \note This function will be replaced with \c SymbolInfo::lookup() in a
89-
/// future update.
90-
static inline int lookupSymbol(const void *address, SymbolInfo *outInfo) {
91-
auto info = SymbolInfo::lookup(address);
92-
if (info.has_value()) {
93-
*outInfo = info.value();
94-
return 1;
95-
} else {
96-
return 0;
97-
}
98-
}
99-
10079
} // end namespace swift
10180

10281
#endif

0 commit comments

Comments
 (0)