diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -1032,8 +1032,8 @@ } // Initialize InputSections. - for (InputFile *file : inputFiles) { - for (SubsectionMap &map : file->subsections) { + for (const InputFile *file : inputFiles) { + for (const SubsectionMap &map : file->subsections) { for (const auto &p : map) { InputSection *isec = p.second; inputSections.push_back(isec); diff --git a/lld/MachO/Dwarf.cpp b/lld/MachO/Dwarf.cpp --- a/lld/MachO/Dwarf.cpp +++ b/lld/MachO/Dwarf.cpp @@ -25,7 +25,7 @@ // The debugger will locate the debug info via the object file paths that we // emit in our STABS symbols, so we don't need to process & emit them // ourselves. - for (InputSection *isec : obj->debugSections) { + for (const InputSection *isec : obj->debugSections) { if (StringRef *s = StringSwitch(isec->name) .Case("__debug_info", &dObj->infoSection.Data) .Case("__debug_abbrev", &dObj->abbrevSection) diff --git a/lld/MachO/ExportTrie.cpp b/lld/MachO/ExportTrie.cpp --- a/lld/MachO/ExportTrie.cpp +++ b/lld/MachO/ExportTrie.cpp @@ -108,7 +108,7 @@ } // Compute size of all child edges. ++nodeSize; // Byte for number of children. - for (Edge &edge : edges) { + for (const Edge &edge : edges) { nodeSize += edge.substring.size() + 1 // String length. + getULEB128Size(edge.child->offset); // Offset len. } diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp --- a/lld/MachO/SyntheticSections.cpp +++ b/lld/MachO/SyntheticSections.cpp @@ -98,8 +98,8 @@ if (in.exports->hasWeakSymbol || in.weakBinding->hasEntry()) hdr->flags |= MachO::MH_BINDS_TO_WEAK; - for (OutputSegment *seg : outputSegments) { - for (OutputSection *osec : seg->getSections()) { + for (const OutputSegment *seg : outputSegments) { + for (const OutputSection *osec : seg->getSections()) { if (isThreadLocalVariables(osec->flags)) { hdr->flags |= MachO::MH_HAS_TLV_DESCRIPTORS; break; @@ -108,7 +108,7 @@ } uint8_t *p = reinterpret_cast(hdr + 1); - for (LoadCommand *lc : loadCommands) { + for (const LoadCommand *lc : loadCommands) { lc->writeTo(p); p += lc->getSize(); } @@ -767,7 +767,7 @@ // Local symbols aren't in the SymbolTable, so we walk the list of object // files to gather them. - for (InputFile *file : inputFiles) { + for (const InputFile *file : inputFiles) { if (auto *objFile = dyn_cast(file)) { for (Symbol *sym : objFile->symbols) { if (sym == nullptr) diff --git a/lld/MachO/UnwindInfoSection.cpp b/lld/MachO/UnwindInfoSection.cpp --- a/lld/MachO/UnwindInfoSection.cpp +++ b/lld/MachO/UnwindInfoSection.cpp @@ -174,12 +174,12 @@ // is no source address to make a relative location meaningful. static void relocateCompactUnwind(MergedOutputSection *compactUnwindSection, std::vector &cuVector) { - for (InputSection *isec : compactUnwindSection->inputs) { + for (const InputSection *isec : compactUnwindSection->inputs) { uint8_t *buf = reinterpret_cast(cuVector.data()) + isec->outSecFileOff; memcpy(buf, isec->data.data(), isec->data.size()); - for (Reloc &r : isec->relocs) { + for (const Reloc &r : isec->relocs) { uint64_t referentVA = 0; if (auto *referentSym = r.referent.dyn_cast()) { if (!isa(referentSym)) { diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp --- a/lld/MachO/Writer.cpp +++ b/lld/MachO/Writer.cpp @@ -189,7 +189,7 @@ seg->lastSection()->addr + seg->lastSection()->getSize() - c->vmaddr; c->nsects = seg->numNonHiddenSections(); - for (OutputSection *osec : seg->getSections()) { + for (const OutputSection *osec : seg->getSections()) { if (!isZeroFill(osec->flags)) { assert(osec->fileOff >= seg->fileOff); c->filesize = std::max( @@ -616,7 +616,7 @@ }; // TODO: Make sure this handles weak symbols correctly. - for (InputFile *file : inputFiles) + for (const InputFile *file : inputFiles) if (isa(file)) for (lld::macho::Symbol *sym : file->symbols) if (auto *d = dyn_cast(sym)) @@ -828,8 +828,8 @@ void Writer::writeSections() { uint8_t *buf = buffer->getBufferStart(); - for (OutputSegment *seg : outputSegments) - for (OutputSection *osec : seg->getSections()) + for (const OutputSegment *seg : outputSegments) + for (const OutputSection *osec : seg->getSections()) osec->writeTo(buf + osec->fileOff); }