Skip to content

Commit 1c6dccc

Browse files
committed
MIPS/Asm/O32: Don't add another $ to PrivateGlobal symbol
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.
1 parent 78b4e7c commit 1c6dccc

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-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+
if (!IsLocalSym && ABI.IsO32()) {
2924+
// PrivateGlobalPrefix for O32 is '$', while we support '.L' anyway.
2925+
if (Res.getSymA()->getSymbol().getName().starts_with(".L"))
2926+
IsLocalSym = true;
2927+
}
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-local.s

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# RUN: llvm-mc %s -triple=mips-unknown-linux -show-encoding -mcpu=mips32r2 | \
2+
# RUN: FileCheck %s --check-prefixes=CHECK
3+
# RUN: llvm-mc %s -triple=mips-unknown-linux -show-encoding -mcpu=mips32r6 | \
4+
# RUN: FileCheck %s --check-prefixes=CHECK
5+
6+
.text
7+
.abicalls
8+
.option pic2
9+
xx:
10+
la $2,.Lhello #CHECK: lw $2, %got(.Lhello)($gp) # encoding: [0x8f,0x82,A,A]
11+
#CHECK: # fixup A - offset: 0, value: %got(.Lhello), kind: fixup_Mips_GOT
12+
#CHECK: addiu $2, $2, %lo(.Lhello) # encoding: [0x24,0x42,A,A]
13+
#CHECK: # fixup A - offset: 0, value: %lo(.Lhello), kind: fixup_Mips_LO16
14+
15+
la $2,$hello2 #CHECK: lw $2, %got($hello2)($gp) # encoding: [0x8f,0x82,A,A]
16+
#CHECK: # fixup A - offset: 0, value: %got($hello2), kind: fixup_Mips_GOT
17+
#CHECK: addiu $2, $2, %lo($hello2) # encoding: [0x24,0x42,A,A]
18+
#CHECK: # fixup A - offset: 0, value: %lo($hello2), kind: fixup_Mips_LO16
19+
.rdata
20+
.Lhello:
21+
.asciz "Hello world\n"
22+
$hello2:
23+
.asciz "Hello world\n"

0 commit comments

Comments
 (0)