[PATCH] D16925: [mips] Support LA expansion in PIC mode

Daniel Sanders via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 1 02:53:25 PST 2016


dsanders added a comment.

> For example, 'la $5, symbol+8' gives: 'LLVM ERROR: unsupported reloc value'.


Whatever caused this seems to have been fixed. It emits this for me:

  lw $6, %got(symbol)($gp)   # encoding: [A,A,0x86,0x8f]


================
Comment at: lib/Target/Mips/AsmParser/MipsAsmParser.cpp:2485
@@ +2484,3 @@
+            IDLoc, Instructions);
+    if(Sym->isInSection() && !Sym->isExternal())
+       emitRRX(Mips::ADDiu, TmpReg, TmpReg, MCOperand::createExpr(LoExpr),
----------------
mpf wrote:
> The problem here is that you do not know whether a symbol is going to have global or local linkage until the end of the module as the .global directive may appear later. In order to do this you will need to track which symbols are referred to during macro expansion and then at the end of the file check that all the symbols still have the same linkage. If any have changed then raise an error. The restriction you will end up with in LLVM is that a global symbol must be globalized before the first reference to it.
> 
> The test cases are:
> 
> = global =
> .text
> foo:
> la $4, bar
> 
> = local =
> .data
> bar:
> .word 1
> .text
> foo:
> la $4, bar
> 
> = global =
> .data
> .global bar
> bar:
> .word 1
> .text
> foo:
> la $4, bar
> 
> 
> = local (but an error for LLVM) =
> .text
> foo:
> la $4, bar
> .data
> bar:
> .word 1
> 
> = global (but an error for LLVM) =
> .data
> bar:
> .word 1
> .text
> foo:
> la $4, bar
> .global bar
> 
> If the cases which work are sufficient for the codebases you need to support then this is relatively easy to implement. If you need the last two cases to work then there will be a significant amount of framework required as I understand.
> The problem here is that you do not know whether a symbol is going to have global or local
> linkage until the end of the module as the .global directive may appear later.

I should have noticed that given that we've recently had the same problem with jal.

> In order to do this you will need to track which symbols are referred to during macro
> expansion and then at the end of the file check that all the symbols still have the same
> linkage. If any have changed then raise an error. The restriction you will end up with in LLVM
> is that a global symbol must be globalized before the first reference to it.

I like this solution. There's some valid inputs to GAS that won't be supported but it only takes a trivial source change (inserting a '.global bar') to work around it.

I'd limit the 'reference' part of your last sentence to just references involved in this kind of linkage-specific expansion since things like:
    .data
  foo:
    .word bar
  bar:
    .word 1
aren't a problem.

We only need one of the two error cases to be an error don't we? I think we could assume local and error out if it turned out to be global, or assume global and error out if it turned out to be local.

> If you need the last two cases to work then there will be a significant amount of framework required as I understand.

That's my understanding too. We don't have a way to see the whole input before we have to make a decision on how to expand.

================
Comment at: test/MC/Mips/la.pic.s:15
@@ +14,3 @@
+dl:
+la $5,
+                      # CHECK-PIC: lw      $5, %got(dl)($gp)       # encoding: [A,A,0x85,0x8f]
----------------
This instruction is incomplete


http://reviews.llvm.org/D16925





More information about the llvm-commits mailing list