[PATCH] D37520: [ELF] - Fix removing of unused synthetic sections.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 7 03:06:18 PDT 2017
grimar updated this revision to Diff 114135.
grimar added a comment.
- Addressed review comments.
https://reviews.llvm.org/D37520
Files:
ELF/Writer.cpp
test/ELF/linkerscript/unused-synthetic.s
Index: test/ELF/linkerscript/unused-synthetic.s
===================================================================
--- test/ELF/linkerscript/unused-synthetic.s
+++ test/ELF/linkerscript/unused-synthetic.s
@@ -1,9 +1,9 @@
# 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: echo "SECTIONS { \
+# RUN: .got : { *(.got) *(.got) } \
+# RUN: .plt : { *(.plt) } \
+# RUN: .text : { *(.text) } \
# RUN: }" > %t.script
# RUN: ld.lld -shared -o %t.so --script %t.script %t.o
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -1201,19 +1201,22 @@
if ((SS == InX::Got || SS == InX::MipsGot) && ElfSym::GlobalOffsetTable)
continue;
- std::vector<BaseCommand *>::iterator Empty = OS->Commands.end();
- for (auto I = OS->Commands.begin(), E = OS->Commands.end(); I != E; ++I) {
+ // We should remove unused synthetic sections from all input section
+ // descriptions. If description remains empty after that then we remove it
+ // too. That allows to fully remove unused sections from the output.
+ for (auto I = OS->Commands.begin(); I != OS->Commands.end();) {
BaseCommand *B = *I;
if (auto *ISD = dyn_cast<InputSectionDescription>(B)) {
auto P = std::find(ISD->Sections.begin(), ISD->Sections.end(), SS);
if (P != ISD->Sections.end())
ISD->Sections.erase(P);
- if (ISD->Sections.empty())
- Empty = I;
+ if (ISD->Sections.empty()) {
+ I = OS->Commands.erase(I);
+ continue;
+ }
}
+ ++I;
}
- if (Empty != OS->Commands.end())
- OS->Commands.erase(Empty);
// If there are no other sections in the output section, remove it from the
// output.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37520.114135.patch
Type: text/x-patch
Size: 2041 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170907/c767caf4/attachment.bin>
More information about the llvm-commits
mailing list