105 lines · plain
1// Based on lld/test/ELF/libsearch.s2 3// RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %s -o %t.o4// RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown \5// RUN: %p/Inputs/libsearch-dyn.s -o %tdyn.o6// RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown \7// RUN: %p/Inputs/libsearch-st.s -o %tst.o8// RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown \9// RUN: %p/Inputs/use-bar.s -o %tbar.o10// RUN: mkdir -p %t.dir11// RUN: wasm-ld -shared --experimental-pic %tdyn.o -o %t.dir/libls.so12// RUN: cp -f %t.dir/libls.so %t.dir/libls2.so13// RUN: rm -f %t.dir/libls.a14// RUN: llvm-ar rcs %t.dir/libls.a %tst.o15 16// Should fail if no library specified17// RUN: not wasm-ld -l 2>&1 \18// RUN: | FileCheck --check-prefix=NOLIBRARY %s19// NOLIBRARY: -l: missing argument20 21// Should link normally, because _bar is not used22// RUN: wasm-ld -o %t3 %t.o23// Should not link because of undefined symbol _bar24// RUN: not wasm-ld --no-gc-sections -o /dev/null %t.o %tbar.o 2>&1 \25// RUN: | FileCheck --check-prefix=UNDEFINED %s26// UNDEFINED: wasm-ld: error: {{.*}}: undefined symbol: _bar27 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 %s31// NOLIB: unable to find library -lls32 33// Should use explicitly specified static library34// 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.a36// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s37// STATIC: Symbols [38// STATIC: Name: _static39 40// Should use explicitly specified dynamic library41// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -l:libls.so42// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s43// DYNAMIC: Symbols [44// DYNAMIC-NOT: Name: _static45 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 -lls48// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s49 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 -lls52// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s53 54// Check for library search order55// RUN: mkdir -p %t.dir256// RUN: cp %t.dir/libls.a %t.dir257// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir2 -L%t.dir -lls58// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s59 60// -L can be placed after -l61// RUN: wasm-ld -o %t3 %t.o -lls -L%t.dir62 63// Check long forms as well64// RUN: wasm-ld --emit-relocs --no-gc-sections -o %t3 %t.o --library-path=%t.dir --library=ls65// RUN: wasm-ld --emit-relocs --no-gc-sections -o %t3 %t.o --library-path %t.dir --library ls66 67// Should not search for dynamic libraries if -Bstatic is specified68// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -Bstatic -lls69// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s70// 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 %s72// NOLIB2: unable to find library -lls273 74// -Bdynamic should restore default behaviour75// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -Bstatic -Bdynamic -lls76// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s77 78// -Bstatic and -Bdynamic should affect only libraries which follow them79// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -lls -Bstatic -Bdynamic80// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s81// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -Bstatic -lls -Bdynamic82// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s83 84// Check aliases as well85// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -dn -lls86// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s87// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -non_shared -lls88// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s89// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -static -lls90// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=STATIC %s91// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -Bstatic -dy -lls92// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s93// RUN: wasm-ld -pie --experimental-pic --emit-relocs --no-gc-sections -o %t3 %t.o -L%t.dir -Bstatic -call_shared -lls94// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s95 96/// -r implies -Bstatic and has precedence over -Bdynamic.97// RUN: wasm-ld -r -Bdynamic %t.o -L%t.dir -lls -o %t3.ro98// RUN: llvm-readobj -s -h %t3.ro | FileCheck --check-prefix=RELOCATABLE %s99// RELOCATABLE: Name: _static100 101.globl _start, _bar102_start:103 .functype _start () -> ()104 end_function105