1# REQUIRES: x86
2
3# RUN: llvm-mc -triple=i686-windows-gnu %s -filetype=obj -o %t.obj
4
5# RUN: lld-link -lldmingw -dll -out:%t.dll -entry:DllMainCRTStartup@12 %t.obj -implib:%t.lib
6# RUN: llvm-readobj --coff-exports %t.dll | grep Name: | FileCheck %s
7# RUN: llvm-readobj %t.lib | FileCheck -check-prefix=IMPLIB %s
8
9# CHECK: Name:
10# CHECK-NEXT: Name: dataSym
11# CHECK-NEXT: Name: foobar
12# CHECK-EMPTY:
13
14# IMPLIB: Symbol: __imp__dataSym
15# IMPLIB-NOT: Symbol: _dataSym
16# IMPLIB: Symbol: __imp__foobar
17# IMPLIB: Symbol: _foobar
18
19.global _foobar
20.global _DllMainCRTStartup@12
21.global _dataSym
22.global _unexported
23.global __imp__unexported
24.global .refptr._foobar
25.text
26_DllMainCRTStartup@12:
27  ret
28_foobar:
29  ret
30_unexported:
31  ret
32.data
33_dataSym:
34  .int 4
35__imp__unexported:
36  .int _unexported
37.refptr._foobar:
38  .int _foobar
39
40# Test specifying -export-all-symbols, on an object file that contains
41# dllexport directive for some of the symbols.
42
43# RUN: yaml2obj < %p/Inputs/export.yaml > %t.obj
44#
45# RUN: lld-link -safeseh:no -out:%t.dll -dll %t.obj -lldmingw -export-all-symbols -output-def:%t.def
46# RUN: llvm-readobj --coff-exports %t.dll | FileCheck -check-prefix=CHECK2 %s
47# RUN: cat %t.def | FileCheck -check-prefix=CHECK2-DEF %s
48
49# Note, this will actually export _DllMainCRTStartup as well, since
50# it uses the standard spelling in this object file, not the MinGW one.
51
52# CHECK2: Name: exportfn1
53# CHECK2: Name: exportfn2
54# CHECK2: Name: exportfn3
55
56# CHECK2-DEF: EXPORTS
57# CHECK2-DEF: exportfn1 @3
58# CHECK2-DEF: exportfn2 @4
59# CHECK2-DEF: exportfn3 @5
60
61# Test ignoring certain object files and libs.
62
63# RUN: echo -e ".global foobar\n.global DllMainCRTStartup\n.text\nDllMainCRTStartup:\nret\nfoobar:\ncall mingwfunc\ncall crtfunc\nret\n" > %t.main.s
64# RUN: llvm-mc -triple=x86_64-windows-gnu %t.main.s -filetype=obj -o %t.main.obj
65# RUN: mkdir -p %T/libs
66# RUN: echo -e ".global mingwfunc\n.text\nmingwfunc:\nret\n" > %T/libs/mingwfunc.s
67# RUN: llvm-mc -triple=x86_64-windows-gnu %T/libs/mingwfunc.s -filetype=obj -o %T/libs/mingwfunc.o
68# RUN: rm -f %T/libs/libmingwex.a
69# RUN: llvm-ar rcs %T/libs/libmingwex.a %T/libs/mingwfunc.o
70# RUN: echo -e ".global crtfunc\n.text\ncrtfunc:\nret\n" > %T/libs/crtfunc.s
71# RUN: llvm-mc -triple=x86_64-windows-gnu %T/libs/crtfunc.s -filetype=obj -o %T/libs/crt2.o
72# RUN: lld-link -safeseh:no -out:%t.dll -dll -entry:DllMainCRTStartup %t.main.obj -lldmingw %T/libs/crt2.o %T/libs/libmingwex.a -output-def:%t.def
73# RUN: echo "EOF" >> %t.def
74# RUN: cat %t.def | FileCheck -check-prefix=CHECK-EXCLUDE %s
75
76# CHECK-EXCLUDE: EXPORTS
77# CHECK-EXCLUDE-NEXT: foobar @1
78# CHECK-EXCLUDE-NEXT: EOF
79
80# Test that libraries included with -wholearchive: are autoexported, even if
81# they are in a library that otherwise normally would be excluded.
82
83# RUN: lld-link -safeseh:no -out:%t.dll -dll -entry:DllMainCRTStartup %t.main.obj -lldmingw %T/libs/crt2.o -wholearchive:%T/libs/libmingwex.a -output-def:%t.def
84# RUN: echo "EOF" >> %t.def
85# RUN: cat %t.def | FileCheck -check-prefix=CHECK-WHOLEARCHIVE %s
86
87# CHECK-WHOLEARCHIVE: EXPORTS
88# CHECK-WHOLEARCHIVE-NEXT: foobar @1
89# CHECK-WHOLEARCHIVE-NEXT: mingwfunc @2
90# CHECK-WHOLEARCHIVE-NEXT: EOF
91
92# Test that we handle import libraries together with -opt:noref.
93
94# RUN: yaml2obj < %p/Inputs/hello32.yaml > %t.obj
95# RUN: lld-link -lldmingw -dll -out:%t.dll -entry:main@0 %t.obj -implib:%t.lib -opt:noref %p/Inputs/std32.lib -output-def:%t.def
96# RUN: echo "EOF" >> %t.def
97# RUN: cat %t.def | FileCheck -check-prefix=CHECK-IMPLIB %s
98
99# CHECK-IMPLIB: EXPORTS
100# CHECK-IMPLIB-NEXT: main@0 @1
101# CHECK-IMPLIB-NEXT: EOF
102