Skip to content

Commit df54f62

Browse files
committed
[ELF] Enhance --no-allow-shlib-undefined for non-exported definitions
For a DSO with all DT_NEEDED entries accounted for, if it contains an undefined non-weak symbol that shares a name with a non-exported definition (hidden visibility or localized by a version script), and there is no DSO definition, we should report an error. #70769 implemented the error when we see `ref.so def-hidden.so`. This patch implementes the error when we see `def-hidden.so ref.so`, matching GNU ld. Close #86777
1 parent 09403a6 commit df54f62

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

lld/ELF/InputFiles.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,7 @@ template <class ELFT> void SharedFile::parse() {
15571557
Symbol *s = symtab.addSymbol(
15581558
Undefined{this, name, sym.getBinding(), sym.st_other, sym.getType()});
15591559
s->exportDynamic = true;
1560-
if (s->isUndefined() && sym.getBinding() != STB_WEAK &&
1560+
if (sym.getBinding() != STB_WEAK &&
15611561
config->unresolvedSymbolsInShlib != UnresolvedPolicy::Ignore)
15621562
requiredSymbols.push_back(s);
15631563
continue;

lld/test/ELF/allow-shlib-undefined.s

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,12 @@
3131

3232
## Test some cases when a relocatable object file provides a non-exported definition.
3333
# RUN: not ld.lld main.o a.so def-hidden.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=NONEXPORTED
34-
## TODO
35-
# RUN: ld.lld main.o def-hidden.o a.so -o /dev/null
34+
# RUN: not ld.lld main.o def-hidden.o a.so -o /dev/null 2>&1 | FileCheck %s --check-prefix=NONEXPORTED
3635
# RUN: not ld.lld main.o a.so def-hidden.o -shared --no-allow-shlib-undefined -o /dev/null 2>&1 | FileCheck %s --check-prefix=NONEXPORTED
3736
# RUN: ld.lld main.o a.so def-hidden.o --allow-shlib-undefined --fatal-warnings -o /dev/null
3837
## Test a relocatable object file definition that is converted to STB_LOCAL.
3938
# RUN: not ld.lld main.o a.so def-hidden.o --version-script=local.ver -o /dev/null 2>&1 | FileCheck %s --check-prefix=NONEXPORTED
40-
## TODO
41-
# RUN: ld.lld main.o def-hidden.o a.so --version-script=local.ver -o /dev/null
39+
# RUN: not ld.lld main.o def-hidden.o a.so --version-script=local.ver -o /dev/null 2>&1 | FileCheck %s --check-prefix=NONEXPORTED
4240

4341
## The section containing the definition is discarded, and we report an error.
4442
# RUN: not ld.lld --gc-sections main.o a.so def-hidden.o -o /dev/null 2>&1 | FileCheck %s

lld/test/ELF/shlib-undefined-local.s

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55

66
# RUN: llvm-mc -filetype=obj -triple=x86_64-linux-gnu -o %t2.o %s
77
# RUN: echo "{ local: *; };" > %t.script
8-
# RUN: ld.lld -version-script %t.script -o %t %t2.o %t.so
9-
# RUN: llvm-nm -g %t | FileCheck -allow-empty %s
8+
# RUN: not ld.lld -version-script %t.script %t2.o %t.so -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR
109

11-
# CHECK-NOT: should_not_be_exported
10+
# ERR: error: non-exported symbol 'should_not_be_exported' in '{{.*}}tmp2.o' is referenced by DSO '{{.*}}tmp.so'
1211

1312
.globl should_not_be_exported
1413
should_not_be_exported:

0 commit comments

Comments
 (0)