<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="">LLD Mach-O support was experimental and AFAIK it is unmaintained. It lacks a lots of features to be usable. The only supported linker on macOS is ld64.<div class=""><br class=""><div><blockquote type="cite" class=""><div class="">Le 10 juil. 2017 à 17:36, Patricio Villalobos via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> a écrit :</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">I discovered that lld for darwin is generating the wrong code for lazy bindings in the __stub_helper section (at least for osx 10.12). This is the way i can reproduce this problem, using this program:<div class=""><br class=""></div><div class="">program:</div><div class=""><br class=""></div><div class=""><div class=""><font face="monospace, monospace" class="">#include <stdio.h></font></div><div class=""><font face="monospace, monospace" class=""><br class=""></font></div><div class=""><font face="monospace, monospace" class="">int main(int argc, char **argv) {</font></div><div class=""><font face="monospace, monospace" class="">    printf("C: printf!\n");</font></div><div class=""><font face="monospace, monospace" class="">    puts("C: puts!\n");</font></div><div class=""><font face="monospace, monospace" class="">    return 0;</font></div><div class=""><font face="monospace, monospace" class="">}</font></div><div class=""><br class=""></div><div class="">Then I link it using i have tested it in 3.9, 4.0 and 4.1 versions:</div><div class=""><br class=""></div><div class=""><font face="monospace, monospace" class="">clang -c hello.c</font></div><div class=""><font face="monospace, monospace" class="">lld -flavor darwin hello.o -o h1  -lc<br class=""></font></div><div class=""><br class=""></div><div class="">When i execute the binary h1 the system gives me the following error:</div><div class=""><br class=""></div><div class=""><div class=""><font face="monospace, monospace" class="">C: printf!</font></div><div class=""><font face="monospace, monospace" class="">dyld: lazy symbol binding failed: BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB has segment 4 which is too large (0..3)</font></div><div class=""><font face="monospace, monospace" class="">dyld: BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB has segment 4 which is too large (0..3)</font></div><div class=""><font face="monospace, monospace" class="">Trace/BPT trap: 5</font></div></div><div class=""><br class=""></div><div class="">Investigating the code, it seems that the problem is that the asm code generated in the file StubPass.cpp, specifically in the line <a href="https://github.com/llvm-mirror/lld/blob/master/lib/ReaderWriter/MachO/StubsPass.cpp#L323" class="">323</a> ,when it adds, what it seems an arbitrary number (12) to the offset into the lazy bind opcodes section, but it should be calculated depending on the <font face="monospace, monospace" class="">MachONormalizedFileBinaryWrite::lazyBindingInfo</font> result.</div><div class=""><br class=""></div><div class="">I confirmed this bug by patching the code manually in the binary and writing the right offset in the asm code (__stub_helper). I'm yet not familiarized with the code , so i can't fix it right now , Im unable to find the information of the symbols that <font face="monospace, monospace" class="">MachONormalizedFileBinaryWrite::buildLazyBindInfo</font> has ,since is generated after the pass.</div><div class=""><br class=""></div><div class="">I'll be glad to receive guidance so i can fix it myself and familiarize myself with the code.<br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div>-- <br class=""><div class="gmail_signature"><div dir="ltr" class="">Patricio<div class=""><br class=""></div></div></div>
</div></div>
_______________________________________________<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="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br class=""></div></blockquote></div><br class=""></div></body></html>