<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Oct 6, 2016, at 2:01 AM, Johan Engelen <<a href="mailto:jbc.engelen@gmail.com" class="">jbc.engelen@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote">On Wed, Oct 5, 2016 at 5:44 PM, Mehdi Amini <span dir="ltr" class=""><<a href="mailto:mehdi.amini@apple.com" target="_blank" class="">mehdi.amini@apple.com</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class=""><br class="">
> But some other options are not expressed in IR (e.g. FunctionSections, relocation model).<br class="">
> I see that I can pass LLVM options to the plugin, so one way is to pass all non-default options as plugin-opt cmdline flags. I can't find code in Clang that does that though.<br class="">
<br class="">
</span>The usual model is that the linker interacts with the LTO codegen to pass these options.<br class=""></blockquote><div class=""><br class=""></div><div class="">My question is: how does the linker know what to tell the LTO codegen? ;)</div></div></div></div></div></blockquote><div><br class=""></div><div>Well the linker knows some stuff on what it is linking. In the link I sent:</div><div><br class=""></div><div>- The first if depends a dynamic library or an executable</div><div>- The second branch is triggered by “-static" on the command line.</div><div>- The last one is the architecture we’re linking for.</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Assuming you’d link a program on MacOS with ThinLTO for instance, the linker will derive the “pic model” the following way: <a href="https://github.com/Apple-FOSS-Mirror/ld64/blob/master/src/ld/parsers/lto_file.cpp#L594" rel="noreferrer" target="_blank" class="">https://github.com/Apple-FOSS-<wbr class="">Mirror/ld64/blob/master/src/<wbr class="">ld/parsers/lto_file.cpp#L594</a> (not the call to ::lto_codegen_set_pic_model).<br class=""></blockquote><div class=""><br class=""></div><div class="">Thanks a lot for the pointer. (didn't even realize that `ld64` source is so easily available) This lead me to where `ld64` receives the options, so I can browse through that to see what it accepts (it accepts `-mllvm` so that's nice).</div></div></div></div></blockquote><div><br class=""></div></div>All the -mllvm options are really not intended to be a stable interface though.<div class=""><br class=""></div><div class="">— </div><div class="">Mehdi</div></body></html>