diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 7c1e2ddd76f2..d6f406e5c287 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -297,6 +297,7 @@ void LinkerScript::processCommands(OutputSectionFactory &Factory) { for (InputSectionBase *S : V) S->OutSec = nullptr; Opt.Commands.erase(Iter); + --I; continue; } diff --git a/lld/test/ELF/linkerscript/sections-constraint4.s b/lld/test/ELF/linkerscript/sections-constraint4.s new file mode 100644 index 000000000000..6c2d4c8e1ee4 --- /dev/null +++ b/lld/test/ELF/linkerscript/sections-constraint4.s @@ -0,0 +1,20 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: echo "SECTIONS { \ +# RUN: .foo : ONLY_IF_RO { *(.foo) } \ +# RUN: .bar : {bar1 = .; *(.bar) } }" > %t1.script +# RUN: ld.lld -o %t1 --script %t1.script %t +# RUN: llvm-readobj -t %t1 | FileCheck %s + +# CHECK: Name: bar1 + +.global _start +_start: + nop + +.section .bar, "aw" +bar: + .long 1 + +.section .foo, "aw" + .long 0