[lld] f4a3569 - [ELF] Fix spurious GOT/PLT assertion failure when .dynsym is discarded
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 20 22:49:55 PDT 2022
Author: Fangrui Song
Date: 2022-04-20T22:49:49-07:00
New Revision: f4a3569d0ad61907692fe10b1ffe1fa7763e9c26
URL: https://github.com/llvm/llvm-project/commit/f4a3569d0ad61907692fe10b1ffe1fa7763e9c26
DIFF: https://github.com/llvm/llvm-project/commit/f4a3569d0ad61907692fe10b1ffe1fa7763e9c26.diff
LOG: [ELF] Fix spurious GOT/PLT assertion failure when .dynsym is discarded
Linux kernel arch/arm64/kernel/vmlinux.lds.S discards .dynsym . D123985 triggers
a spurious assertion failure. Detect the case with
`!mainPart->dynSymTab->getParent()`.
Added:
lld/test/ELF/linkerscript/discard-section-dynsym.s
Modified:
lld/ELF/SyntheticSections.cpp
lld/test/ELF/linkerscript/discard-section-err.s
Removed:
################################################################################
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 07bb479d6b2d9..900f17fb299d1 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1593,7 +1593,8 @@ uint32_t DynamicReloc::getSymIndex(SymbolTableBaseSection *symTab) const {
return 0;
size_t index = symTab->getSymbolIndex(sym);
- assert((index != 0 || type != target->gotRel && type != target->pltRel) &&
+ assert((index != 0 || type != target->gotRel && type != target->pltRel ||
+ !mainPart->dynSymTab->getParent()) &&
"GOT or PLT relocation must refer to symbol in dynamic symbol table");
return index;
}
diff --git a/lld/test/ELF/linkerscript/discard-section-dynsym.s b/lld/test/ELF/linkerscript/discard-section-dynsym.s
new file mode 100644
index 0000000000000..7c7c9c29cee84
--- /dev/null
+++ b/lld/test/ELF/linkerscript/discard-section-dynsym.s
@@ -0,0 +1,24 @@
+# REQUIRES: aarch64
+
+## We allow discarding .dynsym, check we don't crash.
+# RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t.o
+
+# RUN: echo 'SECTIONS { /DISCARD/ : { *(.dynsym) } }' > %t.lds
+# RUN: ld.lld -shared -T %t.lds %t.o -o %t.so
+# RUN: llvm-readelf -r %t.so | FileCheck %s
+
+# RUN: echo 'SECTIONS { /DISCARD/ : { *(.dynsym .dynstr) } }' > %t.lds
+# RUN: ld.lld -shared -T %t.lds %t.o -o %t.so
+# RUN: llvm-readelf -r %t.so | FileCheck %s
+
+# CHECK: contains 2 entries:
+# CHECK: R_AARCH64_RELATIVE [[#]]
+# CHECK-NEXT: R_AARCH64_GLOB_DAT 0{{$}}
+
+ adrp x9, :got:var
+ ldr x9, [x9, :got_lo12:var]
+
+.data
+.align 8
+foo:
+.quad foo
diff --git a/lld/test/ELF/linkerscript/discard-section-err.s b/lld/test/ELF/linkerscript/discard-section-err.s
index 592c33fdd5cc0..723d8111c6158 100644
--- a/lld/test/ELF/linkerscript/discard-section-err.s
+++ b/lld/test/ELF/linkerscript/discard-section-err.s
@@ -11,14 +11,6 @@
# RUN: echo "SECTIONS { /DISCARD/ : { *(.dynamic) } }" > %t.script
# RUN: ld.lld -pie -o %t --script %t.script %t.o
-## We allow discarding .dynsym, check we don't crash.
-# RUN: echo "SECTIONS { /DISCARD/ : { *(.dynsym) } }" > %t.script
-# RUN: ld.lld -pie -o %t --script %t.script %t.o
-
-## We allow discarding .dynstr, check we don't crash.
-# RUN: echo "SECTIONS { /DISCARD/ : { *(.dynstr) } }" > %t.script
-# RUN: ld.lld -pie -o %t --script %t.script %t.o
-
# RUN: echo "SECTIONS { /DISCARD/ : { *(.rela.dyn) } }" > %t.script
# RUN: ld.lld -pie -o %t %t.o
# RUN: llvm-readobj -S %t | FileCheck --check-prefix=RELADYN %s
More information about the llvm-commits
mailing list