<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Nov 11, 2014 at 12:31 PM, Nick Kledzik <span dir="ltr"><<a href="mailto:kledzik@apple.com" target="_blank">kledzik@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><span class="">On Nov 11, 2014, at 11:54 AM, Rui Ueyama <<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>> wrote:<br></span><div><span class=""><blockquote type="cite"><div dir="ltr">This falls into the usual topic that whether or not we should have a generic map attached to an atom. You used a reference as an alternative for the map in this case but the basic idea is the same.<div><br></div><div>Although using a reference would be practical, it still feels a hack to me. It's awkward at least. Why don't you add an accessor to the attribute you want to DefinedAtom? We'll have a few or maybe ten more member functions in DefinedAtom, but it's not bad -- architectures that don't need them are able to just not use them. And the number of attributes we want is limited because the number of architectures we want to support in LLD is not that many.</div></div></blockquote></span><div>If there are architecture/platform specific atom attributes, I’ve fine with adding more accessors to DefinedAtom. We just need to review them to see if there is similar needs on multiple flavors and design names and values that are clear.</div><div><br></div><div>Regarding References, the ELF flavor puts the raw ELF relocation type as the Reference Kind. Mach-o does not do that. The mach-o relocation type is only 4 bits. You need to process lots of other information (including other bits in the reloc record, the instruction content, and perhaps a “paired” relocation to determine the “kind”). So, Mach-O Reference Kind values are abstract and internal to the mach-o ArchHandler. Given that, using a Reference Kind to track thumbness (which only ArchHander_arm cares about), works well.</div><div><br></div><div>That said, the ability to handle thumb and arm within a function is probably over engineering. I’d be fine with adding to DefinedAtom something like:</div><div><br></div><div> enum CodeModel { </div><div> // Note: all these values need word smithing</div><div> codeNA,</div><div> codeMIPS_PIC,</div><div><div> codeMIPS_micro,</div><div><div> codeMIPS_16,</div></div><div> codeARM_16,</div><div><div> codeARM_32,</div></div><div> };</div><div><br></div><div>virtual CodeModel codeModel() { return codeNA; }</div></div></div></div></blockquote><div><br></div><div>Yup, that looks good. That would reduce the amount of code and the complexity, I guess. We may want to add some prefix (like "machOCodeModel") for that kind of stuff to make it easy to identify it's used for MachO.</div><div><br></div><div>You made a good point that two or more architectures may have a similar or the same need and want to share the accessors. They have to be designed carefully and named accordingly. We can coordinate that by sending a patch to review if it touches DefinedAtom.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div><span class="HOEnZb"><font color="#888888"><div><br></div></font></span></div><span class="HOEnZb"><font color="#888888"><div>-Nick</div></font></span><div><div class="h5"><div><br></div><br><blockquote type="cite"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 11, 2014 at 11:19 AM, Nick Kledzik <span dir="ltr"><<a href="mailto:kledzik@apple.com" target="_blank">kledzik@apple.com</a>></span> wrote:<br><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">I had a similar issue with arm vs thumb in mach-o. Each function’s thumbness is marked in its symbol table entry.<br>
<br>
But it is even worse, a function could change encoding in the middle (only hand coded assembly could do this).<br>
<br>
My solution was to add a new Reference Kind for mach-o which is the current instruction encoding. The offsetInAtom() is the offset where the encoding kind changes. Usually there is just one at offset zero that sets the encoding for the whole function. So determining the thumbness requires scanning the References. But it turns out in practice the scan is rarely done because the result can be cached by whatever algorithm needs that info.<br>
<span><font color="#888888"><br>
-Nick<br>
</font></span><div><div><br>
<br>
On Nov 11, 2014, at 6:50 AM, Simon Atanasyan <<a href="mailto:simon@atanasyan.com" target="_blank">simon@atanasyan.com</a>> wrote:<br>
> I was too optimistic. It is possible to use the contentTypes field for<br>
> handling STO_MICROMIPS and I have a working solution but the solution<br>
> is really ugly. This approach has at least two the following<br>
> shortcomings:<br>
><br>
> 1. A MIPS ELF symbol can hold multiple STO_xxx flags stored in the<br>
> st_other field (STO_MIPS_PIC, STO_MIPS_MICROMIPS, STO_MIPS_MIPS16<br>
> ...). Sometimes these flags can be even combined. If we use the<br>
> contentTypes field, we have to define a separate ContentType flag for<br>
> each such combination. So we get a combinatorics explosion.<br>
><br>
> 2. If we handle MIPS specific ContentType flags together with other<br>
> flags, it is pollute the common ELF code. If we factor out the<br>
> processing of MIPS specific flags, we have to duplicate code because a<br>
> symbol with say STO_MICROMIPS flag should be processed (setup size,<br>
> permissions etc) the same way as a regular DefinedAtom::typeCode<br>
> symbol.<br>
><br>
> I considered to create a map symbol name => symbol flags, fill this<br>
> map while read object files, and use the map while write a linked<br>
> file. But I need to handle both local and global symbols and it is<br>
> possible to get symbols with the same name.<br>
><br>
> It looks like the only solution (if I do not miss anything else) is to<br>
> add one more filed to the DefinedAtom class to hold<br>
> target/architecture specific set of flags and modify Native and YAML<br>
> formats correspondingly. Interpretation of this field is completely<br>
> target/architecture dependent.<br>
><br>
> Any opinions?<br>
><br>
> On Thu, Nov 6, 2014 at 7:09 PM, Simon Atanasyan <<a href="mailto:simon@atanasyan.com" target="_blank">simon@atanasyan.com</a>> wrote:<br>
>> STO_MIPS16 and STO_MICROMIPS flags denote that the symbol use a<br>
>> different "compressed" instructions encoding. Both these flags can be<br>
>> combined with usual "visibility" flags.<br>
>><br>
>> It looks like adding new flag into the contentTypes set might solve<br>
>> the problem. Thanks for the idea. I try to implement it.<br>
>><br>
>> On Thu, Nov 6, 2014 at 6:52 PM, Shankar Easwaran<br>
>> <<a href="mailto:shankare@codeaurora.org" target="_blank">shankare@codeaurora.org</a>> wrote:<br>
>>> One way to do that is to add new visibility / contentTypes (whatever is<br>
>>> relevant) added for each of the values st_other picks ?<br>
>>><br>
>>> What are the other values st_other can take on MIPS ?<br>
>>><br>
>>> On 11/6/2014 8:50 AM, Simon Atanasyan wrote:<br>
>>>> On MIPS st_other field in the ELF symbols table might contain some<br>
>>>> additional MIPS-specific flags besides visibility ones. These flags<br>
>>>> should be copied to the output linked file. If YAML => Native<br>
>>>> conversion is switched off, there is no problem. But in case of the<br>
>>>> conversion we lose st_other field values.<br>
>>>><br>
>>>> So I need an advice how to keep this information. Is it a good idea to<br>
>>>> extend YAML and Native format to store these data? Is there any<br>
>>>> alternative solutions?<br>
><br>
> --<br>
> Simon Atanasyan<br>
<br>
</div></div></blockquote></div><br></div>
</blockquote></div></div></div><br></div></blockquote></div><br></div></div>