1; REQUIRES: x86 2; RUN: rm -rf %t; split-file %s %t 3; RUN: llc -filetype=obj %t/foo1.ll -o %t/foo1.o 4; RUN: llc -filetype=obj %t/foo2.ll -o %t/foo2.o 5; RUN: llvm-ar rcs %t/libfoo2.a %t/foo2.o 6; RUN: llc -filetype=obj %t/foo3.ll -o %t/foo3.o 7; RUN: llvm-ar rcs %t/libfoo3.a %t/foo3.o 8 9; RUN: llc -filetype=obj %t/zoo2.ll -o %t/zoo2.o 10; RUN: llvm-ar rcs %t/libzoo2.a %t/zoo2.o 11; RUN: llc -filetype=obj %t/zoo3.ll -o %t/zoo3.o 12; RUN: llvm-ar rcs %t/libzoo3.a %t/zoo3.o 13 14; RUN: llc -filetype=obj %t/bar1.ll -o %t/bar1.o 15; RUN: llc -filetype=obj %t/bar2.ll -o %t/bar2.o 16; RUN: llvm-ar rcs %t/libbar2.a %t/bar2.o 17; RUN: llc -filetype=obj %t/bar3.ll -o %t/bar3.o 18; RUN: llvm-ar rcs %t/libbar3.a %t/bar3.o 19 20; RUN: %lld -dylib -lSystem -L%t %t/foo1.o %t/bar1.o -o %t/order.out 21; RUN: llvm-objdump --no-leading-addr --no-show-raw-insn -d %t/order.out | FileCheck %s 22 23; We want to process input object files first 24; before any lc-linker options are actually resolved. 25; The lc-linker options are recursively processed. 26 27; The following shows a chain of auto linker options, 28; starting with foo1.o and bar1.o: 29; 30; foo1.o -> libfoo2.a(foo2.o) -> libfoo3.a(foo3.o) 31; \ 32; -> libzoo2.a(zoo2.o) -> libzoo3.a(zoo3.o) 33; bar1.o -> libbar2.a(bar2.o) -> libbar3.a(bar3.o) 34 35; CHECK: <_foo1>: 36; CHECK: <_bar1>: 37; CHECK: <_foo2>: 38; CHECK: <_zoo2>: 39; CHECK: <_bar2>: 40; CHECK: <_foo3>: 41; CHECK: <_zoo3>: 42; CHECK: <_bar3>: 43 44;--- foo1.ll 45target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 46target triple = "x86_64-apple-macosx10.15.0" 47 48!0 = !{!"-lfoo2"} 49!1 = !{!"-lzoo2"} 50!llvm.linker.options = !{!0, !1} 51 52define i32 @foo1() { 53 %call = call i32 @foo2() 54 %call2 = call i32 @zoo2() 55 %add = add nsw i32 %call, %call2 56 ret i32 %add 57} 58 59declare i32 @foo2() 60declare i32 @zoo2() 61 62;--- foo2.ll 63target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 64target triple = "x86_64-apple-macosx10.15.0" 65 66!0 = !{!"-lfoo3"} 67!llvm.linker.options = !{!0} 68 69define i32 @foo2() { 70 %call = call i32 @foo3() 71 %add = add nsw i32 %call, 2 72 ret i32 %add 73} 74 75declare i32 @foo3() 76 77;--- foo3.ll 78target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 79target triple = "x86_64-apple-macosx10.15.0" 80 81define i32 @foo3() { 82 ret i32 3 83} 84 85;--- zoo2.ll 86target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 87target triple = "x86_64-apple-macosx10.15.0" 88 89!0 = !{!"-lzoo3"} 90!llvm.linker.options = !{!0} 91 92define i32 @zoo2() { 93 %call = call i32 @zoo3() 94 %add = add nsw i32 %call, 2 95 ret i32 %add 96} 97 98declare i32 @zoo3() 99 100;--- zoo3.ll 101target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 102target triple = "x86_64-apple-macosx10.15.0" 103 104define i32 @zoo3() { 105 ret i32 30 106} 107 108;--- bar1.ll 109target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 110target triple = "x86_64-apple-macosx10.15.0" 111 112!0 = !{!"-lbar2"} 113!llvm.linker.options = !{!0} 114 115define i32 @bar1() { 116 %call = call i32 @bar2() 117 %add = add nsw i32 %call, 10 118 ret i32 %add 119} 120 121declare i32 @bar2() 122 123;--- bar2.ll 124target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 125target triple = "x86_64-apple-macosx10.15.0" 126 127!0 = !{!"-lbar3"} 128!llvm.linker.options = !{!0} 129 130define i32 @bar2() { 131 %call = call i32 @bar3() 132 %add = add nsw i32 %call, 200 133 ret i32 %add 134} 135 136declare i32 @bar3() 137 138;--- bar3.ll 139target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 140target triple = "x86_64-apple-macosx10.15.0" 141 142define i32 @bar3() { 143 ret i32 300 144} 145