<div dir="ltr">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><br></div><div>program:</div><div><br></div><div><div><font face="monospace, monospace">#include <stdio.h></font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">int main(int argc, char **argv) {</font></div><div><font face="monospace, monospace">    printf("C: printf!\n");</font></div><div><font face="monospace, monospace">    puts("C: puts!\n");</font></div><div><font face="monospace, monospace">    return 0;</font></div><div><font face="monospace, monospace">}</font></div><div><br></div><div>Then I link it using i have tested it in 3.9, 4.0 and 4.1 versions:</div><div><br></div><div><font face="monospace, monospace">clang -c hello.c</font></div><div><font face="monospace, monospace">lld -flavor darwin hello.o -o h1  -lc<br></font></div><div><br></div><div>When i execute the binary h1 the system gives me the following error:</div><div><br></div><div><div><font face="monospace, monospace">C: printf!</font></div><div><font face="monospace, monospace">dyld: lazy symbol binding failed: BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB has segment 4 which is too large (0..3)</font></div><div><font face="monospace, monospace">dyld: BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB has segment 4 which is too large (0..3)</font></div><div><font face="monospace, monospace">Trace/BPT trap: 5</font></div></div><div><br></div><div>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">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">MachONormalizedFileBinaryWrite::lazyBindingInfo</font> result.</div><div><br></div><div>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">MachONormalizedFileBinaryWrite::buildLazyBindInfo</font> has ,since is generated after the pass.</div><div><br></div><div>I'll be glad to receive guidance so i can fix it myself and familiarize myself with the code.<br></div><div><br></div><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">Patricio<div><br></div></div></div>
</div></div>