<div dir="ltr">This is release_50 branch. The LLVM IR file pasted at the bottom of this email causes LLD to hit unreachable. And this fixes it for me:<div><br></div><div><div>diff --git a/lld/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp b/lld/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp</div><div>index aee9959ca6b..efe23abb914 100644</div><div>--- a/lld/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp</div><div>+++ b/lld/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp</div><div>@@ -621,7 +621,7 @@ void ArchHandler_x86_64::applyFixupFinal(</div><div>     // Fall into llvm_unreachable().</div><div>     break;</div><div>   }</div><div>-  llvm_unreachable("invalid x86_64 Reference Kind");</div><div>+  return;</div><div> }</div><div><br></div><div> void ArchHandler_x86_64::applyFixupRelocatable(const Reference &ref,</div></div><div><br></div><div>Without this "fix":</div><div>$ ~/local/llvm5/bin/clang -c test.ll<br></div><div><div>$ ~/local/llvm5/bin/lld -flavor darwin -o test test.o -arch x86_64 -lSystem</div><div>warning: -sdk_version is required when emitting min version load command.  Setting sdk version to match provided min version</div><div>invalid x86_64 Reference Kind</div><div>UNREACHABLE executed at /Users/andy/Downloads/llvm-project/lld/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp:624!</div><div>0  lld 0x0000000101730af5 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37</div><div>Stack dump:</div><div>0.<span style="white-space:pre">  </span>Program arguments: /Users/andy/local/llvm5/bin/lld -flavor darwin -o test test.o -arch x86_64 -lSystem</div><div>Abort trap: 6</div></div><div><br></div><div>I understand that this is:</div><div>1. Not a satisfying fix to the underlying problem</div><div>2. The MACHO code in LLD is bit rotting right now and nobody cares about it</div><div><br></div><div><br></div><div>Can we have it as a workaround until anyone is ready to take responsibility for this codebase?</div><div><br></div><div>This makes all the Zig behavior tests pass on MacOS.</div><div><br></div><div><br></div><div>test.ll:</div><div><div>; ModuleID = 'test'</div><div>source_filename = "test"</div><div>target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"</div><div>target triple = "x86_64-apple-darwin-unknown"</div><div><br></div><div>%"[]u8" = type { i8*, i64 }</div><div><br></div><div>@__zig_panic_implementation_provided = internal unnamed_addr constant i1 true, align 1</div><div>@assert.1 = internal unnamed_addr constant void (i1)* @assert, align 8</div><div>@is_test = internal unnamed_addr constant i1 false, align 1</div><div>@0 = internal unnamed_addr constant i8* getelementptr inbounds ([24 x i8], [24 x i8]* @1, i64 0, i64 0), align 8</div><div>@1 = internal unnamed_addr constant [24 x i8] c"reached unreachable code", align 16</div><div>@2 = internal unnamed_addr constant { i8*, i64 } { i8* getelementptr inbounds ([24 x i8], [24 x i8]* @1, i64 0, i64 0), i64 24 }, align 8</div><div>@3 = internal unnamed_addr constant i8* getelementptr inbounds ([17 x i8], [17 x i8]* @4, i64 0, i64 0), align 8</div><div>@4 = internal unnamed_addr constant [17 x i8] c"assertion failure", align 16</div><div>@5 = internal unnamed_addr constant { i8*, i64 } { i8* getelementptr inbounds ([17 x i8], [17 x i8]* @4, i64 0, i64 0), i64 17 }, align 8</div><div><br></div><div>; Function Attrs: nobuiltin nounwind sspstrong</div><div>define internal fastcc void @assert(i1) unnamed_addr #0 !dbg !25 {</div><div>Entry:</div><div>  %ok = alloca i1, align 1</div><div>  store i1 %0, i1* %ok</div><div>  call void @llvm.dbg.declare(metadata i1* %ok, metadata !31, metadata !32), !dbg !33</div><div>  %1 = load i1, i1* %ok, !dbg !34</div><div>  %2 = icmp eq i1 %1, false, !dbg !37</div><div>  br i1 %2, label %Then, label %Else, !dbg !37</div><div><br></div><div>Then:                                             ; preds = %Entry</div><div>  %3 = load i8*, i8** getelementptr inbounds ({ i8*, i64 }, { i8*, i64 }* @2, i32 0, i32 0), !dbg !38</div><div>  %4 = load i64, i64* getelementptr inbounds ({ i8*, i64 }, { i8*, i64 }* @2, i32 0, i32 1), !dbg !38</div><div>  call coldcc void @__zig_panic(i8* %3, i64 %4), !dbg !38</div><div>  unreachable, !dbg !38</div><div><br></div><div>Else:                                             ; preds = %Entry</div><div>  br label %EndIf2, !dbg !41</div><div><br></div><div>EndIf2:                                           ; preds = %Else</div><div>  ret void, !dbg !42</div><div>}</div><div><br></div><div>; Function Attrs: nobuiltin nounwind sspstrong</div><div>define i32 @main(i32, i8** nonnull) #0 !dbg !43 {</div><div>Entry:</div><div>  %argc = alloca i32, align 4</div><div>  %argv = alloca i8**, align 8</div><div>  store i32 %0, i32* %argc</div><div>  call void @llvm.dbg.declare(metadata i32* %argc, metadata !51, metadata !32), !dbg !54</div><div>  store i8** %1, i8*** %argv</div><div>  call void @llvm.dbg.declare(metadata i8*** %argv, metadata !52, metadata !32), !dbg !55</div><div>  call fastcc void @nonConstSwitch(i3 2), !dbg !56</div><div>  ret i32 0, !dbg !59</div><div>}</div><div><br></div><div>; Function Attrs: cold nobuiltin noreturn nounwind</div><div>define linkonce coldcc void @__zig_panic(i8* nonnull readonly, i64) #1 !dbg !60 {</div><div>Entry:</div><div>  %2 = alloca %"[]u8", align 8</div><div>  %message_ptr = alloca i8*, align 8</div><div>  %message_len = alloca i64, align 8</div><div>  store i8* %0, i8** %message_ptr</div><div>  call void @llvm.dbg.declare(metadata i8** %message_ptr, metadata !67, metadata !32), !dbg !70</div><div>  store i64 %1, i64* %message_len</div><div>  call void @llvm.dbg.declare(metadata i64* %message_len, metadata !68, metadata !32), !dbg !71</div><div>  %3 = load i64, i64* %message_len, !dbg !72</div><div>  %4 = load i8*, i8** %message_ptr, !dbg !76</div><div>  %5 = getelementptr inbounds %"[]u8", %"[]u8"* %2, i32 0, i32 0, !dbg !76</div><div>  %6 = getelementptr inbounds i8, i8* %4, i64 0, !dbg !76</div><div>  store i8* %6, i8** %5, !dbg !76</div><div>  %7 = getelementptr inbounds %"[]u8", %"[]u8"* %2, i32 0, i32 1, !dbg !76</div><div>  %8 = sub nsw i64 %3, 0, !dbg !76</div><div>  store i64 %8, i64* %7, !dbg !76</div><div>  call fastcc void @panic(%"[]u8"* byval %2), !dbg !77</div><div>  unreachable, !dbg !77</div><div>}</div><div><br></div><div>; Function Attrs: nobuiltin nounwind sspstrong</div><div>define internal fastcc void @nonConstSwitch(i3) unnamed_addr #0 !dbg !78 {</div><div>Entry:</div><div>  %foo = alloca i3, align 1</div><div>  %val = alloca i32, align 4</div><div>  store i3 %0, i3* %foo</div><div>  call void @llvm.dbg.declare(metadata i3* %foo, metadata !82, metadata !32), !dbg !87</div><div>  %1 = load i3, i3* %foo, !dbg !88</div><div>  switch i3 %1, label %SwitchElse [</div><div>    i3 0, label %SwitchProng</div><div>    i3 1, label %SwitchProng1</div><div>    i3 2, label %SwitchProng2</div><div>    i3 3, label %SwitchProng3</div><div>  ], !dbg !88</div><div><br></div><div>SwitchProng:                                      ; preds = %Entry</div><div>  br label %SwitchEnd, !dbg !88</div><div><br></div><div>SwitchProng1:                                     ; preds = %Entry</div><div>  br label %SwitchEnd, !dbg !88</div><div><br></div><div>SwitchProng2:                                     ; preds = %Entry</div><div>  br label %SwitchEnd, !dbg !88</div><div><br></div><div>SwitchProng3:                                     ; preds = %Entry</div><div>  br label %SwitchEnd, !dbg !88</div><div><br></div><div>SwitchElse:                                       ; preds = %Entry</div><div>  %2 = load i8*, i8** getelementptr inbounds ({ i8*, i64 }, { i8*, i64 }* @2, i32 0, i32 0), !dbg !88</div><div>  %3 = load i64, i64* getelementptr inbounds ({ i8*, i64 }, { i8*, i64 }* @2, i32 0, i32 1), !dbg !88</div><div>  call coldcc void @__zig_panic(i8* %2, i64 %3), !dbg !88</div><div>  unreachable, !dbg !88</div><div><br></div><div>SwitchEnd:                                        ; preds = %SwitchProng3, %SwitchProng2, %SwitchProng1, %SwitchProng</div><div>  %4 = phi i32 [ 1, %SwitchProng ], [ 2, %SwitchProng1 ], [ 3, %SwitchProng2 ], [ 4, %SwitchProng3 ], !dbg !88</div><div>  store i32 %4, i32* %val, !dbg !89</div><div>  call void @llvm.dbg.declare(metadata i32* %val, metadata !83, metadata !32), !dbg !89</div><div>  %5 = load i32, i32* %val, !dbg !90</div><div>  %6 = icmp eq i32 %5, 3, !dbg !92</div><div>  call fastcc void @assert(i1 %6), !dbg !93</div><div>  ret void, !dbg !94</div><div>}</div><div><br></div><div>; Function Attrs: nobuiltin noreturn nounwind sspstrong</div><div>define internal fastcc void @panic(%"[]u8"* byval nonnull readonly) unnamed_addr #2 !dbg !95 {</div><div>Entry:</div><div>  call void @llvm.dbg.declare(metadata %"[]u8"* %0, metadata !104, metadata !32), !dbg !105</div><div>  br label %WhileCond, !dbg !106</div><div><br></div><div>WhileCond:                                        ; preds = %WhileCond, %Entry</div><div>  br label %WhileCond, !dbg !106</div><div>}</div><div><br></div><div>; Function Attrs: nounwind readnone speculatable</div><div>declare void @llvm.dbg.declare(metadata, metadata, metadata) #3</div><div><br></div><div>; Function Attrs: nounwind</div><div>declare void @llvm.stackprotector(i8*, i8**) #4</div><div><br></div><div>attributes #0 = { nobuiltin nounwind sspstrong "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "stack-protector-buffer-size"="4" }</div><div>attributes #1 = { cold nobuiltin noreturn nounwind "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" }</div><div>attributes #2 = { nobuiltin noreturn nounwind sspstrong "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "stack-protector-buffer-size"="4" }</div><div>attributes #3 = { nounwind readnone speculatable }</div><div>attributes #4 = { nounwind }</div><div><br></div><div>!llvm.module.flags = !{!0}</div><div>!<a href="http://llvm.dbg.cu">llvm.dbg.cu</a> = !{!1}</div><div><br></div><div>!0 = !{i32 2, !"Debug Info Version", i32 3}</div><div>!1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "zig 0.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !3, globals: !19)</div><div>!2 = !DIFile(filename: "test", directory: ".")</div><div>!3 = !{!4, !12}</div><div>!4 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Foo", scope: !5, file: !5, line: 17, baseType: !6, size: 8, align: 8, elements: !7)</div><div>!5 = !DIFile(filename: "test.zig", directory: "/Users/andy/dev/zig/build")</div><div>!6 = !DIBasicType(name: "u3", size: 8, encoding: DW_ATE_unsigned)</div><div>!7 = !{!8, !9, !10, !11}</div><div>!8 = !DIEnumerator(name: "A", value: 0)</div><div>!9 = !DIEnumerator(name: "B", value: 1)</div><div>!10 = !DIEnumerator(name: "C", value: 2)</div><div>!11 = !DIEnumerator(name: "D", value: 3)</div><div>!12 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "GlobalLinkage", scope: !13, file: !13, line: 138, baseType: !6, size: 8, align: 8, elements: !14)</div><div>!13 = !DIFile(filename: "builtin.zig", directory: "/Users/andy/dev/zig/build/zig-cache")</div><div>!14 = !{!15, !16, !17, !18}</div><div>!15 = !DIEnumerator(name: "Internal", value: 0)</div><div>!16 = !DIEnumerator(name: "Strong", value: 1)</div><div>!17 = !DIEnumerator(name: "Weak", value: 2)</div><div>!18 = !DIEnumerator(name: "LinkOnce", value: 3)</div><div>!19 = !{!20, !23}</div><div>!20 = !DIGlobalVariableExpression(var: !21)</div><div>!21 = distinct !DIGlobalVariable(name: "__zig_panic_implementation_provided", linkageName: "__zig_panic_implementation_provided", scope: !13, file: !13, line: 201, type: !22, isLocal: true, isDefinition: true)</div><div>!22 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean)</div><div>!23 = !DIGlobalVariableExpression(var: !24)</div><div>!24 = distinct !DIGlobalVariable(name: "is_test", linkageName: "is_test", scope: !13, file: !13, line: 194, type: !22, isLocal: true, isDefinition: true)</div><div>!25 = distinct !DISubprogram(name: "assert", scope: !26, file: !26, line: 14, type: !27, isLocal: true, isDefinition: true, scopeLine: 14, isOptimized: false, unit: !1, variables: !30)</div><div>!26 = !DIFile(filename: "debug.zig", directory: "/Users/andy/dev/zig/build/lib/zig/std")</div><div>!27 = !DISubroutineType(types: !28)</div><div>!28 = !{!29, !22}</div><div>!29 = !DIBasicType(name: "void", encoding: DW_ATE_unsigned)</div><div>!30 = !{!31}</div><div>!31 = !DILocalVariable(name: "ok", arg: 1, scope: !25, file: !26, line: 14, type: !22)</div><div>!32 = !DIExpression()</div><div>!33 = !DILocation(line: 14, column: 15, scope: !25)</div><div>!34 = !DILocation(line: 15, column: 10, scope: !35)</div><div>!35 = distinct !DILexicalBlock(scope: !36, file: !26, line: 14, column: 25)</div><div>!36 = distinct !DILexicalBlock(scope: !25, file: !26, line: 14, column: 15)</div><div>!37 = !DILocation(line: 15, column: 9, scope: !35)</div><div>!38 = !DILocation(line: 21, column: 13, scope: !39)</div><div>!39 = distinct !DILexicalBlock(scope: !40, file: !26, line: 20, column: 16)</div><div>!40 = distinct !DILexicalBlock(scope: !35, file: !26, line: 15, column: 14)</div><div>!41 = !DILocation(line: 15, column: 5, scope: !35)</div><div>!42 = !DILocation(line: 15, column: 5, scope: !36)</div><div>!43 = distinct !DISubprogram(name: "main", scope: !5, file: !5, line: 4, type: !44, isLocal: false, isDefinition: true, scopeLine: 4, isOptimized: false, unit: !1, variables: !50)</div><div>!44 = !DISubroutineType(types: !45)</div><div>!45 = !{!46, !46, !47}</div><div>!46 = !DIBasicType(name: "c_int", size: 32, encoding: DW_ATE_signed)</div><div>!47 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "&&u8", baseType: !48, size: 64, align: 64)</div><div>!48 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "&u8", baseType: !49, size: 64, align: 64)</div><div>!49 = !DIBasicType(name: "u8", size: 8, encoding: DW_ATE_unsigned_char)</div><div>!50 = !{!51, !52}</div><div>!51 = !DILocalVariable(name: "argc", arg: 1, scope: !43, file: !5, line: 4, type: !46)</div><div>!52 = !DILocalVariable(name: "argv", arg: 2, scope: !53, file: !5, line: 4, type: !47)</div><div>!53 = distinct !DILexicalBlock(scope: !43, file: !5, line: 4, column: 16)</div><div>!54 = !DILocation(line: 4, column: 16, scope: !43)</div><div>!55 = !DILocation(line: 4, column: 29, scope: !53)</div><div>!56 = !DILocation(line: 5, column: 19, scope: !57)</div><div>!57 = distinct !DILexicalBlock(scope: !58, file: !5, line: 4, column: 50)</div><div>!58 = distinct !DILexicalBlock(scope: !53, file: !5, line: 4, column: 29)</div><div>!59 = !DILocation(line: 6, column: 5, scope: !57)</div><div>!60 = distinct !DISubprogram(name: "__zig_panic", scope: !61, file: !61, line: 7, type: !62, isLocal: false, isDefinition: true, scopeLine: 7, isOptimized: false, unit: !1, variables: !66)</div><div>!61 = !DIFile(filename: "zigrt.zig", directory: "/Users/andy/dev/zig/build/lib/zig/std/special")</div><div>!62 = !DISubroutineType(types: !63)</div><div>!63 = !{!29, !64, !65}</div><div>!64 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "&const u8", baseType: !49, size: 64, align: 64)</div><div>!65 = !DIBasicType(name: "usize", size: 64, encoding: DW_ATE_unsigned)</div><div>!66 = !{!67, !68}</div><div>!67 = !DILocalVariable(name: "message_ptr", arg: 1, scope: !60, file: !61, line: 7, type: !64)</div><div>!68 = !DILocalVariable(name: "message_len", arg: 2, scope: !69, file: !61, line: 7, type: !65)</div><div>!69 = distinct !DILexicalBlock(scope: !60, file: !61, line: 7, column: 30)</div><div>!70 = !DILocation(line: 7, column: 30, scope: !60)</div><div>!71 = !DILocation(line: 7, column: 54, scope: !69)</div><div>!72 = !DILocation(line: 12, column: 48, scope: !73)</div><div>!73 = distinct !DILexicalBlock(scope: !74, file: !61, line: 11, column: 54)</div><div>!74 = distinct !DILexicalBlock(scope: !75, file: !61, line: 7, column: 86)</div><div>!75 = distinct !DILexicalBlock(scope: !69, file: !61, line: 7, column: 54)</div><div>!76 = !DILocation(line: 12, column: 43, scope: !73)</div><div>!77 = !DILocation(line: 12, column: 31, scope: !73)</div><div>!78 = distinct !DISubprogram(name: "nonConstSwitch", scope: !5, file: !5, line: 8, type: !79, isLocal: true, isDefinition: true, scopeLine: 8, isOptimized: false, unit: !1, variables: !81)</div><div>!79 = !DISubroutineType(types: !80)</div><div>!80 = !{!29, !4}</div><div>!81 = !{!82, !83}</div><div>!82 = !DILocalVariable(name: "foo", arg: 1, scope: !78, file: !5, line: 8, type: !4)</div><div>!83 = !DILocalVariable(name: "val", scope: !84, file: !5, line: 9, type: !86)</div><div>!84 = distinct !DILexicalBlock(scope: !85, file: !5, line: 8, column: 29)</div><div>!85 = distinct !DILexicalBlock(scope: !78, file: !5, line: 8, column: 19)</div><div>!86 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed)</div><div>!87 = !DILocation(line: 8, column: 19, scope: !78)</div><div>!88 = !DILocation(line: 9, column: 17, scope: !84)</div><div>!89 = !DILocation(line: 9, column: 5, scope: !84)</div><div>!90 = !DILocation(line: 15, column: 12, scope: !91)</div><div>!91 = distinct !DILexicalBlock(scope: !84, file: !5, line: 9, column: 5)</div><div>!92 = !DILocation(line: 15, column: 16, scope: !91)</div><div>!93 = !DILocation(line: 15, column: 11, scope: !91)</div><div>!94 = !DILocation(line: 8, column: 29, scope: !85)</div><div>!95 = distinct !DISubprogram(name: "panic", scope: !5, file: !5, line: 1, type: !96, isLocal: true, isDefinition: true, scopeLine: 1, isOptimized: false, unit: !1, variables: !103)</div><div>!96 = !DISubroutineType(types: !97)</div><div>!97 = !{!29, !98}</div><div>!98 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "&const []const u8", baseType: !99, size: 64, align: 64)</div><div>!99 = !DICompositeType(tag: DW_TAG_structure_type, name: "[]u8", size: 128, align: 128, elements: !100)</div><div>!100 = !{!101, !102}</div><div>!101 = !DIDerivedType(tag: DW_TAG_member, name: "ptr", scope: !99, baseType: !48, size: 64, align: 64)</div><div>!102 = !DIDerivedType(tag: DW_TAG_member, name: "len", scope: !99, baseType: !65, size: 64, align: 64, offset: 64)</div><div>!103 = !{!104}</div><div>!104 = !DILocalVariable(name: "msg", arg: 1, scope: !95, file: !5, line: 1, type: !99)</div><div>!105 = !DILocation(line: 1, column: 14, scope: !95)</div><div>!106 = !DILocation(line: 1, column: 45, scope: !107)</div><div>!107 = distinct !DILexicalBlock(scope: !108, file: !5, line: 1, column: 43)</div><div>!108 = distinct !DILexicalBlock(scope: !95, file: !5, line: 1, column: 14)</div></div><div><br></div></div>