Adds support for LA expansion in PIC mode.
Patch By: Srdjan Obucina
Paths
| Differential D16925
[mips] Support LA expansion in PIC mode Needs RevisionPublic Authored by sdardis on Feb 5 2016, 7:19 AM.
Details Summary Adds support for LA expansion in PIC mode. Patch By: Srdjan Obucina
Diff Detail
Event Timelineobucina updated this object. obucina retitled this revision from [mips] Support LA expandsion in PIC mode to [mips] Support LA expansion in PIC mode.Feb 5 2016, 7:22 AM obucina edited edge metadata. dsanders edited edge metadata. Comment ActionsThe 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'). This revision now requires changes to proceed.Feb 5 2016, 7:45 AM obucina edited edge metadata. Comment ActionsWe 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. mpf added inline comments.
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 This revision now requires changes to proceed.Jul 12 2019, 1:26 PM
Revision Contents
Diff 87422 lib/Target/Mips/AsmParser/MipsAsmParser.cpp
lib/Target/Mips/Mips16HardFloat.cpp
test/CodeGen/Mips/hf16call32_body.ll
test/CodeGen/Mips/hf1_body.ll
test/MC/Mips/macro-la-pic.s
|
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.