Skip to content

Commit 94471e7

Browse files
committed
[MC] Move MCAssembler::isSymbolLinkerVisible to MCSymbolMachO
1 parent 665efe8 commit 94471e7

File tree

5 files changed

+19
-23
lines changed

5 files changed

+19
-23
lines changed

llvm/include/llvm/MC/MCAssembler.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,6 @@ class MCAssembler {
256256
// If this symbol is equivalent to A + Constant, return A.
257257
const MCSymbol *getBaseSymbol(const MCSymbol &Symbol) const;
258258

259-
/// Check whether a particular symbol is visible to the linker and is required
260-
/// in the symbol table, or whether it can be discarded by the assembler. This
261-
/// also effects whether the assembler treats the label as potentially
262-
/// defining a separate atom.
263-
bool isSymbolLinkerVisible(const MCSymbol &SD) const;
264-
265259
/// Emit the section contents to \p OS.
266260
void writeSectionData(raw_ostream &OS, const MCSection *Section) const;
267261

llvm/include/llvm/MC/MCSymbolMachO.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ class MCSymbolMachO : public MCSymbol {
109109
setFlags(Value & SF_DescFlagsMask);
110110
}
111111

112+
// Check whether a particular symbol is visible to the linker and is required
113+
// in the symbol table, or whether it can be discarded by the assembler. This
114+
// also effects whether the assembler treats the label as potentially defining
115+
// a separate atom.
116+
bool isSymbolLinkerVisible() const {
117+
// Non-temporary labels should always be visible to the linker.
118+
if (!isTemporary())
119+
return true;
120+
121+
return isUsedInReloc();
122+
}
123+
112124
/// Get the encoded value of the flags as they will be emitted in to
113125
/// the MachO binary
114126
uint16_t getEncodedFlags(bool EncodeAsAltEntry) const {

llvm/lib/MC/MCAssembler.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,6 @@ bool MCAssembler::isThumbFunc(const MCSymbol *Symbol) const {
160160
return true;
161161
}
162162

163-
bool MCAssembler::isSymbolLinkerVisible(const MCSymbol &Symbol) const {
164-
// Non-temporary labels should always be visible to the linker.
165-
if (!Symbol.isTemporary())
166-
return true;
167-
168-
if (Symbol.isUsedInReloc())
169-
return true;
170-
171-
return false;
172-
}
173-
174163
bool MCAssembler::evaluateFixup(const MCFixup &Fixup, const MCFragment *DF,
175164
MCValue &Target, const MCSubtargetInfo *STI,
176165
uint64_t &Value, bool &WasForced) const {

llvm/lib/MC/MCMachOStreamer.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ void MCMachOStreamer::emitEHSymAttributes(const MCSymbol *Symbol,
198198
void MCMachOStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
199199
// We have to create a new fragment if this is an atom defining symbol,
200200
// fragments cannot span atoms.
201-
if (getAssembler().isSymbolLinkerVisible(*Symbol))
201+
if (cast<MCSymbolMachO>(Symbol)->isSymbolLinkerVisible())
202202
insert(getContext().allocFragment<MCDataFragment>());
203203

204204
MCObjectStreamer::emitLabel(Symbol, Loc);
@@ -507,8 +507,9 @@ void MCMachOStreamer::finishImpl() {
507507
// defining symbols.
508508
DenseMap<const MCFragment *, const MCSymbol *> DefiningSymbolMap;
509509
for (const MCSymbol &Symbol : getAssembler().symbols()) {
510-
if (getAssembler().isSymbolLinkerVisible(Symbol) && Symbol.isInSection() &&
511-
!Symbol.isVariable() && !cast<MCSymbolMachO>(Symbol).isAltEntry()) {
510+
auto &Sym = cast<MCSymbolMachO>(Symbol);
511+
if (Sym.isSymbolLinkerVisible() && Sym.isInSection() && !Sym.isVariable() &&
512+
!Sym.isAltEntry()) {
512513
// An atom defining symbol should never be internal to a fragment.
513514
assert(Symbol.getOffset() == 0 &&
514515
"Invalid offset in atom defining symbol!");

llvm/lib/MC/MachObjectWriter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ void MachObjectWriter::computeSymbolTable(
582582

583583
// Build the string table.
584584
for (const MCSymbol &Symbol : Asm.symbols()) {
585-
if (!Asm.isSymbolLinkerVisible(Symbol))
585+
if (!cast<MCSymbolMachO>(Symbol).isSymbolLinkerVisible())
586586
continue;
587587

588588
StringTable.add(Symbol.getName());
@@ -596,7 +596,7 @@ void MachObjectWriter::computeSymbolTable(
596596
// important for letting us diff .o files.
597597
for (const MCSymbol &Symbol : Asm.symbols()) {
598598
// Ignore non-linker visible symbols.
599-
if (!Asm.isSymbolLinkerVisible(Symbol))
599+
if (!cast<MCSymbolMachO>(Symbol).isSymbolLinkerVisible())
600600
continue;
601601

602602
if (!Symbol.isExternal() && !Symbol.isUndefined())
@@ -622,7 +622,7 @@ void MachObjectWriter::computeSymbolTable(
622622
// Now add the data for local symbols.
623623
for (const MCSymbol &Symbol : Asm.symbols()) {
624624
// Ignore non-linker visible symbols.
625-
if (!Asm.isSymbolLinkerVisible(Symbol))
625+
if (!cast<MCSymbolMachO>(Symbol).isSymbolLinkerVisible())
626626
continue;
627627

628628
if (Symbol.isExternal() || Symbol.isUndefined())

0 commit comments

Comments
 (0)