[llvm] 94471e7 - [MC] Move MCAssembler::isSymbolLinkerVisible to MCSymbolMachO
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 3 17:25:15 PDT 2024
Author: Fangrui Song
Date: 2024-07-03T17:25:10-07:00
New Revision: 94471e73fe3a6e5ddf700ed79941b1f1c8d2127b
URL: https://github.com/llvm/llvm-project/commit/94471e73fe3a6e5ddf700ed79941b1f1c8d2127b
DIFF: https://github.com/llvm/llvm-project/commit/94471e73fe3a6e5ddf700ed79941b1f1c8d2127b.diff
LOG: [MC] Move MCAssembler::isSymbolLinkerVisible to MCSymbolMachO
Added:
Modified:
llvm/include/llvm/MC/MCAssembler.h
llvm/include/llvm/MC/MCSymbolMachO.h
llvm/lib/MC/MCAssembler.cpp
llvm/lib/MC/MCMachOStreamer.cpp
llvm/lib/MC/MachObjectWriter.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCAssembler.h b/llvm/include/llvm/MC/MCAssembler.h
index 9cd65d388d247..61188d88b9179 100644
--- a/llvm/include/llvm/MC/MCAssembler.h
+++ b/llvm/include/llvm/MC/MCAssembler.h
@@ -256,12 +256,6 @@ class MCAssembler {
// If this symbol is equivalent to A + Constant, return A.
const MCSymbol *getBaseSymbol(const MCSymbol &Symbol) const;
- /// Check whether a particular symbol is visible to the linker and is required
- /// in the symbol table, or whether it can be discarded by the assembler. This
- /// also effects whether the assembler treats the label as potentially
- /// defining a separate atom.
- bool isSymbolLinkerVisible(const MCSymbol &SD) const;
-
/// Emit the section contents to \p OS.
void writeSectionData(raw_ostream &OS, const MCSection *Section) const;
diff --git a/llvm/include/llvm/MC/MCSymbolMachO.h b/llvm/include/llvm/MC/MCSymbolMachO.h
index f75f61c198c11..730fbea0059a6 100644
--- a/llvm/include/llvm/MC/MCSymbolMachO.h
+++ b/llvm/include/llvm/MC/MCSymbolMachO.h
@@ -109,6 +109,18 @@ class MCSymbolMachO : public MCSymbol {
setFlags(Value & SF_DescFlagsMask);
}
+ // Check whether a particular symbol is visible to the linker and is required
+ // in the symbol table, or whether it can be discarded by the assembler. This
+ // also effects whether the assembler treats the label as potentially defining
+ // a separate atom.
+ bool isSymbolLinkerVisible() const {
+ // Non-temporary labels should always be visible to the linker.
+ if (!isTemporary())
+ return true;
+
+ return isUsedInReloc();
+ }
+
/// Get the encoded value of the flags as they will be emitted in to
/// the MachO binary
uint16_t getEncodedFlags(bool EncodeAsAltEntry) const {
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index 14790f508323e..cdac58c5fbf68 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -160,17 +160,6 @@ bool MCAssembler::isThumbFunc(const MCSymbol *Symbol) const {
return true;
}
-bool MCAssembler::isSymbolLinkerVisible(const MCSymbol &Symbol) const {
- // Non-temporary labels should always be visible to the linker.
- if (!Symbol.isTemporary())
- return true;
-
- if (Symbol.isUsedInReloc())
- return true;
-
- return false;
-}
-
bool MCAssembler::evaluateFixup(const MCFixup &Fixup, const MCFragment *DF,
MCValue &Target, const MCSubtargetInfo *STI,
uint64_t &Value, bool &WasForced) const {
diff --git a/llvm/lib/MC/MCMachOStreamer.cpp b/llvm/lib/MC/MCMachOStreamer.cpp
index 0b34d87033b7b..6eb9f44de44fd 100644
--- a/llvm/lib/MC/MCMachOStreamer.cpp
+++ b/llvm/lib/MC/MCMachOStreamer.cpp
@@ -198,7 +198,7 @@ void MCMachOStreamer::emitEHSymAttributes(const MCSymbol *Symbol,
void MCMachOStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
// We have to create a new fragment if this is an atom defining symbol,
// fragments cannot span atoms.
- if (getAssembler().isSymbolLinkerVisible(*Symbol))
+ if (cast<MCSymbolMachO>(Symbol)->isSymbolLinkerVisible())
insert(getContext().allocFragment<MCDataFragment>());
MCObjectStreamer::emitLabel(Symbol, Loc);
@@ -507,8 +507,9 @@ void MCMachOStreamer::finishImpl() {
// defining symbols.
DenseMap<const MCFragment *, const MCSymbol *> DefiningSymbolMap;
for (const MCSymbol &Symbol : getAssembler().symbols()) {
- if (getAssembler().isSymbolLinkerVisible(Symbol) && Symbol.isInSection() &&
- !Symbol.isVariable() && !cast<MCSymbolMachO>(Symbol).isAltEntry()) {
+ auto &Sym = cast<MCSymbolMachO>(Symbol);
+ if (Sym.isSymbolLinkerVisible() && Sym.isInSection() && !Sym.isVariable() &&
+ !Sym.isAltEntry()) {
// An atom defining symbol should never be internal to a fragment.
assert(Symbol.getOffset() == 0 &&
"Invalid offset in atom defining symbol!");
diff --git a/llvm/lib/MC/MachObjectWriter.cpp b/llvm/lib/MC/MachObjectWriter.cpp
index 12048e2e53442..e9499558a90db 100644
--- a/llvm/lib/MC/MachObjectWriter.cpp
+++ b/llvm/lib/MC/MachObjectWriter.cpp
@@ -582,7 +582,7 @@ void MachObjectWriter::computeSymbolTable(
// Build the string table.
for (const MCSymbol &Symbol : Asm.symbols()) {
- if (!Asm.isSymbolLinkerVisible(Symbol))
+ if (!cast<MCSymbolMachO>(Symbol).isSymbolLinkerVisible())
continue;
StringTable.add(Symbol.getName());
@@ -596,7 +596,7 @@ void MachObjectWriter::computeSymbolTable(
// important for letting us
diff .o files.
for (const MCSymbol &Symbol : Asm.symbols()) {
// Ignore non-linker visible symbols.
- if (!Asm.isSymbolLinkerVisible(Symbol))
+ if (!cast<MCSymbolMachO>(Symbol).isSymbolLinkerVisible())
continue;
if (!Symbol.isExternal() && !Symbol.isUndefined())
@@ -622,7 +622,7 @@ void MachObjectWriter::computeSymbolTable(
// Now add the data for local symbols.
for (const MCSymbol &Symbol : Asm.symbols()) {
// Ignore non-linker visible symbols.
- if (!Asm.isSymbolLinkerVisible(Symbol))
+ if (!cast<MCSymbolMachO>(Symbol).isSymbolLinkerVisible())
continue;
if (Symbol.isExternal() || Symbol.isUndefined())
More information about the llvm-commits
mailing list