forked from OSchip/llvm-project
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. llvm-svn: 282285
This commit is contained in:
parent
0d26de3922
commit
65499b9040
|
@ -383,10 +383,13 @@ template <class ELFT> void LinkerScript<ELFT>::output(InputSection<ELFT> *S) {
|
|||
}
|
||||
|
||||
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<ELFT>::process(BaseCommand &Base) {
|
|||
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(OutputSectionCommand *Cmd) {
|
|||
.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()); });
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue