Skip to content

Commit f017d89

Browse files
committed
MCAssembler: Move SubsectionsViaSymbols; to MCObjectWriter
1 parent 5da4310 commit f017d89

File tree

7 files changed

+11
-22
lines changed

7 files changed

+11
-22
lines changed

llvm/include/llvm/MC/MCAssembler.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ class MCAssembler {
6565

6666
bool HasLayout = false;
6767
bool RelaxAll = false;
68-
bool SubsectionsViaSymbols = false;
6968

7069
SectionListType Sections;
7170

@@ -204,10 +203,6 @@ class MCAssembler {
204203
// Layout all section and prepare them for emission.
205204
void layout();
206205

207-
// FIXME: This does not belong here.
208-
bool getSubsectionsViaSymbols() const { return SubsectionsViaSymbols; }
209-
void setSubsectionsViaSymbols(bool Value) { SubsectionsViaSymbols = Value; }
210-
211206
bool hasLayout() const { return HasLayout; }
212207
bool getRelaxAll() const { return RelaxAll; }
213208
void setRelaxAll(bool Value) { RelaxAll = Value; }

llvm/include/llvm/MC/MCObjectWriter.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class MCObjectWriter {
3838
std::string CompilerVersion;
3939
std::vector<const MCSymbol *> AddrsigSyms;
4040
bool EmitAddrsigSection = false;
41+
bool SubsectionsViaSymbols = false;
4142

4243
struct CGProfileEntry {
4344
const MCSymbolRefExpr *From;
@@ -114,6 +115,10 @@ class MCObjectWriter {
114115
std::vector<const MCSymbol *> &getAddrsigSyms() { return AddrsigSyms; }
115116
SmallVector<CGProfileEntry, 0> &getCGProfile() { return CGProfile; }
116117

118+
// Mach-O specific: Whether .subsections_via_symbols is enabled.
119+
bool getSubsectionsViaSymbols() const { return SubsectionsViaSymbols; }
120+
void setSubsectionsViaSymbols(bool Value) { SubsectionsViaSymbols = Value; }
121+
117122
/// Write the object file and returns the number of bytes written.
118123
///
119124
/// This routine is called by the assembler after layout and relaxation is

llvm/lib/MC/MCAssembler.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ MCAssembler::~MCAssembler() = default;
9090

9191
void MCAssembler::reset() {
9292
RelaxAll = false;
93-
SubsectionsViaSymbols = false;
9493
Sections.clear();
9594
Symbols.clear();
9695
ThumbFuncs.clear();
@@ -1095,7 +1094,7 @@ bool MCAssembler::relaxLEB(MCLEBFragment &LF) {
10951094
// Use evaluateKnownAbsolute for Mach-O as a hack: .subsections_via_symbols
10961095
// requires that .uleb128 A-B is foldable where A and B reside in different
10971096
// fragments. This is used by __gcc_except_table.
1098-
bool Abs = getSubsectionsViaSymbols()
1097+
bool Abs = getWriter().getSubsectionsViaSymbols()
10991098
? LF.getValue().evaluateKnownAbsolute(Value, *this)
11001099
: LF.getValue().evaluateAsAbsolute(Value, *this);
11011100
if (!Abs) {

llvm/lib/MC/MCELFStreamer.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,6 @@ void MCELFStreamer::emitLabelAtPos(MCSymbol *S, SMLoc Loc, MCDataFragment &F,
8888
void MCELFStreamer::emitAssemblerFlag(MCAssemblerFlag Flag) {
8989
// Let the target do whatever target specific stuff it needs to do.
9090
getAssembler().getBackend().handleAssemblerFlag(Flag);
91-
// Do any generic stuff we need to do.
92-
switch (Flag) {
93-
case MCAF_SyntaxUnified: return; // no-op here.
94-
case MCAF_Code16: return; // Change parsing mode; no-op here.
95-
case MCAF_Code32: return; // Change parsing mode; no-op here.
96-
case MCAF_Code64: return; // Change parsing mode; no-op here.
97-
case MCAF_SubsectionsViaSymbols:
98-
getAssembler().setSubsectionsViaSymbols(true);
99-
return;
100-
}
101-
102-
llvm_unreachable("invalid assembler flag!");
10391
}
10492

10593
// If bundle alignment is used and there are any instructions in the section, it

llvm/lib/MC/MCMachOStreamer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ void MCMachOStreamer::emitAssemblerFlag(MCAssemblerFlag Flag) {
220220
case MCAF_Code32: return; // Change parsing mode; no-op here.
221221
case MCAF_Code64: return; // Change parsing mode; no-op here.
222222
case MCAF_SubsectionsViaSymbols:
223-
getAssembler().setSubsectionsViaSymbols(true);
223+
getWriter().setSubsectionsViaSymbols(true);
224224
return;
225225
}
226226
}

llvm/lib/MC/MCObjectWriter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ MCObjectWriter::~MCObjectWriter() = default;
2222
void MCObjectWriter::reset() {
2323
FileNames.clear();
2424
AddrsigSyms.clear();
25+
EmitAddrsigSection = false;
26+
SubsectionsViaSymbols = false;
2527
CGProfile.clear();
2628
}
2729

llvm/lib/MC/MachObjectWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ bool MachObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
744744
if (!hasReliableSymbolDifference) {
745745
if (!SA.isInSection() || &SecA != &SecB ||
746746
(!SA.isTemporary() && FB.getAtom() != SA.getFragment()->getAtom() &&
747-
Asm.getSubsectionsViaSymbols()))
747+
SubsectionsViaSymbols))
748748
return false;
749749
return true;
750750
}
@@ -894,7 +894,7 @@ uint64_t MachObjectWriter::writeObject(MCAssembler &Asm) {
894894

895895
// Write the prolog, starting with the header and load command...
896896
writeHeader(MachO::MH_OBJECT, NumLoadCommands, LoadCommandsSize,
897-
Asm.getSubsectionsViaSymbols());
897+
SubsectionsViaSymbols);
898898
uint32_t Prot =
899899
MachO::VM_PROT_READ | MachO::VM_PROT_WRITE | MachO::VM_PROT_EXECUTE;
900900
writeSegmentLoadCommand("", NumSections, 0, VMSize, SectionDataStart,

0 commit comments

Comments
 (0)