Linker script: Fix bug with several .bss

When final image has several .bss sections, lld fails
because second .bss always has zero VA. This causes 
link error "Not enough space for ELF and program headers"

llvm-svn: 282067
This commit is contained in:
Eugene Leviant 2016-09-21 11:29:28 +00:00
parent 451dd080ed
commit 2506cb4ddb
2 changed files with 18 additions and 1 deletions

View File

@ -453,10 +453,11 @@ void LinkerScript<ELFT>::assignOffsets(OutputSectionCommand *Cmd) {
process(**I);
flush();
for (OutputSectionBase<ELFT> *Base : Sections) {
if (!AlreadyOutputOS.insert(Base).second)
if (AlreadyOutputOS.count(Base))
continue;
switchTo(Base);
Dot += CurOutSec->getSize();
flush();
}
std::for_each(E, Cmd->Commands.end(),
[this](std::unique_ptr<BaseCommand> &B) { process(*B.get()); });

View File

@ -0,0 +1,16 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: echo "SECTIONS { .text : { *(.text*) } }" > %t.script
# 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
.globl _start
_start:
jmp _start
.bss
.zero 4
.comm q,128,8