Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CHERIoT][LLD] Provide a better error message when a compartment export annotation is omitted. #73

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions lld/ELF/Relocations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,39 @@ static void reportUndefinedSymbol(const UndefinedDiag &undef,
}
}

// Provide a spelling-like hint when we fail to resolve a local symbol but
// find a corresponding export in another compartment.
// FIXME: Is there a better way to test for cheriot here?
if (config->isCheriAbi && config->emachine == EM_RISCV &&
config->capabilitySize == 8) {
StringRef SymName = sym.getName();
for (auto GlobalSymbol : symtab.getSymbols()) {
if (!GlobalSymbol->isGlobal())
continue;
if (!GlobalSymbol->isDefined())
continue;

StringRef GlobalName = GlobalSymbol->getName();
if (!GlobalName.consume_front("__export_"))
continue;
size_t functionNameStart = GlobalName.find("__Z");
if (functionNameStart == StringRef::npos)
continue;

StringRef GlobalCompartmentName =
GlobalName.take_front(functionNameStart);
StringRef GlobalFunctionName = GlobalName.substr(functionNameStart + 1);
if (GlobalFunctionName == SymName) {
msg += "\n>>> did you mean the \"" + toString(sym) +
"\" export from compartment \"" +
toString(GlobalCompartmentName) + "\"?";
msg += "\n>>> defined in: " + toString(GlobalSymbol->file);
msg += "\n>>> the declaration may be missing a compartment annotation";
break;
}
}
}

if (sym.getName().starts_with("_ZTV"))
msg +=
"\n>>> the vtable symbol may be undefined because the class is missing "
Expand Down