[lld] 070d7af - [ELF] --export-dynamic: don't create dynamic sections for non-PIC static links
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 27 20:05:04 PDT 2024
Author: Fangrui Song
Date: 2024-03-27T20:04:59-07:00
New Revision: 070d7af0c56b993806fa47f77b607b1849a2172f
URL: https://github.com/llvm/llvm-project/commit/070d7af0c56b993806fa47f77b607b1849a2172f
DIFF: https://github.com/llvm/llvm-project/commit/070d7af0c56b993806fa47f77b607b1849a2172f.diff
LOG: [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.
Added:
Modified:
lld/ELF/Driver.cpp
lld/test/ELF/weak-undef.s
Removed:
lld/test/ELF/static-with-export-dynamic.s
################################################################################
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index f14a2376601b08..b43da7727e22ae 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -2724,14 +2724,8 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
parseFiles(files, armCmseImpLib);
- // Now that we have every file, we can decide if we will need a
- // dynamic symbol table.
- // We need one if we were asked to export dynamic symbols or if we are
- // producing a shared library.
- // We also need one if any shared libraries are used and for pie executables
- // (probably because the dynamic linker needs it).
- config->hasDynSymTab =
- !ctx.sharedFiles.empty() || config->isPic || config->exportDynamic;
+ // Create dynamic sections for dynamic linking and static PIE.
+ config->hasDynSymTab = !ctx.sharedFiles.empty() || config->isPic;
script->addScriptReferencedSymbolsToSymTable();
diff --git a/lld/test/ELF/static-with-export-dynamic.s b/lld/test/ELF/static-with-export-dynamic.s
deleted file mode 100644
index b0349b85e30343..00000000000000
--- a/lld/test/ELF/static-with-export-dynamic.s
+++ /dev/null
@@ -1,32 +0,0 @@
-// REQUIRES: x86
-// RUN: llvm-mc -filetype=obj -triple=i686-unknown-cloudabi %s -o %t.o
-// RUN: ld.lld --export-dynamic %t.o -o %t
-// RUN: llvm-readobj --dyn-syms %t | FileCheck %s
-
-// Ensure that a dynamic symbol table is present when --export-dynamic
-// is passed in, even when creating statically linked executables.
-//
-// CHECK: DynamicSymbols [
-// CHECK-NEXT: Symbol {
-// CHECK-NEXT: Name:
-// CHECK-NEXT: Value: 0x0
-// CHECK-NEXT: Size: 0
-// CHECK-NEXT: Binding: Local
-// CHECK-NEXT: Type: None
-// CHECK-NEXT: Other: 0
-// CHECK-NEXT: Section: Undefined
-// CHECK-NEXT: }
-// CHECK-NEXT: Symbol {
-// CHECK-NEXT: Name: _start
-// CHECK-NEXT: Value:
-// CHECK-NEXT: Size: 0
-// CHECK-NEXT: Binding: Global
-// CHECK-NEXT: Type: None
-// CHECK-NEXT: Other: 0
-// CHECK-NEXT: Section: .text
-// CHECK-NEXT: }
-// CHECK-NEXT: ]
-
-.global _start
-_start:
- ret
diff --git a/lld/test/ELF/weak-undef.s b/lld/test/ELF/weak-undef.s
index 3a9d5f462c21b6..21488023a79e10 100644
--- a/lld/test/ELF/weak-undef.s
+++ b/lld/test/ELF/weak-undef.s
@@ -16,10 +16,11 @@
# RELOC-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
# RELOC-NEXT: {{.*}} 0000000100000001 R_X86_64_64 0000000000000000 foo + 0
-# COMMON: Symbol table '.dynsym' contains 2 entries:
-# COMMON-NEXT: Num: Value Size Type Bind Vis Ndx Name
-# COMMON-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
-# COMMON-NEXT: 1: 0000000000000000 0 NOTYPE WEAK DEFAULT UND foo
+# NORELOC-NOT: Symbol table '.dynsym'
+# RELOC: Symbol table '.dynsym' contains 2 entries:
+# RELOC-NEXT: Num: Value Size Type Bind Vis Ndx Name
+# RELOC-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
+# RELOC-NEXT: 1: 0000000000000000 0 NOTYPE WEAK DEFAULT UND foo
# COMMON: Hex dump of section '.data':
# COMMON-NEXT: {{.*}} 00000000 00000000
# COMMON-EMPTY:
More information about the llvm-commits
mailing list