Re-commit "Split LinkerScript::createSections".

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 26 03:35:10 PDT 2016


>Re-commit r276543 with a fix for buildbots.
>
>Modified:
>   lld/trunk/ELF/LinkerScript.cpp
>    lld/trunk/ELF/LinkerScript.h
+LinkerScript<ELFT>::filter(std::vector<OutputSectionBase<ELFT> *> &Sections) {
+  // Sections and OutputSectionCommands are parallel arrays.
+  // In this loop, we remove output sections if they don't satisfy
+  // requested properties.
+  auto It = Sections.begin();
+  for (const std::unique_ptr<BaseCommand> &Base : Opt.Commands) {
+    auto *Cmd = dyn_cast<OutputSectionCommand>(Base.get());
+    if (!Cmd || Cmd->Name == "/DISCARD/")
+      continue;
+
+    if (Cmd->Constraint == ConstraintKind::NoConstraint) {
+      ++It;
+      continue;
+    }

That is not correct. We can have Opt.Commands size greater then Sections.size().
For example imagine you have next script:

SECTIONS { 
.aaa : { *(.aaa) }           
.bbb : { *(.bbb) }   
.ccc : { *(.ccc) }   
}

and code:

.global _start
_start:
 nop

.section .aaa,"a"
 .quad 0

This way Opt.Commands will be greater than Sections and if we have all commands as
NoConstraint, then ++It will overflow.

I am working on a fix and will commit soon.

George.




More information about the llvm-commits mailing list