Skip to content

[ELF] Suppress --no-allow-shlib-undefined diagnostic when a SharedSymbol is overridden by a hidden visibility Defined which is later discarded #70130

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions lld/ELF/InputFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,7 @@ template <class ELFT> void SharedFile::parse() {
auto *s = symtab.addSymbol(
SharedSymbol{*this, name, sym.getBinding(), sym.st_other,
sym.getType(), sym.st_value, sym.st_size, alignment});
s->dsoDefined = true;
if (s->file == this)
s->versionId = ver;
}
Expand All @@ -1563,6 +1564,7 @@ template <class ELFT> void SharedFile::parse() {
auto *s = symtab.addSymbol(
SharedSymbol{*this, saver().save(name), sym.getBinding(), sym.st_other,
sym.getType(), sym.st_value, sym.st_size, alignment});
s->dsoDefined = true;
if (s->file == this)
s->versionId = idx;
}
Expand Down
10 changes: 7 additions & 3 deletions lld/ELF/Symbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,13 @@ class Symbol {
// of the symbol.
uint8_t scriptDefined : 1;

// True if defined in a DSO. There may also be a definition in a relocatable
// object file.
uint8_t dsoDefined : 1;

// True if defined in a DSO as protected visibility.
uint8_t dsoProtected : 1;

// True if targeted by a range extension thunk.
uint8_t thunkAccessed : 1;

// Temporary flags used to communicate which symbol entries need PLT and GOT
// entries during postScanRelocations();
std::atomic<uint16_t> flags;
Expand All @@ -320,6 +321,9 @@ class Symbol {
uint16_t versionId;
uint8_t versionScriptAssigned : 1;

// True if targeted by a range extension thunk.
uint8_t thunkAccessed : 1;

void setFlags(uint16_t bits) {
flags.fetch_or(bits, std::memory_order_relaxed);
}
Expand Down
7 changes: 7 additions & 0 deletions lld/ELF/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2025,6 +2025,11 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
// to catch more cases. That is too much for us. Our approach resembles
// the one used in ld.gold, achieves a good balance to be useful but not
// too smart.
//
// If a DSO reference is resolved by a SharedSymbol, but the SharedSymbol
// is overridden by a hidden visibility Defined (which is later discarded
// due to GC), don't report the diagnostic. However, this may indicate an
// unintended SharedSymbol.
for (SharedFile *file : ctx.sharedFiles) {
bool allNeededIsKnown =
llvm::all_of(file->dtNeeded, [&](StringRef needed) {
Expand All @@ -2033,6 +2038,8 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
if (!allNeededIsKnown)
continue;
for (Symbol *sym : file->requiredSymbols) {
if (sym->dsoDefined)
continue;
if (sym->isUndefined() && !sym->isWeak()) {
diagnose("undefined reference due to --no-allow-shlib-undefined: " +
toString(*sym) + "\n>>> referenced by " + toString(file));
Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/allow-shlib-undefined.s
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
# RUN: not ld.lld --gc-sections main.o a.so def-hidden.o -o /dev/null 2>&1 | FileCheck %s
## The definition def.so is ignored.
# RUN: ld.lld -shared def.o -o def.so
# RUN: not ld.lld --gc-sections main.o a.so def.so def-hidden.o -o /dev/null 2>&1 | FileCheck %s
# RUN: ld.lld --gc-sections main.o a.so def.so def-hidden.o --fatal-warnings -o /dev/null

# CHECK-NOT: error:
# CHECK: error: undefined reference due to --no-allow-shlib-undefined: x1{{$}}
Expand Down