1// REQUIRES: x86 2// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o 3// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \ 4// RUN: %p/Inputs/libsearch-dyn.s -o %tdyn.o 5// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \ 6// RUN: %p/Inputs/libsearch-st.s -o %tst.o 7// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \ 8// RUN: %p/Inputs/use-bar.s -o %tbar.o 9// RUN: mkdir -p %t.dir 10// RUN: ld.lld -shared %tdyn.o -o %t.dir/libls.so 11// RUN: cp -f %t.dir/libls.so %t.dir/libls2.so 12// RUN: rm -f %t.dir/libls.a 13// RUN: llvm-ar rcs %t.dir/libls.a %tst.o 14 15// Should fail if no library specified 16// RUN: not ld.lld -l 2>&1 \ 17// RUN: | FileCheck --check-prefix=NOLIBRARY %s 18// NOLIBRARY: -l: missing argument 19 20// Should link normally, because _bar is not used 21// RUN: ld.lld -o %t3 %t.o 22// Should not link because of undefined symbol _bar 23// RUN: not ld.lld -o /dev/null %t.o %tbar.o 2>&1 \ 24// RUN: | FileCheck --check-prefix=UNDEFINED %s 25// UNDEFINED: error: undefined symbol: _bar 26// UNDEFINED: >>> referenced by {{.*}}:(.bar+0x0) 27 28// Should fail if cannot find specified library (without -L switch) 29// RUN: not ld.lld -o /dev/null %t.o -lls 2>&1 \ 30// RUN: | FileCheck --check-prefix=NOLIB %s 31// NOLIB: unable to find library -lls 32 33// Should use explicitly specified static library 34// Also ensure that we accept -L <arg> 35// RUN: ld.lld -o %t3 %t.o -L %t.dir -l:libls.a 36// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s 37// STATIC: Symbols [ 38// STATIC: Name: _static 39// STATIC: ] 40 41// Should use explicitly specified dynamic library 42// RUN: ld.lld -o %t3 %t.o -L%t.dir -l:libls.so 43// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s 44// DYNAMIC: Symbols [ 45// DYNAMIC-NOT: Name: _static 46// DYNAMIC: ] 47 48// Should prefer dynamic to static 49// RUN: ld.lld -o %t3 %t.o -L%t.dir -lls 50// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s 51 52// Check for library search order 53// RUN: mkdir -p %t.dir2 54// RUN: cp %t.dir/libls.a %t.dir2 55// RUN: ld.lld -o %t3 %t.o -L%t.dir2 -L%t.dir -lls 56// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s 57 58// -L can be placed after -l 59// RUN: ld.lld -o %t3 %t.o -lls -L%t.dir 60 61// Check long forms as well 62// RUN: ld.lld -o %t3 %t.o --library-path=%t.dir --library=ls 63// RUN: ld.lld -o %t3 %t.o --library-path %t.dir --library ls 64 65// Should not search for dynamic libraries if -Bstatic is specified 66// RUN: ld.lld -o %t3 %t.o -L%t.dir -Bstatic -lls 67// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s 68// RUN: not ld.lld -o /dev/null %t.o -L%t.dir -Bstatic -lls2 2>&1 \ 69// RUN: | FileCheck --check-prefix=NOLIB2 %s 70// NOLIB2: unable to find library -lls2 71 72// -Bdynamic should restore default behaviour 73// RUN: ld.lld -o %t3 %t.o -L%t.dir -Bstatic -Bdynamic -lls 74// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s 75 76// -Bstatic and -Bdynamic should affect only libraries which follow them 77// RUN: ld.lld -o %t3 %t.o -L%t.dir -lls -Bstatic -Bdynamic 78// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s 79// RUN: ld.lld -o %t3 %t.o -L%t.dir -Bstatic -lls -Bdynamic 80// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s 81 82// Check aliases as well 83// RUN: ld.lld -o %t3 %t.o -L%t.dir -dn -lls 84// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s 85// RUN: ld.lld -o %t3 %t.o -L%t.dir -non_shared -lls 86// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s 87// RUN: ld.lld -o %t3 %t.o -L%t.dir -static -lls 88// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s 89// RUN: ld.lld -o %t3 %t.o -L%t.dir -Bstatic -dy -lls 90// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s 91// RUN: ld.lld -o %t3 %t.o -L%t.dir -Bstatic -call_shared -lls 92// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s 93 94/// -r implies -Bstatic and has precedence over -Bdynamic. 95// RUN: ld.lld -r -Bdynamic %t.o -L%t.dir -lls -o %t3.ro 96// RUN: llvm-readelf -s -h %t3.ro | FileCheck --check-prefix=RELOCATABLE %s 97// RELOCATABLE: Type: REL 98// RELOCATABLE: [[#]] _static 99 100// -nostdlib 101// RUN: echo 'SEARCH_DIR("'%t.dir'")' > %t.script 102// RUN: ld.lld -o %t3 %t.o -script %t.script -lls 103// RUN: not ld.lld -o /dev/null %t.o -script %t.script -lls -nostdlib \ 104// RUN: 2>&1 | FileCheck --check-prefix=NOSTDLIB %s 105// NOSTDLIB: unable to find library -lls 106 107.globl _start,_bar 108_start: 109