}
void LinkerScript::discard(InputSectionBase &s) {
- if (&s == in.shStrTab.get() || &s == mainPart->relrDyn.get())
+ if (&s == in.shStrTab.get())
error("discarding " + s.name + " section is not allowed");
- // You can discard .hash and .gnu.hash sections by linker scripts. Since
- // they are synthesized sections, we need to handle them differently than
- // other regular sections.
+ // You can discard .hash, .gnu.hash, and .relr.dyn sections by linker scripts.
+ // Since they are synthesized sections, we need to handle them differently
+ // than other regular sections.
if (&s == mainPart->gnuHashTab)
mainPart->gnuHashTab = nullptr;
- if (&s == mainPart->hashTab)
+ else if (&s == mainPart->hashTab)
mainPart->hashTab = nullptr;
+ else if (&s == mainPart->relrDyn.get())
+ mainPart->relrDyn.reset();
s.markDead();
s.parent = nullptr;
# RUN: llvm-readobj -S %t | FileCheck /dev/null --implicit-check-not='Name: .rela.dyn'
# RUN: echo "SECTIONS { /DISCARD/ : { *(.relr.dyn) } }" > %t.script
-# RUN: not ld.lld -pie --pack-dyn-relocs=relr -o /dev/null --script %t.script %t.o 2>&1 | \
-# RUN: FileCheck -check-prefix=RELRDYN %s
-# RELRDYN: discarding .relr.dyn section is not allowed
+# RUN: ld.lld -pie --pack-dyn-relocs=relr -T %t.script %t.o -o %t
+# RUN: llvm-readobj -S %t | FileCheck /dev/null --implicit-check-not='Name: .relr.dyn'
.data
.align 8