[PATCH] D16925: [mips] Support LA expansion in PIC mode
Srdjan Obucina via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 10 07:49:26 PST 2016
obucina updated this revision to Diff 47453.
obucina added a comment.
We couldn't extend test/MC/Mips/macro-la.s because some tests in it failed in pic mode. For example, 'la $5, symbol+8' gives: 'LLVM ERROR: unsupported reloc value'. Also, istruction la in the case 'la $5, 1f' does not expand properly because symbol 1 is defined at the end of the test file, so condition 'Sym->isInSection()' fails because of one pass structure of assembler.
http://reviews.llvm.org/D16925
Files:
lib/Target/Mips/AsmParser/MipsAsmParser.cpp
test/MC/Mips/la.pic.s
Index: test/MC/Mips/la.pic.s
===================================================================
--- test/MC/Mips/la.pic.s
+++ test/MC/Mips/la.pic.s
@@ -0,0 +1,29 @@
+# RUN: llvm-mc %s -triple=mipsel-unknown-linux -mcpu=mips32 -show-encoding -relocation-model=pic | FileCheck %s -check-prefix=CHECK-PIC
+
+la $5, symbol # CHECK-PIC: lw $5, %got(symbol)($gp) # encoding: [A,A,0x85,0x8f]
+ # CHECK-PIC: # fixup A - offset: 0, value: symbol at GOT, kind: fixup_Mips_GOT_Local
+la $5, symbol($6) # CHECK-PIC: lw $5, %got(symbol)($gp) # encoding: [A,A,0x85,0x8f]
+ # CHECK-PIC: # fixup A - offset: 0, value: symbol at GOT, kind: fixup_Mips_GOT_Local
+ # CHECK-PIC: addu $5, $5, $6 # encoding: [0x21,0x28,0xa6,0x00]
+la $6, symbol($6) # CHECK-PIC: lw $1, %got(symbol)($gp) # encoding: [A,A,0x81,0x8f]
+ # CHECK-PIC: # fixup A - offset: 0, value: symbol at GOT, kind: fixup_Mips_GOT_Local
+ # CHECK-PIC: addu $6, $1, $6 # encoding: [0x21,0x30,0x26,0x00]
+la $4, foo
+ # CHECK-PIC: lw $4, %got(foo)($gp) # encoding: [A,A,0x84,0x8f]
+ # CHECK-PIC: # fixup A - offset: 0, value: foo at GOT, kind: fixup_Mips_GOT_Local
+dl:
+la $5,
+ # CHECK-PIC: lw $5, %got(dl)($gp) # encoding: [A,A,0x85,0x8f]
+ # CHECK-PIC: # fixup A - offset: 0, value: dl at GOT, kind: fixup_Mips_GOT_Local
+ # CHECK-PIC: addiu $5, $5, %lo(dl) # encoding: [A,A,0xa5,0x24]
+ # CHECK-PIC: # fixup A - offset: 0, value: %lo(dl), kind: fixup_Mips_LO16
+.globl dg
+dg:
+la $5, dg
+ # CHECK-PIC: lw $5, %got(dg)($gp) # encoding: [A,A,0x85,0x8f]
+ # CHECK-PIC: # fixup A - offset: 0, value: dg at GOT, kind: fixup_Mips_GOT_Local
+ # CHECK-PIC: addiu $5, $5, %lo(dg) # encoding: [A,A,0xa5,0x24]
+ # CHECK-PIC: # fixup A - offset: 0, value: %lo(dg), kind: fixup_Mips_LO16
+
+
+
Index: lib/Target/Mips/AsmParser/MipsAsmParser.cpp
===================================================================
--- lib/Target/Mips/AsmParser/MipsAsmParser.cpp
+++ lib/Target/Mips/AsmParser/MipsAsmParser.cpp
@@ -2476,10 +2476,22 @@
TmpReg = ATReg;
}
- emitRX(Mips::LUi, TmpReg, MCOperand::createExpr(HiExpr), IDLoc, Instructions);
- emitRRX(Mips::ADDiu, TmpReg, TmpReg, MCOperand::createExpr(LoExpr), IDLoc,
- Instructions);
-
+ const MCSymbol *Sym = getSingleMCSymbol(SymExpr);
+
+ if (inPicMode()) {
+ const MCExpr *Got16RelocExpr = evaluateRelocExpr(SymExpr, "got");
+ emitRRX(Mips::LW, TmpReg, Mips::GP, MCOperand::createExpr(Got16RelocExpr),
+ IDLoc, Instructions);
+ if(Sym->isInSection() && !Sym->isExternal())
+ emitRRX(Mips::ADDiu, TmpReg, TmpReg, MCOperand::createExpr(LoExpr),
+ IDLoc, Instructions);
+ } else {
+ emitRX(Mips::LUi, TmpReg, MCOperand::createExpr(HiExpr), IDLoc,
+ Instructions);
+ emitRRX(Mips::ADDiu, TmpReg, TmpReg, MCOperand::createExpr(LoExpr), IDLoc,
+ Instructions);
+ }
+
if (UseSrcReg)
emitRRR(Mips::ADDu, DstReg, TmpReg, SrcReg, IDLoc, Instructions);
else
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16925.47453.patch
Type: text/x-patch
Size: 3608 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160210/1bee5ea4/attachment.bin>
More information about the llvm-commits
mailing list