<div dir="auto"><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Jan 6, 2018 12:05 PM, "Saleem Abdulrasool via llvm-dev" <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space"><div><div class="quoted-text"><blockquote type="cite"><div>On Jan 5, 2018, at 4:35 PM, Cary Coutant <<a href="mailto:ccoutant@gmail.com" target="_blank">ccoutant@gmail.com</a>> wrote:</div><br class="m_6086716265850525423Apple-interchange-newline"><div><div><blockquote type="cite"><blockquote type="cite">In general I'm in favor of the proposal. Defining a generic way to convey<br>some information from the compiler to the linker is useful, and it looks<br>like it is just a historical reason that the ELF lacks the feature at the<br>moment.<br><br>This is a scenario in which the feature is useful: when you include<br>math.h, a compiler (which is driven by some pragma) could added `-lm` to the<br>note section so that a linker automatically links libm.</blockquote></blockquote></div></div></blockquote><div><br></div></div><div>Glad to have you chime in; I know that you have quit a bit of experience from binutils and gold. I really would love to see this support be implemented there too, and having your input is certainly valuable.</div><div class="quoted-text"><br><blockquote type="cite"><div><div>I agree that this would be a very useful addition to ELF. I've always<br>wanted to reach the point where you could just type "ld main.o" and<br>have all the dependencies automatically linked in. (Go kind of<br>achieves this, I think.)<br></div></div></blockquote><div><br></div></div><div>Excellent! I think that everyone agrees that this is a useful extension to add.</div><div class="quoted-text"><br><blockquote type="cite"><div><div>I'm not in favor of using yet another note section, however. SHT_NOTE<br>sections are intended for the use of "off-axis" tools, not for<br>something the linker would need to look for. I don't want to have the<br>linker parsing individual note entries looking for notes of interest<br>to itself, and then having to decide whether to edit those entries out<br>of the larger section, or merge them together. And I also don't want<br>to key off of individual section names -- the linker is not supposed<br>to have to care about the section name. There should be a new section<br>type for this feature. This is the kind of extension that ELF was<br>designed for.<br></div></div></blockquote><div><br></div></div><div>I’m really not tied to the note approach of implementing this. I am (admittedly) abusing the notes due to a couple of behavioral aspects of them. So, the main things to realize is that this information is embedded into the object files that are built. The information should be processed by the linker and then *discarded*, none of it should be in the final binary (unless it is a relocatable link). I’m concerned about linkers which do not support this feature preserving the contents. Now, this could very well be a misconception on my part. If that is the case, then, I would say that this needs to be entirely reworked, because then adding the section sounds much nicer.</div></div></div></blockquote></div></div></div><div dir="auto"><br></div><div dir="auto">Wouldn't a special section type trigger an "unrecognized section type" error for linkers that don't support it? </div><div dir="auto"><br></div><div dir="auto">-- Sean Silva</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space"><div><div class="elided-text"><br><blockquote type="cite"><div><div><blockquote type="cite"><blockquote type="cite">I think I'm also in favor of the format, which is essentially runs of<br>null-terminated strings (*1) that are basically opaque to compilers.<br></blockquote><br>Yes. However, I think I want to clarify that we want this to be completely<br>opaque to the backend. The front end could possibly have some enhancements<br>to make this better. But, that will be a separate change, and that<br>discussion should take place then. We shouldn’t paint ourselves into a<br>corner. Basically, I think that there is some legitimate concerns here, but<br>they would not be handled at this layer, but above.<br><br><blockquote type="cite">However, you should define as a spec what options are allowed and what<br>their semantics are. We should not accept arbitrary linker options because<br>semantics of some linker options cannot be clearly defined when they appear<br>as embedded options. Just saying "this feature allows you to embed linker<br>options to object files" is too weak as a specification. You need to clearly<br>define a list of options that will be supported by linkers with their clear<br>semantics.<br></blockquote><br>Personally, I would like to see the ability to add support for additional<br>options without having to modify the compiler. That said, I think that<br>there are options which can be scary (e.g. -nopie). I think that the linker<br>should make the decision of what it supports and error out on others. This<br>allows for us to enhance the support over time without a huge overhead. As<br>a starting point, I think that -l and -L are two that would be interesting.<br>I can see -u being useful as well, but the point is that we can slowly grow<br>the support after consideration by delaying the validation of the options.<br><br><blockquote type="cite">(*1) One of the big annoyances that I noticed when I was implementing the<br>same feature for COFF is that the COFF's .drctve section that contains<br>linker options have to be tokenized in the same way as the Windows command<br>line does. So it needs to interpret double quotes and backslashes correctly<br>especially when handling space-containing pathnames. This is a design<br>failure that a COFF file contains just a single string instead of runs of<br>strings that have already been tokenized.<br></blockquote></blockquote><br>I too would like to keep the linker from having to tokenize the<br>strings. I kind of agree with Rafael that there should be defined tags<br>and values, much like a .dynamic section, but I wouldn't want to have<br>values pointing to strings in yet another section, so I'd prefer<br>something in between that and a free-form null-terminated string. I<br>also wouldn't want to open up the complete list of linker options, so<br>I'd prefer a defined list of tags in string form that could easily be<br>augmented without additional backend support. We could start with,<br>perhaps, "lib" to inject a library (a la "-l"), "file" to inject an<br>object file by full name, and "path" to provide a search path (a la<br>"-L"). I don't think an equivalent for "-u" would be needed, since the<br>compiler can simply generate an undef symbol for that case. For the<br>section format, I'd suggest a series of null-terminated strings,<br>alternating between tags and values, so that no quote or escape<br>parsing is necessary.<br></div></div></blockquote><div><br></div></div><div>Sounds like we agree on the direction: we don’t want the backend to be involved in adding new options, we don’t think that all options make sense but want to be able to add options still. As to the `-u` option, Im thinking about cases were an unreferenced symbol would like to be preserved with `—gc-sections` and being built with `-ffunction-sections` and/or `-fdata-sections`.</div><div><br></div><div>So, after discussing some of the items, we ended up somewhere in-between. My current proposal is a semi-pre-tokenized linker response file. Basically, each option/parameter “pair” would be a single string entry in an array of string values. The only difference is instead of TLV entries, it is simply the raw entry. My resistance to the TLV really is driven more by the LLVM IR (which I suppose is possible to alter):</div><div><br></div><div><a href="https://llvm.org/docs/LangRef.html#automatic-linker-flags-named-metadata" target="_blank">https://llvm.org/docs/LangRef.<wbr>html#automatic-linker-flags-<wbr>named-metadata</a></div><div class="quoted-text"><br><blockquote type="cite"><div><div>For the header files, a simple syntax like<br><br> #pragma linker_directive "lib" "m"<br><br>would provide the extensibility needed to add new tags with no<br>additional support in the front end or back end.<br></div></div></blockquote><div><br></div></div><div>I *really* wish to avoid this discussion right now. I am happy to loop you into a subsequent thread discussing that. I figure that this will be a much more contentious issue as syntax is something everyone has differing opinions on. I’m trying to split this work into three distinct pieces: the frontend support to emit the information, the backend to emit this into the object, and the linker to use it.</div><div><br></div><div>As an aside, personally, I was thinking more along the lines of `#pragma comment(lib, “m”)`.</div><br><blockquote type="cite"><div><div>-cary<br></div></div></blockquote></div><br></div><br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div></div></div>