[lld] [llvm] [lld][WebAssembly] Report undefined symbols by default -shared/-pie builds (PR #75242)
Derek Schuff via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 8 10:16:02 PDT 2024
================
@@ -309,13 +310,88 @@ static bool shouldReplace(const Symbol *existing, InputFile *newFile,
return true;
}
+ // Similarly with shared symbols
+ if (existing->isShared()) {
+ LLVM_DEBUG(dbgs() << "replacing existing shared symbol\n");
+ return true;
+ }
+
// Neither symbol is week. They conflict.
error("duplicate symbol: " + toString(*existing) + "\n>>> defined in " +
toString(existing->getFile()) + "\n>>> defined in " +
toString(newFile));
return true;
}
+Symbol *SymbolTable::addSharedFunction(StringRef name, uint32_t flags,
+ InputFile *file,
+ const WasmSignature *sig) {
+ LLVM_DEBUG(dbgs() << "addSharedFunction: " << name << " [" << toString(*sig)
+ << "]\n");
+ Symbol *s;
+ bool wasInserted;
+ std::tie(s, wasInserted) = insert(name, file);
+
+ auto replaceSym = [&](Symbol *sym) {
+ replaceSymbol<SharedFunctionSymbol>(sym, name, flags, file, sig);
+ };
+
+ if (wasInserted) {
+ replaceSym(s);
+ return s;
+ }
+
+ auto existingFunction = dyn_cast<FunctionSymbol>(s);
+ if (!existingFunction) {
+ reportTypeError(s, file, WASM_SYMBOL_TYPE_FUNCTION);
+ return s;
+ }
+
+ // Shared symbols should never replace locally-defined ones
+ if (s->isDefined()) {
+ return s;
+ }
+
+ LLVM_DEBUG(dbgs() << "resolving existing undefined symbol: " << s->getName()
+ << "\n");
+
+ bool checkSig = true;
+ if (auto ud = dyn_cast<UndefinedFunction>(existingFunction))
+ checkSig = ud->isCalledDirectly;
+
+ if (checkSig && !signatureMatches(existingFunction, sig)) {
+ Symbol *variant;
+ if (getFunctionVariant(s, sig, file, &variant))
----------------
dschuff wrote:
I'm not totally sure what this part is for... but also the if and else are identical?
https://github.com/llvm/llvm-project/pull/75242
More information about the llvm-commits
mailing list