LLD/Mach-O - how to work around this bug?

I filed this bug today: https://bugs.llvm.org/show_bug.cgi?id=32376

I understand that the Mach-O linker is not under active development, but there must be some way to work around this bug. Does anyone have a clue?

This trivial IR file gives “dyld: lazy symbol binding failed: bad lazy bind info” at runtime when linked with:

lld -flavor darwin -demangle -dynamic -arch x86_64 -macosx_version_min 10.10.0 -pie -o ./tmp_exe ./tmp_exe.o -lSystem

When linking with the system linker instead, with the same arguments, it works fine. IR file:

target datalayout = “e-m:o-i64:64-f80:128-n8:16:32:64-S128”
target triple = “x86_64-apple-darwin-unknown”

@0 = internal unnamed_addr constant [9 x i8] c"0: %llu\0A\00", align 1

; Function Attrs: nounwind
define i32 @main(i32, i8** nocapture nonnull readnone) local_unnamed_addr #0 {
%putchar = call i32 @putchar(i32 10)
%2 = call i32 (i8*, …) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @0, i64 0, i64 0), i64 0)
ret i32 0

; Function Attrs: nounwind
declare i32 @printf(i8* nocapture readonly, …) #0

declare i32 @putchar(i32) #0

attributes #0 = { nounwind }

CC'ing the owners as they may have ideas. Please consider that lld
MachO hasn't been touched in 6-9 months for anything real, at least.
Even if you work around this bug, chances are you'll find many others.
In other words, don't expect to be on par with ld64.

Hello Andrew,

If you want to try to figure out what is up with the lazy binding info you might try running top of tree llvm-objdump with -lazy-bind to see what error it gives you (that is with my change from Monday with r298292). The other thing you can do on a MacOS machine is:

xcrun dyldinfo -opcodes ./tmp_exe

to show the bind opcodes that the error message from llvm-objdump should be referring to. That may give you a start as to what is wrong if you want to try to fix the problem in lld.

My thoughts,