<div dir="ltr">On Wed, Jan 20, 2016 at 11:26 AM, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">On 20 January 2016 at 14:13, Joe Groff <<a href="mailto:arcata@gmail.com">arcata@gmail.com</a>> wrote:<br>
> jckarter added a comment.<br>
><br>
> 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.<br>
<br>
</span>I fixed the ELF case in r258329.<br></blockquote><div><br></div><div>Fantastic, thanks!</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
Can you give an example in assembly where your transformation would<br>
avoid a subtractor in MachO? I tested with<br>
<br>
.section __DATA,__const<br>
L_foo:<br>
.long L_bar-L_foo<br>
.section __TEXT,__cstring,cstring_literals<br>
L_bar:<br>
<br>
and even with two L symbols I get a subtractor.<br></blockquote><div><br></div><div>You're right. Even using '.' appears to cause mc to produce a subtractor:</div><div><br></div><div><div><div>.data</div><div>L_foo:</div><div>  .long L_bar - .</div><div><br></div><div>.text</div><div>L_bar:</div><div>  .long 0</div></div></div><div><br></div><div>I had honestly only cmp'ed the output of 'L_bar - L_foo' and 'L_bar - .', without looking at the actual relocations. Sorry.</div><div><br></div><div>-Joe</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
Right now I cannot remember why the GOT-like optimization is done<br>
during asm printing. I remember it is an optimization to avoid having<br>
to add a feature to the IR, but I cannot remember why it was not<br>
implemented directly in MC. Bruno, do you remember?<br>
<br>
Cheers,<br>
Rafael<br>
</blockquote></div><br></div></div>