<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Nov 11, 2014, at 12:31 PM, Nick Kledzik <<a href="mailto:kledzik@apple.com" class="">kledzik@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=windows-1252" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">On Nov 11, 2014, at 11:54 AM, Rui Ueyama <<a href="mailto:ruiu@google.com" class="">ruiu@google.com</a>> wrote:<br class=""><div class=""><blockquote type="cite" class=""><div dir="ltr" class="">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 class=""><br class=""></div><div class="">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><div class="">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 class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class=""> enum CodeModel { </div><div class=""> // Note: all these values need word smithing</div><div class=""> codeNA,</div><div class=""> codeMIPS_PIC,</div><div class=""><div class=""> codeMIPS_micro,</div><div class=""><div class=""> codeMIPS_16,</div></div><div class=""> codeARM_16,</div><div class=""><div class=""> codeARM_32,</div></div><div class=""> };</div><div class=""><br class=""></div><div class="">virtual CodeModel codeModel() { return codeNA; }</div><div class=""><br class=""></div></div></div></div></div></blockquote><div><br class=""></div><div>How would this handle getting the code model right for things like x86 boot code that starts in “real” mode then switches to protected mode, typically within the same Atom? Very analogous to your example of a function that has some portions in thumb mode and some in ARM mode.</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class="">-Nick</div><div class=""><br class=""></div><br class=""><blockquote type="cite" class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Tue, Nov 11, 2014 at 11:19 AM, Nick Kledzik <span dir="ltr" class=""><<a href="mailto:kledzik@apple.com" target="_blank" class="">kledzik@apple.com</a>></span> wrote:<br class=""><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; position: static; z-index: auto;">I had a similar issue with arm vs thumb in mach-o. Each function’s thumbness is marked in its symbol table entry.<br class="">
<br class="">
But it is even worse, a function could change encoding in the middle (only hand coded assembly could do this).<br class="">
<br class="">
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 class="">
<span class="HOEnZb"><font color="#888888" class=""><br class="">
-Nick<br class="">
</font></span><div class="HOEnZb"><div class="h5"><br class="">
<br class="">
On Nov 11, 2014, at 6:50 AM, Simon Atanasyan <<a href="mailto:simon@atanasyan.com" class="">simon@atanasyan.com</a>> wrote:<br class="">
> I was too optimistic. It is possible to use the contentTypes field for<br class="">
> handling STO_MICROMIPS and I have a working solution but the solution<br class="">
> is really ugly. This approach has at least two the following<br class="">
> shortcomings:<br class="">
><br class="">
> 1. A MIPS ELF symbol can hold multiple STO_xxx flags stored in the<br class="">
> st_other field (STO_MIPS_PIC, STO_MIPS_MICROMIPS, STO_MIPS_MIPS16<br class="">
> ...). Sometimes these flags can be even combined. If we use the<br class="">
> contentTypes field, we have to define a separate ContentType flag for<br class="">
> each such combination. So we get a combinatorics explosion.<br class="">
><br class="">
> 2. If we handle MIPS specific ContentType flags together with other<br class="">
> flags, it is pollute the common ELF code. If we factor out the<br class="">
> processing of MIPS specific flags, we have to duplicate code because a<br class="">
> symbol with say STO_MICROMIPS flag should be processed (setup size,<br class="">
> permissions etc) the same way as a regular DefinedAtom::typeCode<br class="">
> symbol.<br class="">
><br class="">
> I considered to create a map symbol name => symbol flags, fill this<br class="">
> map while read object files, and use the map while write a linked<br class="">
> file. But I need to handle both local and global symbols and it is<br class="">
> possible to get symbols with the same name.<br class="">
><br class="">
> It looks like the only solution (if I do not miss anything else) is to<br class="">
> add one more filed to the DefinedAtom class to hold<br class="">
> target/architecture specific set of flags and modify Native and YAML<br class="">
> formats correspondingly. Interpretation of this field is completely<br class="">
> target/architecture dependent.<br class="">
><br class="">
> Any opinions?<br class="">
><br class="">
> On Thu, Nov 6, 2014 at 7:09 PM, Simon Atanasyan <<a href="mailto:simon@atanasyan.com" class="">simon@atanasyan.com</a>> wrote:<br class="">
>> STO_MIPS16 and STO_MICROMIPS flags denote that the symbol use a<br class="">
>> different "compressed" instructions encoding. Both these flags can be<br class="">
>> combined with usual "visibility" flags.<br class="">
>><br class="">
>> It looks like adding new flag into the contentTypes set might solve<br class="">
>> the problem. Thanks for the idea. I try to implement it.<br class="">
>><br class="">
>> On Thu, Nov 6, 2014 at 6:52 PM, Shankar Easwaran<br class="">
>> <<a href="mailto:shankare@codeaurora.org" class="">shankare@codeaurora.org</a>> wrote:<br class="">
>>> One way to do that is to add new visibility / contentTypes (whatever is<br class="">
>>> relevant) added for each of the values st_other picks ?<br class="">
>>><br class="">
>>> What are the other values st_other can take on MIPS ?<br class="">
>>><br class="">
>>> On 11/6/2014 8:50 AM, Simon Atanasyan wrote:<br class="">
>>>> On MIPS st_other field in the ELF symbols table might contain some<br class="">
>>>> additional MIPS-specific flags besides visibility ones. These flags<br class="">
>>>> should be copied to the output linked file. If YAML => Native<br class="">
>>>> conversion is switched off, there is no problem. But in case of the<br class="">
>>>> conversion we lose st_other field values.<br class="">
>>>><br class="">
>>>> So I need an advice how to keep this information. Is it a good idea to<br class="">
>>>> extend YAML and Native format to store these data? Is there any<br class="">
>>>> alternative solutions?<br class="">
><br class="">
> --<br class="">
> Simon Atanasyan<br class="">
<br class="">
</div></div></blockquote></div><br class=""></div>
</blockquote></div><br class=""></div>_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:LLVMdev@cs.uiuc.edu" class="">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" class="">http://llvm.cs.uiuc.edu</a><br class=""><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br class=""></div></blockquote></div><br class=""></body></html>