<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jun 6, 2017 at 11:14 PM, Michael Clark via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</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">OK. I see that the Mach-O linker is not even built when LLD is enabled in Release_40, only the PE/COFF and ELF linkers are built.<div><br></div><div>From looking at reviews it appears that Clang was able to be linked with LLD on Darwin about 2 years ago, so Mach-O support seems to have regressed.</div></div></blockquote><div><br></div><div>Only a few changes have been made to the Mach-O port in the last two years, so I'd doubt if it has regressed. It could be the case that clang's output has changed in such a way that the linker is not able to handle it.</div><div> </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>Curious as to pointers to primordial branches with whatever needs to be resurrected. I couldn’t find any Mach-O cmake flags to enable its build. A pointer to a branch or tag that might have a working Mach-O LLD would be a start.<div><div class="h5"><br><div><br><div><blockquote type="cite"><div>On 7 Jun 2017, at 11:38 AM, Michael Clark <<a href="mailto:michaeljclark@mac.com" target="_blank">michaeljclark@mac.com</a>> wrote:</div><br class="m_-7136958054444710928Apple-interchange-newline"><div><div style="word-wrap:break-word">Hi Rui,<div><br></div><div>The motivation would be primarily that LLVM/Clang/LLD are community projects such that if I or someone in the community added support for e.g. symbol aliases, then it could be reviewed and potentially merged. ld64 on the other hand does not have a community process for patch submission and code review that I am aware of so its unlikely that if someone from the community came up with a patch to support aliases that it would be merged.</div><div><br></div><div>In that case I might check out the LLD code and try linking “x86_64-xnu-musl” with it. My requirements are likely simpler than Apple’s however I do need symbol aliases and these are not supported by ld64. The linker synthesised symbols are likely not too difficult to add if they are not present… now on my to do list…</div><div><br></div><div>Michael.</div><div><br><div><blockquote type="cite"><div>On 7 Jun 2017, at 11:30 AM, Rui Ueyama <<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>> wrote:</div><br class="m_-7136958054444710928Apple-interchange-newline"><div><div dir="ltr">Hi Michael,<div><br></div><div>The Mach-O version of LLD is not being developed actively, and if some feature is missing, it is likely that it's just not implemented. What is your motivation to use LLD instead of ld64?</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jun 6, 2017 at 4:08 PM, Michael Clark via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</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"><div>Hi Folks,</div><div><br></div><div>I have a question regarding LLD support for ld64 mach-o linker synthesised symbols. I did a quick search of the LLD source and I can not find support for them so before I start trying to use lld I thought I would ask.</div><div><br></div><div>I have found a couple of cases where they are essential. i.e. where there is no other way to get the required information, such as getting the address of the mach-o headers of the current process, with ASLR enabled, if the process is not dyld as exec on macOS only provides the mach header address to dyld (*1). They are used inside of dyld and I am now using them in “x86_64-xnu-musl”.</div><div><br></div><div>It’s possible to resolve a mach-o segment offset or a mach-o section offset using these special ld64 linker synthesised symbols. See resolveUndefines:</div><div><br></div><div>- <a href="https://opensource.apple.com/source/ld64/ld64-274.2/src/ld/Resolver.cpp.auto.html" target="_blank">https://opensource.apple.com<wbr>/source/ld64/ld64-274.2/src/<wbr>ld/Resolver.cpp.auto.html</a></div><div><br></div><div>There are 4 special symbol prefixes for the mach-o linker synthesised symbols:</div><div><br></div>- segment$start$__SEGMENT<br>- segment$end$__SEGMENT<br>- section$start$__SEGMENT$__sect<wbr>ion<br><div>- section$end$__SEGMENT$__sectio<wbr>n</div><div><br></div><div>In asm:</div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>/* get imagebase and slide for static PIE and ASLR support in x86_64-xnu-musl */</div><div><br></div><div>.align 3</div><div>__image_base:</div><div>.quad segment$start$__TEXT</div><div>__start_static:</div><div>.quad start</div><div>.text</div><div>.align 3</div><div>.global start</div><div>start:</div><div>       xor %rbp,%rbp</div><div>       mov %rsp,%rdi</div><div>       andq $-16,%rsp</div><div>       movq __image_base(%rip), %rsi</div><div>       leaq start(%rip), %rdx</div><div>       subq __start_static(%rip), %rdx</div><div>       call __start_c</div></blockquote><div><br></div><div>In C:</div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>/* run C++ constructors in __libc_start_main for x86_64-xnu-musl */</div><div><br></div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px">typedef void (*__init_fn)(int, char **, char **, char **);<br>extern __init_fn  __init_start  __asm<wbr>("section$start$__DATA$__mod_<wbr>init_func");<br>extern __init_fn  __init_end    __asm("section$end$__DATA$__<wbr>mod_init_func”);<br><div><br></div><div>static void __init_mod(int argc, char **argv, char **envp, char **applep)</div><div>{</div><div>        for (__init_fn *p = &__init_start; p < &__init_end; ++p) {</div><div>                (*p)(argc, argv, envp, applep);</div><div>        }</div><div>}</div></blockquote><div><br></div><div>Michael.</div><div><br></div><div>[1] <a href="https://github.com/opensource-apple/xnu/blob/dc0628e187c3148723505cf1f1d35bb948d3195b/bsd/kern/kern_exec.c#L1072-L1111" target="_blank">https://github.com/opensou<wbr>rce-apple/xnu/blob/dc0628e187c<wbr>3148723505cf1f1d35bb948d3195b/<wbr>bsd/kern/kern_exec.c#L1072-<wbr>L1111</a></div></div><br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">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></blockquote></div><br></div></div></div></blockquote></div><br></div></div></div></div></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>