<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=""><div class="">From the top of ld64’s ld.cpp</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class="">// start temp HACK for cross builds</div><div class="">extern "C" double log2 ( double );</div><div class="">//#define __MATH__</div><div class="">// end temp HACK for cross builds</div></blockquote><div class=""><br class=""></div><div class="">and a bit further down</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>//fprintf(stderr, "FinalSection(%16s, %16s) _segmentOrder=%3d, _sectionOrder=0x%08X\n",<br class=""><span class="Apple-tab-span" style="white-space:pre"> </span>//<span class="Apple-tab-span" style="white-space:pre"> </span>this->segmentName(), this->sectionName(), _segmentOrder, _sectionOrder);<br class=""><br class=""></div><div class="">and a bit further down again ld64 uses qsort instead of std::sort</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>//fprintf(stderr, "UNSORTED final sections:\n");<br class=""><span class="Apple-tab-span" style="white-space:pre"> </span>//for (std::vector<ld::Internal::FinalSection*>::iterator it = sections.begin(); it != sections.end(); ++it) {<br class=""><span class="Apple-tab-span" style="white-space:pre"> </span>//<span class="Apple-tab-span" style="white-space:pre"> </span>fprintf(stderr, "final section %p %s/%s\n", (*it), (*it)->segmentName(), (*it)->sectionName());<br class=""><span class="Apple-tab-span" style="white-space:pre"> </span>//}<br class=""><span class="Apple-tab-span" style="white-space:pre"> </span>qsort(§ions[0], sections.size(), sizeof(FinalSection*), &InternalState::FinalSection::sectionComparer);<br class=""><span class="Apple-tab-span" style="white-space:pre"> </span>//fprintf(stderr, "SORTED final sections:\n");<br class=""><span class="Apple-tab-span" style="white-space:pre"> </span>//for (std::vector<ld::Internal::FinalSection*>::iterator it = sections.begin(); it != sections.end(); ++it) {<br class=""><span class="Apple-tab-span" style="white-space:pre"> </span>//<span class="Apple-tab-span" style="white-space:pre"> </span>fprintf(stderr, "final section %p %s/%s\n", (*it), (*it)->segmentName(), (*it)->sectionName());<br class=""><span class="Apple-tab-span" style="white-space:pre"> </span>//}<br class=""><br class=""></div><div class="">I doubt that would pass the LLVM projects’ code review. I could also raise an issue or fix this ld64 bug if LLD mach-o was supported and it was in the LLVM bugzilla: “Invalid zero page virtual address when linking with -static -image_base 0x7ffe00000000”.</div><div class=""><br class=""></div><div class="">- <a href="https://gist.github.com/michaeljclark/0a805652ec4be987a782afb902f06a99" class="">https://gist.github.com/michaeljclark/0a805652ec4be987a782afb902f06a99</a></div><div class=""><br class=""></div><div class="">I’m not using Objective-C so LLD may well fit my purposes. Now determined to try out LLD on macos :-D</div><br class=""><div><blockquote type="cite" class=""><div class="">On 7 Jun 2017, at 11:30 AM, 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="">Hi Michael,<div class=""><br class=""></div><div class="">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 class=""><div class="gmail_quote">On Tue, Jun 6, 2017 at 4:08 PM, Michael Clark via llvm-dev <span dir="ltr" class=""><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class="">Hi Folks,</div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">- <a href="https://opensource.apple.com/source/ld64/ld64-274.2/src/ld/Resolver.cpp.auto.html" target="_blank" class="">https://opensource.apple.<wbr class="">com/source/ld64/ld64-274.2/<wbr class="">src/ld/Resolver.cpp.auto.html</a></div><div class=""><br class=""></div><div class="">There are 4 special symbol prefixes for the mach-o linker synthesised symbols:</div><div class=""><br class=""></div>- segment$start$__SEGMENT<br class="">- segment$end$__SEGMENT<br class="">- section$start$__SEGMENT$__<wbr class="">section<br class=""><div class="">- section$end$__SEGMENT$__<wbr class="">section</div><div class=""><br class=""></div><div class="">In asm:</div><div class=""><br class=""></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class=""><div class="">/* get imagebase and slide for static PIE and ASLR support in x86_64-xnu-musl */</div><div class=""><br class=""></div><div class="">.align 3</div><div class="">__image_base:</div><div class="">.quad segment$start$__TEXT</div><div class="">__start_static:</div><div class="">.quad start</div><div class="">.text</div><div class="">.align 3</div><div class="">.global start</div><div class="">start:</div><div class=""> xor %rbp,%rbp</div><div class=""> mov %rsp,%rdi</div><div class=""> andq $-16,%rsp</div><div class=""> movq __image_base(%rip), %rsi</div><div class=""> leaq start(%rip), %rdx</div><div class=""> subq __start_static(%rip), %rdx</div><div class=""> call __start_c</div></blockquote><div class=""><br class=""></div><div class="">In C:</div><div class=""><br class=""></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class=""><div class="">/* run C++ constructors in __libc_start_main for x86_64-xnu-musl */</div><div class=""><br class=""></div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class="">typedef void (*__init_fn)(int, char **, char **, char **);<br class="">extern __init_fn __init_start __<wbr class="">asm("section$start$__DATA$__<wbr class="">mod_init_func");<br class="">extern __init_fn __init_end __asm("section$end$__DATA$__<wbr class="">mod_init_func”);<br class=""><div class=""><br class=""></div><div class="">static void __init_mod(int argc, char **argv, char **envp, char **applep)</div><div class="">{</div><div class=""> for (__init_fn *p = &__init_start; p < &__init_end; ++p) {</div><div class=""> (*p)(argc, argv, envp, applep);</div><div class=""> }</div><div class="">}</div></blockquote><div class=""><br class=""></div><div class="">Michael.</div><div class=""><br class=""></div><div class="">[1] <a href="https://github.com/opensource-apple/xnu/blob/dc0628e187c3148723505cf1f1d35bb948d3195b/bsd/kern/kern_exec.c#L1072-L1111" target="_blank" class="">https://github.com/<wbr class="">opensource-apple/xnu/blob/<wbr class="">dc0628e187c3148723505cf1f1d35b<wbr class="">b948d3195b/bsd/kern/kern_exec.<wbr class="">c#L1072-L1111</a></div></div><br class="">______________________________<wbr class="">_________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/<wbr class="">mailman/listinfo/llvm-dev</a><br class="">
<br class=""></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></body></html>