[lld] 3370619 - [lld-macho][nfc] Rename MergedOutputSection to ConcatOutputSection
Jez Ng via llvm-commits
llvm-commits at lists.llvm.org
Tue May 25 11:58:43 PDT 2021
Author: Jez Ng
Date: 2021-05-25T14:58:29-04:00
New Revision: 33706191d88d34382e07c48ff09fe639fae5881d
URL: https://github.com/llvm/llvm-project/commit/33706191d88d34382e07c48ff09fe639fae5881d
DIFF: https://github.com/llvm/llvm-project/commit/33706191d88d34382e07c48ff09fe639fae5881d.diff
LOG: [lld-macho][nfc] Rename MergedOutputSection to ConcatOutputSection
The ELF format has the concept of merge sections (marked by SHF_MERGE),
which contain data that can be safely deduplicated. The Mach-O
equivalents are called literal sections (marked by S_CSTRING_LITERALS or
S_{4,8,16}BYTE_LITERALS). While the Mach-O format doesn't use the word
'merge', to avoid confusion, I've renamed our MergedOutputSection to
ConcatOutputSection. I believe it's a more descriptive name too.
This renaming sets the stage for {D102964}.
Reviewed By: #lld-macho, alexshap
Differential Revision: https://reviews.llvm.org/D102971
Added:
lld/MachO/ConcatOutputSection.cpp
lld/MachO/ConcatOutputSection.h
Modified:
lld/MachO/CMakeLists.txt
lld/MachO/OutputSection.h
lld/MachO/OutputSegment.cpp
lld/MachO/Symbols.cpp
lld/MachO/SyntheticSections.cpp
lld/MachO/SyntheticSections.h
lld/MachO/UnwindInfoSection.cpp
lld/MachO/UnwindInfoSection.h
lld/MachO/Writer.cpp
Removed:
lld/MachO/MergedOutputSection.cpp
lld/MachO/MergedOutputSection.h
################################################################################
diff --git a/lld/MachO/CMakeLists.txt b/lld/MachO/CMakeLists.txt
index 1ddf5954ff652..1c93a8842a283 100644
--- a/lld/MachO/CMakeLists.txt
+++ b/lld/MachO/CMakeLists.txt
@@ -10,7 +10,7 @@ add_lld_library(lldMachO2
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 @@ add_lld_library(lldMachO2
InputFiles.cpp
InputSection.cpp
LTO.cpp
- MergedOutputSection.cpp
+ MapFile.cpp
ObjC.cpp
OutputSection.cpp
OutputSegment.cpp
@@ -27,7 +27,7 @@ add_lld_library(lldMachO2
Symbols.cpp
SyntheticSections.cpp
Target.cpp
- MapFile.cpp
+ UnwindInfoSection.cpp
Writer.cpp
LINK_COMPONENTS
diff --git a/lld/MachO/MergedOutputSection.cpp b/lld/MachO/ConcatOutputSection.cpp
similarity index 96%
rename from lld/MachO/MergedOutputSection.cpp
rename to lld/MachO/ConcatOutputSection.cpp
index 867f76e326f2f..fa47ccf1dc8b2 100644
--- 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 llvm::MachO;
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 @@ DenseMap<Symbol *, ThunkInfo> lld::macho::thunkMap;
// instructions, whereas CISC (i.e., x86) generally doesn't. RISC only needs
// thunks for programs so large that branch source & destination addresses
// might
diff er 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 @@ bool MergedOutputSection::needsThunks() const {
auto *sym = r.referent.get<Symbol *>();
// 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 @@ bool MergedOutputSection::needsThunks() const {
// 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 @@ uint64_t MergedOutputSection::estimateStubsInRangeVA(size_t callIdx) const {
return stubsInRangeVA;
}
-void MergedOutputSection::finalize() {
+void ConcatOutputSection::finalize() {
uint64_t isecAddr = addr;
uint64_t isecFileOff = fileOff;
auto finalizeOne = [&](InputSection *isec) {
@@ -317,7 +317,7 @@ void MergedOutputSection::finalize() {
", 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 @@ void MergedOutputSection::writeTo(uint8_t *buf) const {
// 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/MergedOutputSection.h b/lld/MachO/ConcatOutputSection.h
similarity index 90%
rename from lld/MachO/MergedOutputSection.h
rename to lld/MachO/ConcatOutputSection.h
index c5f6461027e2e..a266dc498488e 100644
--- 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 @@ class Defined;
// 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 @@ class MergedOutputSection : public OutputSection {
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 @@ class MergedOutputSection : public OutputSection {
std::vector<InputSection *> thunks;
static bool classof(const OutputSection *sec) {
- return sec->kind() == MergedKind;
+ return sec->kind() == ConcatKind;
}
private:
diff --git a/lld/MachO/OutputSection.h b/lld/MachO/OutputSection.h
index f858f45c6e562..8110f756ab218 100644
--- a/lld/MachO/OutputSection.h
+++ b/lld/MachO/OutputSection.h
@@ -25,7 +25,7 @@ class OutputSegment;
class OutputSection {
public:
enum Kind {
- MergedKind,
+ ConcatKind,
SyntheticKind,
};
diff --git a/lld/MachO/OutputSegment.cpp b/lld/MachO/OutputSegment.cpp
index d860ac8d59818..8ed4c3c43b14e 100644
--- 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
index 76b227f17f7c4..853ec7452e520 100644
--- a/lld/MachO/Symbols.cpp
+++ b/lld/MachO/Symbols.cpp
@@ -40,7 +40,7 @@ uint64_t Defined::getVA() const {
// 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.cpp b/lld/MachO/SyntheticSections.cpp
index 2ff93556b46b7..e949ca88da7d3 100644
--- 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/SyntheticSections.h b/lld/MachO/SyntheticSections.h
index 0b033ae37feb7..5778b9ed9c54a 100644
--- a/lld/MachO/SyntheticSections.h
+++ b/lld/MachO/SyntheticSections.h
@@ -296,7 +296,7 @@ class StubsSection : public SyntheticSection {
// 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/UnwindInfoSection.cpp b/lld/MachO/UnwindInfoSection.cpp
index 33f745247c3de..f684f7649c7a2 100644
--- 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 @@ static void checkTextSegment(InputSection *isec) {
// is no source address to make a relative location meaningful.
template <class Ptr>
static void
-relocateCompactUnwind(MergedOutputSection *compactUnwindSection,
+relocateCompactUnwind(ConcatOutputSection *compactUnwindSection,
std::vector<CompactUnwindEntry<Ptr>> &cuVector) {
for (const InputSection *isec : compactUnwindSection->inputs) {
assert(isec->parent == compactUnwindSection);
diff --git a/lld/MachO/UnwindInfoSection.h b/lld/MachO/UnwindInfoSection.h
index 156d7e9f481bd..3f20245b6d5ac 100644
--- 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 @@ class UnwindInfoSection : public SyntheticSection {
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 @@ class UnwindInfoSection : public SyntheticSection {
align = 4;
}
- MergedOutputSection *compactUnwindSection = nullptr;
+ ConcatOutputSection *compactUnwindSection = nullptr;
uint64_t unwindInfoSize = 0;
};
diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp
index 0caecca0d432a..c4cdf73be23dd 100644
--- 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 @@ static void sortSegmentsAndSections() {
firstTLVDataSection = osec;
if (!isecPriorities.empty()) {
- if (auto *merged = dyn_cast<MergedOutputSection>(osec)) {
+ if (auto *merged = dyn_cast<ConcatOutputSection>(osec)) {
llvm::stable_sort(merged->inputs,
[&](InputSection *a, InputSection *b) {
return isecPriorities[a] > isecPriorities[b];
@@ -897,21 +897,21 @@ template <class LP> void Writer::createOutputSections() {
llvm_unreachable("unhandled output file type");
}
- // Then merge input sections into output sections.
- MapVector<NamePair, MergedOutputSection *> mergedOutputSections;
+ // Then add input sections to output sections.
+ MapVector<NamePair, ConcatOutputSection *> 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<MergedOutputSection>(names.second);
- osec->mergeInput(isec);
+ osec = make<ConcatOutputSection>(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 @@ template <class LP> void Writer::createOutputSections() {
}
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 {
More information about the llvm-commits
mailing list