xref: /llvm-project/lld/test/COFF/link-dll-stdcall.s (revision ce211c505b82e5bbb68b936968d9b54608285416)
1# REQUIRES: x86
2
3## Test creating a DLL and linking against the DLL without using an import
4## library.
5
6## Test on i386 with stdcall/fastcall/vectorcall decorated symbols.
7
8## Check that we normally warn about these fixups. If -stdcall-fixup:no
9## (--disable-stdcall-fixup on the MinGW linker level) is passed, we don't
10## do these fixups. If we -stdcall-fixup (--enable-stdcall-fixup on the MinGW
11## linker level) is passed, we don't warn about it at all.
12
13# RUN: split-file %s %t.dir
14
15# RUN: llvm-mc -filetype=obj -triple=i386-windows-gnu %t.dir/lib.s -o %t.lib.o
16# RUN: lld-link -safeseh:no -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=i386-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 2>&1 | FileCheck --check-prefix=LOG %s
19# RUN: llvm-readobj --coff-imports %t.main.exe | FileCheck %s
20# RUN: not lld-link -lldmingw %t.main.o -out:%t.main.exe %t.lib.dll -opt:noref -stdcall-fixup:no 2>&1 | FileCheck --check-prefix=ERROR %s
21# RUN: lld-link -lldmingw %t.main.o -out:%t.main.exe %t.lib.dll -opt:noref -stdcall-fixup 2>&1 | count 0
22
23#--- lib.s
24  .text
25  .globl  _stdcall@8
26  .globl  @fastcall@8
27  .globl  vectorcall@@8
28  .globl  __underscored
29_stdcall@8:
30  movl    8(%esp), %eax
31  addl    4(%esp), %eax
32  retl    $8
33@fastcall@8:
34  movl    8(%esp), %eax
35  addl    4(%esp), %eax
36  retl    $8
37vectorcall@@8:
38  movl    8(%esp), %eax
39  addl    4(%esp), %eax
40  retl    $8
41__underscored:
42  ret
43
44#--- lib.def
45EXPORTS
46stdcall
47fastcall
48vectorcall
49_underscored
50
51#--- main.s
52.text
53.global _mainCRTStartup
54_mainCRTStartup:
55  pushl   $2
56  pushl   $1
57  calll   _stdcall@8
58  movl    $1, %ecx
59  movl    $2, %edx
60  calll   @fastcall@8
61  movl    $1, %ecx
62  movl    $2, %edx
63  calll   vectorcall@@8
64  pushl   $2
65  pushl   $1
66  calll   __underscored
67  addl    $8, %esp
68  xorl    %eax, %eax
69  popl    %ebp
70  retl
71
72# CHECK:      Import {
73# CHECK-NEXT:   Name: link-dll-stdcall.s.tmp.lib.dll
74# CHECK-NEXT:   ImportLookupTableRVA:
75# CHECK-NEXT:   ImportAddressTableRVA
76# CHECK-NEXT:   Symbol: _underscored
77# CHECK-NEXT:   Symbol: fastcall
78# CHECK-NEXT:   Symbol: stdcall
79# CHECK-NEXT:   Symbol: vectorcall
80# CHECK-NEXT: }
81
82# LOG-DAG: Resolving vectorcall@@8 by linking to _vectorcall
83# LOG-DAG: Resolving @fastcall@8 by linking to _fastcall
84# LOG-DAG: Resolving _stdcall@8 by linking to _stdcall
85
86# ERROR-DAG: undefined symbol: _stdcall@8
87# ERROR-DAG: undefined symbol: @fastcall@8
88# ERROR-DAG: undefined symbol: vectorcall@@8
89