Skip to content

Commit f4a3569

Browse files
committed
[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()`.
1 parent 0fd3a1c commit f4a3569

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

lld/ELF/SyntheticSections.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1593,7 +1593,8 @@ uint32_t DynamicReloc::getSymIndex(SymbolTableBaseSection *symTab) const {
15931593
return 0;
15941594

15951595
size_t index = symTab->getSymbolIndex(sym);
1596-
assert((index != 0 || type != target->gotRel && type != target->pltRel) &&
1596+
assert((index != 0 || type != target->gotRel && type != target->pltRel ||
1597+
!mainPart->dynSymTab->getParent()) &&
15971598
"GOT or PLT relocation must refer to symbol in dynamic symbol table");
15981599
return index;
15991600
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# REQUIRES: aarch64
2+
3+
## We allow discarding .dynsym, check we don't crash.
4+
# RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t.o
5+
6+
# RUN: echo 'SECTIONS { /DISCARD/ : { *(.dynsym) } }' > %t.lds
7+
# RUN: ld.lld -shared -T %t.lds %t.o -o %t.so
8+
# RUN: llvm-readelf -r %t.so | FileCheck %s
9+
10+
# RUN: echo 'SECTIONS { /DISCARD/ : { *(.dynsym .dynstr) } }' > %t.lds
11+
# RUN: ld.lld -shared -T %t.lds %t.o -o %t.so
12+
# RUN: llvm-readelf -r %t.so | FileCheck %s
13+
14+
# CHECK: contains 2 entries:
15+
# CHECK: R_AARCH64_RELATIVE [[#]]
16+
# CHECK-NEXT: R_AARCH64_GLOB_DAT 0{{$}}
17+
18+
adrp x9, :got:var
19+
ldr x9, [x9, :got_lo12:var]
20+
21+
.data
22+
.align 8
23+
foo:
24+
.quad foo

lld/test/ELF/linkerscript/discard-section-err.s

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,6 @@
1111
# RUN: echo "SECTIONS { /DISCARD/ : { *(.dynamic) } }" > %t.script
1212
# RUN: ld.lld -pie -o %t --script %t.script %t.o
1313

14-
## We allow discarding .dynsym, check we don't crash.
15-
# RUN: echo "SECTIONS { /DISCARD/ : { *(.dynsym) } }" > %t.script
16-
# RUN: ld.lld -pie -o %t --script %t.script %t.o
17-
18-
## We allow discarding .dynstr, check we don't crash.
19-
# RUN: echo "SECTIONS { /DISCARD/ : { *(.dynstr) } }" > %t.script
20-
# RUN: ld.lld -pie -o %t --script %t.script %t.o
21-
2214
# RUN: echo "SECTIONS { /DISCARD/ : { *(.rela.dyn) } }" > %t.script
2315
# RUN: ld.lld -pie -o %t %t.o
2416
# RUN: llvm-readobj -S %t | FileCheck --check-prefix=RELADYN %s

0 commit comments

Comments
 (0)