[lld] r282285 - Avoid counting sections twice.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 23 13:10:47 PDT 2016
Author: rafael
Date: Fri Sep 23 15:10:47 2016
New Revision: 282285
URL: http://llvm.org/viewvc/llvm-project?rev=282285&view=rev
Log:
Avoid counting sections twice.
We were counting the size of the bss section holding common symbols twice:
Dot += CurOutSec->getSize();
flush();
The new code is also simpler as now flush is the only function that
inserts in AlreadyOutputOS, which makes sense since the set hold fully
output sections.
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/test/ELF/linkerscript/double-bss.s
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=282285&r1=282284&r2=282285&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Fri Sep 23 15:10:47 2016
@@ -383,10 +383,13 @@ template <class ELFT> void LinkerScript<
}
template <class ELFT> void LinkerScript<ELFT>::flush() {
- if (auto *OutSec = dyn_cast_or_null<OutputSection<ELFT>>(CurOutSec)) {
+ if (!CurOutSec || !AlreadyOutputOS.insert(CurOutSec).second)
+ return;
+ if (auto *OutSec = dyn_cast<OutputSection<ELFT>>(CurOutSec)) {
for (InputSection<ELFT> *I : OutSec->Sections)
output(I);
- AlreadyOutputOS.insert(CurOutSec);
+ } else {
+ Dot += CurOutSec->getSize();
}
}
@@ -421,8 +424,8 @@ template <class ELFT> void LinkerScript<
switchTo(IB->OutSec);
if (auto *I = dyn_cast<InputSection<ELFT>>(IB))
output(I);
- else if (AlreadyOutputOS.insert(CurOutSec).second)
- Dot += CurOutSec->getSize();
+ else
+ flush();
}
}
@@ -454,14 +457,9 @@ void LinkerScript<ELFT>::assignOffsets(O
.base();
for (auto I = Cmd->Commands.begin(); I != E; ++I)
process(**I);
- flush();
- for (OutputSectionBase<ELFT> *Base : Sections) {
- if (AlreadyOutputOS.count(Base))
- continue;
+ for (OutputSectionBase<ELFT> *Base : Sections)
switchTo(Base);
- Dot += CurOutSec->getSize();
- flush();
- }
+ flush();
std::for_each(E, Cmd->Commands.end(),
[this](std::unique_ptr<BaseCommand> &B) { process(*B.get()); });
}
Modified: lld/trunk/test/ELF/linkerscript/double-bss.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/double-bss.s?rev=282285&r1=282284&r2=282285&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/double-bss.s (original)
+++ lld/trunk/test/ELF/linkerscript/double-bss.s Fri Sep 23 15:10:47 2016
@@ -4,7 +4,7 @@
# RUN: ld.lld -o %t1 --script %t.script %t
# RUN: llvm-objdump -section-headers %t1 | FileCheck %s
# CHECK: .bss 00000004 0000000000000122 BSS
-# CHECK-NEXT: .bss 00000100 0000000000000128 BSS
+# CHECK-NEXT: .bss 00000080 0000000000000128 BSS
.globl _start
_start:
More information about the llvm-commits
mailing list