diff --git a/lld/MachO/CMakeLists.txt b/lld/MachO/CMakeLists.txt --- a/lld/MachO/CMakeLists.txt +++ b/lld/MachO/CMakeLists.txt @@ -10,7 +10,7 @@ Arch/ARM64Common.cpp Arch/ARM64_32.cpp Arch/X86_64.cpp - UnwindInfoSection.cpp + ConcatOutputSection.cpp Driver.cpp DriverUtils.cpp Dwarf.cpp @@ -18,7 +18,7 @@ InputFiles.cpp InputSection.cpp LTO.cpp - MergedOutputSection.cpp + MapFile.cpp ObjC.cpp OutputSection.cpp OutputSegment.cpp @@ -27,7 +27,7 @@ Symbols.cpp SyntheticSections.cpp Target.cpp - MapFile.cpp + UnwindInfoSection.cpp Writer.cpp LINK_COMPONENTS diff --git a/lld/MachO/MergedOutputSection.h b/lld/MachO/ConcatOutputSection.h rename from lld/MachO/MergedOutputSection.h rename to lld/MachO/ConcatOutputSection.h --- a/lld/MachO/MergedOutputSection.h +++ b/lld/MachO/ConcatOutputSection.h @@ -1,4 +1,4 @@ -//===- OutputSection.h ------------------------------------------*- C++ -*-===// +//===- ConcatOutputSection.h ------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -24,9 +24,10 @@ // files that are labeled with the same segment and section name. This class // contains all such sections and writes the data from each section sequentially // in the final binary. -class MergedOutputSection : public OutputSection { +class ConcatOutputSection : public OutputSection { public: - MergedOutputSection(StringRef name) : OutputSection(MergedKind, name) {} + explicit ConcatOutputSection(StringRef name) + : OutputSection(ConcatKind, name) {} const InputSection *firstSection() const { return inputs.front(); } const InputSection *lastSection() const { return inputs.back(); } @@ -35,7 +36,7 @@ uint64_t getSize() const override { return size; } uint64_t getFileSize() const override { return fileSize; } - void mergeInput(InputSection *input); + void addInput(InputSection *input); void finalize() override; bool needsThunks() const; uint64_t estimateStubsInRangeVA(size_t callIdx) const; @@ -46,7 +47,7 @@ std::vector thunks; static bool classof(const OutputSection *sec) { - return sec->kind() == MergedKind; + return sec->kind() == ConcatKind; } private: diff --git a/lld/MachO/MergedOutputSection.cpp b/lld/MachO/ConcatOutputSection.cpp rename from lld/MachO/MergedOutputSection.cpp rename to lld/MachO/ConcatOutputSection.cpp --- a/lld/MachO/MergedOutputSection.cpp +++ b/lld/MachO/ConcatOutputSection.cpp @@ -1,4 +1,4 @@ -//===- OutputSection.cpp --------------------------------------------------===// +//===- ConcatOutputSection.cpp --------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "MergedOutputSection.h" +#include "ConcatOutputSection.h" #include "Config.h" #include "OutputSegment.h" #include "SymbolTable.h" @@ -25,7 +25,7 @@ using namespace lld; using namespace lld::macho; -void MergedOutputSection::mergeInput(InputSection *input) { +void ConcatOutputSection::addInput(InputSection *input) { if (inputs.empty()) { align = input->align; flags = input->flags; @@ -119,7 +119,7 @@ // instructions, whereas CISC (i.e., x86) generally doesn't. RISC only needs // thunks for programs so large that branch source & destination addresses // might differ more than the range of branch instruction(s). -bool MergedOutputSection::needsThunks() const { +bool ConcatOutputSection::needsThunks() const { if (!target->usesThunks()) return false; uint64_t isecAddr = addr; @@ -135,7 +135,7 @@ auto *sym = r.referent.get(); // Pre-populate the thunkMap and memoize call site counts for every // InputSection and ThunkInfo. We do this for the benefit of - // MergedOutputSection::estimateStubsInRangeVA() + // ConcatOutputSection::estimateStubsInRangeVA() ThunkInfo &thunkInfo = thunkMap[sym]; // Knowing ThunkInfo call site count will help us know whether or not we // might need to create more for this referent at the time we are @@ -151,7 +151,7 @@ // Since __stubs is placed after __text, we must estimate the address // beyond which stubs are within range of a simple forward branch. -uint64_t MergedOutputSection::estimateStubsInRangeVA(size_t callIdx) const { +uint64_t ConcatOutputSection::estimateStubsInRangeVA(size_t callIdx) const { uint64_t branchRange = target->branchRange; size_t endIdx = inputs.size(); InputSection *isec = inputs[callIdx]; @@ -185,7 +185,7 @@ return stubsInRangeVA; } -void MergedOutputSection::finalize() { +void ConcatOutputSection::finalize() { uint64_t isecAddr = addr; uint64_t isecFileOff = fileOff; auto finalizeOne = [&](InputSection *isec) { @@ -317,7 +317,7 @@ ", thunks = " + std::to_string(thunkCount)); } -void MergedOutputSection::writeTo(uint8_t *buf) const { +void ConcatOutputSection::writeTo(uint8_t *buf) const { // Merge input sections from thunk & ordinary vectors size_t i = 0, ie = inputs.size(); size_t t = 0, te = thunks.size(); @@ -337,7 +337,7 @@ // TODO: this is most likely wrong; reconsider how section flags // are actually merged. The logic presented here was written without // any form of informed research. -void MergedOutputSection::mergeFlags(InputSection *input) { +void ConcatOutputSection::mergeFlags(InputSection *input) { uint8_t baseType = flags & SECTION_TYPE; uint8_t inputType = input->flags & SECTION_TYPE; if (baseType != inputType) diff --git a/lld/MachO/OutputSection.h b/lld/MachO/OutputSection.h --- a/lld/MachO/OutputSection.h +++ b/lld/MachO/OutputSection.h @@ -25,7 +25,7 @@ class OutputSection { public: enum Kind { - MergedKind, + ConcatKind, SyntheticKind, }; diff --git a/lld/MachO/OutputSegment.cpp b/lld/MachO/OutputSegment.cpp --- a/lld/MachO/OutputSegment.cpp +++ b/lld/MachO/OutputSegment.cpp @@ -7,8 +7,8 @@ //===----------------------------------------------------------------------===// #include "OutputSegment.h" +#include "ConcatOutputSection.h" #include "InputSection.h" -#include "MergedOutputSection.h" #include "SyntheticSections.h" #include "lld/Common/ErrorHandler.h" diff --git a/lld/MachO/Symbols.cpp b/lld/MachO/Symbols.cpp --- a/lld/MachO/Symbols.cpp +++ b/lld/MachO/Symbols.cpp @@ -40,7 +40,7 @@ // the address of a function that has not yet been finalized. assert(target->usesThunks()); - // MergedOutputSection::finalize() can seek the address of a + // ConcatOutputSection::finalize() can seek the address of a // function before its address is assigned. The thunking algorithm // knows that unfinalized functions will be out of range, so it is // expedient to return a contrived out-of-range address. diff --git a/lld/MachO/SyntheticSections.h b/lld/MachO/SyntheticSections.h --- a/lld/MachO/SyntheticSections.h +++ b/lld/MachO/SyntheticSections.h @@ -296,7 +296,7 @@ // have a corresponding entry in the LazyPointerSection. bool addEntry(Symbol *); uint64_t getVA(uint32_t stubsIndex) const { - // MergedOutputSection::finalize() can seek the address of a + // ConcatOutputSection::finalize() can seek the address of a // stub before its address is assigned. Before __stubs is // finalized, return a contrived out-of-range address. return isFinal ? addr + stubsIndex * target->stubSize diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp --- a/lld/MachO/SyntheticSections.cpp +++ b/lld/MachO/SyntheticSections.cpp @@ -7,11 +7,11 @@ //===----------------------------------------------------------------------===// #include "SyntheticSections.h" +#include "ConcatOutputSection.h" #include "Config.h" #include "ExportTrie.h" #include "InputFiles.h" #include "MachOStructs.h" -#include "MergedOutputSection.h" #include "OutputSegment.h" #include "SymbolTable.h" #include "Symbols.h" diff --git a/lld/MachO/UnwindInfoSection.h b/lld/MachO/UnwindInfoSection.h --- a/lld/MachO/UnwindInfoSection.h +++ b/lld/MachO/UnwindInfoSection.h @@ -9,7 +9,7 @@ #ifndef LLD_MACHO_UNWIND_INFO_H #define LLD_MACHO_UNWIND_INFO_H -#include "MergedOutputSection.h" +#include "ConcatOutputSection.h" #include "SyntheticSections.h" #include "mach-o/compact_unwind_encoding.h" @@ -26,7 +26,7 @@ uint64_t getSize() const override { return unwindInfoSize; } virtual void prepareRelocations(InputSection *) = 0; - void setCompactUnwindSection(MergedOutputSection *cuSection) { + void setCompactUnwindSection(ConcatOutputSection *cuSection) { compactUnwindSection = cuSection; } @@ -36,7 +36,7 @@ align = 4; } - MergedOutputSection *compactUnwindSection = nullptr; + ConcatOutputSection *compactUnwindSection = nullptr; uint64_t unwindInfoSize = 0; }; diff --git a/lld/MachO/UnwindInfoSection.cpp b/lld/MachO/UnwindInfoSection.cpp --- a/lld/MachO/UnwindInfoSection.cpp +++ b/lld/MachO/UnwindInfoSection.cpp @@ -7,9 +7,9 @@ //===----------------------------------------------------------------------===// #include "UnwindInfoSection.h" +#include "ConcatOutputSection.h" #include "Config.h" #include "InputSection.h" -#include "MergedOutputSection.h" #include "OutputSection.h" #include "OutputSegment.h" #include "SymbolTable.h" @@ -212,7 +212,7 @@ // is no source address to make a relative location meaningful. template static void -relocateCompactUnwind(MergedOutputSection *compactUnwindSection, +relocateCompactUnwind(ConcatOutputSection *compactUnwindSection, std::vector> &cuVector) { for (const InputSection *isec : compactUnwindSection->inputs) { assert(isec->parent == compactUnwindSection); diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp --- a/lld/MachO/Writer.cpp +++ b/lld/MachO/Writer.cpp @@ -7,11 +7,11 @@ //===----------------------------------------------------------------------===// #include "Writer.h" +#include "ConcatOutputSection.h" #include "Config.h" #include "InputFiles.h" #include "InputSection.h" #include "MapFile.h" -#include "MergedOutputSection.h" #include "OutputSection.h" #include "OutputSegment.h" #include "SymbolTable.h" @@ -852,7 +852,7 @@ firstTLVDataSection = osec; if (!isecPriorities.empty()) { - if (auto *merged = dyn_cast(osec)) { + if (auto *merged = dyn_cast(osec)) { llvm::stable_sort(merged->inputs, [&](InputSection *a, InputSection *b) { return isecPriorities[a] > isecPriorities[b]; @@ -897,21 +897,21 @@ llvm_unreachable("unhandled output file type"); } - // Then merge input sections into output sections. - MapVector mergedOutputSections; + // Then add input sections to output sections. + MapVector concatOutputSections; for (InputSection *isec : inputSections) { if (isec->shouldOmitFromOutput()) continue; NamePair names = maybeRenameSection({isec->segname, isec->name}); - MergedOutputSection *&osec = mergedOutputSections[names]; + ConcatOutputSection *&osec = concatOutputSections[names]; if (osec == nullptr) - osec = make(names.second); - osec->mergeInput(isec); + osec = make(names.second); + osec->addInput(isec); } - for (const auto &it : mergedOutputSections) { + for (const auto &it : concatOutputSections) { StringRef segname = it.first.first; - MergedOutputSection *osec = it.second; + ConcatOutputSection *osec = it.second; if (segname == segment_names::ld) { assert(osec->name == section_names::compactUnwind); in.unwindInfo->setCompactUnwindSection(osec); @@ -921,8 +921,8 @@ } for (SyntheticSection *ssec : syntheticSections) { - auto it = mergedOutputSections.find({ssec->segname, ssec->name}); - if (it == mergedOutputSections.end()) { + auto it = concatOutputSections.find({ssec->segname, ssec->name}); + if (it == concatOutputSections.end()) { if (ssec->isNeeded()) getOrCreateOutputSegment(ssec->segname)->addOutputSection(ssec); } else {