aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCExpr.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2025-05-26 21:58:17 -0700
committerFangrui Song <i@maskray.me>2025-05-26 21:58:18 -0700
commite015626f189dc76f8df9fdc25a47638c6a2f3feb (patch)
treeea77e8d4093c6bd7f83701d17ec1add55aeddd3e /llvm/lib/MC/MCExpr.cpp
parentde93f7ed0d615060735ad15e720f2497ed1d2468 (diff)
downloadllvm-e015626f189dc76f8df9fdc25a47638c6a2f3feb.zip
llvm-e015626f189dc76f8df9fdc25a47638c6a2f3feb.tar.gz
llvm-e015626f189dc76f8df9fdc25a47638c6a2f3feb.tar.bz2
MC: Allow .set to reassign non-MCConstantExpr expressions
GNU Assembler supports symbol reassignment via .set, .equ, or =. However, LLVM's integrated assembler only allows reassignment for MCConstantExpr cases, as it struggles with scenarios like: ``` .data .set x, 0 .long x // reference the first instance x = .-.data .long x // reference the second instance .set x,.-.data .long x // reference the third instance ``` Between two assignments binds, we cannot ensure that a reference binds to the earlier assignment. We use MCSymbol::IsUsed and other conditions to reject potentially unsafe reassignments, but certain MCConstantExpr uses could be unsafe as well. This patch enables reassignment by cloning the symbol upon reassignment and updating the symbol table. Existing references to the original symbol remain unchanged, and the original symbol is excluded from the emitted symbol table.
Diffstat (limited to 'llvm/lib/MC/MCExpr.cpp')
-rw-r--r--llvm/lib/MC/MCExpr.cpp3
1 files changed, 0 insertions, 3 deletions
diff --git a/llvm/lib/MC/MCExpr.cpp b/llvm/lib/MC/MCExpr.cpp
index 6c9fc94..70c9c5c 100644
--- a/llvm/lib/MC/MCExpr.cpp
+++ b/llvm/lib/MC/MCExpr.cpp
@@ -479,8 +479,6 @@ static bool canExpand(const MCSymbol &Sym, bool InSet) {
if (Sym.isWeakExternal())
return false;
- Sym.getVariableValue(true);
-
if (InSet)
return true;
return !Sym.isInSection();
@@ -508,7 +506,6 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
Asm->getContext().reportError(
Sym.getVariableValue()->getLoc(),
"cyclic dependency detected for symbol '" + Sym.getName() + "'");
- Sym.IsUsed = false;
Sym.setVariableValue(MCConstantExpr::create(0, Asm->getContext()));
}
return false;