}
}
-// If all references to a DSO happen to be weak, the DSO is not added
-// to DT_NEEDED. If that happens, we need to eliminate shared symbols
-// created from the DSO. Otherwise, they become dangling references
-// that point to a non-existent DSO.
-static void demoteSharedSymbols() {
- llvm::TimeTraceScope timeScope("Demote shared symbols");
+// If all references to a DSO happen to be weak, the DSO is not added to
+// DT_NEEDED. If that happens, replace ShardSymbol with Undefined to avoid
+// dangling references to an unneeded DSO. Use a weak binding to avoid
+// --no-allow-shlib-undefined diagnostics. Similarly, demote lazy symbols.
+static void demoteSharedAndLazySymbols() {
+ llvm::TimeTraceScope timeScope("Demote shared and lazy symbols");
for (Symbol *sym : symtab->symbols()) {
auto *s = dyn_cast<SharedSymbol>(sym);
if (!(s && !s->getFile().isNeeded) && !sym->isLazy())
continue;
bool used = sym->used;
+ uint8_t binding = sym->isLazy() ? sym->binding : uint8_t(STB_WEAK);
sym->replace(
- Undefined{nullptr, sym->getName(), STB_WEAK, sym->stOther, sym->type});
+ Undefined{nullptr, sym->getName(), binding, sym->stOther, sym->type});
sym->used = used;
sym->versionId = VER_NDX_GLOBAL;
}
// Garbage collection and removal of shared symbols from unused shared objects.
invokeELFT(markLive);
- demoteSharedSymbols();
+ demoteSharedAndLazySymbols();
// Make copies of any input sections that need to be copied into each
// partition.