Skip to content

Commit 1eb1101

Browse files
Move DataRegions to MCObjectWriter
1 parent c936fef commit 1eb1101

File tree

5 files changed

+19
-17
lines changed

5 files changed

+19
-17
lines changed

llvm/include/llvm/MC/MCMachObjectWriter.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,6 @@ class MCMachObjectTargetWriter : public MCObjectTargetWriter {
8686

8787
class MachObjectWriter : public MCObjectWriter {
8888
public:
89-
struct DataRegionData {
90-
MachO::DataRegionType Kind;
91-
MCSymbol *Start;
92-
MCSymbol *End;
93-
};
94-
9589
// A Major version of 0 indicates that no version information was supplied
9690
// and so the corresponding load command should not be emitted.
9791
using VersionInfoType = struct {
@@ -146,8 +140,6 @@ class MachObjectWriter : public MCObjectWriter {
146140
std::vector<IndirectSymbolData> IndirectSymbols;
147141
DenseMap<const MCSection *, unsigned> IndirectSymBase;
148142

149-
std::vector<DataRegionData> DataRegions;
150-
151143
SectionAddrMap SectionAddress;
152144

153145
// List of sections in layout order. Virtual sections are after non-virtual
@@ -211,7 +203,6 @@ class MachObjectWriter : public MCObjectWriter {
211203
std::vector<IndirectSymbolData> &getIndirectSymbols() {
212204
return IndirectSymbols;
213205
}
214-
std::vector<DataRegionData> &getDataRegions() { return DataRegions; }
215206
const llvm::SmallVectorImpl<MCSection *> &getSectionOrder() const {
216207
return SectionOrder;
217208
}

llvm/include/llvm/MC/MCObjectWriter.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,16 @@ class MCValue;
3333
/// MCAssembler instance, which contains all the symbol and section data which
3434
/// should be emitted as part of writeObject().
3535
class MCObjectWriter {
36+
public:
37+
struct DataRegionData {
38+
unsigned Kind;
39+
MCSymbol *Start;
40+
MCSymbol *End;
41+
};
42+
3643
protected:
44+
std::vector<DataRegionData> DataRegions;
45+
3746
// The list of linker options for LC_LINKER_OPTION.
3847
std::vector<std::vector<std::string>> LinkerOptions;
3948

@@ -74,6 +83,8 @@ class MCObjectWriter {
7483

7584
MCLOHContainer &getLOHContainer() { return LOHContainer; }
7685

86+
std::vector<DataRegionData> &getDataRegions() { return DataRegions; }
87+
7788
/// Perform any late binding of symbols (for example, to assign symbol
7889
/// indices for use when generating relocations).
7990
///

llvm/lib/MC/MCMachOStreamer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,11 @@ void MCMachOStreamer::emitDataRegion(MachO::DataRegionType Kind) {
203203
MCSymbol *Start = getContext().createTempSymbol();
204204
emitLabel(Start);
205205
// Record the region for the object writer to use.
206-
getWriter().getDataRegions().push_back({Kind, Start, nullptr});
206+
getMCObjectWriter().getDataRegions().push_back({Kind, Start, nullptr});
207207
}
208208

209209
void MCMachOStreamer::emitDataRegionEnd() {
210-
auto &Regions = getWriter().getDataRegions();
210+
auto &Regions = getMCObjectWriter().getDataRegions();
211211
assert(!Regions.empty() && "Mismatched .end_data_region!");
212212
auto &Data = Regions.back();
213213
assert(!Data.End && "Mismatched .end_data_region!");

llvm/lib/MC/MCObjectWriter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ void MCObjectWriter::reset() {
2727
CGProfile.clear();
2828
LinkerOptions.clear();
2929
LOHContainer.reset();
30+
DataRegions.clear();
3031
}
3132

3233
bool MCObjectWriter::isSymbolRefDifferenceFullyResolved(

llvm/lib/MC/MachObjectWriter.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,12 @@ void MachObjectWriter::reset() {
4949
Relocations.clear();
5050
IndirectSymBase.clear();
5151
IndirectSymbols.clear();
52-
DataRegions.clear();
5352
SectionAddress.clear();
5453
SectionOrder.clear();
5554
StringTable.clear();
5655
LocalSymbolData.clear();
5756
ExternalSymbolData.clear();
5857
UndefinedSymbolData.clear();
59-
LOHContainer.reset();
6058
VersionInfo.Major = 0;
6159
VersionInfo.SDKVersion = VersionTuple();
6260
TargetVariantVersionInfo.Major = 0;
@@ -1096,10 +1094,11 @@ void MachObjectWriter::writeDataInCodeRegion(MCAssembler &Asm) {
10961094
else
10971095
report_fatal_error("Data region not terminated");
10981096

1099-
LLVM_DEBUG(dbgs() << "data in code region-- kind: " << Data.Kind
1100-
<< " start: " << Start << "(" << Data.Start->getName()
1101-
<< ")" << " end: " << End << "(" << Data.End->getName()
1102-
<< ")" << " size: " << End - Start << "\n");
1097+
LLVM_DEBUG(dbgs() << "data in code region-- kind: "
1098+
<< (MachO::DataRegionType)Data.Kind << " start: "
1099+
<< Start << "(" << Data.Start->getName() << ")"
1100+
<< " end: " << End << "(" << Data.End->getName() << ")"
1101+
<< " size: " << End - Start << "\n");
11031102
W.write<uint32_t>(Start);
11041103
W.write<uint16_t>(End - Start);
11051104
W.write<uint16_t>(Data.Kind);

0 commit comments

Comments
 (0)