Skip to content

Commit 070d7af

Browse files
committed
[ELF] --export-dynamic: don't create dynamic sections for non-PIC static links
The CloudABI (removed from Clang Driver) change from https://reviews.llvm.org/D29982 does not make sense. GNU ld and gold don't create dynamic sections for a non-PIC static link when --export-dynamic is specified. Creating dynamic sections is harmful in this scenario because we would consider undefined weak symbols preemptible and generate GLOB_DAT relocations, breaking the expectation that non-PIC static links only contain IRELATIVE relocations. In addition, there are other options that export symbols (--export-dynamic-symbol, --dynamic-list, etc). It does not make sense to special case --export-dynamic.
1 parent 443baed commit 070d7af

File tree

3 files changed

+7
-44
lines changed

3 files changed

+7
-44
lines changed

lld/ELF/Driver.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -2724,14 +2724,8 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
27242724

27252725
parseFiles(files, armCmseImpLib);
27262726

2727-
// Now that we have every file, we can decide if we will need a
2728-
// dynamic symbol table.
2729-
// We need one if we were asked to export dynamic symbols or if we are
2730-
// producing a shared library.
2731-
// We also need one if any shared libraries are used and for pie executables
2732-
// (probably because the dynamic linker needs it).
2733-
config->hasDynSymTab =
2734-
!ctx.sharedFiles.empty() || config->isPic || config->exportDynamic;
2727+
// Create dynamic sections for dynamic linking and static PIE.
2728+
config->hasDynSymTab = !ctx.sharedFiles.empty() || config->isPic;
27352729

27362730
script->addScriptReferencedSymbolsToSymTable();
27372731

lld/test/ELF/static-with-export-dynamic.s

-32
This file was deleted.

lld/test/ELF/weak-undef.s

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
# RELOC-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
1717
# RELOC-NEXT: {{.*}} 0000000100000001 R_X86_64_64 0000000000000000 foo + 0
1818

19-
# COMMON: Symbol table '.dynsym' contains 2 entries:
20-
# COMMON-NEXT: Num: Value Size Type Bind Vis Ndx Name
21-
# COMMON-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
22-
# COMMON-NEXT: 1: 0000000000000000 0 NOTYPE WEAK DEFAULT UND foo
19+
# NORELOC-NOT: Symbol table '.dynsym'
20+
# RELOC: Symbol table '.dynsym' contains 2 entries:
21+
# RELOC-NEXT: Num: Value Size Type Bind Vis Ndx Name
22+
# RELOC-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
23+
# RELOC-NEXT: 1: 0000000000000000 0 NOTYPE WEAK DEFAULT UND foo
2324
# COMMON: Hex dump of section '.data':
2425
# COMMON-NEXT: {{.*}} 00000000 00000000
2526
# COMMON-EMPTY:

0 commit comments

Comments
 (0)