Skip to content

Commit c007fbb

Browse files
wzssyqaMaskRay
andauthored
MipsAsmParser/O32: Don't add redundant $ to $-prefixed symbol in the la macro (#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: #65020. --------- Co-authored-by: Fangrui Song <[email protected]>
1 parent a78d13d commit c007fbb

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -2920,6 +2920,11 @@ bool MipsAsmParser::loadAndAddSymbolAddress(const MCExpr *SymExpr,
29202920
(Res.getSymA()->getSymbol().isELF() &&
29212921
cast<MCSymbolELF>(Res.getSymA()->getSymbol()).getBinding() ==
29222922
ELF::STB_LOCAL);
2923+
// For O32, "$"-prefixed symbols are recognized as temporary while
2924+
// .L-prefixed symbols are not (PrivateGlobalPrefix is "$"). Recognize ".L"
2925+
// manually.
2926+
if (ABI.IsO32() && Res.getSymA()->getSymbol().getName().starts_with(".L"))
2927+
IsLocalSym = true;
29232928
bool UseXGOT = STI->hasFeature(Mips::FeatureXGOT) && !IsLocalSym;
29242929

29252930
// The case where the result register is $25 is somewhat special. If the
@@ -6359,7 +6364,7 @@ bool MipsAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic) {
63596364
return true;
63606365

63616366
SMLoc E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
6362-
MCSymbol *Sym = getContext().getOrCreateSymbol("$" + Identifier);
6367+
MCSymbol *Sym = getContext().getOrCreateSymbol(Identifier);
63636368
// Otherwise create a symbol reference.
63646369
const MCExpr *SymRef =
63656370
MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, getContext());

llvm/test/CodeGen/Mips/hf1_body.ll

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ entry:
2323
; ALL: .set reorder
2424
; ALL: .reloc 0, R_MIPS_NONE, v_sf
2525
; GAS: la $25, $__fn_local_v_sf
26-
; IAS: lw $25, %got($$__fn_local_v_sf)($gp)
27-
; IAS: addiu $25, $25, %lo($$__fn_local_v_sf)
26+
; IAS: lw $25, %got($__fn_local_v_sf)($gp)
27+
; IAS: addiu $25, $25, %lo($__fn_local_v_sf)
2828
; ALL: mfc1 $4, $f12
2929
; ALL: jr $25
3030
; ALL: .end __fn_stub_v_sf

llvm/test/MC/Mips/macro-la-pic.s

+22
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,25 @@ la $25, 2f
255255
# XN32: lw $25, %got_disp(.Ltmp1)($gp) # encoding: [0x8f,0x99,A,A]
256256
# XN32: # fixup A - offset: 0, value: %got_disp(.Ltmp1), kind: fixup_Mips_GOT_DISP
257257
2:
258+
259+
la $2,.Lstr
260+
# O32: lw $2, %got(.Lstr)($gp) # encoding: [0x8f,0x82,A,A]
261+
# O32-NEXT: # fixup A - offset: 0, value: %got(.Lstr), kind: fixup_Mips_GOT
262+
# O32-NEXT: addiu $2, $2, %lo(.Lstr) # encoding: [0x24,0x42,A,A]
263+
# O32-NEXT: # fixup A - offset: 0, value: %lo(.Lstr), kind: fixup_Mips_LO16
264+
265+
# N32: lw $2, %got_disp(.Lstr)($gp) # encoding: [0x8f,0x82,A,A]
266+
# N32-NEXT: # fixup A - offset: 0, value: %got_disp(.Lstr), kind: fixup_Mips_GOT_DISP
267+
268+
la $2,$str2
269+
# O32: lw $2, %got($str2)($gp) # encoding: [0x8f,0x82,A,A]
270+
# O32-NEXT: # fixup A - offset: 0, value: %got($str2), kind: fixup_Mips_GOT
271+
# O32-NEXT: addiu $2, $2, %lo($str2) # encoding: [0x24,0x42,A,A]
272+
# O32-NEXT: # fixup A - offset: 0, value: %lo($str2), kind: fixup_Mips_LO16
273+
274+
# N32: lw $2, %got_disp($str2)($gp) # encoding: [0x8f,0x82,A,A]
275+
# N32-NEXT: # fixup A - offset: 0, value: %got_disp($str2), kind: fixup_Mips_GOT_DISP
276+
277+
.rodata
278+
.Lstr: .4byte 0
279+
$str2: .4byte 0

0 commit comments

Comments
 (0)