From 2506cb4ddb05a5b1eee261aca2c6bfaa9bca348d Mon Sep 17 00:00:00 2001 From: Eugene Leviant Date: Wed, 21 Sep 2016 11:29:28 +0000 Subject: [PATCH] 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 --- lld/ELF/LinkerScript.cpp | 3 ++- lld/test/ELF/linkerscript/double-bss.s | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 lld/test/ELF/linkerscript/double-bss.s diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index a0bffce6383e..3d1af634950d 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -453,10 +453,11 @@ void LinkerScript::assignOffsets(OutputSectionCommand *Cmd) { process(**I); flush(); for (OutputSectionBase *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 &B) { process(*B.get()); }); diff --git a/lld/test/ELF/linkerscript/double-bss.s b/lld/test/ELF/linkerscript/double-bss.s new file mode 100644 index 000000000000..66a04670c598 --- /dev/null +++ b/lld/test/ELF/linkerscript/double-bss.s @@ -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