xref: /llvm-project/lld/test/wasm/archive.ll (revision fd1c894a4a3690b2e500bfdf71194e9cc3f1b399)
170683b2fSSam Clegg; RUN: llc -filetype=obj %s -o %t.o
270683b2fSSam Clegg; RUN: llc -filetype=obj %S/Inputs/archive1.ll -o %t.a1.o
370683b2fSSam Clegg; RUN: llc -filetype=obj %S/Inputs/archive2.ll -o %t.a2.o
42df314d1SSam Clegg; RUN: llc -filetype=obj %S/Inputs/archive3.ll -o %t.a3.o
5*fd1c894aSSam Clegg; RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %p/Inputs/hello.s -o %t.hello.o
61a721eb3SChris Jackson; RUN: rm -f %t.a
72df314d1SSam Clegg; RUN: llvm-ar rcs %t.a %t.a1.o %t.a2.o %t.a3.o %t.hello.o
831efdcd7SSam Clegg; RUN: rm -f %t.imports
9752494bfSSam Clegg; RUN: not wasm-ld %t.a %t.o -o %t.wasm 2>&1 | FileCheck -check-prefix=CHECK-UNDEFINED %s
1031efdcd7SSam Clegg
1131efdcd7SSam Clegg; CHECK-UNDEFINED: undefined symbol: missing_func
1231efdcd7SSam Clegg
1331efdcd7SSam Clegg; RUN: echo 'missing_func' > %t.imports
14752494bfSSam Clegg; RUN: wasm-ld -r %t.a %t.o -o %t.wasm
1531efdcd7SSam Clegg
16c94d393aSSam Clegg; RUN: llvm-nm -a %t.wasm | FileCheck %s
17c94d393aSSam Clegg
18262e0901SSam Cleggtarget triple = "wasm32-unknown-unknown"
1970683b2fSSam Clegg
20c94d393aSSam Cleggdeclare i32 @foo() local_unnamed_addr #1
2131efdcd7SSam Cleggdeclare i32 @missing_func() local_unnamed_addr #1
22c94d393aSSam Clegg
23279c850cSSam Cleggdefine void @_start() local_unnamed_addr #0 {
24c94d393aSSam Cleggentry:
2531efdcd7SSam Clegg  %call1 = call i32 @foo() #2
2631efdcd7SSam Clegg  %call2 = call i32 @missing_func() #2
27279c850cSSam Clegg  ret void
28c94d393aSSam Clegg}
29c94d393aSSam Clegg
3093102974SSam Clegg; Verify that mutually dependant object files in an archive is handled
3193102974SSam Clegg; correctly.  Since we're using llvm-nm, we must link with --relocatable.
3293102974SSam Clegg;
3393102974SSam Clegg; TODO(ncw): Update LLD so that the symbol table is written out for
3493102974SSam Clegg;   non-relocatable output (with an option to strip it)
35c0181154SSam Clegg
367ab15a79SWouter van Oortmerssen; CHECK:      00000016 T _start
377ab15a79SWouter van Oortmerssen; CHECK-NEXT: 0000000a T archive2_symbol
3831efdcd7SSam Clegg; CHECK-NEXT: 00000001 T bar
397ab15a79SWouter van Oortmerssen; CHECK-NEXT: 0000000d T foo
4093102974SSam Clegg; CHECK-NEXT:          U missing_func
41c0181154SSam Clegg
42c0181154SSam Clegg; Verify that symbols from unused objects don't appear in the symbol table
43c0181154SSam Clegg; CHECK-NOT: hello
44c0181154SSam Clegg
45c0181154SSam Clegg; Specifying the same archive twice is allowed.
46752494bfSSam Clegg; RUN: wasm-ld %t.a %t.a %t.o -o %t.wasm
472df314d1SSam Clegg
482df314d1SSam Clegg; Verfiy errors include library name
492df314d1SSam Clegg; RUN: not wasm-ld -u archive2_symbol -u archive3_symbol %t.a %t.o -o %t.wasm 2>&1 | FileCheck -check-prefix=CHECK-DUP %s
500cfaa247SSam Clegg; And that this also works with --whole-archive
510cfaa247SSam Clegg; RUN: not wasm-ld -u archive2_symbol -u archive3_symbol --whole-archive %t.a %t.o -o %t.wasm 2>&1 | FileCheck -check-prefix=CHECK-DUP %s
522df314d1SSam Clegg; CHECK-DUP: error: duplicate symbol: bar
532df314d1SSam Clegg; CHECK-DUP: >>> defined in {{.*}}.a({{.*}}.a2.o)
542df314d1SSam Clegg; CHECK-DUP: >>> defined in {{.*}}.a({{.*}}.a3.o)
55