Index: llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp =================================================================== --- llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp +++ llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp @@ -305,9 +305,9 @@ SecName.str().c_str()); } -static bool isCompressable(const SectionBase &Section) { - return !(Section.Flags & ELF::SHF_COMPRESSED) && - StringRef(Section.Name).startswith(".debug"); +static bool isCompressable(const SectionBase &Sec) { + return !(Sec.Flags & ELF::SHF_COMPRESSED) && + StringRef(Sec.Name).startswith(".debug"); } static void replaceDebugSections( @@ -398,8 +398,8 @@ // symbols are still 'needed' and which are not. if (Config.StripUnneeded || !Config.UnneededSymbolsToRemove.empty() || !Config.OnlySection.empty()) { - for (auto &Section : Obj.sections()) - Section.markSymbols(); + for (SectionBase &Sec : Obj.sections()) + Sec.markSymbols(); } auto RemoveSymbolsPred = [&](const Symbol &Sym) { Index: llvm/trunk/tools/llvm-objcopy/ELF/Object.cpp =================================================================== --- llvm/trunk/tools/llvm-objcopy/ELF/Object.cpp +++ llvm/trunk/tools/llvm-objcopy/ELF/Object.cpp @@ -1055,29 +1055,28 @@ } // Returns true IFF a section is wholly inside the range of a segment -static bool sectionWithinSegment(const SectionBase &Section, - const Segment &Segment) { +static bool sectionWithinSegment(const SectionBase &Sec, const Segment &Seg) { // If a section is empty it should be treated like it has a size of 1. This is // to clarify the case when an empty section lies on a boundary between two // segments and ensures that the section "belongs" to the second segment and // not the first. - uint64_t SecSize = Section.Size ? Section.Size : 1; + uint64_t SecSize = Sec.Size ? Sec.Size : 1; - if (Section.Type == SHT_NOBITS) { - if (!(Section.Flags & SHF_ALLOC)) + if (Sec.Type == SHT_NOBITS) { + if (!(Sec.Flags & SHF_ALLOC)) return false; - bool SectionIsTLS = Section.Flags & SHF_TLS; - bool SegmentIsTLS = Segment.Type == PT_TLS; + bool SectionIsTLS = Sec.Flags & SHF_TLS; + bool SegmentIsTLS = Seg.Type == PT_TLS; if (SectionIsTLS != SegmentIsTLS) return false; - return Segment.VAddr <= Section.Addr && - Segment.VAddr + Segment.MemSize >= Section.Addr + SecSize; + return Seg.VAddr <= Sec.Addr && + Seg.VAddr + Seg.MemSize >= Sec.Addr + SecSize; } - return Segment.Offset <= Section.OriginalOffset && - Segment.Offset + Segment.FileSize >= Section.OriginalOffset + SecSize; + return Seg.Offset <= Sec.OriginalOffset && + Seg.Offset + Seg.FileSize >= Sec.OriginalOffset + SecSize; } // Returns true IFF a segment's original offset is inside of another segment's @@ -1141,8 +1140,8 @@ } void BasicELFBuilder::initSections() { - for (auto &Section : Obj->sections()) - Section.initialize(Obj->sections()); + for (SectionBase &Sec : Obj->sections()) + Sec.initialize(Obj->sections()); } void BinaryELFBuilder::addData(SymbolTableSection *SymTab) { @@ -1256,10 +1255,9 @@ if (!ExtractPartition) return; - for (const SectionBase &Section : Obj.sections()) { - if (Section.Type == SHT_LLVM_PART_EHDR && - Section.Name == *ExtractPartition) { - EhdrOffset = Section.Offset; + for (const SectionBase &Sec : Obj.sections()) { + if (Sec.Type == SHT_LLVM_PART_EHDR && Sec.Name == *ExtractPartition) { + EhdrOffset = Sec.Offset; return; } } @@ -1288,15 +1286,12 @@ Seg.MemSize = Phdr.p_memsz; Seg.Align = Phdr.p_align; Seg.Index = Index++; - for (SectionBase &Section : Obj.sections()) { - if (sectionWithinSegment(Section, Seg)) { - Seg.addSection(&Section); - if (!Section.ParentSegment || - Section.ParentSegment->Offset > Seg.Offset) { - Section.ParentSegment = &Seg; - } + for (SectionBase &Sec : Obj.sections()) + if (sectionWithinSegment(Sec, Seg)) { + Seg.addSection(&Sec); + if (!Sec.ParentSegment || Sec.ParentSegment->Offset > Seg.Offset) + Sec.ParentSegment = &Seg; } - } } auto &ElfHdr = Obj.ElfHdrSegment; @@ -1550,11 +1545,11 @@ // Now that all sections and symbols have been added we can add // relocations that reference symbols and set the link and info fields for // relocation sections. - for (auto &Section : Obj.sections()) { - if (&Section == Obj.SymbolTable) + for (auto &Sec : Obj.sections()) { + if (&Sec == Obj.SymbolTable) continue; - Section.initialize(Obj.sections()); - if (auto RelSec = dyn_cast(&Section)) { + Sec.initialize(Obj.sections()); + if (auto RelSec = dyn_cast(&Sec)) { auto Shdr = unwrapOrError(ElfFile.sections()).begin() + RelSec->Index; if (RelSec->Type == SHT_REL) initRelocations(RelSec, Obj.SymbolTable, @@ -1562,7 +1557,7 @@ else initRelocations(RelSec, Obj.SymbolTable, unwrapOrError(ElfFile.relas(Shdr))); - } else if (auto GroupSec = dyn_cast(&Section)) { + } else if (auto GroupSec = dyn_cast(&Sec)) { initGroupSection(GroupSec); } } @@ -1913,17 +1908,17 @@ // of the segment we can assign a new offset to the section. For sections not // covered by segments we can just bump Offset to the next valid location. uint32_t Index = 1; - for (auto &Section : Sections) { - Section.Index = Index++; - if (Section.ParentSegment != nullptr) { - auto Segment = *Section.ParentSegment; - Section.Offset = - Segment.Offset + (Section.OriginalOffset - Segment.OriginalOffset); + for (auto &Sec : Sections) { + Sec.Index = Index++; + if (Sec.ParentSegment != nullptr) { + auto Segment = *Sec.ParentSegment; + Sec.Offset = + Segment.Offset + (Sec.OriginalOffset - Segment.OriginalOffset); } else { - Offset = alignTo(Offset, Section.Align == 0 ? 1 : Section.Align); - Section.Offset = Offset; - if (Section.Type != SHT_NOBITS) - Offset += Section.Size; + Offset = alignTo(Offset, Sec.Align == 0 ? 1 : Sec.Align); + Sec.Offset = Offset; + if (Sec.Type != SHT_NOBITS) + Offset += Sec.Size; } } return Offset; @@ -2054,9 +2049,8 @@ // Make sure we add the names of all the sections. Importantly this must be // done after we decide to add or remove SectionIndexes. if (Obj.SectionNames != nullptr) - for (const auto &Section : Obj.sections()) { - Obj.SectionNames->addString(Section.Name); - } + for (const SectionBase &Sec : Obj.sections()) + Obj.SectionNames->addString(Sec.Name); initEhdrSegment(); @@ -2065,7 +2059,7 @@ // size-related fields before doing layout calculations. uint64_t Index = 0; auto SecSizer = std::make_unique>(); - for (auto &Sec : Obj.sections()) { + for (SectionBase &Sec : Obj.sections()) { Sec.Index = Index++; Sec.accept(*SecSizer); } @@ -2092,12 +2086,12 @@ // Finally now that all offsets and indexes have been set we can finalize any // remaining issues. uint64_t Offset = Obj.SHOffset + sizeof(Elf_Shdr); - for (SectionBase &Section : Obj.sections()) { - Section.HeaderOffset = Offset; + for (SectionBase &Sec : Obj.sections()) { + Sec.HeaderOffset = Offset; Offset += sizeof(Elf_Shdr); if (WriteSectionHeaders) - Section.NameIndex = Obj.SectionNames->findIndex(Section.Name); - Section.finalize(); + Sec.NameIndex = Obj.SectionNames->findIndex(Sec.Name); + Sec.finalize(); } if (Error E = Buf.allocate(totalSize())) @@ -2107,9 +2101,9 @@ } Error BinaryWriter::write() { - for (auto &Section : Obj.sections()) - if (Section.Flags & SHF_ALLOC) - Section.accept(*SecWriter); + for (const SectionBase &Sec : Obj.sections()) + if (Sec.Flags & SHF_ALLOC) + Sec.accept(*SecWriter); return Buf.commit(); } @@ -2122,9 +2116,9 @@ // already had it's offset properly set. We only want to consider the segments // that will affect layout of allocated sections so we only add those. std::vector OrderedSegments; - for (SectionBase &Section : Obj.sections()) - if ((Section.Flags & SHF_ALLOC) != 0 && Section.ParentSegment != nullptr) - OrderedSegments.push_back(Section.ParentSegment); + for (const SectionBase &Sec : Obj.sections()) + if ((Sec.Flags & SHF_ALLOC) != 0 && Sec.ParentSegment != nullptr) + OrderedSegments.push_back(Sec.ParentSegment); // For binary output, we're going to use physical addresses instead of // virtual addresses, since a binary output is used for cases like ROM @@ -2172,9 +2166,9 @@ // not hold. Then pass such a range to layoutSections instead of constructing // AllocatedSections here. std::vector AllocatedSections; - for (SectionBase &Section : Obj.sections()) - if (Section.Flags & SHF_ALLOC) - AllocatedSections.push_back(&Section); + for (SectionBase &Sec : Obj.sections()) + if (Sec.Flags & SHF_ALLOC) + AllocatedSections.push_back(&Sec); layoutSections(make_pointee_range(AllocatedSections), Offset); // Now that every section has been laid out we just need to compute the total @@ -2182,9 +2176,9 @@ // layoutSections, because we want to truncate the last segment to the end of // its last section, to match GNU objcopy's behaviour. TotalSize = 0; - for (SectionBase *Section : AllocatedSections) - if (Section->Type != SHT_NOBITS) - TotalSize = std::max(TotalSize, Section->Offset + Section->Size); + for (SectionBase *Sec : AllocatedSections) + if (Sec->Type != SHT_NOBITS) + TotalSize = std::max(TotalSize, Sec->Offset + Sec->Size); if (Error E = Buf.allocate(TotalSize)) return E; @@ -2268,17 +2262,17 @@ // If any section we're to write has segment then we // switch to using physical addresses. Otherwise we // use section virtual address. - for (auto &Section : Obj.sections()) - if (ShouldWrite(Section) && IsInPtLoad(Section)) { + for (const SectionBase &Sec : Obj.sections()) + if (ShouldWrite(Sec) && IsInPtLoad(Sec)) { UseSegments = true; break; } - for (auto &Section : Obj.sections()) - if (ShouldWrite(Section) && (!UseSegments || IsInPtLoad(Section))) { - if (Error E = checkSection(Section)) + for (const SectionBase &Sec : Obj.sections()) + if (ShouldWrite(Sec) && (!UseSegments || IsInPtLoad(Sec))) { + if (Error E = checkSection(Sec)) return E; - Sections.insert(&Section); + Sections.insert(&Sec); } IHexSectionWriterBase LengthCalc(Buf);