[PATCH] D34800: [ELF] Remove unused synthetic sections from script commands
Petr Hosek via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 3 08:50:03 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL307037: [ELF] Remove unused synthetic sections from script commands (authored by phosek).
Changed prior to commit:
https://reviews.llvm.org/D34800?vs=104577&id=105090#toc
Repository:
rL LLVM
https://reviews.llvm.org/D34800
Files:
lld/trunk/ELF/Writer.cpp
lld/trunk/test/ELF/linkerscript/unused-synthetic.s
Index: lld/trunk/ELF/Writer.cpp
===================================================================
--- lld/trunk/ELF/Writer.cpp
+++ lld/trunk/ELF/Writer.cpp
@@ -1149,8 +1149,17 @@
SS->Live = false;
// If there are no other sections in the output section, remove it from the
// output.
- if (OS->Sections.empty())
+ if (OS->Sections.empty()) {
V.erase(std::find(V.begin(), V.end(), OS));
+ // Also remove script commands matching the output section.
+ auto &Cmds = Script->Opt.Commands;
+ auto I = std::remove_if(Cmds.begin(), Cmds.end(), [&](BaseCommand *Cmd) {
+ if (auto *OSCmd = dyn_cast<OutputSectionCommand>(Cmd))
+ return OSCmd->Sec == OS;
+ return false;
+ });
+ Cmds.erase(I, Cmds.end());
+ }
}
}
Index: lld/trunk/test/ELF/linkerscript/unused-synthetic.s
===================================================================
--- lld/trunk/test/ELF/linkerscript/unused-synthetic.s
+++ lld/trunk/test/ELF/linkerscript/unused-synthetic.s
@@ -0,0 +1,18 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: echo "SECTIONS { \
+# RUN: .got : { *(.got) } \
+# RUN: .plt : { *(.plt) } \
+# RUN: .text : { *(.text) } \
+# RUN: }" > %t.script
+# RUN: ld.lld -shared -o %t.so --script %t.script %t.o
+
+# RUN: llvm-objdump -section-headers %t.so | FileCheck %s
+# CHECK-NOT: .got
+# CHECK-NOT: .plt
+# CHECK: .text
+# CHECK-NEXT: .dynsym
+
+.global _start
+_start:
+ nop
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34800.105090.patch
Type: text/x-patch
Size: 1517 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170703/557178a0/attachment.bin>
More information about the llvm-commits
mailing list