<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hello,<div class=""><br class=""></div><div class="">As the guy that came up with the “temporary” Mach-O hack to use .subsections_via_symbols a long while back I wanted throw out my thinking, though these are old thoughts before the atom concept existed.</div><div class=""><br class=""></div><div class="">Back in the day we needed some way to do dead code stripping at the static link editor level as code coming from the Mac OS 9 world would simply not link without this feature moving to what was to become Mac OS X (much code that was not used that had references to undefined symbols). So we needed a quick hack and an static link editor that implemented dead code stripping asap.</div><div class=""><br class=""></div><div class="">I did not feel it was the linker’s place to divide up sections into smaller parts as this really should be done by the compiler that understood the language semantics it was translating. As things like blocks of code with multiple entry points (what Fortran does), C++ constructs as explicit vs implicit Instantiation, and which blocks of code, data, exception info, and debug info to make up a group (for things like comdat).</div><div class=""><br class=""></div><div class="">But I felt to do this right we would have to extend the object file format and the assembly language to add support for subsections. Then let the compiler group things in to the smallest indivisible part of the language for translation. Then symbols would be part of a specific subsection and subsections could have zero or more symbols. Having zero symbols for some blocks and them only having references to the assembly temporary symbols that got removed I felt would be cleaner that carrying along fake symbols that must be there to divide up the section later.</div><div class=""><br class=""></div><div class="">The relocation entries would be per subsection and the subsection would carry the alignment directly (so it would not have to be inferred by the hack of dividing up the section). The design would allow subsections to types (regular, literals, etc), and signature symbols (weak and non-weak) for things like comdat. </div><div class=""><br class=""></div><div class="">But to do this it would have had us make extensive changes to our BSD derived Mach-O object file format that we started with. As we had a symbol struct with only an 8 bit section number and we had another hack back in the 32-bit days to do scattered relocation entries based on 24-bits of address reference to allow references for pic code like RefSymbol - PicBaseSym.</div><div class=""><br class=""></div><div class="">All this could have been changed but it was deemed too aggressive and the atom model of the ld64 design prevailed as it exists today in the Mac OS X linker.</div><div class=""><br class=""></div><div class="">But today with clang one could see the compiler being the one deciding the smallest unit based on the target. In the Mac OS X and iOS cases that would be the atoms, and for other targets that would be sections. So maybe by stepping back up the compiler chain the LLD improvement plan could be better.</div><div class=""><br class=""></div><div class="">Some old thoughts,</div><div class="">Kev</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On May 11, 2015, at 12:01 PM, Rui Ueyama <<a href="mailto:ruiu@google.com" class="">ruiu@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote">On Mon, May 11, 2015 at 11:21 AM, David Blaikie <span dir="ltr" class=""><<a href="mailto:dblaikie@gmail.com" target="_blank" class="">dblaikie@gmail.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><br class=""><div class="gmail_extra"><br class=""><div class="gmail_quote"><span class="">On Mon, May 11, 2015 at 11:13 AM, Rui Ueyama <span dir="ltr" class=""><<a href="mailto:ruiu@google.com" target="_blank" class="">ruiu@google.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">If you attach two ore more symbols along with offsets to a chunk of data, it would be a pretty similar to a section. That means that if you want to do something on the atom model, now you have to treat the atoms like sections. </div></blockquote></span><div class=""><br class="">What do you lose/pay by having to treat the atoms like sections?<br class=""></div></div></div></div></blockquote><div class=""><br class=""></div><div class="">I can think of a few, maybe more.</div><div class=""><br class=""></div><div class="">An atom model with multiple names is not as simple as before.</div><div class=""><br class=""></div><div class="">We still need to read all relocation tables to complete a graph as they form edges, even for duplicate COMDAT sections.</div><div class=""><br class=""></div><div class="">It still can't model some section-linker features, such as "select largest" COMDAT sections, because the new atom is still different from the section. (This is not an issue if we really treat atoms like sections, but that means in turn we would be going to create a Mach-O linker based on the section model.)</div><div class=""><br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""> </div><div class=""><div class="h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">I looks like a bad mix of the two.</div><div class="gmail_extra"><br class=""><div class="gmail_quote"><span class="">On Mon, May 11, 2015 at 10:56 AM, James Y Knight <span dir="ltr" class=""><<a href="mailto:jyknight@google.com" target="_blank" class="">jyknight@google.com</a>></span> wrote:<br class=""></span><div class=""><div class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">Nobody in this long thread appears to have yet explained why it's a bad idea to allow atomic fragments of code/data (whatever you want to call them: atoms, sections, who cares) to have more than one global symbol attached to them in LLD's internal representation.<div class=""><br class=""></div><div class="">That seems like it'd provide the flexibility needed for ELF without hurting MachO. If that change'd allow you to avoid splitting the linker into two-codebases-in-one, isn't that preferable?</div><div class=""><br class=""></div></div><div class=""><div class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Thu, May 7, 2015 at 9:38 AM, Joerg Sonnenberger <span dir="ltr" class=""><<a href="mailto:joerg@britannica.bec.de" target="_blank" class="">joerg@britannica.bec.de</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Wed, May 06, 2015 at 09:28:54PM -0500, Shankar Easwaran wrote:<br class="">
> The atom model allowed lld to have a single intermediate<br class="">
> representation for all the formats ELF/COFF/Mach-O. The native model<br class="">
> allowed the intermediate representation to be serialized to disk<br class="">
> too. If the intermediate representations data structures are made<br class="">
> available to scripting languages most of all linker script script<br class="">
> layout can be implemented by the end user. A new language also can<br class="">
> be developed as most of the users need it and it can work on this<br class="">
> intermediate representation.<br class="">
><br class="">
> The atom model also simplified a lot of usecases like garbage<br class="">
> collection and having the resolve to deal just with atoms. The<br class="">
> section model would sound simple from the outside but it it has its<br class="">
> own challenges like separating the symbol information from section<br class="">
> information.<br class="">
<br class="">
</span>I'm sorry, but I don't get why any of this requires an atom based<br class="">
representation. Saying that a single intermediate representation for<br class="">
ELF/COFF on one hand and Mach-O on the other is ironic given the already<br class="">
mentioned hacks on various layers. Garbage collection doesn't become<br class="">
more expensive when attaching more than one symbol to each code/data<br class="">
fragment. Symbol resolution doesn't change when attaching more than one<br class="">
symbol to each code/data fragment. The list goes on. The single natural<br class="">
advantage is that you can use a single pointer to the canonical symbol<br class="">
from a code/data fragment and don't have to use a list/array. Given the<br class="">
necessary and expensive hacks for splitting sections into (pseudo)<br class="">
atoms, that doesn't feel like a win. So once again, what actual<br class="">
advantages for ELF or COFF have been created by the atom model? Mach-O<br class="">
hardly counts as it doesn't allow the flexibility of the section model<br class="">
as has been discussed before.<br class="">
<span class=""><font color="#888888" class=""><br class="">
Joerg<br class="">
</font></span><div class=""><div class="">_______________________________________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank" class="">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu/" target="_blank" class="">http://llvm.cs.uiuc.edu</a><br class="">
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br class="">
</div></div></blockquote></div><br class=""></div>
</div></div><br class="">_______________________________________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank" class="">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu/" target="_blank" class="">http://llvm.cs.uiuc.edu</a><br class="">
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br class="">
<br class=""></blockquote></div></div></div><br class=""></div>
<br class="">_______________________________________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank" class="">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu/" target="_blank" class="">http://llvm.cs.uiuc.edu</a><br class="">
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br class="">
<br class=""></blockquote></div></div></div><br class=""></div></div>
</blockquote></div><br class=""></div></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=""></div></body></html>