summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/LinkerScript.cpp7
-rw-r--r--lld/test/ELF/linkerscript/discard-section-err.s10
-rw-r--r--lld/test/ELF/linkerscript/synthetic-relsec-layout.s16
3 files changed, 31 insertions, 2 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index e16b49e785b..2240f7a0887 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -380,7 +380,10 @@ LinkerScript::computeInputSections(const InputSectionDescription *Cmd) {
// For -emit-relocs we have to ignore entries like
// .rela.dyn : { *(.rela.data) }
// which are common because they are in the default bfd script.
- if (Sec->Type == SHT_REL || Sec->Type == SHT_RELA)
+ // We do not ignore SHT_REL[A] linker-synthesized sections here because
+ // want to support scripts that do custom layout for them.
+ if (!isa<SyntheticSection>(Sec) &&
+ (Sec->Type == SHT_REL || Sec->Type == SHT_RELA))
continue;
std::string Filename = getFilename(Sec->File);
@@ -405,7 +408,7 @@ LinkerScript::computeInputSections(const InputSectionDescription *Cmd) {
void LinkerScript::discard(ArrayRef<InputSection *> V) {
for (InputSection *S : V) {
if (S == InX::ShStrTab || S == InX::Dynamic || S == InX::DynSymTab ||
- S == InX::DynStrTab)
+ S == InX::DynStrTab || S == InX::RelaPlt || S == InX::RelaDyn)
error("discarding " + S->Name + " section is not allowed");
// You can discard .hash and .gnu.hash sections by linker scripts. Since
diff --git a/lld/test/ELF/linkerscript/discard-section-err.s b/lld/test/ELF/linkerscript/discard-section-err.s
index 8ad5b486cb3..f1d3b96691b 100644
--- a/lld/test/ELF/linkerscript/discard-section-err.s
+++ b/lld/test/ELF/linkerscript/discard-section-err.s
@@ -22,4 +22,14 @@
# RUN: FileCheck -check-prefix=DYNSTR %s
# DYNSTR: discarding .dynstr section is not allowed
+# RUN: echo "SECTIONS { /DISCARD/ : { *(.rela.plt) } }" > %t.script
+# RUN: not ld.lld -pie -o %t --script %t.script %t.o 2>&1 | \
+# RUN: FileCheck -check-prefix=RELAPLT %s
+# RELAPLT: discarding .rela.plt section is not allowed
+
+# RUN: echo "SECTIONS { /DISCARD/ : { *(.rela.dyn) } }" > %t.script
+# RUN: not ld.lld -pie -o %t --script %t.script %t.o 2>&1 | \
+# RUN: FileCheck -check-prefix=RELADYN %s
+# RELADYN: discarding .rela.dyn section is not allowed
+
.comm foo,4,4
diff --git a/lld/test/ELF/linkerscript/synthetic-relsec-layout.s b/lld/test/ELF/linkerscript/synthetic-relsec-layout.s
new file mode 100644
index 00000000000..efaa946cbaa
--- /dev/null
+++ b/lld/test/ELF/linkerscript/synthetic-relsec-layout.s
@@ -0,0 +1,16 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: echo "SECTIONS { .foo : { *(.rela.dyn) } }" > %t.script
+# RUN: ld.lld -T %t.script %t.o -o %t.so -shared
+# RUN: llvm-readobj -r %t.so | FileCheck %s
+
+# Check we are able to do custom layout for synthetic sections.
+# (here we check we can place synthetic .rela.dyn into .foo).
+
+# CHECK: Relocations [
+# CHECK: Section ({{.*}}) .foo {
+# CHECK: R_X86_64_64 .foo 0x0
+# CHECK: }
+
+.data
+.quad .foo
OpenPOWER on IntegriCloud