llvm-project
66 строк · 1.6 Кб
1# REQUIRES: x86
2
3## Test creating a DLL and linking against the DLL without using an import
4## library.
5
6## Explicitly creating an import library but naming it differently than the
7## DLL, to avoid any risk of implicitly referencing it instead of the DLL
8## itself.
9
10## Linking the executable with -opt:noref, to make sure that we don't
11## pull in more import entries than what's needed, even if not running GC.
12
13# RUN: split-file %s %t.dir
14
15# RUN: llvm-mc -filetype=obj -triple=x86_64-windows-gnu %t.dir/lib.s -o %t.lib.o
16# RUN: lld-link -noentry -dll -def:%t.dir/lib.def %t.lib.o -out:%t.lib.dll -implib:%t.implib.lib
17# RUN: llvm-mc -filetype=obj -triple=x86_64-windows-gnu %t.dir/main.s -o %t.main.o
18# RUN: lld-link -lldmingw %t.main.o -out:%t.main.exe %t.lib.dll -opt:noref -verbose 2>&1 | FileCheck --check-prefix=LOG %s
19# RUN: llvm-readobj --coff-imports %t.main.exe | FileCheck %s
20
21#--- lib.s
22.text
23.global func1
24func1:
25ret
26.global func2
27func2:
28ret
29.global func3
30func3:
31ret
32.data
33.global variable
34variable:
35.int 42
36
37#--- lib.def
38EXPORTS
39func1
40func2
41func3
42variable
43
44#--- main.s
45.text
46.global mainCRTStartup
47mainCRTStartup:
48call func2
49movq .refptr.variable(%rip), %rax
50movl (%rax), %eax
51ret
52
53.section .rdata$.refptr.variable,"dr",discard,.refptr.variable
54.globl .refptr.variable
55.refptr.variable:
56.quad variable
57
58# CHECK: Import {
59# CHECK-NEXT: Name: link-dll.s.tmp.lib.dll
60# CHECK-NEXT: ImportLookupTableRVA:
61# CHECK-NEXT: ImportAddressTableRVA
62# CHECK-NEXT: Symbol: func2
63# CHECK-NEXT: Symbol: variable
64# CHECK-NEXT: }
65
66# LOG: Automatically importing variable from link-dll.s.tmp.lib.dll
67