This is an archive of the discontinued LLVM Phabricator instance.

[Sparc] Add support for 13-bit PIC
ClosedPublic

Authored by dcederman on May 21 2018, 5:31 AM.

Details

Summary

When compiling with -fpic, in contrast to -fPIC, use only the immediate field to index into the GOT. This saves space if the GOT is known to be small. The linker will warn if the GOT is too large for this method.

Diff Detail

Event Timeline

dcederman created this revision.May 21 2018, 5:31 AM

It doesn't look like we can parse the textual asm produced by this. E.g.:

test.s:

ld      [%i0+x], %i0
.common x,4,4

Then running llvm-mc -filetype=obj -position-independent -triple sparc -o test.o test.s hits an assert in SparcMCCodeEmitter::getMachineOpValue at SparcMCCodeEmitter.cpp:152, because it got parsed as a <MCOperand Expr:(x)>, not as a SparcMCExpr with the VK_SPARC_GOT13 kind, as it should.

Same failure, actually, without the -position-independent, too, actually, should've parsed as VK_SPARC_13. But at least we don't ever actually generate that on output.

lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp
61

Strange that this doesn't print %got13. But, checking with gcc and gnu as, they don't support it. So, great, more magic just like %got22, %got10, %pc22, and %pc10.

Same failure, actually, without the -position-independent, too, actually, should've parsed as VK_SPARC_13. But at least we don't ever actually generate that on output.

I ran into this problem before and tried to fix it. I will combine that patch with this and add the GOT13 part to the assembler.

dcederman updated this revision to Diff 148359.May 24 2018, 2:20 AM

Added support to the assembler so that it can properly parse the output generated by -fpic.

jyknight accepted this revision.Jun 8 2018, 8:10 AM
This revision is now accepted and ready to land.Jun 8 2018, 8:10 AM
This revision was automatically updated to reflect the committed changes.