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