[PATCH] D15635: AsmPrinter: Produce PC-relative cstexprs when possible.

Rafael EspĂ­ndola via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 20 11:26:39 PST 2016


On 20 January 2016 at 14:13, Joe Groff <arcata at gmail.com> wrote:
> jckarter added a comment.
>
> No worries, thanks for the feedback, Rafael. I was following the example of how we handle rewriting relative references to GOT-equivalent globals into GOTPCREL relocations, which also happens in the AsmPrinter. It'd be great if MC could be made smarter about choosing relocations. The issue also impacts Mach-O, though unlike ELF, Mach-O does support generalized subtractor relocations, so it isn't a showstopper there. These subtractor relocations have however been giving me heartache, exposing unused corners of Darwin's ld and MCJIT, so I think it's better to favor PCREL relocation if we can get them on Mach-O too, since those are much better exercised.

I fixed the ELF case in r258329.

Can you give an example in assembly where your transformation would
avoid a subtractor in MachO? I tested with

.section __DATA,__const
L_foo:
.long L_bar-L_foo
.section __TEXT,__cstring,cstring_literals
L_bar:

and even with two L symbols I get a subtractor.

Right now I cannot remember why the GOT-like optimization is done
during asm printing. I remember it is an optimization to avoid having
to add a feature to the IR, but I cannot remember why it was not
implemented directly in MC. Bruno, do you remember?

Cheers,
Rafael


More information about the llvm-commits mailing list