Rename CODE_OWNERS -> Maintainers (#114544)
[llvm-project.git] / lld / test / COFF / autoimport-refptr.s
blob4071d6be0809ec129bb0f3c365ade8f4e5cb9898
1 # REQUIRES: x86
3 # RUN: echo -e ".global variable\n.global DllMainCRTStartup\n.text\nDllMainCRTStartup:\nret\n.data\nvariable:\n.long 42" > %t-lib.s
4 # RUN: llvm-mc -triple=x86_64-windows-gnu %t-lib.s -filetype=obj -o %t-lib.obj
5 # RUN: lld-link -out:%t-lib.dll -dll -entry:DllMainCRTStartup %t-lib.obj -lldmingw -implib:%t-lib.lib
7 # RUN: llvm-mc -triple=x86_64-windows-gnu %s -defsym listptrs=1 -filetype=obj -o %t.obj
8 # RUN: lld-link -lldmingw -out:%t.exe -entry:main %t.obj %t-lib.lib -verbose
10 # RUN: llvm-readobj --coff-imports %t.exe | FileCheck -check-prefix=IMPORTS %s
11 # RUN: llvm-objdump --no-print-imm-hex -d %t.exe | FileCheck --check-prefix=DISASM %s
12 # RUN: llvm-objdump -s %t.exe | FileCheck --check-prefix=CONTENTS %s
14 ## Check that we can autoimport these variables with pseudo relocs disabled.
15 # RUN: llvm-mc -triple=x86_64-windows-gnu %s -defsym listptrs=0 -filetype=obj -o %t.noptrs.obj
16 # RUN: lld-link -lldmingw -runtime-pseudo-reloc:no -out:%t.exe -entry:main %t.noptrs.obj %t-lib.lib
18 ## Check that we can't autoimport them with autoimport disabled.
19 # RUN: not lld-link -lldmingw -auto-import:no -out:%t.exe -entry:main %t.noptrs.obj %t-lib.lib 2>&1 | FileCheck --check-prefix=NO-AUTOIMPORT %s
21 # IMPORTS: Import {
22 # IMPORTS-NEXT: Name: autoimport-refptr.s.tmp-lib.dll
23 # IMPORTS-NEXT: ImportLookupTableRVA: 0x2050
24 # IMPORTS-NEXT: ImportAddressTableRVA: 0x2060
25 # IMPORTS-NEXT: Symbol: variable (0)
26 # IMPORTS-NEXT: }
28 # DISASM: Disassembly of section .text:
29 # DISASM-EMPTY:
30 # DISASM: <.text>:
31 # Relative offset at 0x1002 pointing at the IAT at 0x2060
32 # DISASM: 140001000: 48 8b 05 59 10 00 00 movq 4185(%rip), %rax
33 # DISASM: 140001007: 8b 00 movl (%rax), %eax
34 # Relative offset at 0x100b pointing at the .refptr.localvar stub at
35 # 0x2000
36 # DISASM: 140001009: 48 8b 0d f0 0f 00 00 movq 4080(%rip), %rcx
37 # DISASM: 140001010: 03 01 addl (%rcx), %eax
38 # DISASM: 140001012: c3 retq
40 # relocs: pointing at an empty list of runtime pseudo relocs.
41 # localvar: 42
42 # CONTENTS: Contents of section .data:
43 # CONTENTS: 140003000 08200040 01000000 08200040 01000000
44 # CONTENTS: 140003010 2a000000
46 # NO-AUTOIMPORT: error: undefined symbol: variable
48 .global main
49 .global localvar
50 .text
51 main:
52 movq .refptr.variable(%rip), %rax
53 movl (%rax), %eax
54 movq .refptr.localvar(%rip), %rcx
55 addl (%rcx), %eax
56 ret
58 .data
59 .if listptrs==1
60 relocs:
61 .quad __RUNTIME_PSEUDO_RELOC_LIST__
62 .quad __RUNTIME_PSEUDO_RELOC_LIST_END__
63 .endif
64 localvar:
65 .int 42
67 # Normally the compiler wouldn't emit a stub for a variable that is
68 # emitted in the same translation unit.
69 .section .rdata$.refptr.localvar,"dr",discard,.refptr.localvar
70 .global .refptr.localvar
71 .refptr.localvar:
72 .quad localvar
74 .section .rdata$.refptr.variable,"dr",discard,.refptr.variable
75 .global .refptr.variable
76 .refptr.variable:
77 .quad variable