Adds support for LA expansion in PIC mode.
Patch By: Srdjan Obucina
Differential D16925
[mips] Support LA expansion in PIC mode sdardis on Feb 5 2016, 7:19 AM. Authored by
Details Adds support for LA expansion in PIC mode. Patch By: Srdjan Obucina
Diff Detail Event TimelineComment Actions The code change looks right to me but I have some comments about the test case. Rather than make a new test file, could you extend test/MC/Mips/macro-la.s? This is mostly to keep our test directories tidy but it will also allow us to test that the other cases (e.g. 'la $5, 1') are unaffected and we'll have better coverage of the variety of expressions (e.g. 'la $5, symbol+8($6)', 'la $6, symbol+8($6)', and 'la $5, 1f'). Comment Actions 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.
Comment Actions
Whatever caused this seems to have been fixed. It emits this for me: lw $6, %got(symbol)($gp) # encoding: [A,A,0x86,0x8f]
Comment Actions Update to trunk, account in tests for difference between emitting assembly and objects. Comment Actions Just removing a 3 year old patch from my queue. Feel free to re-add me if this is still needed and you want me to take another look |
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.