-
Notifications
You must be signed in to change notification settings - Fork 14.3k
MipsAsmParser/O32: Don't add redundant $ to $-prefixed symbol in the la macro #80644
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
@llvm/pr-subscribers-mc Author: YunQiang Su (wzssyqa) ChangesFor asm code like: MIPS O32 use We also set symbols that starts with See: #65020. Full diff: https://github.com/llvm/llvm-project/pull/80644.diff 2 Files Affected:
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"
|
69163b8
to
1c6dccc
Compare
llvm/test/MC/Mips/macro-la-local.s
Outdated
.abicalls | ||
.option pic2 | ||
xx: | ||
la $2,.Lhello #CHECK: lw $2, %got(.Lhello)($gp) # encoding: [0x8f,0x82,A,A] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# CHECK: lw ...
# CHECK-NEXT: fixup A ...
# CHECK-NEXT: ...
la $2, $hello2
@@ -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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is confusing.
// For O32, "$"-prefixed symbols are recognized as temporary while .L-prefixed symbols are not (PrivateGlobalPrefix is "$"). Recognize ".L" manually.
llvm/test/MC/Mips/macro-la-local.s
Outdated
@@ -0,0 +1,23 @@ | |||
# RUN: llvm-mc %s -triple=mips-unknown-linux -show-encoding -mcpu=mips32r2 | \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove -unknown-linux
whenever applicable, to emphasize that this is generic ELF behavior.
✅ With the latest revision this PR passed the C/C++ code formatter. |
Suggested description: When parsing the
Remove the duplicate prefix. In addition, recognize |
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: llvm#65020.
0b3d613
to
800d8be
Compare
…la macro (llvm#80644) When parsing the `la` macro, we add a duplicate `$` prefix in `getOrCreateSymbol`, leading to `error: Undefined temporary symbol $$yy` for code like: ``` xx: la $2,$yy $yy: nop ``` Remove the duplicate prefix. In addition, recognize `.L`-prefixed symbols as local for O32. See: llvm#65020. --------- Co-authored-by: Fangrui Song <i@maskray.me> (cherry picked from commit c007fbb)
…la macro (llvm#80644) When parsing the `la` macro, we add a duplicate `$` prefix in `getOrCreateSymbol`, leading to `error: Undefined temporary symbol $$yy` for code like: ``` xx: la $2,$yy $yy: nop ``` Remove the duplicate prefix. In addition, recognize `.L`-prefixed symbols as local for O32. See: llvm#65020. --------- Co-authored-by: Fangrui Song <i@maskray.me> (cherry picked from commit c007fbb)
When parsing the
la
macro, we add a duplicate$
prefix ingetOrCreateSymbol
,leading to
error: Undefined temporary symbol $$yy
for code like:Remove the duplicate prefix.
In addition, recognize
.L
-prefixed symbols as local for O32.See: #65020.