xref: /llvm-project/lld/test/COFF/lto-weak-undefined.ll (revision deab451e7a7f2dff42097049274637052c87eabd)
1; REQUIRES: x86
2
3;; Test linking of weak symbols with LTO. The weak symbol may be defined
4;; by another object file, or may be left undefined. When compiling the
5;; IR with an undefined weak symbol, the emitted object file will contain
6;; a weak alias pointing at an absolute symbol for the address null.
7;; Make sure both cases can be linked correctly.
8
9; RUN: split-file %s %t.dir
10; RUN: llvm-as %t.dir/main.ll -o %t.main.obj
11; RUN: llvm-as %t.dir/optional.ll -o %t.optional.obj
12
13; RUN: lld-link /entry:main %t.main.obj /out:%t-undef.exe
14; RUN: lld-link /entry:main %t.main.obj %t.optional.obj /out:%t-def.exe
15
16;--- main.ll
17target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
18target triple = "x86_64-pc-windows-msvc"
19
20define dso_local i32 @main() {
21entry:
22  %cmp = icmp ne ptr @optionalFunc, null
23  br i1 %cmp, label %if.then, label %if.end
24
25if.then:
26  tail call void @optionalFunc()
27  br label %if.end
28
29if.end:
30  ret i32 0
31}
32
33declare extern_weak void @optionalFunc()
34
35;--- optional.ll
36target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
37target triple = "x86_64-pc-windows-msvc"
38
39define void @optionalFunc() {
40  ret void
41}
42