1// Based on lld/test/ELF/libsearch.s 2 3// RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %s -o %t.o 4// RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown \ 5// RUN: %p/Inputs/libsearch-dyn.s -o %tdyn.o 6// RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown \ 7// RUN: %p/Inputs/libsearch-st.s -o %tst.o 8// RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown \ 9// RUN: %p/Inputs/use-bar.s -o %tbar.o 10// RUN: mkdir -p %t.dir 11// RUN: wasm-ld -shared --experimental-pic %tdyn.o -o %t.dir/libls.so 12// RUN: cp -f %t.dir/libls.so %t.dir/libls2.so 13// RUN: rm -f %t.dir/libls.a 14// RUN: llvm-ar rcs %t.dir/libls.a %tst.o 15 16// Should fail if no library specified 17// RUN: not wasm-ld -l 2>&1 \ 18// RUN: | FileCheck --check-prefix=NOLIBRARY %s 19// NOLIBRARY: -l: missing argument 20 21// Should link normally, because _bar is not used 22// RUN: wasm-ld -o %t3 %t.o 23// Should not link because of undefined symbol _bar 24// RUN: not wasm-ld --no-gc-sections -o /dev/null %t.o %tbar.o 2>&1 \ 25// RUN: | FileCheck --check-prefix=UNDEFINED %s 26// UNDEFINED: wasm-ld: error: {{.*}}: undefined symbol: _bar 27 28// Should fail if cannot find specified library (without -L switch) 29// RUN: not wasm-ld -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: wasm-ld --emit-relocs --no-gc-sections -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 40// Should use explicitly specified dynamic library 41// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -l:libls.so 42// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s 43// DYNAMIC: Symbols [ 44// DYNAMIC-NOT: Name: _static 45 46// Should prefer static to dynamic when linking regular executable. 47// RUN: wasm-ld --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -lls 48// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s 49 50// Should prefer dynamic when linking PIE. 51// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -lls 52// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s 53 54// Check for library search order 55// RUN: mkdir -p %t.dir2 56// RUN: cp %t.dir/libls.a %t.dir2 57// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir2 -L%t.dir -lls 58// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s 59 60// -L can be placed after -l 61// RUN: wasm-ld -o %t3 %t.o -lls -L%t.dir 62 63// Check long forms as well 64// RUN: wasm-ld --emit-relocs --no-gc-sections -o %t3 %t.o --library-path=%t.dir --library=ls 65// RUN: wasm-ld --emit-relocs --no-gc-sections -o %t3 %t.o --library-path %t.dir --library ls 66 67// Should not search for dynamic libraries if -Bstatic is specified 68// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -Bstatic -lls 69// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s 70// RUN: not wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o /dev/null %t.o -L%t.dir -Bstatic -lls2 2>&1 \ 71// RUN: | FileCheck --check-prefix=NOLIB2 %s 72// NOLIB2: unable to find library -lls2 73 74// -Bdynamic should restore default behaviour 75// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -Bstatic -Bdynamic -lls 76// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s 77 78// -Bstatic and -Bdynamic should affect only libraries which follow them 79// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -lls -Bstatic -Bdynamic 80// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s 81// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -Bstatic -lls -Bdynamic 82// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s 83 84// Check aliases as well 85// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -dn -lls 86// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s 87// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -non_shared -lls 88// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s 89// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -static -lls 90// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s 91// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -Bstatic -dy -lls 92// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s 93// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -Bstatic -call_shared -lls 94// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s 95 96.globl _start, _bar 97_start: 98 .functype _start () -> () 99 end_function 100