<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Apr 13, 2017 at 8:52 AM, Simon Atanasyan <span dir="ltr"><<a href="mailto:simon@atanasyan.com" target="_blank">simon@atanasyan.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Tue, Apr 11, 2017 at 3:42 AM, Rui Ueyama <<a href="mailto:ruiu@google.com">ruiu@google.com</a>> wrote:<br>
> On Mon, Apr 10, 2017 at 5:13 PM, Davide Italiano <<a href="mailto:davide@freebsd.org">davide@freebsd.org</a>> wrote:<br>
>><br>
>> On Mon, Apr 10, 2017 at 4:58 PM, Rui Ueyama via llvm-commits<br>
>> <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br>
>> > On Sat, Apr 8, 2017 at 12:08 AM, Simon Atanasyan <<a href="mailto:simon@atanasyan.com">simon@atanasyan.com</a>><br>
>> > wrote:<br>
>> >><br>
>> >> On Tue, Apr 4, 2017 at 9:09 PM, Rui Ueyama <<a href="mailto:ruiu@google.com">ruiu@google.com</a>> wrote:<br>
>> >> > On Tue, Apr 4, 2017 at 5:46 AM, Simon Atanasyan <<a href="mailto:simon@atanasyan.com">simon@atanasyan.com</a>><br>
>> >> > wrote:<br>
>> >> >><br>
>> >> >> On Sat, Apr 1, 2017 at 4:20 AM, Rui Ueyama via Phabricator<br>
>> >> >> <<a href="mailto:reviews@reviews.llvm.org">reviews@reviews.llvm.org</a>> wrote:<br>
>> >> >> ><br>
>> >> >> > This is not your fault, but I have to say that this MIPS GOT<br>
>> >> >> > layout<br>
>> >> >> > is<br>
>> >> >> > very odd,<br>
>> >> >> > too different from other architectures, and too complicated. I<br>
>> >> >> > want<br>
>> >> >> > to<br>
>> >> >> > avoid supporting<br>
>> >> >> > this unless I'm convinced that it is absolutely necessary. It<br>
>> >> >> > seems<br>
>> >> >> > to<br>
>> >> >> > me that MIPS<br>
>> >> >> > needs a clean, common new ABI. Only the MIPS ABI imposes a lot of<br>
>> >> >> > restrictions<br>
>> >> >> > on the size of GOT sections and the order of GOT section members,<br>
>> >> >> > even<br>
>> >> >> > though MIPS<br>
>> >> >> > as a processor is an ordinary RISC ISA. This change would really<br>
>> >> >> > hurt<br>
>> >> >> > maintainability<br>
>> >> >> > of LLD which I already found some MIPS-specific behavior is hard<br>
>> >> >> > to<br>
>> >> >> > keep<br>
>> >> >> > it right<br>
>> >> >> > when editing code for all the other architectures.<br>
>> >> >><br>
>> >> >> MIPS will not always use old, obsoleted ABIs. It will switch to new<br>
>> >> >> one. But it does not<br>
>> >> >> happen this year or so. Besides other obstacles, there is a hardware<br>
>> >> >> problem prevents from<br>
>> >> >> fast switching and common acceptance of the new ABI. Historically<br>
>> >> >> many<br>
>> >> >> MIPS instructions<br>
>> >> >> are partitioned as 16 bit for opcode and 16 bit bit for<br>
>> >> >> address/index.<br>
>> >> >> That is one of<br>
>> >> >> the source of GOT size limitation and reason of multi-GOT invention.<br>
>> >> >><br>
>> >> >> The biggest part of the patch isolated in the MipsGotSection class.<br>
>> >> >> It<br>
>> >> >> adds some new<br>
>> >> >> MIPS specific code like new constructor of the DynamicReloc class.<br>
>> >> >> But<br>
>> >> >> at the same<br>
>> >> >> time it removes some `if (Config->EMachine == EM_MIPS)` statements<br>
>> >> >> and<br>
>> >> >> MIPS specific<br>
>> >> >> fields from the `SymbolBody` class.<br>
>> >> ><br>
>> >> ><br>
>> >> > It is isolated as a separate class, but we still need to understand<br>
>> >> > and<br>
>> >> > modify it when we need to do something for relocation processing. I'm<br>
>> >> > actually trying to change the design of relocation processing, to<br>
>> >> > increase<br>
>> >> > parallelism of relocation processing. We can't parallelize it<br>
>> >> > entirely,<br>
>> >> > but<br>
>> >> > some part (such as making a decision whether a symbol needs a GOT<br>
>> >> > slot<br>
>> >> > or<br>
>> >> > not) can be processed per-file or per-relocation basis.<br>
>> >> ><br>
>> >> > Then I found that this part of code is very complex and has grown<br>
>> >> > organically. I tried to reduce its complexity and found that keeping<br>
>> >> > everything right for MIPS is hard. I'm really don't want to increase<br>
>> >> > complexity of this code. If you increase the complexity, I won't be<br>
>> >> > able<br>
>> >> > to<br>
>> >> > refactor it anymore because I'm struggling to do that even for the<br>
>> >> > current<br>
>> >> > code.<br>
>> >> ><br>
>> >> > In addition to that, the MIPS multi-GOT ABI doesn't seem a right<br>
>> >> > design<br>
>> >> > to<br>
>> >> > me. If multi-GOT is in use, only the first GOT is recognized as a<br>
>> >> > real<br>
>> >> > GOT<br>
>> >> > by the dynamic linker, and secondary GOTs are just some sections that<br>
>> >> > simulates GOT. It's too hacky, isn't it?<br>
>> >> ><br>
>> >> >> > I wonder what is the performance penalty you would have to pay<br>
>> >> >> > when<br>
>> >> >> > you<br>
>> >> >> > use the -mxgot<br>
>> >> >> > option. With the option, you'll need three instructions as opposed<br>
>> >> >> > to<br>
>> >> >> > a<br>
>> >> >> > single instruction<br>
>> >> >> > to access an GOT entry. Does that actually make observable<br>
>> >> >> > difference<br>
>> >> >> > in<br>
>> >> >> > performance?<br>
>> >> >><br>
>> >> >> Regular (without -mxgot) access to GOT requires a single<br>
>> >> >> instruction:<br>
>> >> >><br>
>> >> >> lw  t9,0(gp)<br>
>> >> >><br>
>> >> >> I was wrong when say about two instructions. With -mxgot option we<br>
>> >> >> get<br>
>> >> >> three instructions.<br>
>> >> >><br>
>> >> >> lui     at,0x0<br>
>> >> >> addu    at,at,gp<br>
>> >> >> lw      t9,0(at)<br>
>> >> >><br>
>> >> >> In case of MIPS global offset table is used not only to call<br>
>> >> >> external<br>
>> >> >> functions / access<br>
>> >> >> external data but for local calls / access under some conditions. So<br>
>> >> >> using -mxgot we can<br>
>> >> >> easily grow the code size and reduce performance.<br>
>> >> ><br>
>> >> ><br>
>> >> > How much is the actual performance hit?<br>
>> >><br>
>> >> Multi-GOT is an attempt to bypass say limitation of MIPS architecture.<br>
>> >> It's not my invention, this feature was implemented in GNU linker more<br>
>> >> than ten years ago. Every time when GOT exceeds ~64KB limit BFD and<br>
>> >> gold linkers create multi-GOT layout.<br>
>> >><br>
>> >> I do not think that my implementation of multi-GOT makes LLD much more<br>
>> >> complicated. General idea remains the same - collect information about<br>
>> >> various type of required GOT entries, layout GOT entries, write this<br>
>> >> layout. Merging multiple GOT created for each file into larger GOT is<br>
>> >> rather complicated routine though. From another side, creating a<br>
>> >> separate GOT for each input file makes possible to parallelize this<br>
>> >> process. Current implementation, where MipsGotSection maintains a<br>
>> >> single `GotEntries` vector for all files, does not allow to process<br>
>> >> multiple input files at the same time without some sort of "locks".<br>
>> ><br>
>> ><br>
>> > I understand that you are just trying to implement a MIPS ABI, and I<br>
>> > also<br>
>> > understand that you made your effort to write good code. Your code seems<br>
>> > to<br>
>> > be a straightforward implementation of the ABI if I understand it<br>
>> > correctly.<br>
>> > But still new code inevitably adds complexity, and that's particularly<br>
>> > true<br>
>> > for this patch that introduces a new notion of "multi-GOT" only for<br>
>> > MIPS.<br>
>> > Also, it is not my fault to say that this feature is too odd, because I<br>
>> > think it's a consequence of MIPS ABI's peculiarities. I believe many<br>
>> > peculiarities in the MIPS ABI could have been fixed by now since they<br>
>> > were<br>
>> > implemented more than 10 years ago.<br>
>> ><br>
>> > I really do not want to add this much complexity to our relocation<br>
>> > processing code which is already too complicated. Even I don't<br>
>> > understand<br>
>> > the exact behavior of the current code, and I'm am trying to refactor<br>
>> > that<br>
>> > code now. This patch could make my refactoring impossible.<br>
>> ><br>
>> >> Performance degradation in case of using -mxgot depends on<br>
>> >> application. My tests show that application use -mxgot slower on<br>
>> >> 1%-4%. But it's more important that there are large applications which<br>
>> >> cannot be linked without multi-GOT at all even if they built with<br>
>> >> -mxgot option. Because there are some relocations which operate by<br>
>> >> 16-bit GOT index only.<br>
>> >><br>
>><br>
>> I don't necessarily disagree, but what you're saying is true for a<br>
>> bunch of features in MIPS, which is the in-tree lld backend with more,<br>
>> let's say, "peculiarities". I'm under the impression that as a project<br>
>> we should make a call and decide whether we want to support the MIPS<br>
>> ABI entirely or just don't support it at all (unless there's an OK<br>
>> reason to drop some features). In this case, unless I'm reading the<br>
>> patch incorrectly, this is needed to link/self-host clang/lld, so this<br>
>> feature seems needed (in some form). What do you think?<br>
><br>
><br>
> We should support MIPS, but my point is that 1) the current code is already<br>
> complicated that even I do not understand, and 2) this patch will likely to<br>
> make it impossible to hack anymore because of an additional complexity. So<br>
> adding this code right now is not a good idea. I want to explore other way<br>
> to circumvent this ABI, and if it is impossible to do, I want to implement<br>
> it in a really good way, probably after cleaning up the current code with<br>
> the multi-GOT in mind.<br>
<br>
</div></div>As to me, "cleaning up the current code with the multi-GOT in mind" while<br>
"even I do not understand" is not the best strategy. Various parts of LLVM<br>
code are successfully refactored constantly and it does not prevent<br>
implementation<br>
of new features, targets, ABIs.<br></blockquote><div><br></div><div>If it is designed cleanly, it might be true, but this is not the case. I found that in order to refactor the code for relocation processing, I had to understand the every detail of all architectures that LLD currently supports, and editing it without breaking the existing implementation is incredibly hard. And again, since MIPS is pretty different from other ABIs, it is always the largest roadblock.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
One more point is your desire "to implement it in a really good way". Could<br>
you please describe shortcomings of the current implementation? Probably<br>
if I know them, I will be able to make multi-GOT better.<br></blockquote><div><br></div><div>The ABI is just too complicated. We already have probably too much code for MIPS, while other ABIs are straightforward to support. If I knew that the current MIPS ABI is this much different from other ELF ABIs from the beginning, we could have this discussion before start working on MIPS. But the real situation is that MIPS-specific features were added one at a time without presenting the whole picture and grows to the point that I start thinking if we really wanted this situation.</div><div><br></div><div>Is "multi-GOT" the last feature you want for MIPS? I wonder if there any more peculiarities in the MIPS ABI.<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
And last but not least, what about at least rough time estimations? I would<br>
like to include multi-GOT in the next (4.1 ?) release of LLD because now LLD<br>
on MIPS is just partly usable. When do you plan to finish the LLD refactoring<br>
so it will be ready to include multi-GOT implementation?</blockquote><div><br></div><div>I cannot promise, but I personally want to finish it in a few months. However, finishing refactoring doesn't immediately mean that we want MIPS multi-GOT support, as I wish to reduce complexity that MIPS brings in.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
> Also, the MIPS ABI needs updating. Only MIPS is very weird among ELF ABIs.<br>
> Someone really needs to make an effort to streamline it. I'm ok to accept<br>
> MIPS peculiarities if it is transient ("transient" can be like 10 years),<br>
> but if no effort is being made to make it compatible with other ELF ABIs, I<br>
> think I can say "no, this really needs fixing."<br>
<br>
</span>New ABI is under development / discussions but transient period will be large<br>
because part of the MIPS ABI peculiarities have a hardware nature.<br></blockquote><div><br></div><div>Where is it discussed?</div><div><br></div><div>I could imagine that if the new ABI will greatly simplified the MIPS ABI, we'd be able to have a choice to support only the new ABI in LLD and continue using the existing linker for the old ABI.</div><div><br></div><div>I'm sorry to say this, but as you know I don't really like the current MIPS ABI and the current situation that no improvements seem to have been made to improve it, although it could have been fixed, say, 10 years ago. I don't like to blindly support it just because it is the current ABI.</div></div></div></div>