Skip to content

Commit 7b33d2c

Browse files
committed
[Runtime] Fatal error when resolving a symbolic reference to NULL.
We crash in ResolveAsSymbolicReference::operator() when a symbolic reference targets a missing symbol. We usually have very little information about what was missing when this happens. Instead of crashing, explicitly check for NULL and fatal error in that case, including information about the location of the symbolic reference that it came from.
1 parent 700bcb4 commit 7b33d2c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,22 @@ ResolveAsSymbolicReference::operator()(SymbolicReferenceKind kind,
118118
const void *base) {
119119
// Resolve the absolute pointer to the entity being referenced.
120120
auto ptr = resolveSymbolicReferenceOffset(kind, isIndirect, offset, base);
121+
if (SWIFT_UNLIKELY(!ptr)) {
122+
auto symInfo = SymbolInfo::lookup(base);
123+
const char *fileName = "<unknown>";
124+
const char *symbolName = "<unknown>";
125+
if (symInfo) {
126+
if (symInfo->getFilename())
127+
fileName = symInfo->getFilename();
128+
if (symInfo->getSymbolName())
129+
symbolName = symInfo->getSymbolName();
130+
}
131+
swift::fatalError(
132+
0,
133+
"Failed to look up symbolic reference at %p - offset %" PRId32
134+
" - symbol %s in %s\n",
135+
base, offset, symbolName, fileName);
136+
}
121137

122138
// Figure out this symbolic reference's grammatical role.
123139
Node::Kind nodeKind;

0 commit comments

Comments
 (0)