Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -239,23 +239,27 @@ continue; } - OutputSectionBase *Sec = findSection(Sections, Cmd.SectionName); - if (!Sec) - continue; - - if ((Sec->getFlags() & SHF_TLS) && Sec->getType() == SHT_NOBITS) { - uintX_t TVA = Dot + ThreadBssOffset; - TVA = alignTo(TVA, Sec->getAlign()); - Sec->setVA(TVA); - ThreadBssOffset = TVA - Dot + Sec->getSize(); - continue; - } + // Find all the sections with required name. There can be more than + // ont section with such name, if the alignment, flags or type + // attribute differs. + for (OutputSectionBase *Sec : Sections) { + if (Sec->getName() != Cmd.SectionName) + continue; + + if ((Sec->getFlags() & SHF_TLS) && Sec->getType() == SHT_NOBITS) { + uintX_t TVA = Dot + ThreadBssOffset; + TVA = alignTo(TVA, Sec->getAlign()); + Sec->setVA(TVA); + ThreadBssOffset = TVA - Dot + Sec->getSize(); + continue; + } - if (Sec->getFlags() & SHF_ALLOC) { - Dot = alignTo(Dot, Sec->getAlign()); - Sec->setVA(Dot); - Dot += Sec->getSize(); - continue; + if (Sec->getFlags() & SHF_ALLOC) { + Dot = alignTo(Dot, Sec->getAlign()); + Sec->setVA(Dot); + Dot += Sec->getSize(); + continue; + } } } }