[llvm] f8f9be3 - [ARM, MC] Replace getSymA()->getSymbol() with getAddSym. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 5 14:41:52 PDT 2025
Author: Fangrui Song
Date: 2025-04-05T14:41:47-07:00
New Revision: f8f9be32411d63fa65832306cbc9207ef91446af
URL: https://github.com/llvm/llvm-project/commit/f8f9be32411d63fa65832306cbc9207ef91446af
DIFF: https://github.com/llvm/llvm-project/commit/f8f9be32411d63fa65832306cbc9207ef91446af.diff
LOG: [ARM,MC] Replace getSymA()->getSymbol() with getAddSym. NFC
We will replace the MCSymbolRefExpr member in MCValue with MCSymbol.
This change reduces dependence on MCSymbolRefExpr.
Added:
Modified:
llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
index 9cf8584d82337..afe4be54fa843 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
@@ -460,9 +460,9 @@ unsigned ARMAsmBackend::adjustFixupValue(const MCAssembler &Asm,
// Other relocation types don't want this bit though (branches couldn't encode
// it if it *was* present, and no other relocations exist) and it can
// interfere with checking valid expressions.
- if (const MCSymbolRefExpr *A = Target.getSymA()) {
- if (A->hasSubsectionsViaSymbols() && Asm.isThumbFunc(&A->getSymbol()) &&
- A->getSymbol().isExternal() &&
+ bool IsMachO = Asm.getContext().getObjectFileType() == MCContext::IsMachO;
+ if (const auto *SA = Target.getAddSym()) {
+ if (IsMachO && Asm.isThumbFunc(SA) && SA->isExternal() &&
(Kind == FK_Data_4 || Kind == ARM::fixup_arm_movw_lo16 ||
Kind == ARM::fixup_arm_movt_hi16 || Kind == ARM::fixup_t2_movw_lo16 ||
Kind == ARM::fixup_t2_movt_hi16))
@@ -958,8 +958,7 @@ bool ARMAsmBackend::shouldForceRelocation(const MCAssembler &Asm,
const MCFixup &Fixup,
const MCValue &Target,
const MCSubtargetInfo *STI) {
- const MCSymbolRefExpr *A = Target.getSymA();
- const MCSymbol *Sym = A ? &A->getSymbol() : nullptr;
+ const MCSymbol *Sym = Target.getAddSym();
const unsigned FixupKind = Fixup.getKind();
if (FixupKind == ARM::fixup_arm_thumb_bl) {
assert(Sym && "How did we resolve this?");
@@ -989,10 +988,10 @@ bool ARMAsmBackend::shouldForceRelocation(const MCAssembler &Asm,
// We must always generate a relocation for BL/BLX instructions if we have
// a symbol to reference, as the linker relies on knowing the destination
// symbol's thumb-ness to get interworking right.
- if (A && (FixupKind == ARM::fixup_arm_thumb_blx ||
- FixupKind == ARM::fixup_arm_blx ||
- FixupKind == ARM::fixup_arm_uncondbl ||
- FixupKind == ARM::fixup_arm_condbl))
+ if (Sym && (FixupKind == ARM::fixup_arm_thumb_blx ||
+ FixupKind == ARM::fixup_arm_blx ||
+ FixupKind == ARM::fixup_arm_uncondbl ||
+ FixupKind == ARM::fixup_arm_condbl))
return true;
return false;
}
diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
index f9c8f5f820e6f..42838bb83781c 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
@@ -122,10 +122,10 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target,
"invalid fixup for 4-byte pc-relative data relocation");
return ELF::R_ARM_NONE;
case ARMMCExpr::VK_None: {
- if (const MCSymbolRefExpr *SymRef = Target.getSymA()) {
+ if (const auto *SA = Target.getAddSym()) {
// For GNU AS compatibility expressions such as
// _GLOBAL_OFFSET_TABLE_ - label emit a R_ARM_BASE_PREL relocation.
- if (SymRef->getSymbol().getName() == "_GLOBAL_OFFSET_TABLE_")
+ if (SA->getName() == "_GLOBAL_OFFSET_TABLE_")
return ELF::R_ARM_BASE_PREL;
}
return ELF::R_ARM_REL32;
diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp
index 353e4fa5b2a9d..03ad4149f766b 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp
@@ -386,9 +386,7 @@ void ARMMachObjectWriter::recordRelocation(MachObjectWriter *Writer,
}
// Get the symbol data, if any.
- const MCSymbol *A = nullptr;
- if (Target.getSymA())
- A = Target.getAddSym();
+ const MCSymbol *A = Target.getAddSym();
// FIXME: For other platforms, we need to use scattered relocations for
// internal relocations with offsets. If this is an internal relocation with
More information about the llvm-commits
mailing list