[llvm] MIPS/Asm/O32: Don't add another $ to PrivateGlobal symbol (PR #80644)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 5 00:22:31 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mc
Author: YunQiang Su (wzssyqa)
<details>
<summary>Changes</summary>
For asm code like:
xx:
la $2,$yy
$yy:
nop
MIPS O32 use `$` as PrivateGlobalPrefix, while another `$` is added for getOrCreateSymbol, thus:
error: Undefined temporary symbol $$yy
We also set symbols that starts with `.L` as local for O32.
See: #<!-- -->65020.
---
Full diff: https://github.com/llvm/llvm-project/pull/80644.diff
2 Files Affected:
- (modified) llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp (+6-1)
- (added) llvm/test/MC/Mips/macro-la-local.s (+23)
``````````diff
diff --git a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
index 3c673ae938fde..2ddd8a6f31756 100644
--- a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
+++ b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
@@ -2920,6 +2920,11 @@ bool MipsAsmParser::loadAndAddSymbolAddress(const MCExpr *SymExpr,
(Res.getSymA()->getSymbol().isELF() &&
cast<MCSymbolELF>(Res.getSymA()->getSymbol()).getBinding() ==
ELF::STB_LOCAL);
+ if (!IsLocalSym && ABI.IsO32()) {
+ // PrivateGlobalPrefix for O32 is '$', while we support '.L' anyway.
+ if (Res.getSymA()->getSymbol().getName().starts_with(".L"))
+ IsLocalSym = true;
+ }
bool UseXGOT = STI->hasFeature(Mips::FeatureXGOT) && !IsLocalSym;
// The case where the result register is $25 is somewhat special. If the
@@ -6359,7 +6364,7 @@ bool MipsAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic) {
return true;
SMLoc E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
- MCSymbol *Sym = getContext().getOrCreateSymbol("$" + Identifier);
+ MCSymbol *Sym = getContext().getOrCreateSymbol(Identifier);
// Otherwise create a symbol reference.
const MCExpr *SymRef =
MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, getContext());
diff --git a/llvm/test/MC/Mips/macro-la-local.s b/llvm/test/MC/Mips/macro-la-local.s
new file mode 100644
index 0000000000000..14c8e1b689ac9
--- /dev/null
+++ b/llvm/test/MC/Mips/macro-la-local.s
@@ -0,0 +1,23 @@
+# RUN: llvm-mc %s -triple=mips-unknown-linux -show-encoding -mcpu=mips32r2 | \
+# RUN: FileCheck %s --check-prefixes=CHECK
+# RUN: llvm-mc %s -triple=mips-unknown-linux -show-encoding -mcpu=mips32r6 | \
+# RUN: FileCheck %s --check-prefixes=CHECK
+
+ .text
+ .abicalls
+ .option pic2
+xx:
+ la $2,.Lhello #CHECK: lw $2, %got(.Lhello)($gp) # encoding: [0x8f,0x82,A,A]
+ #CHECK: # fixup A - offset: 0, value: %got(.Lhello), kind: fixup_Mips_GOT
+ #CHECK: addiu $2, $2, %lo(.Lhello) # encoding: [0x24,0x42,A,A]
+ #CHECK: # fixup A - offset: 0, value: %lo(.Lhello), kind: fixup_Mips_LO16
+
+ la $2,$hello2 #CHECK: lw $2, %got($hello2)($gp) # encoding: [0x8f,0x82,A,A]
+ #CHECK: # fixup A - offset: 0, value: %got($hello2), kind: fixup_Mips_GOT
+ #CHECK: addiu $2, $2, %lo($hello2) # encoding: [0x24,0x42,A,A]
+ #CHECK: # fixup A - offset: 0, value: %lo($hello2), kind: fixup_Mips_LO16
+ .rdata
+.Lhello:
+ .asciz "Hello world\n"
+$hello2:
+ .asciz "Hello world\n"
``````````
</details>
https://github.com/llvm/llvm-project/pull/80644
More information about the llvm-commits
mailing list