summaryrefslogtreecommitdiff
path: root/test/COFF
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-12-30 11:57:38 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-12-30 11:57:38 +0000
commit5a5c549fe9a3fef595297bd21d36bed8409dc37d (patch)
treea964c8f5ac85b7b641cac022c5f9bf4eed3d2b9b /test/COFF
parentfb911942f1434f3d1750f83f25f5e42c80e60638 (diff)
Notes
Diffstat (limited to 'test/COFF')
-rw-r--r--test/COFF/Inputs/armnt-executable.obj.yaml29
-rw-r--r--test/COFF/Inputs/armnt-executable.s13
-rw-r--r--test/COFF/Inputs/conflict.ll6
-rw-r--r--test/COFF/Inputs/entry-mangled.ll6
-rw-r--r--test/COFF/Inputs/export.ll18
-rw-r--r--test/COFF/Inputs/export.yaml57
-rw-r--r--test/COFF/Inputs/export2.yaml29
-rw-r--r--test/COFF/Inputs/hello32.yaml82
-rw-r--r--test/COFF/Inputs/hello64.asm24
-rw-r--r--test/COFF/Inputs/hello64.objbin0 -> 682 bytes
-rw-r--r--test/COFF/Inputs/import.yaml41
-rw-r--r--test/COFF/Inputs/imports-mangle.libbin0 -> 2114 bytes
-rw-r--r--test/COFF/Inputs/include1a.yaml33
-rw-r--r--test/COFF/Inputs/include1b.yaml33
-rw-r--r--test/COFF/Inputs/include1c.yaml29
-rwxr-xr-xtest/COFF/Inputs/library.libbin0 -> 1694 bytes
-rw-r--r--test/COFF/Inputs/lto-chkstk-chkstk.s3
-rw-r--r--test/COFF/Inputs/lto-chkstk-foo.s3
-rw-r--r--test/COFF/Inputs/lto-comdat1.ll13
-rw-r--r--test/COFF/Inputs/lto-comdat2.ll13
-rw-r--r--test/COFF/Inputs/lto-dep.ll10
-rw-r--r--test/COFF/Inputs/machine-x64.yaml29
-rw-r--r--test/COFF/Inputs/machine-x86.yaml29
-rw-r--r--test/COFF/Inputs/resource.resbin0 -> 108 bytes
-rw-r--r--test/COFF/Inputs/ret42.libbin0 -> 550 bytes
-rw-r--r--test/COFF/Inputs/ret42.objbin0 -> 408 bytes
-rw-r--r--test/COFF/Inputs/ret42.yaml45
-rw-r--r--test/COFF/Inputs/std32.libbin0 -> 1898 bytes
-rw-r--r--test/COFF/Inputs/std64.libbin0 -> 2068 bytes
-rw-r--r--test/COFF/Inputs/weak-external.ll6
-rw-r--r--test/COFF/Inputs/weak-external2.ll6
-rw-r--r--test/COFF/Inputs/weak-external3.ll8
-rw-r--r--test/COFF/alternatename.test61
-rw-r--r--test/COFF/ar-comdat.test38
-rw-r--r--test/COFF/armnt-blx23t.test66
-rw-r--r--test/COFF/armnt-branch24t.test59
-rw-r--r--test/COFF/armnt-entry-point.test5
-rw-r--r--test/COFF/armnt-imports.test51
-rw-r--r--test/COFF/armnt-mov32t-exec.test60
-rw-r--r--test/COFF/armnt-movt32t.test72
-rw-r--r--test/COFF/base.test57
-rw-r--r--test/COFF/baserel.test215
-rw-r--r--test/COFF/common.test102
-rw-r--r--test/COFF/conflict.test41
-rw-r--r--test/COFF/debug.test38
-rw-r--r--test/COFF/defparser.test13
-rw-r--r--test/COFF/delayimports.test41
-rw-r--r--test/COFF/delayimports32.test86
-rw-r--r--test/COFF/dll.test53
-rw-r--r--test/COFF/dllorder.test65
-rw-r--r--test/COFF/driver.test3
-rw-r--r--test/COFF/entry-inference.test50
-rw-r--r--test/COFF/entry-inference2.test39
-rw-r--r--test/COFF/entry-inference32.test35
-rw-r--r--test/COFF/entry-mangled.test35
-rw-r--r--test/COFF/entrylib.ll11
-rw-r--r--test/COFF/export-exe.test11
-rw-r--r--test/COFF/export.test82
-rw-r--r--test/COFF/export32.test133
-rw-r--r--test/COFF/failifmismatch.test11
-rw-r--r--test/COFF/filetype.test4
-rw-r--r--test/COFF/force.test43
-rw-r--r--test/COFF/heap.test25
-rw-r--r--test/COFF/hello32.test129
-rw-r--r--test/COFF/help.test3
-rw-r--r--test/COFF/icf-circular.test81
-rw-r--r--test/COFF/icf-circular2.test69
-rw-r--r--test/COFF/icf-different-align.test61
-rw-r--r--test/COFF/icf-local.test66
-rw-r--r--test/COFF/icf-simple.test71
-rw-r--r--test/COFF/imports-mangle.test66
-rw-r--r--test/COFF/imports.test35
-rw-r--r--test/COFF/include.test83
-rw-r--r--test/COFF/include2.test14
-rw-r--r--test/COFF/internal.test42
-rw-r--r--test/COFF/invalid-obj.test14
-rw-r--r--test/COFF/largeaddressaware.test21
-rw-r--r--test/COFF/libpath.test18
-rw-r--r--test/COFF/linkenv.test4
-rw-r--r--test/COFF/lldmap.test8
-rw-r--r--test/COFF/loadcfg.ll15
-rw-r--r--test/COFF/loadcfg.test59
-rw-r--r--test/COFF/loadcfg32.test42
-rw-r--r--test/COFF/locally-imported.test61
-rw-r--r--test/COFF/locally-imported32.test50
-rw-r--r--test/COFF/long-section-name.test58
-rw-r--r--test/COFF/lto-chkstk.ll17
-rw-r--r--test/COFF/lto-comdat.ll131
-rw-r--r--test/COFF/lto-linker-opts.ll11
-rw-r--r--test/COFF/lto-new-symbol.ll16
-rw-r--r--test/COFF/lto-opt-level.ll21
-rw-r--r--test/COFF/lto-parallel.ll20
-rw-r--r--test/COFF/lto.ll130
-rw-r--r--test/COFF/machine.test30
-rw-r--r--test/COFF/manifest.test61
-rw-r--r--test/COFF/merge.test53
-rw-r--r--test/COFF/nodefaultlib.test30
-rw-r--r--test/COFF/noentry.test11
-rw-r--r--test/COFF/opt.test69
-rw-r--r--test/COFF/options.test51
-rw-r--r--test/COFF/order.test15
-rw-r--r--test/COFF/out.test16
-rw-r--r--test/COFF/reloc-arm.test71
-rw-r--r--test/COFF/reloc-x64.test102
-rw-r--r--test/COFF/reloc-x86.test82
-rw-r--r--test/COFF/resource.test14
-rw-r--r--test/COFF/responsefile.test7
-rw-r--r--test/COFF/safeseh.test51
-rw-r--r--test/COFF/seh.test70
-rw-r--r--test/COFF/sort-debug.test296
-rw-r--r--test/COFF/stack.test25
-rw-r--r--test/COFF/subsystem-inference.test74
-rw-r--r--test/COFF/subsystem.test19
-rw-r--r--test/COFF/symtab.test254
-rw-r--r--test/COFF/tls.test43
-rw-r--r--test/COFF/tls32.test43
-rw-r--r--test/COFF/unwind.test198
-rw-r--r--test/COFF/version.test19
-rw-r--r--test/COFF/weak-external.test36
-rw-r--r--test/COFF/weak-external2.test30
-rw-r--r--test/COFF/weak-external3.test32
121 files changed, 5388 insertions, 0 deletions
diff --git a/test/COFF/Inputs/armnt-executable.obj.yaml b/test/COFF/Inputs/armnt-executable.obj.yaml
new file mode 100644
index 0000000000000..33b2c886b8607
--- /dev/null
+++ b/test/COFF/Inputs/armnt-executable.obj.yaml
@@ -0,0 +1,29 @@
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_ARMNT
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_PURGEABLE, IMAGE_SCN_MEM_16BIT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: '7047'
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 2
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 1
+ - Name: mainCRTStartup
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/Inputs/armnt-executable.s b/test/COFF/Inputs/armnt-executable.s
new file mode 100644
index 0000000000000..7e1a8ce821204
--- /dev/null
+++ b/test/COFF/Inputs/armnt-executable.s
@@ -0,0 +1,13 @@
+# void mainCRTStartup() {}
+ .syntax unified
+ .thumb
+ .text
+ .def mainCRTStartup
+ .scl 2
+ .type 32
+ .endef
+ .global mainCRTStartup
+ .align 2
+ .thumb_func
+mainCRTStartup:
+ bx lr
diff --git a/test/COFF/Inputs/conflict.ll b/test/COFF/Inputs/conflict.ll
new file mode 100644
index 0000000000000..8cd7d706e5fb5
--- /dev/null
+++ b/test/COFF/Inputs/conflict.ll
@@ -0,0 +1,6 @@
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+define void @foo() {
+ ret void
+}
diff --git a/test/COFF/Inputs/entry-mangled.ll b/test/COFF/Inputs/entry-mangled.ll
new file mode 100644
index 0000000000000..b6fac214dfc16
--- /dev/null
+++ b/test/COFF/Inputs/entry-mangled.ll
@@ -0,0 +1,6 @@
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc18.0.0"
+
+define void @"\01?main@@YAHXZ"() {
+ ret void
+}
diff --git a/test/COFF/Inputs/export.ll b/test/COFF/Inputs/export.ll
new file mode 100644
index 0000000000000..d254683cdd6f9
--- /dev/null
+++ b/test/COFF/Inputs/export.ll
@@ -0,0 +1,18 @@
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+define void @_DllMainCRTStartup() {
+ ret void
+}
+
+define void @exportfn1() {
+ ret void
+}
+
+define void @exportfn2() {
+ ret void
+}
+
+define dllexport void @exportfn3() {
+ ret void
+}
diff --git a/test/COFF/Inputs/export.yaml b/test/COFF/Inputs/export.yaml
new file mode 100644
index 0000000000000..25b57288a1bf7
--- /dev/null
+++ b/test/COFF/Inputs/export.yaml
@@ -0,0 +1,57 @@
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: B800000000506800000000680000000050E80000000050E800000000
+ - Name: .drectve
+ Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ]
+ Alignment: 2147483648
+ SectionData: 2f6578706f72743a6578706f7274666e3300 # /export:exportfn3
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 28
+ NumberOfRelocations: 4
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: _DllMainCRTStartup
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: exportfn1
+ Value: 8
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: exportfn2
+ Value: 16
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: exportfn3
+ Value: 16
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: '?mangled@@YAHXZ'
+ Value: 16
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/Inputs/export2.yaml b/test/COFF/Inputs/export2.yaml
new file mode 100644
index 0000000000000..592b76526ffa6
--- /dev/null
+++ b/test/COFF/Inputs/export2.yaml
@@ -0,0 +1,29 @@
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: B800000000506800000000680000000050E80000000050E800000000
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 28
+ NumberOfRelocations: 4
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: '?mangled2@@YAHXZ'
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/Inputs/hello32.yaml b/test/COFF/Inputs/hello32.yaml
new file mode 100644
index 0000000000000..ea5a5c84c4f15
--- /dev/null
+++ b/test/COFF/Inputs/hello32.yaml
@@ -0,0 +1,82 @@
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_I386
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 16
+ SectionData: 33DB538D0500000000508D05000000005053E80000000050E800000000
+ Relocations:
+ - VirtualAddress: 5
+ SymbolName: caption
+ Type: IMAGE_REL_I386_DIR32
+ - VirtualAddress: 12
+ SymbolName: message
+ Type: IMAGE_REL_I386_DIR32
+ - VirtualAddress: 19
+ SymbolName: '_MessageBoxA@16'
+ Type: IMAGE_REL_I386_REL32
+ - VirtualAddress: 25
+ SymbolName: '_ExitProcess@4'
+ Type: IMAGE_REL_I386_REL32
+ - Name: .data
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
+ Alignment: 16
+ SectionData: 48656C6C6F0048656C6C6F20576F726C642100
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 29
+ NumberOfRelocations: 4
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: .data
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 19
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: '_ExitProcess@4'
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: '_MessageBoxA@16'
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: message
+ Value: 6
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ - Name: caption
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ - Name: '_main@0'
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/Inputs/hello64.asm b/test/COFF/Inputs/hello64.asm
new file mode 100644
index 0000000000000..6605213224bc0
--- /dev/null
+++ b/test/COFF/Inputs/hello64.asm
@@ -0,0 +1,24 @@
+;; ml64 hello64.asm /link /subsystem:windows /defaultlib:kernel32 \
+;; /defaultlib:user32 /out:hello64.exe /entry:main
+
+extern ExitProcess : PROC
+extern MessageBoxA : PROC
+extern ImportByOrdinal: PROC
+
+.data
+ caption db 'Hello', 0
+ message db 'Hello World!', 0
+
+.code
+main PROC
+ sub rsp,28h
+ mov rcx, 0
+ lea rdx, message
+ lea r8, caption
+ mov r9d, 0
+ call MessageBoxA
+ mov ecx, 0
+ call ExitProcess
+ call ImportByOrdinal
+main ENDP
+END
diff --git a/test/COFF/Inputs/hello64.obj b/test/COFF/Inputs/hello64.obj
new file mode 100644
index 0000000000000..90c1ce4aa4cff
--- /dev/null
+++ b/test/COFF/Inputs/hello64.obj
Binary files differ
diff --git a/test/COFF/Inputs/import.yaml b/test/COFF/Inputs/import.yaml
new file mode 100644
index 0000000000000..2c5fdc545b484
--- /dev/null
+++ b/test/COFF/Inputs/import.yaml
@@ -0,0 +1,41 @@
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: 0000000000000000
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 8
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: exportfn1
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: exportfn2
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/Inputs/imports-mangle.lib b/test/COFF/Inputs/imports-mangle.lib
new file mode 100644
index 0000000000000..f3c722ad07462
--- /dev/null
+++ b/test/COFF/Inputs/imports-mangle.lib
Binary files differ
diff --git a/test/COFF/Inputs/include1a.yaml b/test/COFF/Inputs/include1a.yaml
new file mode 100644
index 0000000000000..7fca9833cb7bb
--- /dev/null
+++ b/test/COFF/Inputs/include1a.yaml
@@ -0,0 +1,33 @@
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: B800000000506800000000680000000050E80000000050E800000000
+ - Name: .drectve
+ Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ]
+ Alignment: 2147483648
+ SectionData: 2f696e636c7564653a666f6f00 # /include:foo
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 28
+ NumberOfRelocations: 4
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/Inputs/include1b.yaml b/test/COFF/Inputs/include1b.yaml
new file mode 100644
index 0000000000000..e4151be27cc37
--- /dev/null
+++ b/test/COFF/Inputs/include1b.yaml
@@ -0,0 +1,33 @@
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: B800000000506800000000680000000050E80000000050E800000000
+ - Name: .drectve
+ Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ]
+ Alignment: 2147483648
+ SectionData: 2f696e636c7564653a62617200 # /include:bar
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 28
+ NumberOfRelocations: 4
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: foo
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/Inputs/include1c.yaml b/test/COFF/Inputs/include1c.yaml
new file mode 100644
index 0000000000000..78dd29659e228
--- /dev/null
+++ b/test/COFF/Inputs/include1c.yaml
@@ -0,0 +1,29 @@
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: B800000000506800000000680000000050E80000000050E800000000
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 28
+ NumberOfRelocations: 4
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: bar
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/Inputs/library.lib b/test/COFF/Inputs/library.lib
new file mode 100755
index 0000000000000..2f4207d7983da
--- /dev/null
+++ b/test/COFF/Inputs/library.lib
Binary files differ
diff --git a/test/COFF/Inputs/lto-chkstk-chkstk.s b/test/COFF/Inputs/lto-chkstk-chkstk.s
new file mode 100644
index 0000000000000..292b30d5ffabf
--- /dev/null
+++ b/test/COFF/Inputs/lto-chkstk-chkstk.s
@@ -0,0 +1,3 @@
+.globl __chkstk
+__chkstk:
+ret
diff --git a/test/COFF/Inputs/lto-chkstk-foo.s b/test/COFF/Inputs/lto-chkstk-foo.s
new file mode 100644
index 0000000000000..a69f870a1b60e
--- /dev/null
+++ b/test/COFF/Inputs/lto-chkstk-foo.s
@@ -0,0 +1,3 @@
+.globl foo
+foo:
+ret
diff --git a/test/COFF/Inputs/lto-comdat1.ll b/test/COFF/Inputs/lto-comdat1.ll
new file mode 100644
index 0000000000000..7a9f50c0f9db2
--- /dev/null
+++ b/test/COFF/Inputs/lto-comdat1.ll
@@ -0,0 +1,13 @@
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+$comdat = comdat any
+
+define void @f1() {
+ call void @comdat()
+ ret void
+}
+
+define linkonce_odr void @comdat() comdat {
+ ret void
+}
diff --git a/test/COFF/Inputs/lto-comdat2.ll b/test/COFF/Inputs/lto-comdat2.ll
new file mode 100644
index 0000000000000..c2af2a4de597b
--- /dev/null
+++ b/test/COFF/Inputs/lto-comdat2.ll
@@ -0,0 +1,13 @@
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+$comdat = comdat any
+
+define void @f2() {
+ call void @comdat()
+ ret void
+}
+
+define linkonce_odr void @comdat() comdat {
+ ret void
+}
diff --git a/test/COFF/Inputs/lto-dep.ll b/test/COFF/Inputs/lto-dep.ll
new file mode 100644
index 0000000000000..d6d47f2349172
--- /dev/null
+++ b/test/COFF/Inputs/lto-dep.ll
@@ -0,0 +1,10 @@
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+define void @foo() {
+ ret void
+}
+
+define internal void @internal() {
+ ret void
+}
diff --git a/test/COFF/Inputs/machine-x64.yaml b/test/COFF/Inputs/machine-x64.yaml
new file mode 100644
index 0000000000000..d70e0808a2e1f
--- /dev/null
+++ b/test/COFF/Inputs/machine-x64.yaml
@@ -0,0 +1,29 @@
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: 000000000000
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 6
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/Inputs/machine-x86.yaml b/test/COFF/Inputs/machine-x86.yaml
new file mode 100644
index 0000000000000..6b6cfae09c572
--- /dev/null
+++ b/test/COFF/Inputs/machine-x86.yaml
@@ -0,0 +1,29 @@
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_I386
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: 000000000000
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 6
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: _main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/Inputs/resource.res b/test/COFF/Inputs/resource.res
new file mode 100644
index 0000000000000..f1c799fbbb08f
--- /dev/null
+++ b/test/COFF/Inputs/resource.res
Binary files differ
diff --git a/test/COFF/Inputs/ret42.lib b/test/COFF/Inputs/ret42.lib
new file mode 100644
index 0000000000000..f60a9cdf6f903
--- /dev/null
+++ b/test/COFF/Inputs/ret42.lib
Binary files differ
diff --git a/test/COFF/Inputs/ret42.obj b/test/COFF/Inputs/ret42.obj
new file mode 100644
index 0000000000000..1765f0e7c36ed
--- /dev/null
+++ b/test/COFF/Inputs/ret42.obj
Binary files differ
diff --git a/test/COFF/Inputs/ret42.yaml b/test/COFF/Inputs/ret42.yaml
new file mode 100644
index 0000000000000..2b38cc7f0d6ba
--- /dev/null
+++ b/test/COFF/Inputs/ret42.yaml
@@ -0,0 +1,45 @@
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: '.text$mn'
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 16
+ SectionData: B82A000000C3
+ - Name: .data
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
+ Alignment: 16
+ SectionData: ''
+symbols:
+ - Name: '.text$mn'
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 6
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: .data
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 0
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/Inputs/std32.lib b/test/COFF/Inputs/std32.lib
new file mode 100644
index 0000000000000..7401ff3faf9e9
--- /dev/null
+++ b/test/COFF/Inputs/std32.lib
Binary files differ
diff --git a/test/COFF/Inputs/std64.lib b/test/COFF/Inputs/std64.lib
new file mode 100644
index 0000000000000..bbd223c59f401
--- /dev/null
+++ b/test/COFF/Inputs/std64.lib
Binary files differ
diff --git a/test/COFF/Inputs/weak-external.ll b/test/COFF/Inputs/weak-external.ll
new file mode 100644
index 0000000000000..4775d50456c99
--- /dev/null
+++ b/test/COFF/Inputs/weak-external.ll
@@ -0,0 +1,6 @@
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+define void @g() {
+ ret void
+}
diff --git a/test/COFF/Inputs/weak-external2.ll b/test/COFF/Inputs/weak-external2.ll
new file mode 100644
index 0000000000000..2102c3b6a526b
--- /dev/null
+++ b/test/COFF/Inputs/weak-external2.ll
@@ -0,0 +1,6 @@
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+define void @f() {
+ ret void
+}
diff --git a/test/COFF/Inputs/weak-external3.ll b/test/COFF/Inputs/weak-external3.ll
new file mode 100644
index 0000000000000..f9a51360a89d2
--- /dev/null
+++ b/test/COFF/Inputs/weak-external3.ll
@@ -0,0 +1,8 @@
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+@f = weak alias void(), void()* @g
+
+define void @g() {
+ ret void
+}
diff --git a/test/COFF/alternatename.test b/test/COFF/alternatename.test
new file mode 100644
index 0000000000000..5b9dc470af161
--- /dev/null
+++ b/test/COFF/alternatename.test
@@ -0,0 +1,61 @@
+# RUN: yaml2obj < %p/Inputs/ret42.yaml > %t.obj
+# RUN: lld-link /entry:foo /subsystem:console \
+# RUN: /alternatename:foo=main /out:%t.exe %t.obj
+# RUN: lld-link /entry:foo /subsystem:console \
+# RUN: /alternatename:foo=main \
+# RUN: /alternatename:foo=main \
+# RUN: /alternatename:nosuchsym1=nosuchsym2 \
+# RUN: /out:%t.exe %t.obj
+
+# RUN: yaml2obj < %s > %t.obj
+# RUN: lld-link /entry:foo /subsystem:console /out:%t.exe %t.obj
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: '.text$mn'
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 16
+ SectionData: B82A000000C3
+ - Name: .data
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
+ Alignment: 16
+ SectionData: ''
+ - Name: .drectve
+ Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ]
+ Alignment: 2147483648
+ SectionData: 2f616c7465726e6174656e616d653a666f6f3d6d61696e00 # /alternatename:foo=main
+symbols:
+ - Name: '.text$mn'
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 6
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: .data
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 0
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/ar-comdat.test b/test/COFF/ar-comdat.test
new file mode 100644
index 0000000000000..af7d732ea3c00
--- /dev/null
+++ b/test/COFF/ar-comdat.test
@@ -0,0 +1,38 @@
+# RUN: yaml2obj %s > %t1.obj
+# RUN: yaml2obj %s > %t2.obj
+# RUN: llvm-lib /out:%t.lib %t1.obj %t2.obj
+# RUN: lld-link /out:%t.exe /lldmap:%t.map /entry:main /subsystem:console %p/Inputs/ret42.obj %t.lib
+# RUN: FileCheck %s < %t.map
+
+# CHECK-NOT: .lib
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: [ ]
+sections:
+ - Name: .bss
+ Characteristics: [ IMAGE_SCN_CNT_UNINITIALIZED_DATA, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
+ Alignment: 4
+ SectionData: ''
+symbols:
+ - Name: .bss
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 4
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 1
+ Selection: IMAGE_COMDAT_SELECT_ANY
+ - Name: x
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/armnt-blx23t.test b/test/COFF/armnt-blx23t.test
new file mode 100644
index 0000000000000..fdc2bf51afb39
--- /dev/null
+++ b/test/COFF/armnt-blx23t.test
@@ -0,0 +1,66 @@
+# REQUIRES: arm
+
+# RUN: yaml2obj < %s > %t.obj
+# RUN: llvm-objdump -d %t.obj | FileCheck %s -check-prefix BEFORE
+# RUN: lld-link /entry:function /subsystem:console /out:%t.exe %t.obj
+# RUN: llvm-objdump -d %t.exe | FileCheck %s -check-prefix AFTER
+
+# BEFORE: Disassembly of section .text:
+# BEFORE: 0: 70 47 bx lr
+# BEFORE: 2: 00 bf nop
+# BEFORE: 4: 2d e9 00 48 push.w {r11, lr}
+# BEFORE: 8: eb 46 mov r11, sp
+# BEFORE: a: 20 20 movs r0, #32
+# BEFORE: c: 00 f0 00 f8 bl #0
+# BEFORE: 10: 01 30 adds r0, #1
+# BEFORE: 12: bd e8 00 88 pop.w {r11, pc}
+
+# AFTER: Disassembly of section .text:
+# AFTER: 1000: 70 47 bx lr
+# AFTER: 1002: 00 bf nop
+# AFTER: 1004: 2d e9 00 48 push.w {r11, lr}
+# AFTER: 1008: eb 46 mov r11, sp
+# AFTER: 100a: 20 20 movs r0, #32
+# AFTER: 100c: ff f7 f8 ff bl #-16
+# AFTER: 1010: 01 30 adds r0, #1
+# AFTER: 1012: bd e8 00 88 pop.w {r11, pc}
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_ARMNT
+ Characteristics: [ ]
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_PURGEABLE, IMAGE_SCN_MEM_16BIT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: 704700BF2DE90048EB46202000F000F80130BDE80088
+ Relocations:
+ - VirtualAddress: 12
+ SymbolName: identity
+ Type: 21
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 22
+ NumberOfRelocations: 1
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 1
+ - Name: identity
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: function
+ Value: 4
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/armnt-branch24t.test b/test/COFF/armnt-branch24t.test
new file mode 100644
index 0000000000000..358b603303b31
--- /dev/null
+++ b/test/COFF/armnt-branch24t.test
@@ -0,0 +1,59 @@
+# REQUIRES: arm
+
+# RUN: yaml2obj < %s > %t.obj
+# RUN: llvm-objdump -d %t.obj | FileCheck %s -check-prefix BEFORE
+# RUN: lld-link /entry:function /subsystem:console /out:%t.exe %t.obj
+# RUN: llvm-objdump -d %t.exe | FileCheck %s -check-prefix AFTER
+
+# BEFORE: Disassembly of section .text:
+# BEFORE: 0: 70 47 bx lr
+# BEFORE: 2: 00 bf nop
+# BEFORE: 4: 20 20 movs r0, #32
+# BEFORE: 6: 00 f0 00 b8 b.w #0
+
+# AFTER: Disassembly of section .text:
+# AFTER: .text:
+# AFTER: 1000: 70 47 bx lr
+# AFTER: 1002: 00 bf nop
+# AFTER: 1004: 20 20 movs r0, #32
+# AFTER: 1006: ff f7 fb bf b.w #-10
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_ARMNT
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_PURGEABLE, IMAGE_SCN_MEM_16BIT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: 704700BF202000F000B8
+ Relocations:
+ - VirtualAddress: 6
+ SymbolName: identity
+ Type: 20
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 10
+ NumberOfRelocations: 1
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 1
+ - Name: identity
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: function
+ Value: 4
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/armnt-entry-point.test b/test/COFF/armnt-entry-point.test
new file mode 100644
index 0000000000000..7b1bd100e0835
--- /dev/null
+++ b/test/COFF/armnt-entry-point.test
@@ -0,0 +1,5 @@
+# RUN: yaml2obj < %p/Inputs/armnt-executable.obj.yaml > %t.obj
+# RUN: lld-link /out:%t.exe /entry:mainCRTStartup /subsystem:console %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s
+
+CHECK: AddressOfEntryPoint: 0x1001
diff --git a/test/COFF/armnt-imports.test b/test/COFF/armnt-imports.test
new file mode 100644
index 0000000000000..3842259a7a72a
--- /dev/null
+++ b/test/COFF/armnt-imports.test
@@ -0,0 +1,51 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: lld-link /out:%t.exe /subsystem:console %t.obj \
+# RUN: /entry:mainCRTStartup %p/Inputs/library.lib
+# RUN: llvm-readobj -coff-imports %t.exe | FileCheck %s
+
+# CHECK: Import {
+# CHECK: Name: library.dll
+# CHECK: ImportLookupTableRVA: 0x2028
+# CHECK: ImportAddressTableRVA: 0x2030
+# CHECK: Symbol: function (0)
+# CHECK: }
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_ARMNT
+ Characteristics: [ ]
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_PURGEABLE, IMAGE_SCN_MEM_16BIT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: 40F20000C0F2000000680047
+ Relocations:
+ - VirtualAddress: 0
+ SymbolName: __imp_function
+ Type: 17
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 12
+ NumberOfRelocations: 1
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 1
+ - Name: mainCRTStartup
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: __imp_function
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/armnt-mov32t-exec.test b/test/COFF/armnt-mov32t-exec.test
new file mode 100644
index 0000000000000..7fa9952e95470
--- /dev/null
+++ b/test/COFF/armnt-mov32t-exec.test
@@ -0,0 +1,60 @@
+# REQUIRES: arm
+
+# RUN: yaml2obj < %s > %t.obj
+# RUN: llvm-objdump -d %t.obj | FileCheck %s -check-prefix BEFORE
+# RUN: lld-link /out:%t.exe /subsystem:console /entry:get_function %t.obj
+# RUN: llvm-objdump -d %t.exe | FileCheck %s -check-prefix AFTER
+
+# BEFORE: Disassembly of section .text:
+# BEFORE: 0: 70 47 bx lr
+# BEFORE: 2: 00 bf nop
+# BEFORE: 4: 40 f2 00 00 movw r0, #0
+# BEFORE: 8: c0 f2 00 00 movt r0, #0
+# BEFORE: c: 70 47 bx lr
+
+# AFTER: Disassembly of section .text:
+# AFTER: 1000: 70 47 bx lr
+# AFTER: 1002: 00 bf nop
+# AFTER: 1004: 41 f2 01 00 movw r0, #4097
+# AFTER: 1008: c0 f2 40 00 movt r0, #64
+# AFTER: 100c: 70 47 bx lr
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_ARMNT
+ Characteristics: [ ]
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_PURGEABLE, IMAGE_SCN_MEM_16BIT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: 704700BF40F20000C0F200007047
+ Relocations:
+ - VirtualAddress: 4
+ SymbolName: function
+ Type: 17
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 14
+ NumberOfRelocations: 1
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 1
+ - Name: function
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: get_function
+ Value: 4
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/armnt-movt32t.test b/test/COFF/armnt-movt32t.test
new file mode 100644
index 0000000000000..be292cb393008
--- /dev/null
+++ b/test/COFF/armnt-movt32t.test
@@ -0,0 +1,72 @@
+# REQUIRES: arm
+
+# RUN: yaml2obj < %s > %t.obj
+# RUN: llvm-objdump -d %t.obj | FileCheck %s -check-prefix BEFORE
+# RUN: lld-link /entry:get_buffer /subsystem:console /out:%t.exe %t.obj
+# RUN: llvm-objdump -d %t.exe | FileCheck %s -check-prefix AFTER
+
+# BEFORE: Disassembly of section .text:
+# BEFORE: 0: 40 f2 00 00 movw r0, #0
+# BEFORE: 4: c0 f2 00 00 movt r0, #0
+# BEFORE: 8: 70 47 bx lr
+
+# AFTER: Disassembly of section .text:
+# AFTER: 0: 41 f2 00 00 movw r0, #4096
+# AFTER: 4: c0 f2 40 00 movt r0, #64
+# AFTER: 8: 70 47 bx lr
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_ARMNT
+ Characteristics: [ ]
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_PURGEABLE, IMAGE_SCN_MEM_16BIT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: 40F20000C0F200007047
+ Relocations:
+ - VirtualAddress: 0
+ SymbolName: buffer
+ Type: 17
+ - Name: .rdata
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
+ Alignment: 1
+ SectionData: '62756666657200'
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 10
+ NumberOfRelocations: 1
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 1
+ - Name: .rdata
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 7
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 2
+ - Name: get_buffer
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: buffer
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+...
diff --git a/test/COFF/base.test b/test/COFF/base.test
new file mode 100644
index 0000000000000..f03e321fc23a2
--- /dev/null
+++ b/test/COFF/base.test
@@ -0,0 +1,57 @@
+# RUN: yaml2obj < %s > %t.obj
+
+# RUN: lld-link /out:%t.exe /entry:main %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=DEFAULT-HEADER %s
+# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=DEFAULT-TEXT %s
+
+# DEFAULT-HEADER: ImageBase: 0x140000000
+# DEFAULT-TEXT: Contents of section .text:
+# DEFAULT-TEXT-NEXT: 1000 00000040 01000000
+
+# RUN: lld-link /out:%t.exe /entry:main %t.obj /base:0x280000000
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=BASE-HEADER %s
+# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=BASE-TEXT %s
+
+# BASE-HEADER: ImageBase: 0x280000000
+# BASE-TEXT: Contents of section .text:
+# BASE-TEXT-NEXT: 1000 00000080 02000000
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4096
+ SectionData: 0000000000000000
+ Relocations:
+ - VirtualAddress: 0
+ SymbolName: __ImageBase
+ Type: IMAGE_REL_AMD64_ADDR64
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 8
+ NumberOfRelocations: 1
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: __ImageBase
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/baserel.test b/test/COFF/baserel.test
new file mode 100644
index 0000000000000..bac9c22cbc3d0
--- /dev/null
+++ b/test/COFF/baserel.test
@@ -0,0 +1,215 @@
+# RUN: yaml2obj < %s > %t.obj
+#
+# RUN: lld-link /out:%t.exe /entry:main %t.obj %p/Inputs/std64.lib
+# RUN: llvm-readobj -coff-basereloc %t.exe | FileCheck %s -check-prefix=BASEREL
+#
+# RUN: lld-link /out:%t.exe /entry:main /fixed %t.obj %p/Inputs/std64.lib
+# RUN: llvm-readobj -coff-basereloc %t.exe | FileCheck %s -check-prefix=NOBASEREL
+#
+# BASEREL: BaseReloc [
+# BASEREL-NEXT: Entry {
+# BASEREL-NEXT: Type: DIR64
+# BASEREL-NEXT: Address: 0x2007
+# BASEREL-NEXT: }
+# BASEREL-NEXT: Entry {
+# BASEREL-NEXT: Type: DIR64
+# BASEREL-NEXT: Address: 0x200C
+# BASEREL-NEXT: }
+# BASEREL-NEXT: Entry {
+# BASEREL-NEXT: Type: DIR64
+# BASEREL-NEXT: Address: 0x201E
+# BASEREL-NEXT: }
+# BASEREL-NEXT: Entry {
+# BASEREL-NEXT: Type: ABSOLUTE
+# BASEREL-NEXT: Address: 0x2000
+# BASEREL-NEXT: }
+# BASEREL-NEXT: Entry {
+# BASEREL-NEXT: Type: DIR64
+# BASEREL-NEXT: Address: 0x3007
+# BASEREL-NEXT: }
+# BASEREL-NEXT: Entry {
+# BASEREL-NEXT: Type: DIR64
+# BASEREL-NEXT: Address: 0x300C
+# BASEREL-NEXT: }
+# BASEREL-NEXT: Entry {
+# BASEREL-NEXT: Type: DIR64
+# BASEREL-NEXT: Address: 0x301E
+# BASEREL-NEXT: }
+# BASEREL-NEXT: Entry {
+# BASEREL-NEXT: Type: ABSOLUTE
+# BASEREL-NEXT: Address: 0x3000
+# BASEREL-NEXT: }
+#
+# NOBASEREL: BaseReloc [
+# NOBASEREL-NEXT: ]
+#
+# RUN: lld-link /out:%t.exe /entry:main %t.obj %p/Inputs/std64.lib
+# RUN: llvm-readobj -file-headers -sections %t.exe | FileCheck %s \
+# RUN: --check-prefix=BASEREL-HEADER
+#
+# RN: lld-link /out:%t.exe /entry:main /fixed %t.obj %p/Inputs/std64.lib
+# RN: llvm-readobj -file-headers %t.exe | FileCheck %s \
+# RN: --check-prefix=NOBASEREL-HEADER
+#
+# BASEREL-HEADER-NOT: IMAGE_FILE_RELOCS_STRIPPED
+#
+# NOBASEREL-HEADER: IMAGE_FILE_RELOCS_STRIPPED
+#
+# BASEREL-HEADER: BaseRelocationTableRVA: 0x5000
+# BASEREL-HEADER: BaseRelocationTableSize: 0x20
+# BASEREL-HEADER: Name: .reloc (2E 72 65 6C 6F 63 00 00)
+# BASEREL-HEADER-NEXT: VirtualSize: 0x20
+# BASEREL-HEADER-NEXT: VirtualAddress: 0x5000
+# BASEREL-HEADER-NEXT: RawDataSize: 512
+# BASEREL-HEADER-NEXT: PointerToRawData: 0xC00
+# BASEREL-HEADER-NEXT: PointerToRelocations: 0x0
+# BASEREL-HEADER-NEXT: PointerToLineNumbers: 0x0
+# BASEREL-HEADER-NEXT: RelocationCount: 0
+# BASEREL-HEADER-NEXT: LineNumberCount: 0
+# BASEREL-HEADER-NEXT: Characteristics [ (0x42000040)
+# BASEREL-HEADER-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40)
+# BASEREL-HEADER-NEXT: IMAGE_SCN_MEM_DISCARDABLE (0x2000000)
+# BASEREL-HEADER-NEXT: IMAGE_SCN_MEM_READ (0x40000000)
+# BASEREL-HEADER-NEXT: ]
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4096
+ SectionData: B800000000000000005068000000000000000068000000000000000050E8000000000000000050E8000000000000000050E80000000000000000
+ Relocations:
+ - VirtualAddress: 0
+ SymbolName: abs_symbol
+ Type: IMAGE_REL_AMD64_ADDR64
+ - VirtualAddress: 7
+ SymbolName: caption
+ Type: IMAGE_REL_AMD64_ADDR64
+ - VirtualAddress: 12
+ SymbolName: message
+ Type: IMAGE_REL_AMD64_ADDR64
+ - VirtualAddress: 18
+ SymbolName: MessageBoxA
+ Type: IMAGE_REL_AMD64_REL32
+ - VirtualAddress: 24
+ SymbolName: ExitProcess
+ Type: IMAGE_REL_AMD64_REL32
+ - VirtualAddress: 30
+ SymbolName: __ImageBase
+ Type: IMAGE_REL_AMD64_ADDR64
+ - Name: .text2
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4096
+ SectionData: B800000000000000005068000000000000000068000000000000000050E8000000000000000050E8000000000000000050E80000000000000000
+ Relocations:
+ - VirtualAddress: 0
+ SymbolName: abs_symbol
+ Type: IMAGE_REL_AMD64_ADDR64
+ - VirtualAddress: 7
+ SymbolName: caption
+ Type: IMAGE_REL_AMD64_ADDR64
+ - VirtualAddress: 12
+ SymbolName: message
+ Type: IMAGE_REL_AMD64_ADDR64
+ - VirtualAddress: 18
+ SymbolName: MessageBoxA
+ Type: IMAGE_REL_AMD64_REL32
+ - VirtualAddress: 24
+ SymbolName: ExitProcess
+ Type: IMAGE_REL_AMD64_REL32
+ - VirtualAddress: 30
+ SymbolName: __ImageBase
+ Type: IMAGE_REL_AMD64_ADDR64
+ - Name: .data
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
+ Alignment: 4
+ SectionData: 48656C6C6F0048656C6C6F20576F726C6400
+symbols:
+ - Name: "@comp.id"
+ Value: 10394907
+ SectionNumber: 65535
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 28
+ NumberOfRelocations: 6
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: .text2
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 28
+ NumberOfRelocations: 6
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: .data
+ Value: 0
+ SectionNumber: 3
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 18
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: MessageBoxA
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: ExitProcess
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: message
+ Value: 6
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ - Name: main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: caption
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ - Name: abs_symbol
+ Value: 0xDEADBEEF
+ SectionNumber: -1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: __ImageBase
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/common.test b/test/COFF/common.test
new file mode 100644
index 0000000000000..de25848674edd
--- /dev/null
+++ b/test/COFF/common.test
@@ -0,0 +1,102 @@
+# RUN: yaml2obj %s > %t.obj
+# RUN: lld-link /out:%t.exe /entry:main %t.obj %t.obj
+# RUN: llvm-objdump -d %t.exe | FileCheck %s
+
+# Operands of B8 (MOV EAX) are common symbols
+# CHECK: 3000: b8 00 10 00 40
+# CHECK: 3005: b8 04 10 00 40
+# CHECK: 300a: b8 20 10 00 40
+# CHECK: 300f: b8 60 10 00 40
+# CHECK: 3014: b8 80 10 00 40
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: b800000000b800000000b800000000b800000000b800000000
+ Relocations:
+ - VirtualAddress: 1
+ SymbolName: bssdata4
+ Type: IMAGE_REL_AMD64_ADDR32
+ - VirtualAddress: 6
+ SymbolName: bsspad1
+ Type: IMAGE_REL_AMD64_ADDR32
+ - VirtualAddress: 11
+ SymbolName: bssdata64
+ Type: IMAGE_REL_AMD64_ADDR32
+ - VirtualAddress: 16
+ SymbolName: bsspad2
+ Type: IMAGE_REL_AMD64_ADDR32
+ - VirtualAddress: 21
+ SymbolName: bssdata16
+ Type: IMAGE_REL_AMD64_ADDR32
+ - Name: .data
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
+ Alignment: 4
+ SectionData: 03000000
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 0
+ NumberOfRelocations: 5
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: .data
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 4
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: bssdata4
+ Value: 4
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: bsspad1
+ Value: 1
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: bssdata64
+ Value: 64
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: bsspad2
+ Value: 1
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: bssdata16
+ Value: 16
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/conflict.test b/test/COFF/conflict.test
new file mode 100644
index 0000000000000..3d5725ab79ee8
--- /dev/null
+++ b/test/COFF/conflict.test
@@ -0,0 +1,41 @@
+# RUN: yaml2obj < %s > %t1.obj
+# RUN: yaml2obj < %s > %t2.obj
+# RUN: not lld-link /out:%t.exe %t1.obj %t2.obj >& %t.log
+# RUN: FileCheck %s < %t.log
+
+# RUN: llvm-as -o %t.lto1.obj %S/Inputs/conflict.ll
+# RUN: llvm-as -o %t.lto2.obj %S/Inputs/conflict.ll
+# RUN: not lld-link /out:%t.exe %t.lto1.obj %t.lto2.obj >& %t.log
+# RUN: FileCheck %s < %t.log
+
+# CHECK: duplicate symbol: foo {{.+}}1.obj and foo {{.+}}2.obj
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 16
+ SectionData: 000000000000
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 6
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: foo
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/debug.test b/test/COFF/debug.test
new file mode 100644
index 0000000000000..52e0f60fe3f54
--- /dev/null
+++ b/test/COFF/debug.test
@@ -0,0 +1,38 @@
+# RUN: yaml2obj %s > %t.obj
+# RUN: lld-link /out:%t.exe /entry:main /subsystem:console %t.obj
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: B82A000000C3
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 6
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: debug
+ Value: 0
+ SectionNumber: -2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/defparser.test b/test/COFF/defparser.test
new file mode 100644
index 0000000000000..2e5223a699df2
--- /dev/null
+++ b/test/COFF/defparser.test
@@ -0,0 +1,13 @@
+# RUN: yaml2obj < %p/Inputs/ret42.yaml > %t.obj
+
+# RUN: echo -e "LIBRARY foo\nEXPORTS ? @" > %t.def
+# RUN: not lld-link /def:%t.def %t.obj
+
+# RUN: echo -e "LIBRARY foo\nHEAP abc" > %t.def
+# RUN: not lld-link /def:%t.def %t.obj
+
+# RUN: echo -e "LIBRARY foo\nSTACK abc" > %t.def
+# RUN: not lld-link /def:%t.def %t.obj
+
+# RUN: echo -e "foo" > %t.def
+# RUN: not lld-link /def:%t.def %t.obj
diff --git a/test/COFF/delayimports.test b/test/COFF/delayimports.test
new file mode 100644
index 0000000000000..2c27d58dc793b
--- /dev/null
+++ b/test/COFF/delayimports.test
@@ -0,0 +1,41 @@
+# RUN: lld-link /out:%t.exe /entry:main /subsystem:console \
+# RUN: %p/Inputs/hello64.obj %p/Inputs/std64.lib /delayload:STD64.DLL \
+# RUN: /alternatename:__delayLoadHelper2=main
+# RUN: llvm-readobj -coff-imports %t.exe | FileCheck -check-prefix=IMPORT %s
+# RUN: llvm-readobj -coff-basereloc %t.exe | FileCheck -check-prefix=BASEREL %s
+
+IMPORT: DelayImport {
+IMPORT-NEXT: Name: std64.dll
+IMPORT-NEXT: Attributes: 0x1
+IMPORT-NEXT: ModuleHandle: 0x1018
+IMPORT-NEXT: ImportAddressTable: 0x1020
+IMPORT-NEXT: ImportNameTable: 0x3040
+IMPORT-NEXT: BoundDelayImportTable: 0x0
+IMPORT-NEXT: UnloadDelayImportTable: 0x0
+IMPORT-NEXT: Import {
+IMPORT-NEXT: Symbol: ExitProcess (0)
+IMPORT-NEXT: Address: 0x140002066
+IMPORT-NEXT: }
+IMPORT-NEXT: Import {
+IMPORT-NEXT: Symbol: (50)
+IMPORT-NEXT: Address: 0x1400020BD
+IMPORT-NEXT: }
+IMPORT-NEXT: Import {
+IMPORT-NEXT: Symbol: MessageBoxA (0)
+IMPORT-NEXT: Address: 0x140002114
+IMPORT-NEXT: }
+IMPORT-NEXT: }
+
+BASEREL: BaseReloc [
+BASEREL-NEXT: Entry {
+BASEREL-NEXT: Type: DIR64
+BASEREL-NEXT: Address: 0x1020
+BASEREL-NEXT: }
+BASEREL-NEXT: Entry {
+BASEREL-NEXT: Type: DIR64
+BASEREL-NEXT: Address: 0x1028
+BASEREL-NEXT: }
+BASEREL-NEXT: Entry {
+BASEREL-NEXT: Type: DIR64
+BASEREL-NEXT: Address: 0x1030
+BASEREL-NEXT: }
diff --git a/test/COFF/delayimports32.test b/test/COFF/delayimports32.test
new file mode 100644
index 0000000000000..328b34504ac5f
--- /dev/null
+++ b/test/COFF/delayimports32.test
@@ -0,0 +1,86 @@
+# RUN: yaml2obj < %p/Inputs/hello32.yaml > %t.obj
+# RUN: lld-link %t.obj %p/Inputs/std32.lib /subsystem:console \
+# RUN: /entry:main@0 /alternatename:___delayLoadHelper2@8=_main@0 \
+# RUN: /debug /delayload:std32.dll /out:%t.exe
+# RUN: llvm-readobj -coff-imports %t.exe | FileCheck -check-prefix=IMPORT %s
+# RUN: llvm-readobj -coff-basereloc %t.exe | FileCheck -check-prefix=BASEREL %s
+# RUN: llvm-objdump -d %t.exe | FileCheck -check-prefix=DISASM %s
+
+IMPORT: Format: COFF-i386
+IMPORT-NEXT: Arch: i386
+IMPORT-NEXT: AddressSize: 32bit
+IMPORT-NEXT: DelayImport {
+IMPORT-NEXT: Name: std32.dll
+IMPORT-NEXT: Attributes: 0x1
+IMPORT-NEXT: ModuleHandle: 0x1018
+IMPORT-NEXT: ImportAddressTable: 0x1020
+IMPORT-NEXT: ImportNameTable: 0x3040
+IMPORT-NEXT: BoundDelayImportTable: 0x0
+IMPORT-NEXT: UnloadDelayImportTable: 0x0
+IMPORT-NEXT: Import {
+IMPORT-NEXT: Symbol: ExitProcess (0)
+IMPORT-NEXT: Address: 0x402029
+IMPORT-NEXT: }
+IMPORT-NEXT: Import {
+IMPORT-NEXT: Symbol: MessageBoxA (0)
+IMPORT-NEXT: Address: 0x40203E
+IMPORT-NEXT: }
+IMPORT-NEXT: }
+
+BASEREL: BaseReloc [
+BASEREL-NEXT: Entry {
+BASEREL-NEXT: Type: HIGHLOW
+BASEREL-NEXT: Address: 0x1020
+BASEREL-NEXT: }
+BASEREL-NEXT: Entry {
+BASEREL-NEXT: Type: HIGHLOW
+BASEREL-NEXT: Address: 0x1024
+BASEREL-NEXT: }
+BASEREL-NEXT: Entry {
+BASEREL-NEXT: Type: HIGHLOW
+BASEREL-NEXT: Address: 0x2005
+BASEREL-NEXT: }
+BASEREL-NEXT: Entry {
+BASEREL-NEXT: Type: HIGHLOW
+BASEREL-NEXT: Address: 0x200C
+BASEREL-NEXT: }
+BASEREL-NEXT: Entry {
+BASEREL-NEXT: Type: HIGHLOW
+BASEREL-NEXT: Address: 0x201F
+BASEREL-NEXT: }
+BASEREL-NEXT: Entry {
+BASEREL-NEXT: Type: HIGHLOW
+BASEREL-NEXT: Address: 0x2025
+BASEREL-NEXT: }
+BASEREL-NEXT: Entry {
+BASEREL-NEXT: Type: HIGHLOW
+BASEREL-NEXT: Address: 0x202C
+BASEREL-NEXT: }
+BASEREL-NEXT: Entry {
+BASEREL-NEXT: Type: HIGHLOW
+BASEREL-NEXT: Address: 0x2031
+BASEREL-NEXT: }
+BASEREL-NEXT: Entry {
+BASEREL-NEXT: Type: HIGHLOW
+BASEREL-NEXT: Address: 0x2041
+BASEREL-NEXT: }
+BASEREL-NEXT: Entry {
+BASEREL-NEXT: Type: HIGHLOW
+BASEREL-NEXT: Address: 0x2046
+BASEREL-NEXT: }
+BASEREL-NEXT: ]
+
+DISASM: 202b: 68 20 10 40 00 pushl $4198432
+DISASM-NEXT: 2030: 68 00 30 40 00 pushl $4206592
+DISASM-NEXT: 2035: e8 c6 ff ff ff calll -58 <_main@0>
+DISASM-NEXT: 203a: 5a popl %edx
+DISASM-NEXT: 203b: 59 popl %ecx
+DISASM-NEXT: 203c: ff e0 jmpl *%eax
+DISASM-NEXT: 203e: 51 pushl %ecx
+DISASM-NEXT: 203f: 52 pushl %edx
+DISASM-NEXT: 2040: 68 24 10 40 00 pushl $4198436
+DISASM-NEXT: 2045: 68 00 30 40 00 pushl $4206592
+DISASM-NEXT: 204a: e8 b1 ff ff ff calll -79 <_main@0>
+DISASM-NEXT: 204f: 5a popl %edx
+DISASM-NEXT: 2050: 59 popl %ecx
+DISASM-NEXT: 2051: ff e0 jmpl *%eax
diff --git a/test/COFF/dll.test b/test/COFF/dll.test
new file mode 100644
index 0000000000000..bafd3c233c87d
--- /dev/null
+++ b/test/COFF/dll.test
@@ -0,0 +1,53 @@
+# REQUIRES: winres
+# REQUIRES: winlib
+
+# RUN: yaml2obj < %p/Inputs/export.yaml > %t.obj
+# RUN: lld-link /out:%t.dll /dll %t.obj /export:exportfn1 /export:exportfn2 \
+# RUN: /export:mangled
+# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=EXPORT %s
+
+EXPORT: Export Table:
+EXPORT: DLL name: dll.test.tmp.dll
+EXPORT: Ordinal RVA Name
+EXPORT-NEXT: 0 0
+EXPORT-NEXT: 1 0x1008 exportfn1
+EXPORT-NEXT: 2 0x1010 exportfn2
+EXPORT-NEXT: 3 0x1010 exportfn3
+EXPORT-NEXT: 4 0x1010 mangled
+
+# RUN: yaml2obj < %p/Inputs/export2.yaml > %t5.obj
+# RUN: rm -f %t5.lib
+# RUN: llvm-ar cru %t5.lib %t5.obj
+# RUN: lld-link /out:%t5.dll /dll %t.obj %t5.lib /export:mangled2
+# RUN: llvm-objdump -p %t5.dll | FileCheck -check-prefix=EXPORT2 %s
+
+EXPORT2: Export Table:
+EXPORT2: DLL name: dll.test.tmp5.dll
+EXPORT2: Ordinal RVA Name
+EXPORT2-NEXT: 0 0
+EXPORT2-NEXT: 1 0x1010 exportfn3
+EXPORT2-NEXT: 2 0x101c mangled2
+
+# RUN: llvm-as -o %t.lto.obj %p/Inputs/export.ll
+# RUN: lld-link /out:%t.lto.dll /dll %t.lto.obj /export:exportfn1 /export:exportfn2
+# RUN: llvm-objdump -p %t.lto.dll | FileCheck -check-prefix=EXPORT-LTO %s
+
+EXPORT-LTO: Export Table:
+EXPORT-LTO: DLL name: dll.test.tmp.lto.dll
+EXPORT-LTO: Ordinal RVA Name
+EXPORT-LTO-NEXT: 0 0
+EXPORT-LTO-NEXT: 1 0x1010 exportfn1
+EXPORT-LTO-NEXT: 2 0x1020 exportfn2
+EXPORT-LTO-NEXT: 3 0x1030 exportfn3
+
+# RUN: lld-link /out:%t.dll /dll %t.obj /implib:%t2.lib \
+# RUN: /export:exportfn1 /export:exportfn2
+# RUN: yaml2obj < %p/Inputs/import.yaml > %t2.obj
+# RUN: lld-link /out:%t2.exe /entry:main %t2.obj %t2.lib
+# RUN: llvm-readobj -coff-imports %t2.exe | FileCheck -check-prefix=IMPORT %s
+
+# RUN: lld-link /out:%t2.lto.exe /entry:main %t2.obj %t.lto.lib
+# RUN: llvm-readobj -coff-imports %t2.lto.exe | FileCheck -check-prefix=IMPORT %s
+
+IMPORT: Symbol: exportfn1
+IMPORT: Symbol: exportfn2
diff --git a/test/COFF/dllorder.test b/test/COFF/dllorder.test
new file mode 100644
index 0000000000000..417483d33086e
--- /dev/null
+++ b/test/COFF/dllorder.test
@@ -0,0 +1,65 @@
+# REQUIRES: winlib
+
+# RUN: yaml2obj < %s > %t.obj
+# RUN: mkdir -p %tlib
+# RUN: rm -f %tlib/lib1.lib
+# RUN: rm -f %tlib/lib2.lib
+
+# RUN: echo EXPORTS sym1 > %t1.def
+# RUN: echo EXPORTS sym2 > %t2.def
+# RUN: lib /nologo /machine:amd64 /def:%t1.def /out:%tlib\lib1.lib
+# RUN: lib /nologo /machine:amd64 /def:%t2.def /out:%tlib\lib2.lib
+
+# RUN: lld-link /out:%t1.exe /entry:main /libpath:%tlib %t.obj /defaultlib:lib1 /defaultlib:lib2
+# RUN: lld-link /out:%t2.exe /entry:main /libpath:%tlib %t.obj /defaultlib:lib2 /defaultlib:lib1
+
+# RUN: llvm-readobj -coff-imports %t1.exe | FileCheck -check-prefix=CHECK1 %s
+# RUN: llvm-readobj -coff-imports %t2.exe | FileCheck -check-prefix=CHECK2 %s
+
+# CHECK1: Name: dllorder.test.tmp1.dll
+# CHECK1: Name: dllorder.test.tmp2.dll
+
+# CHECK2: Name: dllorder.test.tmp2.dll
+# CHECK2: Name: dllorder.test.tmp1.dll
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4096
+ SectionData: 0000000000000000
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 8
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: __imp_sym1
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: __imp_sym2
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/driver.test b/test/COFF/driver.test
new file mode 100644
index 0000000000000..0832350a4f30a
--- /dev/null
+++ b/test/COFF/driver.test
@@ -0,0 +1,3 @@
+# RUN: not lld-link nosuchfile.obj >& %t.log
+# RUN: FileCheck -check-prefix=MISSING %s < %t.log
+MISSING: nosuchfile.obj: {{[Nn]}}o such file or directory
diff --git a/test/COFF/entry-inference.test b/test/COFF/entry-inference.test
new file mode 100644
index 0000000000000..2063f28edc772
--- /dev/null
+++ b/test/COFF/entry-inference.test
@@ -0,0 +1,50 @@
+# RUN: sed -e s/ENTRYNAME/main/ %s | yaml2obj > %t.obj
+# RUN: not lld-link /out:%t.exe %t.obj > %t.log 2>&1
+# RUN: FileCheck -check-prefix=MAIN %s < %t.log
+
+# RUN: sed s/ENTRYNAME/wmain/ %s | yaml2obj > %t.obj
+# RUN: not lld-link /out:%t.exe %t.obj > %t.log 2>&1
+# RUN: FileCheck -check-prefix=WMAIN %s < %t.log
+
+# RUN: sed s/ENTRYNAME/WinMain/ %s | yaml2obj > %t.obj
+# RUN: not lld-link /out:%t.exe %t.obj > %t.log 2>&1
+# RUN: FileCheck -check-prefix=WINMAIN %s < %t.log
+
+# RUN: sed s/ENTRYNAME/wWinMain/ %s | yaml2obj > %t.obj
+# RUN: not lld-link /out:%t.exe %t.obj > %t.log 2>&1
+# RUN: FileCheck -check-prefix=WWINMAIN %s < %t.log
+
+# MAIN: <root>: undefined symbol: mainCRTStartup
+# WMAIN: <root>: undefined symbol: wmainCRTStartup
+# WINMAIN: <root>: undefined symbol: WinMainCRTStartup
+# WWINMAIN: <root>: undefined symbol: wWinMainCRTStartup
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: B82A000000C3
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 6
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: ENTRYNAME
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/entry-inference2.test b/test/COFF/entry-inference2.test
new file mode 100644
index 0000000000000..afac80859d104
--- /dev/null
+++ b/test/COFF/entry-inference2.test
@@ -0,0 +1,39 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: not lld-link /out:%t.exe %t.obj /verbose > %t.log 2>&1
+# RUN: FileCheck %s < %t.log
+
+# CHECK: Entry name inferred: WinMainCRTStartup
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: B82A000000C3
+ - Name: .drectve
+ Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ]
+ Alignment: 2147483648
+ SectionData: 2f616c7465726e6174656e616d653a6d61696e3d57696e4d61696e00 # /alternatename:main=WinMain
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 6
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: WinMain
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/entry-inference32.test b/test/COFF/entry-inference32.test
new file mode 100644
index 0000000000000..6e1a5f925180f
--- /dev/null
+++ b/test/COFF/entry-inference32.test
@@ -0,0 +1,35 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: not lld-link /out:%t.exe %t.obj /verbose > %t.log 2>&1
+# RUN: FileCheck %s < %t.log
+
+# CHECK: Entry name inferred: _WinMainCRTStartup
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_I386
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: B82A000000C3
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 6
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: _WinMain@16
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/entry-mangled.test b/test/COFF/entry-mangled.test
new file mode 100644
index 0000000000000..41620336513e0
--- /dev/null
+++ b/test/COFF/entry-mangled.test
@@ -0,0 +1,35 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: lld-link /out:%t.exe /entry:main %t.obj
+# RUN: llvm-as -o %t.lto.obj %S/Inputs/entry-mangled.ll
+# RUN: lld-link /out:%t.exe /entry:main %t.lto.obj
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: 000000000000
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 6
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ Selection: IMAGE_COMDAT_SELECT_ANY
+ - Name: '?main@@YAHXZ'
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/entrylib.ll b/test/COFF/entrylib.ll
new file mode 100644
index 0000000000000..4ffa42c44a3e8
--- /dev/null
+++ b/test/COFF/entrylib.ll
@@ -0,0 +1,11 @@
+; RUN: llvm-as -o %t.obj %s
+; RUN: rm -f %t.lib
+; RUN: llvm-ar cru %t.lib %t.obj
+; RUN: lld-link /out:%t.exe /entry:main %t.lib
+
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+define i32 @main() {
+ ret i32 0
+}
diff --git a/test/COFF/export-exe.test b/test/COFF/export-exe.test
new file mode 100644
index 0000000000000..7a345160faa90
--- /dev/null
+++ b/test/COFF/export-exe.test
@@ -0,0 +1,11 @@
+# REQUIRES: winlib
+# RUN: lld-link /entry:main /out:%t.exe /subsystem:windows \
+# RUN: %p/Inputs/ret42.obj /export:main
+# RUN: llvm-objdump -p %t.exe | FileCheck %s
+
+CHECK: Export Table:
+CHECK-NEXT: DLL name: export-exe.test.tmp.exe
+CHECK-NEXT: Ordinal base: 0
+CHECK-NEXT: Ordinal RVA Name
+CHECK-NEXT: 0 0
+CHECK-NEXT: 1 0x1000 main
diff --git a/test/COFF/export.test b/test/COFF/export.test
new file mode 100644
index 0000000000000..a3ea0ab9bca24
--- /dev/null
+++ b/test/COFF/export.test
@@ -0,0 +1,82 @@
+# RUN: yaml2obj < %p/Inputs/export.yaml > %t.obj
+#
+# RUN: lld-link /out:%t.dll /dll %t.obj /export:exportfn1 /export:exportfn2
+# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=CHECK1 %s
+# REQUIRES: winlib
+
+CHECK1: Export Table:
+CHECK1: DLL name: export.test.tmp.dll
+CHECK1: Ordinal RVA Name
+CHECK1-NEXT: 0 0
+CHECK1-NEXT: 1 0x1008 exportfn1
+CHECK1-NEXT: 2 0x1010 exportfn2
+
+# RUN: lld-link /out:%t.dll /dll %t.obj /export:exportfn1,@5 /export:exportfn2
+# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=CHECK2 %s
+
+CHECK2: Export Table:
+CHECK2: DLL name: export.test.tmp.dll
+CHECK2: Ordinal RVA Name
+CHECK2-NEXT: 0 0
+CHECK2-NEXT: 1 0
+CHECK2-NEXT: 2 0
+CHECK2-NEXT: 3 0
+CHECK2-NEXT: 4 0
+CHECK2-NEXT: 5 0x1008 exportfn1
+CHECK2-NEXT: 6 0x1010 exportfn2
+CHECK2-NEXT: 7 0x1010 exportfn3
+
+# RUN: lld-link /out:%t.dll /dll %t.obj /export:exportfn1,@5,noname /export:exportfn2
+# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=CHECK3 %s
+
+CHECK3: Export Table:
+CHECK3: DLL name: export.test.tmp.dll
+CHECK3: Ordinal RVA Name
+CHECK3-NEXT: 0 0
+CHECK3-NEXT: 1 0
+CHECK3-NEXT: 2 0
+CHECK3-NEXT: 3 0
+CHECK3-NEXT: 4 0
+CHECK3-NEXT: 5 0x1008
+CHECK3-NEXT: 6 0x1010 exportfn2
+
+# RUN: lld-link /out:%t.dll /dll %t.obj /export:f1=exportfn1 /export:f2=exportfn2
+# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=CHECK4 %s
+
+CHECK4: Export Table:
+CHECK4: DLL name: export.test.tmp.dll
+CHECK4: Ordinal RVA Name
+CHECK4-NEXT: 0 0
+CHECK4-NEXT: 1 0x1010 exportfn3
+CHECK4-NEXT: 2 0x1008 f1
+CHECK4-NEXT: 3 0x1010 f2
+
+# RUN: echo "EXPORTS exportfn1 @3" > %t.def
+# RUN: echo "fn2=exportfn2 @2" >> %t.def
+# RUN: lld-link /out:%t.dll /dll %t.obj /def:%t.def
+# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=CHECK5 %s
+
+CHECK5: Export Table:
+CHECK5: DLL name: export.test.tmp.dll
+CHECK5: Ordinal RVA Name
+CHECK5-NEXT: 0 0
+CHECK5-NEXT: 1 0
+CHECK5-NEXT: 2 0x1010 fn2
+CHECK5-NEXT: 3 0x1008 exportfn1
+CHECK5-NEXT: 4 0x1010 exportfn3
+
+# RUN: lld-link /out:%t.DLL /dll %t.obj /export:exportfn1 /export:exportfn2 \
+# RUN: /export:exportfn1 /export:exportfn2,@5 >& %t.log
+# RUN: FileCheck -check-prefix=CHECK6 %s < %t.log
+
+CHECK6: duplicate /export option: exportfn2
+CHECK6-NOT: duplicate /export option: exportfn1
+
+# RUN: llvm-nm -M %t.lib | FileCheck --check-prefix=SYMTAB %s
+
+SYMTAB: __imp_exportfn1 in export.test.tmp.DLL
+SYMTAB: exportfn1 in export.test.tmp.DLL
+SYMTAB: __imp_exportfn2 in export.test.tmp.DLL
+SYMTAB: exportfn2 in export.test.tmp.DLL
+SYMTAB: __imp_exportfn3 in export.test.tmp.DLL
+SYMTAB: exportfn3 in export.test.tmp.DLL
diff --git a/test/COFF/export32.test b/test/COFF/export32.test
new file mode 100644
index 0000000000000..5d7b2708dcbad
--- /dev/null
+++ b/test/COFF/export32.test
@@ -0,0 +1,133 @@
+# RUN: yaml2obj < %s > %t.obj
+#
+# RUN: lld-link /out:%t.dll /dll %t.obj /export:exportfn1 /export:exportfn2
+# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=CHECK1 %s
+# REQUIRES: winlib
+
+# CHECK1: Export Table:
+# CHECK1: DLL name: export32.test.tmp.dll
+# CHECK1: Ordinal RVA Name
+# CHECK1-NEXT: 0 0
+# CHECK1-NEXT: 1 0x1008 exportfn1
+# CHECK1-NEXT: 2 0x1010 exportfn2
+
+# RUN: lld-link /out:%t.dll /dll %t.obj /export:exportfn1,@5 \
+# RUN: /export:exportfn2 /export:mangled
+# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=CHECK2 %s
+
+# CHECK2: Export Table:
+# CHECK2: DLL name: export32.test.tmp.dll
+# CHECK2: Ordinal RVA Name
+# CHECK2-NEXT: 0 0
+# CHECK2-NEXT: 1 0
+# CHECK2-NEXT: 2 0
+# CHECK2-NEXT: 3 0
+# CHECK2-NEXT: 4 0
+# CHECK2-NEXT: 5 0x1008 exportfn1
+# CHECK2-NEXT: 6 0x1010 exportfn2
+# CHECK2-NEXT: 7 0x1010 exportfn3
+# CHECK2-NEXT: 8 0x1010 mangled
+
+# RUN: lld-link /out:%t.dll /dll %t.obj /export:exportfn1,@5,noname /export:exportfn2
+# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=CHECK3 %s
+
+# CHECK3: Export Table:
+# CHECK3: DLL name: export32.test.tmp.dll
+# CHECK3: Ordinal RVA Name
+# CHECK3-NEXT: 0 0
+# CHECK3-NEXT: 1 0
+# CHECK3-NEXT: 2 0
+# CHECK3-NEXT: 3 0
+# CHECK3-NEXT: 4 0
+# CHECK3-NEXT: 5 0x1008
+# CHECK3-NEXT: 6 0x1010 exportfn2
+
+# RUN: lld-link /out:%t.dll /dll %t.obj /export:f1=exportfn1 /export:f2=exportfn2
+# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=CHECK4 %s
+
+# CHECK4: Export Table:
+# CHECK4: DLL name: export32.test.tmp.dll
+# CHECK4: Ordinal RVA Name
+# CHECK4-NEXT: 0 0
+# CHECK4-NEXT: 1 0x1010 exportfn3
+# CHECK4-NEXT: 2 0x1008 f1
+# CHECK4-NEXT: 3 0x1010 f2
+
+# RUN: echo "EXPORTS exportfn1 @3" > %t.def
+# RUN: echo "fn2=exportfn2 @2" >> %t.def
+# RUN: lld-link /out:%t.dll /dll %t.obj /def:%t.def
+# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=CHECK5 %s
+
+# CHECK5: Export Table:
+# CHECK5: DLL name: export32.test.tmp.dll
+# CHECK5: Ordinal RVA Name
+# CHECK5-NEXT: 0 0
+# CHECK5-NEXT: 1 0
+# CHECK5-NEXT: 2 0x1010 fn2
+# CHECK5-NEXT: 3 0x1008 exportfn1
+# CHECK5-NEXT: 4 0x1010 exportfn3
+
+# RUN: lld-link /out:%t.dll /dll %t.obj /export:exportfn1 /export:exportfn2 \
+# RUN: /export:exportfn1 /export:exportfn2,@5 >& %t.log
+# RUN: FileCheck -check-prefix=CHECK6 %s < %t.log
+
+# CHECK6: duplicate /export option: _exportfn2
+# CHECK6-NOT: duplicate /export option: _exportfn1
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_I386
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: B800000000506800000000680000000050E80000000050E800000000
+ - Name: .drectve
+ Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ]
+ Alignment: 2147483648
+ SectionData: 2f6578706f72743a5f6578706f7274666e3300 # /export:_exportfn3
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 28
+ NumberOfRelocations: 4
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: __DllMainCRTStartup@12
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: _exportfn1
+ Value: 8
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: _exportfn2@4
+ Value: 16
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: _exportfn3
+ Value: 16
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: '?mangled@@YAHXZ'
+ Value: 16
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/failifmismatch.test b/test/COFF/failifmismatch.test
new file mode 100644
index 0000000000000..021d91b644c44
--- /dev/null
+++ b/test/COFF/failifmismatch.test
@@ -0,0 +1,11 @@
+# RUN: lld-link /entry:main /subsystem:console /out:%t.exe \
+# RUN: %p/Inputs/ret42.obj
+
+# RUN: lld-link /entry:main /subsystem:console /out:%t.exe \
+# RUN: %p/Inputs/ret42.obj /failifmismatch:k1=v1 /failifmismatch:k2=v1
+
+# RUN: lld-link /entry:main /subsystem:console /out:%t.exe \
+# RUN: %p/Inputs/ret42.obj /failifmismatch:k1=v1 /failifmismatch:k1=v1
+
+# RUN: not lld-link /entry:main /subsystem:console /out:%t.exe \
+# RUN: %p/Inputs/ret42.obj /failifmismatch:k1=v1 /failifmismatch:k1=v2
diff --git a/test/COFF/filetype.test b/test/COFF/filetype.test
new file mode 100644
index 0000000000000..e161910ec2c8a
--- /dev/null
+++ b/test/COFF/filetype.test
@@ -0,0 +1,4 @@
+# Make sure input file type is detected by file magic and not by extension.
+
+# RUN: yaml2obj < %p/Inputs/ret42.yaml > %t.lib
+# RUN: lld-link /out:%t.exe /entry:main %t.lib
diff --git a/test/COFF/force.test b/test/COFF/force.test
new file mode 100644
index 0000000000000..44e5722dab5df
--- /dev/null
+++ b/test/COFF/force.test
@@ -0,0 +1,43 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: not lld-link /out:%t.exe /entry:main %t.obj >& %t.log
+# RUN: FileCheck %s < %t.log
+# RUN: lld-link /out:%t.exe /entry:main %t.obj /force >& %t.log
+# RUN: FileCheck %s < %t.log
+
+# CHECK: .obj: undefined symbol: foo
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: 000000000000
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 6
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: foo
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/heap.test b/test/COFF/heap.test
new file mode 100644
index 0000000000000..1eb70a2f19539
--- /dev/null
+++ b/test/COFF/heap.test
@@ -0,0 +1,25 @@
+# RUN: yaml2obj < %p/Inputs/ret42.yaml > %t.obj
+
+# RUN: lld-link /out:%t.exe /entry:main %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=DEFAULT %s
+
+DEFAULT: SizeOfHeapReserve: 1048576
+DEFAULT: SizeOfHeapCommit: 4096
+
+# RUN: lld-link /out:%t.exe /entry:main /heap:0x3000 %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=CHECK1 %s
+# RUN: echo "HEAPSIZE 12288" > %t.def
+# RUN: lld-link /out:%t.exe /entry:main /def:%t.def %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=CHECK1 %s
+
+CHECK1: SizeOfHeapReserve: 12288
+CHECK1: SizeOfHeapCommit: 4096
+
+# RUN: lld-link /out:%t.exe /entry:main /heap:0x5000,0x3000 %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=CHECK2 %s
+# RUN: echo "HEAPSIZE 20480,12288" > %t.def
+# RUN: lld-link /out:%t.exe /entry:main /def:%t.def %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=CHECK2 %s
+
+CHECK2: SizeOfHeapReserve: 20480
+CHECK2: SizeOfHeapCommit: 12288
diff --git a/test/COFF/hello32.test b/test/COFF/hello32.test
new file mode 100644
index 0000000000000..4307d4bf89a9f
--- /dev/null
+++ b/test/COFF/hello32.test
@@ -0,0 +1,129 @@
+# RUN: yaml2obj < %p/Inputs/hello32.yaml > %t.obj
+# RUN: lld-link %t.obj %p/Inputs/std32.lib /subsystem:console \
+# RUN: /entry:main@0 /out:%t.exe
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=HEADER %s
+# RUN: llvm-readobj -coff-imports %t.exe | FileCheck -check-prefix=IMPORTS %s
+# RUN: llvm-readobj -coff-basereloc %t.exe | FileCheck -check-prefix=BASEREL %s
+
+HEADER: Format: COFF-i386
+HEADER-NEXT: Arch: i386
+HEADER-NEXT: AddressSize: 32bit
+HEADER-NEXT: ImageFileHeader {
+HEADER-NEXT: Machine: IMAGE_FILE_MACHINE_I386 (0x14C)
+HEADER-NEXT: SectionCount: 4
+HEADER-NEXT: TimeDateStamp: 1970-01-01 00:00:00 (0x0)
+HEADER-NEXT: PointerToSymbolTable: 0x0
+HEADER-NEXT: SymbolCount: 0
+HEADER-NEXT: OptionalHeaderSize: 224
+HEADER-NEXT: Characteristics [ (0x102)
+HEADER-NEXT: IMAGE_FILE_32BIT_MACHINE (0x100)
+HEADER-NEXT: IMAGE_FILE_EXECUTABLE_IMAGE (0x2)
+HEADER-NEXT: ]
+HEADER-NEXT: }
+HEADER-NEXT: ImageOptionalHeader {
+HEADER-NEXT: MajorLinkerVersion: 0
+HEADER-NEXT: MinorLinkerVersion: 0
+HEADER-NEXT: SizeOfCode: 512
+HEADER-NEXT: SizeOfInitializedData: 1536
+HEADER-NEXT: SizeOfUninitializedData: 0
+HEADER-NEXT: AddressOfEntryPoint: 0x2000
+HEADER-NEXT: BaseOfCode: 0x2000
+HEADER-NEXT: BaseOfData: 0x0
+HEADER-NEXT: ImageBase: 0x400000
+HEADER-NEXT: SectionAlignment: 4096
+HEADER-NEXT: FileAlignment: 512
+HEADER-NEXT: MajorOperatingSystemVersion: 6
+HEADER-NEXT: MinorOperatingSystemVersion: 0
+HEADER-NEXT: MajorImageVersion: 0
+HEADER-NEXT: MinorImageVersion: 0
+HEADER-NEXT: MajorSubsystemVersion: 6
+HEADER-NEXT: MinorSubsystemVersion: 0
+HEADER-NEXT: SizeOfImage: 16896
+HEADER-NEXT: SizeOfHeaders: 512
+HEADER-NEXT: Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI (0x3)
+HEADER-NEXT: Characteristics [ (0x8140)
+HEADER-NEXT: IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE (0x40)
+HEADER-NEXT: IMAGE_DLL_CHARACTERISTICS_NX_COMPAT (0x100)
+HEADER-NEXT: IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE (0x8000)
+HEADER-NEXT: ]
+HEADER-NEXT: SizeOfStackReserve: 1048576
+HEADER-NEXT: SizeOfStackCommit: 4096
+HEADER-NEXT: SizeOfHeapReserve: 1048576
+HEADER-NEXT: SizeOfHeapCommit: 4096
+HEADER-NEXT: NumberOfRvaAndSize: 16
+HEADER-NEXT: DataDirectory {
+HEADER-NEXT: ExportTableRVA: 0x0
+HEADER-NEXT: ExportTableSize: 0x0
+HEADER-NEXT: ImportTableRVA: 0x3000
+HEADER-NEXT: ImportTableSize: 0x28
+HEADER-NEXT: ResourceTableRVA: 0x0
+HEADER-NEXT: ResourceTableSize: 0x0
+HEADER-NEXT: ExceptionTableRVA: 0x0
+HEADER-NEXT: ExceptionTableSize: 0x0
+HEADER-NEXT: CertificateTableRVA: 0x0
+HEADER-NEXT: CertificateTableSize: 0x0
+HEADER-NEXT: BaseRelocationTableRVA: 0x4000
+HEADER-NEXT: BaseRelocationTableSize: 0x10
+HEADER-NEXT: DebugRVA: 0x0
+HEADER-NEXT: DebugSize: 0x0
+HEADER-NEXT: ArchitectureRVA: 0x0
+HEADER-NEXT: ArchitectureSize: 0x0
+HEADER-NEXT: GlobalPtrRVA: 0x0
+HEADER-NEXT: GlobalPtrSize: 0x0
+HEADER-NEXT: TLSTableRVA: 0x0
+HEADER-NEXT: TLSTableSize: 0x0
+HEADER-NEXT: LoadConfigTableRVA: 0x0
+HEADER-NEXT: LoadConfigTableSize: 0x0
+HEADER-NEXT: BoundImportRVA: 0x0
+HEADER-NEXT: BoundImportSize: 0x0
+HEADER-NEXT: IATRVA: 0x3034
+HEADER-NEXT: IATSize: 0xC
+HEADER-NEXT: DelayImportDescriptorRVA: 0x0
+HEADER-NEXT: DelayImportDescriptorSize: 0x0
+HEADER-NEXT: CLRRuntimeHeaderRVA: 0x0
+HEADER-NEXT: CLRRuntimeHeaderSize: 0x0
+HEADER-NEXT: ReservedRVA: 0x0
+HEADER-NEXT: ReservedSize: 0x0
+HEADER-NEXT: }
+HEADER-NEXT: }
+HEADER-NEXT: DOSHeader {
+HEADER-NEXT: Magic: MZ
+HEADER-NEXT: UsedBytesInTheLastPage: 0
+HEADER-NEXT: FileSizeInPages: 0
+HEADER-NEXT: NumberOfRelocationItems: 0
+HEADER-NEXT: HeaderSizeInParagraphs: 0
+HEADER-NEXT: MinimumExtraParagraphs: 0
+HEADER-NEXT: MaximumExtraParagraphs: 0
+HEADER-NEXT: InitialRelativeSS: 0
+HEADER-NEXT: InitialSP: 0
+HEADER-NEXT: Checksum: 0
+HEADER-NEXT: InitialIP: 0
+HEADER-NEXT: InitialRelativeCS: 0
+HEADER-NEXT: AddressOfRelocationTable: 64
+HEADER-NEXT: OverlayNumber: 0
+HEADER-NEXT: OEMid: 0
+HEADER-NEXT: OEMinfo: 0
+HEADER-NEXT: AddressOfNewExeHeader: 64
+HEADER-NEXT: }
+
+IMPORTS: Format: COFF-i386
+IMPORTS: Arch: i386
+IMPORTS: AddressSize: 32bit
+IMPORTS: Import {
+IMPORTS: Name: std32.dll
+IMPORTS: ImportLookupTableRVA: 0x3028
+IMPORTS: ImportAddressTableRVA: 0x3034
+IMPORTS: Symbol: ExitProcess (0)
+IMPORTS: Symbol: MessageBoxA (1)
+IMPORTS: }
+
+BASEREL: BaseReloc [
+BASEREL: Entry {
+BASEREL: Type: HIGHLOW
+BASEREL: Address: 0x2005
+BASEREL: }
+BASEREL: Entry {
+BASEREL: Type: HIGHLOW
+BASEREL: Address: 0x200C
+BASEREL: }
+BASEREL: ]
diff --git a/test/COFF/help.test b/test/COFF/help.test
new file mode 100644
index 0000000000000..d36fe6d785fa6
--- /dev/null
+++ b/test/COFF/help.test
@@ -0,0 +1,3 @@
+# RUN: lld-link /help | FileCheck %s
+
+CHECK: OVERVIEW: LLVM Linker
diff --git a/test/COFF/icf-circular.test b/test/COFF/icf-circular.test
new file mode 100644
index 0000000000000..7319e135e2e69
--- /dev/null
+++ b/test/COFF/icf-circular.test
@@ -0,0 +1,81 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: lld-link /entry:foo /out:%t.exe /subsystem:console /include:bar \
+# RUN: /verbose %t.obj > %t.log 2>&1
+# RUN: FileCheck %s < %t.log
+
+# CHECK: Selected foo
+# CHECK: Removed bar
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: '.text$mn'
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 16
+ SectionData: 4883EC28E8000000004883C428C3
+ Relocations:
+ - VirtualAddress: 5
+ SymbolName: foo
+ Type: IMAGE_REL_AMD64_REL32
+ - VirtualAddress: 10
+ SymbolName: __ImageBase
+ Type: IMAGE_REL_AMD64_REL32
+ - Name: '.text$mn'
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 16
+ SectionData: 4883EC28E8000000004883C428C3
+ Relocations:
+ - VirtualAddress: 5
+ SymbolName: bar
+ Type: IMAGE_REL_AMD64_REL32
+ - VirtualAddress: 10
+ SymbolName: __ImageBase
+ Type: IMAGE_REL_AMD64_REL32
+symbols:
+ - Name: '.text$mn'
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 14
+ NumberOfRelocations: 1
+ NumberOfLinenumbers: 0
+ CheckSum: 1682752513
+ Number: 0
+ Selection: IMAGE_COMDAT_SELECT_NODUPLICATES
+ - Name: '.text$mn'
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 14
+ NumberOfRelocations: 1
+ NumberOfLinenumbers: 0
+ CheckSum: 1682752513
+ Number: 0
+ Selection: IMAGE_COMDAT_SELECT_NODUPLICATES
+ - Name: foo
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: bar
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: __ImageBase
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/icf-circular2.test b/test/COFF/icf-circular2.test
new file mode 100644
index 0000000000000..e7598c1243650
--- /dev/null
+++ b/test/COFF/icf-circular2.test
@@ -0,0 +1,69 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: lld-link /entry:foo /out:%t.exe /subsystem:console /include:bar \
+# RUN: /verbose %t.obj > %t.log 2>&1
+# RUN: FileCheck %s < %t.log
+
+# CHECK: Selected foo
+# CHECK: Removed bar
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: '.text$mn'
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 16
+ SectionData: 4883EC28E8000000004883C428C3
+ Relocations:
+ - VirtualAddress: 5
+ SymbolName: foo
+ Type: IMAGE_REL_AMD64_REL32
+ - Name: '.text$mn'
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 16
+ SectionData: 4883EC28E8000000004883C428C3
+ Relocations:
+ - VirtualAddress: 5
+ SymbolName: foo
+ Type: IMAGE_REL_AMD64_REL32
+symbols:
+ - Name: '.text$mn'
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 14
+ NumberOfRelocations: 1
+ NumberOfLinenumbers: 0
+ CheckSum: 1682752513
+ Number: 0
+ Selection: IMAGE_COMDAT_SELECT_NODUPLICATES
+ - Name: '.text$mn'
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 14
+ NumberOfRelocations: 1
+ NumberOfLinenumbers: 0
+ CheckSum: 1682752513
+ Number: 0
+ Selection: IMAGE_COMDAT_SELECT_NODUPLICATES
+ - Name: foo
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: bar
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/icf-different-align.test b/test/COFF/icf-different-align.test
new file mode 100644
index 0000000000000..6876048a5d402
--- /dev/null
+++ b/test/COFF/icf-different-align.test
@@ -0,0 +1,61 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: lld-link /entry:foo /out:%t.exe /subsystem:console /include:bar \
+# RUN: /verbose %t.obj > %t.log 2>&1
+# RUN: FileCheck %s < %t.log
+
+# CHECK-NOT: Selected foo
+# CHECK-NOT: Removed bar
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: '.text$mn'
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 8
+ SectionData: 4883EC28E8000000004883C428C3
+ - Name: '.text$mn'
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 16
+ SectionData: 4883EC28E8000000004883C428C3
+symbols:
+ - Name: '.text$mn'
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 14
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 1682752513
+ Number: 0
+ Selection: IMAGE_COMDAT_SELECT_NODUPLICATES
+ - Name: '.text$mn'
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 14
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 1682752513
+ Number: 0
+ Selection: IMAGE_COMDAT_SELECT_NODUPLICATES
+ - Name: foo
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: bar
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/icf-local.test b/test/COFF/icf-local.test
new file mode 100644
index 0000000000000..a0b4c91559a3a
--- /dev/null
+++ b/test/COFF/icf-local.test
@@ -0,0 +1,66 @@
+# COMDAT sections with non-external linkage should not be merged by ICF.
+
+# RUN: yaml2obj < %s > %t1.obj
+# RUN: sed s/foo/main/ %s | yaml2obj > %t2.obj
+# RUN: lld-link /out:%t.exe /entry:main /subsystem:console /verbose \
+# RUN: %t1.obj %t2.obj > %t.log 2>&1
+# RUN: FileCheck %s < %t.log
+
+# CHECK-NOT: Removed bar
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 16
+ SectionData: 488D0500000000C3
+ Relocations:
+ - VirtualAddress: 3
+ SymbolName: bar
+ Type: IMAGE_REL_AMD64_REL32
+ - Name: .rdata
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_READ ]
+ Alignment: 8
+ SectionData: 2A000000000000002B00000000000000
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 8
+ NumberOfRelocations: 1
+ NumberOfLinenumbers: 0
+ CheckSum: 1092178131
+ Number: 1
+ - Name: .rdata
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 16
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 1200668497
+ Number: 5
+ Selection: IMAGE_COMDAT_SELECT_ANY
+ - Name: foo
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: bar
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+...
diff --git a/test/COFF/icf-simple.test b/test/COFF/icf-simple.test
new file mode 100644
index 0000000000000..ae72fd9d9d73f
--- /dev/null
+++ b/test/COFF/icf-simple.test
@@ -0,0 +1,71 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: lld-link /entry:foo /out:%t.exe /subsystem:console /include:bar \
+# RUN: /verbose %t.obj > %t.log 2>&1
+# RUN: FileCheck -check-prefix=ICF %s < %t.log
+
+# ICF: Selected foo
+# ICF: Removed bar
+
+# RUN: lld-link /entry:foo /out:%t.exe /subsystem:console /include:bar \
+# RUN: /verbose /opt:noicf %t.obj > %t.log 2>&1
+# RUN: FileCheck -check-prefix=NOICF %s < %t.log
+# RUN: lld-link /entry:foo /out:%t.exe /subsystem:console /include:bar \
+# RUN: /verbose /opt:noref,noicf %t.obj > %t.log 2>&1
+# RUN: FileCheck -check-prefix=NOICF %s < %t.log
+
+# NOICF-NOT: Removed foo
+# NOICF-NOT: Removed bar
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: '.text$mn'
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 16
+ SectionData: 4883EC28E8000000004883C428C3
+ - Name: '.text$mn'
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 16
+ SectionData: 4883EC28E8000000004883C428C3
+symbols:
+ - Name: '.text$mn'
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 14
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 1682752513
+ Number: 0
+ Selection: IMAGE_COMDAT_SELECT_NODUPLICATES
+ - Name: '.text$mn'
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 14
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 1682752513
+ Number: 0
+ Selection: IMAGE_COMDAT_SELECT_NODUPLICATES
+ - Name: foo
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: bar
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/imports-mangle.test b/test/COFF/imports-mangle.test
new file mode 100644
index 0000000000000..35b3855590054
--- /dev/null
+++ b/test/COFF/imports-mangle.test
@@ -0,0 +1,66 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: lld-link /out:%t.exe /opt:noref /entry:main \
+# RUN: %t.obj %p/Inputs/imports-mangle.lib
+# RUN: llvm-readobj -coff-imports %t.exe | FileCheck %s
+
+# CHECK: Import {
+# CHECK: Symbol: sym4 (0)
+# CHECK: Symbol: _sym3 (1)
+# CHECK: Symbol: sym1 (2)
+# CHECK: Symbol: (2)
+# CHECK: }
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: 000000000000
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 6
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ Selection: IMAGE_COMDAT_SELECT_ANY
+ - Name: main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: sym1
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: sym2
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: __sym3
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: '?sym4@@YAHH@Z'
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/imports.test b/test/COFF/imports.test
new file mode 100644
index 0000000000000..584c24eb1b76e
--- /dev/null
+++ b/test/COFF/imports.test
@@ -0,0 +1,35 @@
+# Verify that the lld can handle .lib files and emit .idata sections.
+#
+# RUN: lld-link /out:%t.exe /entry:main /subsystem:console \
+# RUN: %p/Inputs/hello64.obj %p/Inputs/std64.lib
+# RUN: llvm-objdump -d %t.exe | FileCheck -check-prefix=TEXT %s
+# RUN: llvm-readobj -coff-imports %t.exe | FileCheck -check-prefix=IMPORT %s
+
+# RUN: lld-link /out:%t.exe /entry:main /subsystem:console \
+# RUN: %p/Inputs/hello64.obj %p/Inputs/std64.lib /include:ExitProcess
+# RUN: llvm-objdump -d %t.exe | FileCheck -check-prefix=TEXT %s
+# RUN: llvm-readobj -coff-imports %t.exe | FileCheck -check-prefix=IMPORT %s
+
+TEXT: Disassembly of section .text:
+TEXT-NEXT: .text:
+TEXT-NEXT: subq $40, %rsp
+TEXT-NEXT: movq $0, %rcx
+TEXT-NEXT: leaq -4108(%rip), %rdx
+TEXT-NEXT: leaq -4121(%rip), %r8
+TEXT-NEXT: movl $0, %r9d
+TEXT-NEXT: callq 60
+TEXT-NEXT: movl $0, %ecx
+TEXT-NEXT: callq 18
+TEXT-NEXT: callq 29
+TEXT: jmpq *4098(%rip)
+TEXT: jmpq *4090(%rip)
+TEXT: jmpq *4082(%rip)
+
+IMPORT: Import {
+IMPORT-NEXT: Name: std64.dll
+IMPORT-NEXT: ImportLookupTableRVA: 0x3028
+IMPORT-NEXT: ImportAddressTableRVA: 0x3048
+IMPORT-NEXT: Symbol: ExitProcess (0)
+IMPORT-NEXT: Symbol: (50)
+IMPORT-NEXT: Symbol: MessageBoxA (1)
+IMPORT-NEXT: }
diff --git a/test/COFF/include.test b/test/COFF/include.test
new file mode 100644
index 0000000000000..b9e5f49b4fb66
--- /dev/null
+++ b/test/COFF/include.test
@@ -0,0 +1,83 @@
+# RUN: yaml2obj < %s > %t.obj
+
+# RUN: lld-link /out:%t.exe /entry:main %t.obj /verbose >& %t.log
+### FileCheck doesn't like empty input, so write something.
+# RUN: echo dummy >> %t.log
+# RUN: FileCheck -check-prefix=CHECK1 %s < %t.log
+
+# RUN: lld-link /out:%t.exe /entry:main %t.obj /verbose /include:unused >& %t.log
+# RUN: echo dummy >> %t.log
+# RUN: FileCheck -check-prefix=CHECK2 %s < %t.log
+
+# CHECK1: Discarded unused
+# CHECK1-NOT: Discarded used
+# CHECK2-NOT: Discarded unused
+# CHECK2-NOT: Discarded used
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: '.text$mn'
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: B82A000000C3
+ - Name: '.text$mn'
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: B82A000000C3
+ - Name: '.text$mn'
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: B82A000000C3
+ - Name: .drectve
+ Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ]
+ Alignment: 2147483648
+ SectionData: 2f696e636c7564653a7573656400 # /include:used
+symbols:
+ - Name: '.text$mn'
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 6
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ Selection: IMAGE_COMDAT_SELECT_ANY
+ - Name: '.text$mn'
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 6
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ Selection: IMAGE_COMDAT_SELECT_ANY
+ - Name: main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: used
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: unused
+ Value: 0
+ SectionNumber: 3
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/include2.test b/test/COFF/include2.test
new file mode 100644
index 0000000000000..f2379eaede40d
--- /dev/null
+++ b/test/COFF/include2.test
@@ -0,0 +1,14 @@
+# RUN: yaml2obj < %p/Inputs/include1a.yaml > %t1.obj
+# RUN: yaml2obj < %p/Inputs/include1b.yaml > %t2.obj
+# RUN: yaml2obj < %p/Inputs/include1c.yaml > %t3.obj
+# RUN: rm -f %t2.lib %t3.lib
+# RUN: llvm-ar cru %t2.lib %t2.obj
+# RUN: llvm-ar cru %t3.lib %t3.obj
+# RUN: lld-link /out:%t.exe /entry:main %t1.obj %t2.lib %t3.lib /verbose >& %t.log
+# RUN: FileCheck %s < %t.log
+
+CHECK: include2.test.tmp1.obj
+CHECK: include2.test.tmp2.lib
+CHECK: include2.test.tmp3.lib
+CHECK: include2.test.tmp2.lib(include2.test.tmp2.obj) for foo
+CHECK: include2.test.tmp3.lib(include2.test.tmp3.obj) for bar
diff --git a/test/COFF/internal.test b/test/COFF/internal.test
new file mode 100644
index 0000000000000..80a5332847de2
--- /dev/null
+++ b/test/COFF/internal.test
@@ -0,0 +1,42 @@
+# Test that non-external symbols don't conflict
+
+# RUN: yaml2obj < %s > %t1.obj
+# RUN: yaml2obj < %s > %t2.obj
+# RUN: yaml2obj < %p/Inputs/ret42.yaml > %t3.obj
+# RUN: lld-link /out:%t.exe /entry:main %t1.obj %t2.obj %t3.obj
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: 000000000000
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 6
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: defined
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ - Name: absolute
+ Value: 0xdeadbeef
+ SectionNumber: -1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+...
diff --git a/test/COFF/invalid-obj.test b/test/COFF/invalid-obj.test
new file mode 100644
index 0000000000000..fd63f7874cc11
--- /dev/null
+++ b/test/COFF/invalid-obj.test
@@ -0,0 +1,14 @@
+# RUN: yaml2obj %s > %t.obj
+# RUN: not lld-link %t.obj 2>&1 | FileCheck %s
+
+# CHECK: getSectionName failed: #1:
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: '/1'
+ Characteristics: []
+ SectionData: 00
+symbols:
diff --git a/test/COFF/largeaddressaware.test b/test/COFF/largeaddressaware.test
new file mode 100644
index 0000000000000..d035e7ce99934
--- /dev/null
+++ b/test/COFF/largeaddressaware.test
@@ -0,0 +1,21 @@
+# RUN: yaml2obj < %p/Inputs/hello32.yaml > %t.obj
+# RUN: lld-link %t.obj %p/Inputs/std32.lib /subsystem:console \
+# RUN: /entry:main@0 /out:%t.exe /largeaddressaware
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=HEADER %s
+
+HEADER: Format: COFF-i386
+HEADER-NEXT: Arch: i386
+HEADER-NEXT: AddressSize: 32bit
+HEADER-NEXT: ImageFileHeader {
+HEADER-NEXT: Machine: IMAGE_FILE_MACHINE_I386 (0x14C)
+HEADER-NEXT: SectionCount: 4
+HEADER-NEXT: TimeDateStamp: 1970-01-01 00:00:00 (0x0)
+HEADER-NEXT: PointerToSymbolTable: 0x0
+HEADER-NEXT: SymbolCount: 0
+HEADER-NEXT: OptionalHeaderSize: 224
+HEADER-NEXT: Characteristics [ (0x122)
+HEADER-NEXT: IMAGE_FILE_32BIT_MACHINE (0x100)
+HEADER-NEXT: IMAGE_FILE_EXECUTABLE_IMAGE (0x2)
+HEADER-NEXT: IMAGE_FILE_LARGE_ADDRESS_AWARE (0x20)
+HEADER-NEXT: ]
+HEADER-NEXT: }
diff --git a/test/COFF/libpath.test b/test/COFF/libpath.test
new file mode 100644
index 0000000000000..da465bc556bc7
--- /dev/null
+++ b/test/COFF/libpath.test
@@ -0,0 +1,18 @@
+# RUN: mkdir -p %t/a %t/b %t/c
+# RUN: cp %p/Inputs/std64.lib %t/a/
+# RUN: cp %p/Inputs/std64.lib %t/b/
+# RUN: cp %p/Inputs/std64.lib %t/c/
+
+# RUN: env LIB=%t/a lld-link /out:%t.exe /entry:main /verbose \
+# RUN: std64.lib /subsystem:console %p/Inputs/hello64.obj \
+# RUN: /libpath:%t/b /libpath:%t/c > %t.log
+# RUN: FileCheck -check-prefix=CHECK1 %s < %t.log
+
+CHECK1: b{{[/\\]}}std64.lib
+
+# RUN: lld-link /out:%t.exe /entry:main /verbose \
+# RUN: std64.lib /subsystem:console %p/Inputs/hello64.obj \
+# RUN: /libpath:%t/a /libpath:%t/b /libpath:%t/c > %t.log
+# RUN: FileCheck -check-prefix=CHECK2 %s < %t.log
+
+CHECK2: a{{[/\\]}}std64.lib
diff --git a/test/COFF/linkenv.test b/test/COFF/linkenv.test
new file mode 100644
index 0000000000000..5dfb875a7daf0
--- /dev/null
+++ b/test/COFF/linkenv.test
@@ -0,0 +1,4 @@
+# RUN: env LINK=-help lld-link > %t.log
+# RUN: FileCheck %s < %t.log
+
+CHECK: OVERVIEW: LLVM Linker
diff --git a/test/COFF/lldmap.test b/test/COFF/lldmap.test
new file mode 100644
index 0000000000000..a4c2da09ca337
--- /dev/null
+++ b/test/COFF/lldmap.test
@@ -0,0 +1,8 @@
+# RUN: yaml2obj < %p/Inputs/ret42.yaml > %t.obj
+# RUN: lld-link /out:%t.exe /entry:main /lldmap:%t.map %t.obj
+# RUN: FileCheck %s < %t.map
+
+# CHECK: .obj:
+# CHECK-NEXT: 140001000 .text$mn
+# CHECK-NEXT: 140001000 .data
+# CHECK-NEXT: 140001000 main
diff --git a/test/COFF/loadcfg.ll b/test/COFF/loadcfg.ll
new file mode 100644
index 0000000000000..3166881032b4a
--- /dev/null
+++ b/test/COFF/loadcfg.ll
@@ -0,0 +1,15 @@
+; RUN: llvm-as -o %t.obj %s
+; RUN: lld-link /out:%t.exe %t.obj /entry:main /subsystem:console
+; RUN: llvm-readobj -file-headers %t.exe | FileCheck %s
+
+; CHECK: LoadConfigTableRVA: 0x1000
+; CHECK: LoadConfigTableSize: 0x70
+
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+@_load_config_used = constant i32 1
+
+define void @main() {
+ ret void
+}
diff --git a/test/COFF/loadcfg.test b/test/COFF/loadcfg.test
new file mode 100644
index 0000000000000..a84f864b4b538
--- /dev/null
+++ b/test/COFF/loadcfg.test
@@ -0,0 +1,59 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: lld-link /out:%t.exe %t.obj /entry:main /subsystem:console
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s
+
+# CHECK: LoadConfigTableRVA: 0x1008
+# CHECK: LoadConfigTableSize: 0x70
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: B82A000000C3
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: B82A000000C3
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 6
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: .text
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 6
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ Selection: IMAGE_COMDAT_SELECT_ANY
+ - Name: main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: _load_config_used
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/loadcfg32.test b/test/COFF/loadcfg32.test
new file mode 100644
index 0000000000000..f7780e1d0373e
--- /dev/null
+++ b/test/COFF/loadcfg32.test
@@ -0,0 +1,42 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: lld-link /out:%t.exe %t.obj /entry:main /subsystem:console
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s
+
+# CHECK: LoadConfigTableRVA: 0x1000
+# CHECK: LoadConfigTableSize: 0x40
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_I386
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: B82A000000C3
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 6
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: _main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: __load_config_used
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/locally-imported.test b/test/COFF/locally-imported.test
new file mode 100644
index 0000000000000..7c43666c8c1e6
--- /dev/null
+++ b/test/COFF/locally-imported.test
@@ -0,0 +1,61 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: lld-link /out:%t.exe /entry:main %t.obj
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+# RUN: llvm-readobj -coff-basereloc %t.exe | FileCheck -check-prefix=BASEREL %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 1000 00200000
+# CHECK: Contents of section .rdata:
+# CHECK-NEXT: 2000 04100040 01000000
+
+# BASEREL: BaseReloc [
+# BASEREL-NEXT: Entry {
+# BASEREL-NEXT: Type: DIR64
+# BASEREL-NEXT: Address: 0x2000
+# BASEREL-NEXT: }
+# BASEREL-NEXT: Entry {
+# BASEREL-NEXT: Type: ABSOLUTE
+# BASEREL-NEXT: Address: 0x2000
+# BASEREL-NEXT: }
+# BASEREL-NEXT: ]
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: 00000000
+ Relocations:
+ - VirtualAddress: 0
+ SymbolName: __imp_main
+ Type: IMAGE_REL_AMD64_ADDR32NB
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 4
+ NumberOfRelocations: 1
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ Selection: IMAGE_COMDAT_SELECT_ANY
+ - Name: main
+ Value: 4
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: __imp_main
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/locally-imported32.test b/test/COFF/locally-imported32.test
new file mode 100644
index 0000000000000..7f604d2a04950
--- /dev/null
+++ b/test/COFF/locally-imported32.test
@@ -0,0 +1,50 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: lld-link /out:%t.exe /entry:main %t.obj
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 1000 00200000
+
+# CHECK: Contents of section .rdata:
+# CHECK-NEXT: 2000 04104000
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_I386
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: 00000000
+ Relocations:
+ - VirtualAddress: 0
+ SymbolName: __imp__main
+ Type: IMAGE_REL_I386_DIR32NB
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 4
+ NumberOfRelocations: 1
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ Selection: IMAGE_COMDAT_SELECT_ANY
+ - Name: _main
+ Value: 4
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: __imp__main
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/long-section-name.test b/test/COFF/long-section-name.test
new file mode 100644
index 0000000000000..a3dad33ec2cfb
--- /dev/null
+++ b/test/COFF/long-section-name.test
@@ -0,0 +1,58 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: lld-link /debug /out:%t.exe /entry:main %t.obj
+# RUN: llvm-readobj -sections %t.exe | FileCheck %s
+
+# CHECK: Name: .data_long_section_name
+# CHECK: Name: .text_long_section_name
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: [ ]
+sections:
+ - Name: .text_long_section_name
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: B82A000000C3
+ - Name: .data_long_section_name
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
+ Alignment: 4
+ SectionData: "00"
+symbols:
+ - Name: "@comp.id"
+ Value: 10394907
+ SectionNumber: 65535
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ - Name: .text_long_section_name
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 6
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: .data_long_section_name
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 0
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/lto-chkstk.ll b/test/COFF/lto-chkstk.ll
new file mode 100644
index 0000000000000..43b0bff164e32
--- /dev/null
+++ b/test/COFF/lto-chkstk.ll
@@ -0,0 +1,17 @@
+; RUN: llvm-as -o %t.obj %s
+; RUN: llvm-mc -triple=x86_64-pc-windows-msvc -filetype=obj -o %T/lto-chkstk-foo.obj %S/Inputs/lto-chkstk-foo.s
+; RUN: llvm-mc -triple=x86_64-pc-windows-msvc -filetype=obj -o %T/lto-chkstk-chkstk.obj %S/Inputs/lto-chkstk-chkstk.s
+; RUN: llvm-ar cru %t.lib %T/lto-chkstk-chkstk.obj
+; RUN: lld-link /out:%t.exe /entry:main /subsystem:console %t.obj %T/lto-chkstk-foo.obj %t.lib
+
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+define void @main() {
+entry:
+ %array4096 = alloca [4096 x i8]
+ call void @foo([4096 x i8]* %array4096)
+ ret void
+}
+
+declare void @foo([4096 x i8]*)
diff --git a/test/COFF/lto-comdat.ll b/test/COFF/lto-comdat.ll
new file mode 100644
index 0000000000000..aaa7a16c4afba
--- /dev/null
+++ b/test/COFF/lto-comdat.ll
@@ -0,0 +1,131 @@
+; RUN: llvm-as -o %T/comdat-main.lto.obj %s
+; RUN: llvm-as -o %T/comdat1.lto.obj %S/Inputs/lto-comdat1.ll
+; RUN: llvm-as -o %T/comdat2.lto.obj %S/Inputs/lto-comdat2.ll
+; RUN: rm -f %T/comdat.lto.lib
+; RUN: llvm-ar cru %T/comdat.lto.lib %T/comdat1.lto.obj %T/comdat2.lto.obj
+
+; RUN: llc -filetype=obj -o %T/comdat-main.obj %s
+; RUN: llc -filetype=obj -o %T/comdat1.obj %S/Inputs/lto-comdat1.ll
+; RUN: llc -filetype=obj -o %T/comdat2.obj %S/Inputs/lto-comdat2.ll
+; RUN: rm -f %T/comdat.lib
+; RUN: llvm-ar cru %T/comdat.lib %T/comdat1.obj %T/comdat2.obj
+
+; RUN: lld-link /out:%T/comdat-main.exe /entry:main /subsystem:console %T/comdat-main.lto.obj %T/comdat1.lto.obj %T/comdat2.lto.obj
+; RUN: llvm-readobj -file-headers %T/comdat-main.exe | FileCheck -check-prefix=HEADERS-11 %s
+; RUN: llvm-objdump -d %T/comdat-main.exe | FileCheck -check-prefix=TEXT-11 %s
+; RUN: lld-link /out:%T/comdat-main.exe /entry:main /subsystem:console %T/comdat-main.lto.obj %T/comdat.lto.lib
+; RUN: llvm-readobj -file-headers %T/comdat-main.exe | FileCheck -check-prefix=HEADERS-11 %s
+; RUN: llvm-objdump -d %T/comdat-main.exe | FileCheck -check-prefix=TEXT-11 %s
+
+; RUN: lld-link /out:%T/comdat-main.exe /entry:main /subsystem:console %T/comdat-main.obj %T/comdat1.lto.obj %T/comdat2.lto.obj
+; RUN: llvm-readobj -file-headers %T/comdat-main.exe | FileCheck -check-prefix=HEADERS-01 %s
+; RUN: llvm-objdump -d %T/comdat-main.exe | FileCheck -check-prefix=TEXT-01 %s
+; RUN: lld-link /out:%T/comdat-main.exe /entry:main /subsystem:console %T/comdat-main.obj %T/comdat.lto.lib
+; RUN: llvm-readobj -file-headers %T/comdat-main.exe | FileCheck -check-prefix=HEADERS-01 %s
+; RUN: llvm-objdump -d %T/comdat-main.exe | FileCheck -check-prefix=TEXT-01 %s
+
+; RUN: lld-link /out:%T/comdat-main.exe /entry:main /subsystem:console %T/comdat-main.lto.obj %T/comdat1.obj %T/comdat2.obj
+; RUN: llvm-readobj -file-headers %T/comdat-main.exe | FileCheck -check-prefix=HEADERS-10 %s
+; RUN: llvm-objdump -d %T/comdat-main.exe | FileCheck -check-prefix=TEXT-10 %s
+; RUN: lld-link /out:%T/comdat-main.exe /entry:main /subsystem:console %T/comdat-main.lto.obj %T/comdat.lib
+; RUN: llvm-readobj -file-headers %T/comdat-main.exe | FileCheck -check-prefix=HEADERS-10 %s
+; RUN: llvm-objdump -d %T/comdat-main.exe | FileCheck -check-prefix=TEXT-10 %s
+
+; HEADERS-11: AddressOfEntryPoint: 0x1000
+; TEXT-11: Disassembly of section .text:
+; TEXT-11-NEXT: .text:
+; TEXT-11-NEXT: xorl %eax, %eax
+; TEXT-11-NEXT: retq
+
+; HEADERS-01: AddressOfEntryPoint: 0x2000
+; TEXT-01: Disassembly of section .text:
+; TEXT-01-NEXT: .text:
+; TEXT-01-NEXT: subq $40, %rsp
+; TEXT-01-NEXT: callq 39
+; TEXT-01-NEXT: callq 50
+; TEXT-01-NEXT: callq 13
+; TEXT-01-NEXT: xorl %eax, %eax
+; TEXT-01-NEXT: addq $40, %rsp
+; TEXT-01-NEXT: retq
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: retq
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: retq
+; TEXT-01-NEXT: nopw %cs:(%rax,%rax)
+; TEXT-01-NEXT: retq
+
+; HEADERS-10: AddressOfEntryPoint: 0x2030
+; TEXT-10: Disassembly of section .text:
+; TEXT-10-NEXT: .text:
+; TEXT-10-NEXT: subq $40, %rsp
+; TEXT-10-NEXT: callq 7
+; TEXT-10-NEXT: nop
+; TEXT-10-NEXT: addq $40, %rsp
+; TEXT-10-NEXT: retq
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: retq
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: subq $40, %rsp
+; TEXT-10-NEXT: callq -25
+; TEXT-10-NEXT: nop
+; TEXT-10-NEXT: addq $40, %rsp
+; TEXT-10-NEXT: retq
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: subq $40, %rsp
+; TEXT-10-NEXT: callq -57
+; TEXT-10-NEXT: callq -30
+; TEXT-10-NEXT: xorl %eax, %eax
+; TEXT-10-NEXT: addq $40, %rsp
+; TEXT-10-NEXT: retq
+
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+$comdat = comdat any
+
+define i32 @main() {
+ call void @f1()
+ call void @f2()
+ call void @comdat()
+ ret i32 0
+}
+
+define linkonce_odr void @comdat() comdat {
+ ret void
+}
+
+declare void @f1()
+declare void @f2()
diff --git a/test/COFF/lto-linker-opts.ll b/test/COFF/lto-linker-opts.ll
new file mode 100644
index 0000000000000..0c183701b6867
--- /dev/null
+++ b/test/COFF/lto-linker-opts.ll
@@ -0,0 +1,11 @@
+; RUN: llvm-as -o %T/lto-linker-opts.obj %s
+; RUN: env LIB=%S/Inputs lld-link /out:%T/lto-linker-opts.exe /entry:main /subsystem:console %T/lto-linker-opts.obj
+
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+!llvm.module.flags = !{!0}
+
+!0 = !{i32 6, !"Linker Options", !1}
+!1 = !{!2}
+!2 = !{!"/DEFAULTLIB:ret42.lib"}
diff --git a/test/COFF/lto-new-symbol.ll b/test/COFF/lto-new-symbol.ll
new file mode 100644
index 0000000000000..d9e14eb932647
--- /dev/null
+++ b/test/COFF/lto-new-symbol.ll
@@ -0,0 +1,16 @@
+; RUN: llvm-as -o %t.obj %s
+; RUN: lld-link /out:%t.exe /entry:foo /subsystem:console %t.obj
+
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+define void @foo(<4 x i32>* %p, <4 x float>* %q, i1 %t) nounwind {
+entry:
+ br label %loop
+loop:
+ store <4 x i32><i32 1073741824, i32 1073741824, i32 1073741824, i32 1073741824>, <4 x i32>* %p
+ store <4 x float><float 2.0, float 2.0, float 2.0, float 2.0>, <4 x float>* %q
+ br i1 %t, label %loop, label %ret
+ret:
+ ret void
+}
diff --git a/test/COFF/lto-opt-level.ll b/test/COFF/lto-opt-level.ll
new file mode 100644
index 0000000000000..674b6cc0f934a
--- /dev/null
+++ b/test/COFF/lto-opt-level.ll
@@ -0,0 +1,21 @@
+; RUN: llvm-as -o %t.obj %s
+; RUN: lld-link /out:%t0.exe /entry:main /subsystem:console /opt:lldlto=0 /debug %t.obj
+; RUN: llvm-nm %t0.exe | FileCheck --check-prefix=CHECK-O0 %s
+; RUN: lld-link /out:%t2.exe /entry:main /subsystem:console /opt:lldlto=2 /debug %t.obj
+; RUN: llvm-nm %t2.exe | FileCheck --check-prefix=CHECK-O2 %s
+; RUN: lld-link /out:%t2a.exe /entry:main /subsystem:console /debug %t.obj
+; RUN: llvm-nm %t2a.exe | FileCheck --check-prefix=CHECK-O2 %s
+
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+; CHECK-O0: foo
+; CHECK-O2-NOT: foo
+define internal void @foo() {
+ ret void
+}
+
+define void @main() {
+ call void @foo()
+ ret void
+}
diff --git a/test/COFF/lto-parallel.ll b/test/COFF/lto-parallel.ll
new file mode 100644
index 0000000000000..2303797019a5f
--- /dev/null
+++ b/test/COFF/lto-parallel.ll
@@ -0,0 +1,20 @@
+; RUN: llvm-as -o %t.obj %s
+; RUN: lld-link /out:%t.exe /entry:foo /include:bar /opt:lldltojobs=2 /subsystem:console /lldmap:%t.map %t.obj
+; RUN: FileCheck %s < %t.map
+
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+; CHECK: <lto object>:
+; CHECK: foo
+define void @foo() {
+ call void @bar()
+ ret void
+}
+
+; CHECK: <lto object>:
+; CHECK: bar
+define void @bar() {
+ call void @foo()
+ ret void
+}
diff --git a/test/COFF/lto.ll b/test/COFF/lto.ll
new file mode 100644
index 0000000000000..b8f8d7063343d
--- /dev/null
+++ b/test/COFF/lto.ll
@@ -0,0 +1,130 @@
+; RUN: llvm-as -o %T/main.lto.obj %s
+; RUN: llvm-as -o %T/foo.lto.obj %S/Inputs/lto-dep.ll
+; RUN: rm -f %T/foo.lto.lib
+; RUN: llvm-ar cru %T/foo.lto.lib %T/foo.lto.obj
+
+; RUN: llc -filetype=obj -o %T/main.obj %s
+; RUN: llc -filetype=obj -o %T/foo.obj %S/Inputs/lto-dep.ll
+; RUN: rm -f %T/foo.lib
+; RUN: llvm-ar cru %T/foo.lib %T/foo.obj
+
+; RUN: lld-link /out:%T/main.exe /entry:main /include:f2 /subsystem:console %T/main.lto.obj %T/foo.lto.obj
+; RUN: llvm-readobj -file-headers %T/main.exe | FileCheck -check-prefix=HEADERS-11 %s
+; RUN: llvm-objdump -d %T/main.exe | FileCheck -check-prefix=TEXT-11 %s
+; RUN: lld-link /out:%T/main.exe /entry:main /include:f2 /subsystem:console %T/main.lto.obj %T/foo.lto.lib /verbose 2>&1 | FileCheck -check-prefix=VERBOSE %s
+; RUN: llvm-readobj -file-headers %T/main.exe | FileCheck -check-prefix=HEADERS-11 %s
+; RUN: llvm-objdump -d %T/main.exe | FileCheck -check-prefix=TEXT-11 %s
+
+; RUN: lld-link /out:%T/main.exe /entry:main /subsystem:console %T/main.obj %T/foo.lto.obj
+; RUN: llvm-readobj -file-headers %T/main.exe | FileCheck -check-prefix=HEADERS-01 %s
+; RUN: llvm-objdump -d %T/main.exe | FileCheck -check-prefix=TEXT-01 %s
+; RUN: lld-link /out:%T/main.exe /entry:main /subsystem:console %T/main.obj %T/foo.lto.lib
+; RUN: llvm-readobj -file-headers %T/main.exe | FileCheck -check-prefix=HEADERS-01 %s
+; RUN: llvm-objdump -d %T/main.exe | FileCheck -check-prefix=TEXT-01 %s
+
+; RUN: lld-link /out:%T/main.exe /entry:main /subsystem:console %T/main.lto.obj %T/foo.obj
+; RUN: llvm-readobj -file-headers %T/main.exe | FileCheck -check-prefix=HEADERS-10 %s
+; RUN: llvm-objdump -d %T/main.exe | FileCheck -check-prefix=TEXT-10 %s
+; RUN: lld-link /out:%T/main.exe /entry:main /subsystem:console %T/main.lto.obj %T/foo.lib
+; RUN: llvm-readobj -file-headers %T/main.exe | FileCheck -check-prefix=HEADERS-10 %s
+; RUN: llvm-objdump -d %T/main.exe | FileCheck -check-prefix=TEXT-10 %s
+
+; VERBOSE: foo.lto.lib({{.*}}foo.lto.obj)
+
+; HEADERS-11: AddressOfEntryPoint: 0x1000
+; TEXT-11: Disassembly of section .text:
+; TEXT-11-NEXT: .text:
+; TEXT-11-NEXT: xorl %eax, %eax
+; TEXT-11-NEXT: retq
+; TEXT-11-NEXT: int3
+; TEXT-11-NEXT: int3
+; TEXT-11-NEXT: int3
+; TEXT-11-NEXT: int3
+; TEXT-11-NEXT: int3
+; TEXT-11-NEXT: int3
+; TEXT-11-NEXT: int3
+; TEXT-11-NEXT: int3
+; TEXT-11-NEXT: int3
+; TEXT-11-NEXT: int3
+; TEXT-11-NEXT: int3
+; TEXT-11-NEXT: int3
+; TEXT-11-NEXT: int3
+; TEXT-11-NEXT: movl $2, %eax
+; TEXT-11-NEXT: retq
+
+; HEADERS-01: AddressOfEntryPoint: 0x2000
+; TEXT-01: Disassembly of section .text:
+; TEXT-01-NEXT: .text:
+; TEXT-01-NEXT: subq $40, %rsp
+; TEXT-01-NEXT: callq 23
+; TEXT-01-NEXT: xorl %eax, %eax
+; TEXT-01-NEXT: addq $40, %rsp
+; TEXT-01-NEXT: retq
+; TEXT-01-NEXT: retq
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: int3
+; TEXT-01-NEXT: retq
+
+; HEADERS-10: AddressOfEntryPoint: 0x2020
+; TEXT-10: Disassembly of section .text:
+; TEXT-10-NEXT: .text:
+; TEXT-10-NEXT: retq
+; TEXT-10-NEXT: nopw %cs:(%rax,%rax)
+; TEXT-10-NEXT: retq
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: int3
+; TEXT-10-NEXT: subq $40, %rsp
+; TEXT-10-NEXT: callq -41
+; TEXT-10-NEXT: xorl %eax, %eax
+; TEXT-10-NEXT: addq $40, %rsp
+; TEXT-10-NEXT: retq
+
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+define i32 @main() {
+ call void @foo()
+ ret i32 0
+}
+
+declare void @foo()
+
+$f1 = comdat any
+define i32 @f1() comdat($f1) {
+ ret i32 1
+}
+
+$f2 = comdat any
+define i32 @f2() comdat($f2) {
+ ret i32 2
+}
+
+define internal void @internal() {
+ ret void
+}
diff --git a/test/COFF/machine.test b/test/COFF/machine.test
new file mode 100644
index 0000000000000..847018f20fbd1
--- /dev/null
+++ b/test/COFF/machine.test
@@ -0,0 +1,30 @@
+# RUN: yaml2obj %p/Inputs/machine-x64.yaml > %t.obj
+# RUN: lld-link /entry:main /subsystem:console /out:%t.exe %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=AMD64 %s
+# RUN: lld-link /entry:main /subsystem:console /machine:x64 \
+# RUN: /out:%t.exe %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=AMD64 %s
+
+AMD64: Machine: IMAGE_FILE_MACHINE_AMD64
+
+# RUN: yaml2obj %p/Inputs/machine-x86.yaml > %t.obj
+# RUN: lld-link /entry:main /subsystem:console /out:%t.exe %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=I386 %s
+# RUN: lld-link /entry:main /subsystem:console /machine:x86 \
+# RUN: /out:%t.exe %t.obj /fixed
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=I386 %s
+
+I386: Machine: IMAGE_FILE_MACHINE_I386
+
+# RUN: yaml2obj %p/Inputs/machine-x64.yaml > %t.obj
+# RUN: not lld-link /entry:main /subsystem:console /machine:x86 \
+# RUN: /out:%t.exe %t.obj /fixed >& %t.log
+# RUN: FileCheck -check-prefix=INCOMPAT %s < %t.log
+
+# RUN: yaml2obj %p/Inputs/machine-x86.yaml > %t1.obj
+# RUN: sed -e s/main/foo/ %p/Inputs/machine-x64.yaml | yaml2obj > %t2.obj
+# RUN: not lld-link /entry:main /subsystem:console /out:%t.exe \
+# RUN: %t1.obj %t2.obj >& %t.log
+# RUN: FileCheck -check-prefix=INCOMPAT %s < %t.log
+
+INCOMPAT: .obj: machine type x64 conflicts with x86
diff --git a/test/COFF/manifest.test b/test/COFF/manifest.test
new file mode 100644
index 0000000000000..33e80e75a4d5d
--- /dev/null
+++ b/test/COFF/manifest.test
@@ -0,0 +1,61 @@
+# RUN: yaml2obj %p/Inputs/ret42.yaml > %t.obj
+
+# RUN: lld-link /out:%t.exe /entry:main %t.obj
+# RUN: FileCheck -check-prefix=MANIFEST %s < %t.exe.manifest
+
+MANIFEST: <?xml version="1.0" standalone="yes"?>
+MANIFEST: <assembly xmlns="urn:schemas-microsoft-com:asm.v1"
+MANIFEST: manifestVersion="1.0">
+MANIFEST: <trustInfo>
+MANIFEST: <security>
+MANIFEST: <requestedPrivileges>
+MANIFEST: <requestedExecutionLevel level='asInvoker' uiAccess='false'/>
+MANIFEST: </requestedPrivileges>
+MANIFEST: </security>
+MANIFEST: </trustInfo>
+MANIFEST: </assembly>
+
+# RUN: lld-link /out:%t.exe /entry:main \
+# RUN: /manifestuac:"level='requireAdministrator' uiAccess='true'" %t.obj
+# RUN: FileCheck -check-prefix=UAC %s < %t.exe.manifest
+
+UAC: <?xml version="1.0" standalone="yes"?>
+UAC: <assembly xmlns="urn:schemas-microsoft-com:asm.v1"
+UAC: manifestVersion="1.0">
+UAC: <trustInfo>
+UAC: <security>
+UAC: <requestedPrivileges>
+UAC: <requestedExecutionLevel level='requireAdministrator' uiAccess='true'/>
+UAC: </requestedPrivileges>
+UAC: </security>
+UAC: </trustInfo>
+UAC: </assembly>
+
+# RUN: lld-link /out:%t.exe /entry:main \
+# RUN: /manifestdependency:"foo='bar'" %t.obj
+# RUN: FileCheck -check-prefix=DEPENDENCY %s < %t.exe.manifest
+
+DEPENDENCY: <?xml version="1.0" standalone="yes"?>
+DEPENDENCY: <assembly xmlns="urn:schemas-microsoft-com:asm.v1"
+DEPENDENCY: manifestVersion="1.0">
+DEPENDENCY: <trustInfo>
+DEPENDENCY: <security>
+DEPENDENCY: <requestedPrivileges>
+DEPENDENCY: <requestedExecutionLevel level='asInvoker' uiAccess='false'/>
+DEPENDENCY: </requestedPrivileges>
+DEPENDENCY: </security>
+DEPENDENCY: </trustInfo>
+DEPENDENCY: <dependency>
+DEPENDENCY: <dependentAssembly>
+DEPENDENCY: <assemblyIdentity foo='bar' />
+DEPENDENCY: </dependentAssembly>
+DEPENDENCY: </dependency>
+DEPENDENCY: </assembly>
+
+# RUN: lld-link /out:%t.exe /entry:main /manifestuac:no %t.obj
+# RUN: FileCheck -check-prefix=NOUAC %s < %t.exe.manifest
+
+NOUAC: <?xml version="1.0" standalone="yes"?>
+NOUAC: <assembly xmlns="urn:schemas-microsoft-com:asm.v1"
+NOUAC: manifestVersion="1.0">
+NOUAC: </assembly>
diff --git a/test/COFF/merge.test b/test/COFF/merge.test
new file mode 100644
index 0000000000000..45ab4efe37a86
--- /dev/null
+++ b/test/COFF/merge.test
@@ -0,0 +1,53 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: lld-link /out:%t.exe /entry:main /subsystem:console /force \
+# RUN: /merge:.foo=.abc /merge:.bar=.def %t.obj /debug
+# RUN: llvm-readobj -sections %t.exe | FileCheck %s
+
+# CHECK: Name: .def
+# CHECK: Name: .abc
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .foo
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
+ Alignment: 4
+ SectionData: 000000000000
+ - Name: .bar
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
+ Alignment: 4
+ SectionData: 000000000000
+symbols:
+ - Name: .foo
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 6
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: .bar
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 6
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/nodefaultlib.test b/test/COFF/nodefaultlib.test
new file mode 100644
index 0000000000000..867dc8f18e78a
--- /dev/null
+++ b/test/COFF/nodefaultlib.test
@@ -0,0 +1,30 @@
+# RUN: cp %p/Inputs/hello64.obj %T
+# RUN: cp %p/Inputs/std64.lib %T
+
+# RUN: not lld-link /out:%t.exe /entry:main /subsystem:console \
+# RUN: hello64.obj /defaultlib:std64.lib >& %t.log
+# RUN: FileCheck -check-prefix=CHECK1 %s < %t.log
+
+# RUN: not lld-link /out:%t.exe /entry:main /subsystem:console \
+# RUN: hello64 /defaultlib:std64.lib >& %t.log
+# RUN: FileCheck -check-prefix=CHECK2 %s < %t.log
+
+# RUN: lld-link /libpath:%T /out:%t.exe /entry:main \
+# RUN: /subsystem:console hello64.obj /defaultlib:std64.lib \
+# RUN: /nodefaultlib:std64.lib >& %t.log || true
+# RUN: FileCheck -check-prefix=CHECK3 %s < %t.log
+
+# RUN: lld-link /libpath:%T /out:%t.exe /entry:main \
+# RUN: /subsystem:console hello64.obj /defaultlib:std64 \
+# RUN: /nodefaultlib:std64.lib >& %t.log || true
+# RUN: FileCheck -check-prefix=CHECK3 %s < %t.log
+
+CHECK1: hello64.obj: {{[Nn]}}o such file or directory
+CHECK2: hello64: {{[Nn]}}o such file or directory
+CHECK3: hello64.obj: undefined symbol: MessageBoxA
+
+# RUN: lld-link /libpath:%T /out:%t.exe /entry:main \
+# RUN: /subsystem:console hello64.obj /defaultlib:std64.lib
+
+# RUN: env LIB=%T lld-link /out:%t.exe /entry:main \
+# RUN: /subsystem:console hello64.obj /defaultlib:std64.lib
diff --git a/test/COFF/noentry.test b/test/COFF/noentry.test
new file mode 100644
index 0000000000000..80f387fe03c8d
--- /dev/null
+++ b/test/COFF/noentry.test
@@ -0,0 +1,11 @@
+# REQUIRES: winres
+# REQUIRES: winlib
+
+# RUN: yaml2obj < %p/Inputs/export.yaml > %t.obj
+# RUN: lld-link /out:%t.dll /dll %t.obj
+# RUN: llvm-readobj -file-headers %t.dll | FileCheck -check-prefix=ENTRY %s
+# RUN: lld-link /out:%t.dll /dll /noentry %t.obj
+# RUN: llvm-readobj -file-headers %t.dll | FileCheck -check-prefix=NOENTRY %s
+
+ENTRY: AddressOfEntryPoint: 0x1000
+NOENTRY: AddressOfEntryPoint: 0x0
diff --git a/test/COFF/opt.test b/test/COFF/opt.test
new file mode 100644
index 0000000000000..652734b2f68af
--- /dev/null
+++ b/test/COFF/opt.test
@@ -0,0 +1,69 @@
+# RUN: yaml2obj < %s > %t.obj
+
+# RUN: lld-link /out:%t.exe /entry:main %t.obj \
+# RUN: /verbose >& %t.log
+### FileCheck doesn't like empty input, so write something.
+# RUN: echo dummy >> %t.log
+# RUN: FileCheck -check-prefix=CHECK1 %s < %t.log
+
+# RUN: lld-link /out:%t.exe /entry:main %t.obj \
+# RUN: /verbose /opt:noref >& %t.log
+# RUN: echo dummy >> %t.log
+# RUN: FileCheck -check-prefix=CHECK2 %s < %t.log
+
+# CHECK1: Discarded unused
+# CHECK2-NOT: Discarded unused
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: '.text$mn'
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: B82A000000C3
+ - Name: '.text$mn'
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: B82A000000C3
+symbols:
+ - Name: '.text$mn'
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 6
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ Selection: IMAGE_COMDAT_SELECT_ANY
+ - Name: '.text$mn'
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 6
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ Selection: IMAGE_COMDAT_SELECT_ANY
+ - Name: main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: unused
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/options.test b/test/COFF/options.test
new file mode 100644
index 0000000000000..39f944beddbc6
--- /dev/null
+++ b/test/COFF/options.test
@@ -0,0 +1,51 @@
+# RUN: yaml2obj < %p/Inputs/ret42.yaml > %t.obj
+
+# RUN: lld-link /out:%t.exe /entry:main %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=BIND %s
+# RUN: lld-link /allowbind /out:%t.exe /entry:main %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=BIND %s
+BIND-NOT: IMAGE_DLL_CHARACTERISTICS_NO_BIND
+
+# RUN: lld-link /allowbind:no /out:%t.exe /entry:main %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=NOBIND %s
+NOBIND: IMAGE_DLL_CHARACTERISTICS_NO_BIND
+
+# RUN: lld-link /out:%t.exe /entry:main %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=ISO %s
+# RUN: lld-link /allowisolation /out:%t.exe /entry:main %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=ISO %s
+ISO-NOT: IMAGE_DLL_CHARACTERISTICS_NO_ISOLATION
+
+# RUN: lld-link /allowisolation:no /out:%t.exe /entry:main %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=NOISO %s
+NOISO: IMAGE_DLL_CHARACTERISTICS_NO_ISOLATION
+
+# RUN: lld-link /out:%t.exe /entry:main %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=ENT %s
+# RUN: lld-link /out:%t.exe /entry:main /highentropyva %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=ENT %s
+ENT: IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA
+
+# RUN: lld-link /out:%t.exe /highentropyva:no /out:%t.exe /entry:main %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=NOENT %s
+NOENT-NOT: IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA
+
+# RUN: lld-link /out:%t.exe /entry:main %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=NXCOMPAT %s
+# RUN: lld-link /out:%t.exe /entry:main /nxcompat %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=NXCOMPAT %s
+NXCOMPAT: IMAGE_DLL_CHARACTERISTICS_NX_COMPAT
+
+# RUN: lld-link /out:%t.exe /nxcompat:no /out:%t.exe /entry:main %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=NONXCOMPAT %s
+NONXCOMPAT-NOT: IMAGE_DLL_CHARACTERISTICS_NX_COMPAT
+
+# RUN: lld-link /out:%t.exe /entry:main %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=TSAWARE %s
+# RUN: lld-link /out:%t.exe /entry:main /tsaware %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=TSAWARE %s
+TSAWARE: IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE
+
+# RUN: lld-link /tsaware:no /out:%t.exe /entry:main %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=NOTSAWARE %s
+NOTSAWARE-NOT: IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE
diff --git a/test/COFF/order.test b/test/COFF/order.test
new file mode 100644
index 0000000000000..6a0cee8a32ea3
--- /dev/null
+++ b/test/COFF/order.test
@@ -0,0 +1,15 @@
+# RUN: yaml2obj < %p/Inputs/include1a.yaml > %t1.obj
+# RUN: yaml2obj < %p/Inputs/include1b.yaml > %t2.obj
+# RUN: yaml2obj < %p/Inputs/include1c.yaml > %t3.obj
+# RUN: rm -f %t2.lib %t3.lib
+# RUN: llvm-ar cru %t2.lib %t2.obj
+# RUN: llvm-ar cru %t3.lib %t3.obj
+# RUN: lld-link /out:%t.exe /entry:main \
+# RUN: %t1.obj %t2.lib %t3.obj %t3.lib /verbose >& %t.log
+# RUN: FileCheck %s < %t.log
+
+CHECK: order.test.tmp1.obj
+CHECK: order.test.tmp3.obj
+CHECK: order.test.tmp2.lib
+CHECK: order.test.tmp3.lib
+CHECK: order.test.tmp2.lib(order.test.tmp2.obj) for foo
diff --git a/test/COFF/out.test b/test/COFF/out.test
new file mode 100644
index 0000000000000..a216fc9add8fb
--- /dev/null
+++ b/test/COFF/out.test
@@ -0,0 +1,16 @@
+# RUN: yaml2obj < %p/Inputs/ret42.yaml > %t.obj
+
+# RUN: mkdir -p %T/out/tmp
+# RUN: cp %t.obj %T/out/out1.obj
+# RUN: cp %t.obj %T/out/tmp/out2
+# RUN: cp %t.obj %T/out/tmp/out3.xyz
+
+# RUN: lld-link /entry:main %T/out/out1.obj
+# RUN: lld-link /entry:main %T/out/tmp/out2
+# RUN: lld-link /entry:main %T/out/tmp/out3.xyz
+
+# RUN: llvm-readobj out1.exe | FileCheck %s
+# RUN: llvm-readobj out2.exe | FileCheck %s
+# RUN: llvm-readobj out3.exe | FileCheck %s
+
+CHECK: File:
diff --git a/test/COFF/reloc-arm.test b/test/COFF/reloc-arm.test
new file mode 100644
index 0000000000000..b44c0822bb7ff
--- /dev/null
+++ b/test/COFF/reloc-arm.test
@@ -0,0 +1,71 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: lld-link /out:%t.exe /entry:main %t.obj
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+# CHECK: .text:
+# CHECK: 402000 01104000 00000000 00000000 00000000
+# CHECK: 402010 01100000 00000000 00000000 00000000
+# CHECK: 402020 01000100 00004000 00000000 00000000
+# CHECK: 402030 fe07e62f 00000000 00000000 00000000
+# CHECK: 402040 3e04de2f 00000000 00000000 00000000
+# CHECK: 402050 fe07d62f 00000000 00000000 00000000
+# CHECK: 402060 00000000 00000000 00000000 00000000
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_ARMNT
+ Characteristics: []
+sections:
+ - Name: .aaa
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_PURGEABLE, IMAGE_SCN_MEM_16BIT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4096
+ SectionData: 0000000000000000
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_PURGEABLE, IMAGE_SCN_MEM_16BIT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4096
+ SectionData: 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+ Relocations:
+ - VirtualAddress: 0
+ SymbolName: foo
+ Type: 1 # IMAGE_REL_ARM_ADDR32
+ - VirtualAddress: 16
+ SymbolName: foo
+ Type: 2 # IMAGE_REL_ARM_ADDR32NB
+ - VirtualAddress: 32
+ SymbolName: foo
+ Type: 17 # IMAGE_REL_AMD64_MOV32T
+ - VirtualAddress: 48
+ SymbolName: foo
+ Type: 20 # IMAGE_REL_AMD64_BRANCH24T
+ - VirtualAddress: 64
+ SymbolName: foo
+ Type: 18 # IMAGE_REL_ARM_BRANCH20T
+ - VirtualAddress: 80
+ SymbolName: foo
+ Type: 21 # IMAGE_REL_AMD64_BLX23T
+symbols:
+ - Name: .aaa
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ - Name: .text
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ - Name: main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: foo
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/reloc-x64.test b/test/COFF/reloc-x64.test
new file mode 100644
index 0000000000000..5513f2eaa6476
--- /dev/null
+++ b/test/COFF/reloc-x64.test
@@ -0,0 +1,102 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: lld-link /out:%t.exe /entry:main %t.obj
+# RUN: llvm-objdump -d %t.exe | FileCheck %s
+
+# CHECK: .text:
+# CHECK: 1000: a1 03 20 00 40 00 00 00 00
+# CHECK: 1009: a1 03 20 00 40 01 00 00 00
+# CHECK: 1012: a1 03 20 00 00 00 00 00 00
+# CHECK: 101b: a1 e3 0f 00 00 00 00 00 00
+# CHECK: 1024: a1 d9 0f 00 00 00 00 00 00
+# CHECK: 102d: a1 cf 0f 00 00 00 00 00 00
+# CHECK: 1036: a1 c5 0f 00 00 00 00 00 00
+# CHECK: 103f: a1 bb 0f 00 00 00 00 00 00
+# CHECK: 1048: a1 b1 0f 00 00 00 00 00 00
+# CHECK: 1051: a1 02 00 00 00 00 00 00 00
+# CHECK: 105a: a1 03 00 00 00 00 00 00 00
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4096
+ SectionData: A10000000000000000A10000000000000000A10000000000000000A10000000000000000A10000000000000000A10000000000000000A10000000000000000A10000000000000000A10000000000000000A10000000000000000A10000000000000000
+ Relocations:
+ - VirtualAddress: 1
+ SymbolName: foo
+ Type: IMAGE_REL_AMD64_ADDR32
+ - VirtualAddress: 10
+ SymbolName: foo
+ Type: IMAGE_REL_AMD64_ADDR64
+ - VirtualAddress: 19
+ SymbolName: foo
+ Type: IMAGE_REL_AMD64_ADDR32NB
+ - VirtualAddress: 28
+ SymbolName: foo
+ Type: IMAGE_REL_AMD64_REL32
+ - VirtualAddress: 37
+ SymbolName: foo
+ Type: IMAGE_REL_AMD64_REL32_1
+ - VirtualAddress: 46
+ SymbolName: foo
+ Type: IMAGE_REL_AMD64_REL32_2
+ - VirtualAddress: 55
+ SymbolName: foo
+ Type: IMAGE_REL_AMD64_REL32_3
+ - VirtualAddress: 64
+ SymbolName: foo
+ Type: IMAGE_REL_AMD64_REL32_4
+ - VirtualAddress: 73
+ SymbolName: foo
+ Type: IMAGE_REL_AMD64_REL32_5
+ - VirtualAddress: 82
+ SymbolName: foo
+ Type: IMAGE_REL_AMD64_SECTION
+ - VirtualAddress: 91
+ SymbolName: foo
+ Type: IMAGE_REL_AMD64_SECREL
+ - Name: .zzz
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
+ Alignment: 4096
+ SectionData: 0000000000000000
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 6
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: .zzz
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 8
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: foo
+ Value: 3
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/reloc-x86.test b/test/COFF/reloc-x86.test
new file mode 100644
index 0000000000000..d189ca02f0158
--- /dev/null
+++ b/test/COFF/reloc-x86.test
@@ -0,0 +1,82 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: lld-link /out:%t.exe /entry:main /base:0x400000 %t.obj
+# RUN: llvm-objdump -d %t.exe | FileCheck %s
+
+# CHECK: .text:
+# CHECK: 1000: a1 00 00 00 00
+# CHECK: 1005: a1 03 20 40 00
+# CHECK: 100a: a1 03 20 00 00
+# CHECK: 100f: a1 ef 0f 00 00
+# CHECK: 1014: a1 00 00 02 00
+# CHECK: 1019: a1 03 00 00 00
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_I386
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4096
+ SectionData: A100000000A100000000A100000000A100000000A100000000A100000000
+ Relocations:
+ - VirtualAddress: 1
+ SymbolName: _foo
+ Type: IMAGE_REL_I386_ABSOLUTE
+ - VirtualAddress: 6
+ SymbolName: _foo
+ Type: IMAGE_REL_I386_DIR32
+ - VirtualAddress: 11
+ SymbolName: _foo
+ Type: IMAGE_REL_I386_DIR32NB
+ - VirtualAddress: 16
+ SymbolName: _foo
+ Type: IMAGE_REL_I386_REL32
+ - VirtualAddress: 23
+ SymbolName: _foo
+ Type: IMAGE_REL_I386_SECTION
+ - VirtualAddress: 26
+ SymbolName: _foo
+ Type: IMAGE_REL_I386_SECREL
+ - Name: .zzz
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
+ Alignment: 4096
+ SectionData: 0000000000000000
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 6
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: .zzz
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 8
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: _main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: _foo
+ Value: 3
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/resource.test b/test/COFF/resource.test
new file mode 100644
index 0000000000000..7b6090d89f65f
--- /dev/null
+++ b/test/COFF/resource.test
@@ -0,0 +1,14 @@
+# REQUIRES: winres
+
+# RUN: yaml2obj < %p/Inputs/ret42.yaml > %t.obj
+# RUN: lld-link /out:%t.exe /entry:main %t.obj %p/Inputs/resource.res
+
+# Check if the binary contains UTF-16LE string "Hello" copied from resource.res.
+# RUN: FileCheck --check-prefix=EXE %s < %t.exe
+
+EXE: {{H.e.l.l.o}}
+
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck --check-prefix=HEADER %s
+
+HEADER: ResourceTableRVA: 0x1000
+HEADER: ResourceTableSize: 0x88
diff --git a/test/COFF/responsefile.test b/test/COFF/responsefile.test
new file mode 100644
index 0000000000000..fd4d221c20dcc
--- /dev/null
+++ b/test/COFF/responsefile.test
@@ -0,0 +1,7 @@
+# RUN: yaml2obj < %p/Inputs/ret42.yaml > %t.obj
+
+# RUN: echo /out:%t.exe /entry:main %t.obj > %t.rsp
+# RUN: lld-link @%t.rsp /heap:0x3000
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s
+
+CHECK: SizeOfHeapReserve: 12288
diff --git a/test/COFF/safeseh.test b/test/COFF/safeseh.test
new file mode 100644
index 0000000000000..f8308a6131b61
--- /dev/null
+++ b/test/COFF/safeseh.test
@@ -0,0 +1,51 @@
+# RUN: sed s/FEAT_VALUE/1/ %s | yaml2obj > %t.obj
+# RUN: lld-link /out:%t.exe /subsystem:console /entry:main /safeseh %t.obj
+
+# RUN: sed s/FEAT_VALUE/0/ %s | yaml2obj > %t.obj
+# RUN: not lld-link /out:%t.exe /subsystem:console /entry:main \
+# RUN: /safeseh %t.obj >& %t.log
+# RUN: FileCheck %s < %t.log
+
+# CHECK: /safeseh: {{.*}} is not compatible with SEH
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_I386
+ Characteristics: [ ]
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
+ Alignment: 1
+ SectionData: 0000000000000000
+symbols:
+ - Name: '@comp.id'
+ Value: 14766605
+ SectionNumber: 65535
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ - Name: '@feat.00'
+ Value: FEAT_VALUE
+ SectionNumber: 65535
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 8
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: _main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/seh.test b/test/COFF/seh.test
new file mode 100644
index 0000000000000..b3ff66cf09b8e
--- /dev/null
+++ b/test/COFF/seh.test
@@ -0,0 +1,70 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: lld-link /out:%t.exe /subsystem:console /entry:main %t.obj
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+# CHECK: Contents of section .rdata:
+# CHECK: 1000 00200000 02200000
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_I386
+ Characteristics: [ ]
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
+ Alignment: 1
+ SectionData: 0000000000000000
+ - Name: .sxdata
+ Characteristics: [ IMAGE_SCN_LNK_INFO ]
+ Alignment: 4
+ SectionData: 0600000007000000
+symbols:
+ - Name: '@comp.id'
+ Value: 14766605
+ SectionNumber: 65535
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ - Name: '@feat.00'
+ Value: 2147484049
+ SectionNumber: 65535
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 8
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: .sxdata
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 8
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: _main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: _foo
+ Value: 2
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/sort-debug.test b/test/COFF/sort-debug.test
new file mode 100644
index 0000000000000..c099f2dc19b1d
--- /dev/null
+++ b/test/COFF/sort-debug.test
@@ -0,0 +1,296 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: lld-link /debug /out:%t.exe /entry:main %t.obj
+# RUN: llvm-readobj -sections %t.exe | FileCheck %s
+
+# CHECK: Name: .text
+# CHECK: Name: .debug_abbrev
+# CHECK: Name: .debug_info
+# CHECK: Name: .debug_line
+# CHECK: Name: .debug_pubnames
+# CHECK: Name: .debug_pubtypes
+# CHECK: Name: .reloc
+
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_I386
+ Characteristics: [ ]
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 16
+ SectionData: 508D0500000000C70424000000005AC3
+ Relocations:
+ - VirtualAddress: 3
+ SymbolName: '?x@@3HA'
+ Type: IMAGE_REL_I386_DIR32
+ - Name: .data
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
+ Alignment: 4
+ SectionData: ''
+ - Name: .bss
+ Characteristics: [ IMAGE_SCN_CNT_UNINITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
+ Alignment: 4
+ SectionData: ''
+ - Name: '.debug$S'
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
+ Alignment: 1
+ SectionData: 04000000F1000000300000002A00471100000000000000000000000010000000000000000000000000000000000000000000006D61696E0002004F11F200000024000000000000000000010010000000000000000100000018000000000000000100000000000000F4000000080000000100000000000000F30000003C000000005C7573725C6C6F63616C5C676F6F676C655C686F6D655C6D616A6E656D65725C6C6C766D5C7372635C746F6F6C735C6C6C645C3C737464696E3E00
+ Relocations:
+ - VirtualAddress: 44
+ SymbolName: _main
+ Type: IMAGE_REL_I386_SECREL
+ - VirtualAddress: 48
+ SymbolName: _main
+ Type: IMAGE_REL_I386_SECTION
+ - VirtualAddress: 68
+ SymbolName: _main
+ Type: IMAGE_REL_I386_SECREL
+ - VirtualAddress: 72
+ SymbolName: _main
+ Type: IMAGE_REL_I386_SECTION
+ - Name: .debug_str
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
+ Alignment: 1
+ SectionData: ''
+ - Name: .debug_loc
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
+ Alignment: 1
+ SectionData: ''
+ - Name: .debug_abbrev
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
+ Alignment: 1
+ SectionData: 011101250E1305030E10171B0E110112060000023400030E49133F193A0B3B0B02186E0E0000032400030E3E0B0B0B0000042E0011011206E77F194018030E3A0B3B0B49133F19000000
+ - Name: .debug_info
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
+ Alignment: 1
+ SectionData: 54000000040000000000040100000000040037000000000000003F000000000000001000000002720000003B0000000101050300000000780000000374000000050404000000001000000001548000000001013B00000000
+ Relocations:
+ - VirtualAddress: 6
+ SymbolName: .debug_abbrev
+ Type: IMAGE_REL_I386_SECREL
+ - VirtualAddress: 12
+ SymbolName: .debug_str
+ Type: IMAGE_REL_I386_SECREL
+ - VirtualAddress: 18
+ SymbolName: .debug_str
+ Type: IMAGE_REL_I386_SECREL
+ - VirtualAddress: 22
+ SymbolName: .debug_line
+ Type: IMAGE_REL_I386_SECREL
+ - VirtualAddress: 26
+ SymbolName: .debug_str
+ Type: IMAGE_REL_I386_SECREL
+ - VirtualAddress: 30
+ SymbolName: .text
+ Type: IMAGE_REL_I386_DIR32
+ - VirtualAddress: 39
+ SymbolName: .debug_str
+ Type: IMAGE_REL_I386_SECREL
+ - VirtualAddress: 51
+ SymbolName: '?x@@3HA'
+ Type: IMAGE_REL_I386_DIR32
+ - VirtualAddress: 55
+ SymbolName: .debug_str
+ Type: IMAGE_REL_I386_SECREL
+ - VirtualAddress: 60
+ SymbolName: .debug_str
+ Type: IMAGE_REL_I386_SECREL
+ - VirtualAddress: 67
+ SymbolName: .text
+ Type: IMAGE_REL_I386_DIR32
+ - VirtualAddress: 77
+ SymbolName: .debug_str
+ Type: IMAGE_REL_I386_SECREL
+ - Name: .debug_ranges
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
+ Alignment: 1
+ SectionData: ''
+ - Name: .debug_pubnames
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
+ Alignment: 1
+ SectionData: 1D00000002000000000058000000420000006D61696E0026000000780000000000
+ Relocations:
+ - VirtualAddress: 6
+ SymbolName: .debug_info
+ Type: IMAGE_REL_I386_SECREL
+ - Name: .debug_pubtypes
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
+ Alignment: 1
+ SectionData: 16000000020000000000580000003B000000696E740000000000
+ Relocations:
+ - VirtualAddress: 6
+ SymbolName: .debug_info
+ Type: IMAGE_REL_I386_SECREL
+ - Name: .debug_line
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
+ Alignment: 1
+ SectionData: 3300000002001E0000000101FB0E0D000101010100000001000001003C737464696E3E000000000000050200000000010AD60202000101
+ Relocations:
+ - VirtualAddress: 43
+ SymbolName: .text
+ Type: IMAGE_REL_I386_DIR32
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 16
+ NumberOfRelocations: 1
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 1
+ - Name: .data
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 0
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 2
+ - Name: .bss
+ Value: 0
+ SectionNumber: 3
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 4
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 3
+ - Name: '.debug$S'
+ Value: 0
+ SectionNumber: 4
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 188
+ NumberOfRelocations: 4
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 4
+ - Name: .debug_str
+ Value: 0
+ SectionNumber: 5
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 133
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 5
+ - Name: .debug_loc
+ Value: 0
+ SectionNumber: 6
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 0
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 6
+ - Name: .debug_abbrev
+ Value: 0
+ SectionNumber: 7
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 74
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 7
+ - Name: .debug_info
+ Value: 0
+ SectionNumber: 8
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 88
+ NumberOfRelocations: 12
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 8
+ - Name: .debug_ranges
+ Value: 0
+ SectionNumber: 9
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 0
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 9
+ - Name: .debug_pubnames
+ Value: 0
+ SectionNumber: 10
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 33
+ NumberOfRelocations: 1
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 10
+ - Name: .debug_pubtypes
+ Value: 0
+ SectionNumber: 11
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 26
+ NumberOfRelocations: 1
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 11
+ - Name: .debug_line
+ Value: 0
+ SectionNumber: 12
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 55
+ NumberOfRelocations: 1
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 12
+ - Name: '@feat.00'
+ Value: 1
+ SectionNumber: -1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ - Name: _main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: '?x@@3HA'
+ Value: 0
+ SectionNumber: 3
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/stack.test b/test/COFF/stack.test
new file mode 100644
index 0000000000000..df066b16c20d3
--- /dev/null
+++ b/test/COFF/stack.test
@@ -0,0 +1,25 @@
+# RUN: yaml2obj < %p/Inputs/ret42.yaml > %t.obj
+
+# RUN: lld-link /out:%t.exe /entry:main %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=DEFAULT %s
+
+DEFAULT: SizeOfStackReserve: 1048576
+DEFAULT: SizeOfStackCommit: 4096
+
+# RUN: lld-link /out:%t.exe /entry:main %t.obj /stack:0x3000
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=CHECK1 %s
+# RUN: echo "STACKSIZE 12288" > %t.def
+# RUN: lld-link /out:%t.exe /entry:main /def:%t.def %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=CHECK1 %s
+
+CHECK1: SizeOfStackReserve: 12288
+CHECK1: SizeOfStackCommit: 4096
+
+# RUN: lld-link /out:%t.exe /entry:main %t.obj /stack:0x5000,0x3000
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=CHECK2 %s
+# RUN: echo "STACKSIZE 20480,12288" > %t.def
+# RUN: lld-link /out:%t.exe /entry:main /def:%t.def %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=CHECK2 %s
+
+CHECK2: SizeOfStackReserve: 20480
+CHECK2: SizeOfStackCommit: 12288
diff --git a/test/COFF/subsystem-inference.test b/test/COFF/subsystem-inference.test
new file mode 100644
index 0000000000000..da4f573c2e02f
--- /dev/null
+++ b/test/COFF/subsystem-inference.test
@@ -0,0 +1,74 @@
+# RUN: sed -e s/ENTRYNAME/main/ %s | yaml2obj > %t.obj
+# RUN: lld-link /out:%t.exe %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=MAIN %s
+
+# RUN: sed s/ENTRYNAME/wmain/ %s | yaml2obj > %t.obj
+# RUN: lld-link /out:%t.exe %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=WMAIN %s
+
+# RUN: sed s/ENTRYNAME/WinMain/ %s | yaml2obj > %t.obj
+# RUN: lld-link /out:%t.exe %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=WINMAIN %s
+
+# RUN: sed s/ENTRYNAME/wWinMain/ %s | yaml2obj > %t.obj
+# RUN: lld-link /out:%t.exe %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=WWINMAIN %s
+
+# MAIN: Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI
+# WMAIN: Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI
+# WINMAIN: Subsystem: IMAGE_SUBSYSTEM_WINDOWS_GUI
+# WWINMAIN: Subsystem: IMAGE_SUBSYSTEM_WINDOWS_GUI
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: B82A000000C3
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 6
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: ENTRYNAME
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: mainCRTStartup
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: wmainCRTStartup
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: WinMainCRTStartup
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: wWinMainCRTStartup
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/subsystem.test b/test/COFF/subsystem.test
new file mode 100644
index 0000000000000..5e72706dd1cb9
--- /dev/null
+++ b/test/COFF/subsystem.test
@@ -0,0 +1,19 @@
+# RUN: lld-link /entry:main /out:%t.exe /subsystem:windows \
+# RUN: %p/Inputs/ret42.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=CHECK1 %s
+
+CHECK1: MajorOperatingSystemVersion: 6
+CHECK1: MinorOperatingSystemVersion: 0
+CHECK1: MajorSubsystemVersion: 6
+CHECK1: MinorSubsystemVersion: 0
+CHECK1: Subsystem: IMAGE_SUBSYSTEM_WINDOWS_GUI
+
+# RUN: lld-link /entry:main /out:%t.exe /subsystem:windows,8.9 \
+# RUN: %p/Inputs/ret42.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=CHECK2 %s
+
+CHECK2: MajorOperatingSystemVersion: 8
+CHECK2: MinorOperatingSystemVersion: 9
+CHECK2: MajorSubsystemVersion: 8
+CHECK2: MinorSubsystemVersion: 9
+CHECK2: Subsystem: IMAGE_SUBSYSTEM_WINDOWS_GUI
diff --git a/test/COFF/symtab.test b/test/COFF/symtab.test
new file mode 100644
index 0000000000000..14ae9a3e816ca
--- /dev/null
+++ b/test/COFF/symtab.test
@@ -0,0 +1,254 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: lld-link /debug /out:%t.exe /entry:main %t.obj %p/Inputs/std64.lib
+# RUN: llvm-readobj -symbols %t.exe | FileCheck %s
+# RUN: lld-link /debug /opt:noref /out:%t.exe /entry:main %t.obj %p/Inputs/std64.lib
+# RUN: llvm-readobj -symbols %t.exe | FileCheck %s
+
+# RUN: lld-link /debug /nosymtab /out:%t.exe /entry:main %t.obj %p/Inputs/std64.lib
+# RUN: llvm-readobj -symbols %t.exe | FileCheck -check-prefix=NO %s
+
+# CHECK: Symbols [
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: .text
+# CHECK-NEXT: Value: 0
+# CHECK-NEXT: Section: .text (2)
+# CHECK-NEXT: BaseType: Null (0x0)
+# CHECK-NEXT: ComplexType: Null (0x0)
+# CHECK-NEXT: StorageClass: Static (0x3)
+# CHECK-NEXT: AuxSymbolCount: 0
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: .text2
+# CHECK-NEXT: Value: 0
+# CHECK-NEXT: Section: .text (2)
+# CHECK-NEXT: BaseType: Null (0x0)
+# CHECK-NEXT: ComplexType: Null (0x0)
+# CHECK-NEXT: StorageClass: Static (0x3)
+# CHECK-NEXT: AuxSymbolCount: 0
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: .data
+# CHECK-NEXT: Value: 0
+# CHECK-NEXT: Section: .data (1)
+# CHECK-NEXT: BaseType: Null (0x0)
+# CHECK-NEXT: ComplexType: Null (0x0)
+# CHECK-NEXT: StorageClass: Static (0x3)
+# CHECK-NEXT: AuxSymbolCount: 0
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: message
+# CHECK-NEXT: Value: 6
+# CHECK-NEXT: Section: .text2 (3)
+# CHECK-NEXT: BaseType: Null (0x0)
+# CHECK-NEXT: ComplexType: Null (0x0)
+# CHECK-NEXT: StorageClass: Static (0x3)
+# CHECK-NEXT: AuxSymbolCount: 0
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: main
+# CHECK-NEXT: Value: 0
+# CHECK-NEXT: Section: .text (2)
+# CHECK-NEXT: BaseType: Null (0x0)
+# CHECK-NEXT: ComplexType: Null (0x0)
+# CHECK-NEXT: StorageClass: External (0x2)
+# CHECK-NEXT: AuxSymbolCount: 0
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: caption
+# CHECK-NEXT: Value: 0
+# CHECK-NEXT: Section: .text2 (3)
+# CHECK-NEXT: BaseType: Null (0x0)
+# CHECK-NEXT: ComplexType: Null (0x0)
+# CHECK-NEXT: StorageClass: Static (0x3)
+# CHECK-NEXT: AuxSymbolCount: 0
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: abs_symbol
+# CHECK-NEXT: Value: 2662186735
+# CHECK-NEXT: Section: IMAGE_SYM_ABSOLUTE (-1)
+# CHECK-NEXT: BaseType: Null (0x0)
+# CHECK-NEXT: ComplexType: Null (0x0)
+# CHECK-NEXT: StorageClass: External (0x2)
+# CHECK-NEXT: AuxSymbolCount: 0
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: __imp_ExitProcess
+# CHECK-NEXT: Value: 64
+# CHECK-NEXT: Section: .idata (4)
+# CHECK-NEXT: BaseType: Null (0x0)
+# CHECK-NEXT: ComplexType: Null (0x0)
+# CHECK-NEXT: StorageClass: External (0x2)
+# CHECK-NEXT: AuxSymbolCount: 0
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: ExitProcess
+# CHECK-NEXT: Value: 64
+# CHECK-NEXT: Section: .text (2)
+# CHECK-NEXT: BaseType: Null (0x0)
+# CHECK-NEXT: ComplexType: Null (0x0)
+# CHECK-NEXT: StorageClass: External (0x2)
+# CHECK-NEXT: AuxSymbolCount: 0
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: __imp_MessageBoxA
+# CHECK-NEXT: Value: 72
+# CHECK-NEXT: Section: .idata (4)
+# CHECK-NEXT: BaseType: Null (0x0)
+# CHECK-NEXT: ComplexType: Null (0x0)
+# CHECK-NEXT: StorageClass: External (0x2)
+# CHECK-NEXT: AuxSymbolCount: 0
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: MessageBoxA
+# CHECK-NEXT: Value: 80
+# CHECK-NEXT: Section: .text (2)
+# CHECK-NEXT: BaseType: Null (0x0)
+# CHECK-NEXT: ComplexType: Null (0x0)
+# CHECK-NEXT: StorageClass: External (0x2)
+# CHECK-NEXT: AuxSymbolCount: 0
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
+
+# NO: Symbols [
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4096
+ SectionData: B800000000000000005068000000000000000068000000000000000050E8000000000000000050E8000000000000000050E80000000000000000
+ Relocations:
+ - VirtualAddress: 0
+ SymbolName: abs_symbol
+ Type: IMAGE_REL_AMD64_ADDR64
+ - VirtualAddress: 7
+ SymbolName: caption
+ Type: IMAGE_REL_AMD64_ADDR64
+ - VirtualAddress: 12
+ SymbolName: message
+ Type: IMAGE_REL_AMD64_ADDR64
+ - VirtualAddress: 18
+ SymbolName: MessageBoxA
+ Type: IMAGE_REL_AMD64_REL32
+ - VirtualAddress: 24
+ SymbolName: ExitProcess
+ Type: IMAGE_REL_AMD64_REL32
+ - VirtualAddress: 30
+ SymbolName: __ImageBase
+ Type: IMAGE_REL_AMD64_ADDR64
+ - Name: .text2
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4096
+ SectionData: B800000000000000005068000000000000000068000000000000000050E8000000000000000050E8000000000000000050E80000000000000000
+ Relocations:
+ - VirtualAddress: 0
+ SymbolName: abs_symbol
+ Type: IMAGE_REL_AMD64_ADDR64
+ - VirtualAddress: 7
+ SymbolName: caption
+ Type: IMAGE_REL_AMD64_ADDR64
+ - VirtualAddress: 12
+ SymbolName: message
+ Type: IMAGE_REL_AMD64_ADDR64
+ - VirtualAddress: 18
+ SymbolName: MessageBoxA
+ Type: IMAGE_REL_AMD64_REL32
+ - VirtualAddress: 24
+ SymbolName: ExitProcess
+ Type: IMAGE_REL_AMD64_REL32
+ - VirtualAddress: 30
+ SymbolName: __ImageBase
+ Type: IMAGE_REL_AMD64_ADDR64
+ - Name: .data
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
+ Alignment: 4
+ SectionData: 48656C6C6F0048656C6C6F20576F726C6400
+symbols:
+ - Name: "@comp.id"
+ Value: 10394907
+ SectionNumber: 65535
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 28
+ NumberOfRelocations: 6
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: .text2
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 28
+ NumberOfRelocations: 6
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: .data
+ Value: 0
+ SectionNumber: 3
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 18
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: MessageBoxA
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: ExitProcess
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: message
+ Value: 6
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ - Name: main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: caption
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ - Name: abs_symbol
+ Value: 0xDEADBEEF
+ SectionNumber: -1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: __ImageBase
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/tls.test b/test/COFF/tls.test
new file mode 100644
index 0000000000000..395916dfdd679
--- /dev/null
+++ b/test/COFF/tls.test
@@ -0,0 +1,43 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: lld-link /out:%t.exe /entry:main %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s
+
+# CHECK: TLSTableRVA: 0x1000
+# CHECK: TLSTableSize: 0x28
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: 00000000
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 4
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ Selection: IMAGE_COMDAT_SELECT_ANY
+ - Name: main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: _tls_used
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/tls32.test b/test/COFF/tls32.test
new file mode 100644
index 0000000000000..4fe020eb9e108
--- /dev/null
+++ b/test/COFF/tls32.test
@@ -0,0 +1,43 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: lld-link /out:%t.exe /entry:main %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s
+
+# CHECK: TLSTableRVA: 0x1000
+# CHECK: TLSTableSize: 0x28
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_I386
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: 00000000
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 4
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ Selection: IMAGE_COMDAT_SELECT_ANY
+ - Name: _main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: __tls_used
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/unwind.test b/test/COFF/unwind.test
new file mode 100644
index 0000000000000..48e94165b9bdd
--- /dev/null
+++ b/test/COFF/unwind.test
@@ -0,0 +1,198 @@
+# RUN: yaml2obj < %s > %t.obj
+#
+# RUN: lld-link /out:%t.exe /entry:main %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=HEADER %s
+# RUN: llvm-objdump -unwind-info %t.exe | FileCheck -check-prefix=UNWIND %s
+#
+# HEADER: ExceptionTableRVA: 0x1000
+#
+# UNWIND: Function Table:
+# UNWIND: Start Address: 0x2000
+# UNWIND: End Address: 0x201b
+# UNWIND: Unwind Info Address: 0x3000
+# UNWIND: Version: 1
+# UNWIND: Flags: 1 UNW_ExceptionHandler
+# UNWIND: Size of prolog: 18
+# UNWIND: Number of Codes: 8
+# UNWIND: Frame register: RBX
+# UNWIND: Frame offset: 0
+# UNWIND: Unwind Codes:
+# UNWIND: 0x12: UOP_SetFPReg
+# UNWIND: 0x0f: UOP_PushNonVol RBX
+# UNWIND: 0x0e: UOP_SaveXMM128 XMM8 [0x0000]
+# UNWIND: 0x09: UOP_SaveNonVol RSI [0x0010]
+# UNWIND: 0x04: UOP_AllocSmall 24
+# UNWIND: 0x00: UOP_PushMachFrame w/o error code
+# UNWIND: Function Table:
+# UNWIND: Start Address: 0x2012
+# UNWIND: End Address: 0x2012
+# UNWIND: Unwind Info Address: 0x301c
+# UNWIND: Version: 1
+# UNWIND: Flags: 4 UNW_ChainInfo
+# UNWIND: Size of prolog: 0
+# UNWIND: Number of Codes: 0
+# UNWIND: No frame pointer used
+# UNWIND: Function Table:
+# UNWIND: Start Address: 0x201b
+# UNWIND: End Address: 0x201c
+# UNWIND: Unwind Info Address: 0x302c
+# UNWIND: Version: 1
+# UNWIND: Flags: 0
+# UNWIND: Size of prolog: 0
+# UNWIND: Number of Codes: 0
+# UNWIND: No frame pointer used
+# UNWIND: Function Table:
+# UNWIND: Start Address: 0x201c
+# UNWIND: End Address: 0x2039
+# UNWIND: Unwind Info Address: 0x3034
+# UNWIND: Version: 1
+# UNWIND: Flags: 0
+# UNWIND: Size of prolog: 14
+# UNWIND: Number of Codes: 6
+# UNWIND: No frame pointer used
+# UNWIND: Unwind Codes:
+# UNWIND: 0x0e: UOP_AllocLarge 8454128
+# UNWIND: 0x07: UOP_AllocLarge 8190
+# UNWIND: 0x00: UOP_PushMachFrame w/o error code
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: [ ]
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: 4883EC184889742410440F110424534889E3488D235B4883C418C3C34881ECF0FF00004881ECF0FF80004881C4F0FF80004881C4F0FF0000C3
+ - Name: .xdata
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: 0912080312030F300E880000096402000422001A000000000000000021000000000000001B000000000000000100000000000000010E06000E11F0FF80000701FE1F001A
+ Relocations:
+ - VirtualAddress: 20
+ SymbolName: __C_specific_handler
+ Type: IMAGE_REL_AMD64_ADDR32NB
+ - VirtualAddress: 32
+ SymbolName: func
+ Type: IMAGE_REL_AMD64_ADDR32NB
+ - VirtualAddress: 36
+ SymbolName: func
+ Type: IMAGE_REL_AMD64_ADDR32NB
+ - VirtualAddress: 40
+ SymbolName: .xdata
+ Type: IMAGE_REL_AMD64_ADDR32NB
+ - Name: .pdata
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: 000000001B0000000000000012000000120000001C00000000000000010000002C000000000000001D00000034000000
+ Relocations:
+ - VirtualAddress: 0
+ SymbolName: func
+ Type: IMAGE_REL_AMD64_ADDR32NB
+ - VirtualAddress: 4
+ SymbolName: func
+ Type: IMAGE_REL_AMD64_ADDR32NB
+ - VirtualAddress: 8
+ SymbolName: .xdata
+ Type: IMAGE_REL_AMD64_ADDR32NB
+ - VirtualAddress: 12
+ SymbolName: func
+ Type: IMAGE_REL_AMD64_ADDR32NB
+ - VirtualAddress: 16
+ SymbolName: func
+ Type: IMAGE_REL_AMD64_ADDR32NB
+ - VirtualAddress: 20
+ SymbolName: .xdata
+ Type: IMAGE_REL_AMD64_ADDR32NB
+ - VirtualAddress: 24
+ SymbolName: smallFunc
+ Type: IMAGE_REL_AMD64_ADDR32NB
+ - VirtualAddress: 28
+ SymbolName: smallFunc
+ Type: IMAGE_REL_AMD64_ADDR32NB
+ - VirtualAddress: 32
+ SymbolName: .xdata
+ Type: IMAGE_REL_AMD64_ADDR32NB
+ - VirtualAddress: 36
+ SymbolName: allocFunc
+ Type: IMAGE_REL_AMD64_ADDR32NB
+ - VirtualAddress: 40
+ SymbolName: allocFunc
+ Type: IMAGE_REL_AMD64_ADDR32NB
+ - VirtualAddress: 44
+ SymbolName: .xdata
+ Type: IMAGE_REL_AMD64_ADDR32NB
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 57
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 1
+ - Name: .xdata
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 68
+ NumberOfRelocations: 4
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 2
+ - Name: .pdata
+ Value: 0
+ SectionNumber: 3
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 48
+ NumberOfRelocations: 12
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 3
+ - Name: func
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: __C_specific_handler
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: smallFunc
+ Value: 27
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: allocFunc
+ Value: 28
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: __C_specific_handler
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/version.test b/test/COFF/version.test
new file mode 100644
index 0000000000000..69fa93394a0f4
--- /dev/null
+++ b/test/COFF/version.test
@@ -0,0 +1,19 @@
+# RUN: yaml2obj < %p/Inputs/ret42.yaml > %t.obj
+
+# RUN: lld-link /out:%t.exe /entry:main %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=DEFAULT %s
+
+DEFAULT: MajorImageVersion: 0
+DEFAULT: MinorImageVersion: 0
+
+# RUN: lld-link /out:%t.exe /entry:main %t.obj /version:11
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=CHECK1 %s
+
+CHECK1: MajorImageVersion: 11
+CHECK1: MinorImageVersion: 0
+
+# RUN: lld-link /out:%t.exe /entry:main %t.obj /version:11.22
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=CHECK2 %s
+
+CHECK2: MajorImageVersion: 11
+CHECK2: MinorImageVersion: 22
diff --git a/test/COFF/weak-external.test b/test/COFF/weak-external.test
new file mode 100644
index 0000000000000..3997170b897a7
--- /dev/null
+++ b/test/COFF/weak-external.test
@@ -0,0 +1,36 @@
+# RUN: yaml2obj %s > %t.obj
+# RUN: llvm-as -o %t.lto.obj %S/Inputs/weak-external.ll
+# RUN: lld-link /out:%t1.exe /entry:g /subsystem:console %t.obj
+# RUN: lld-link /out:%t2.exe /entry:g /subsystem:console /lldmap:%t2.map %t.obj %t.lto.obj
+# RUN: FileCheck %s < %t2.map
+
+# CHECK: <lto object>:
+# CHECK-NOT: :
+# CHECK: {{ g$}}
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: [ ]
+sections:
+ - Name: '.text'
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 16
+ SectionData: 00
+symbols:
+ - Name: 'g'
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_WEAK_EXTERNAL
+ WeakExternal:
+ TagIndex: 2
+ Characteristics: IMAGE_WEAK_EXTERN_SEARCH_LIBRARY
+ - Name: 'f'
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
diff --git a/test/COFF/weak-external2.test b/test/COFF/weak-external2.test
new file mode 100644
index 0000000000000..6afaac29219dd
--- /dev/null
+++ b/test/COFF/weak-external2.test
@@ -0,0 +1,30 @@
+# RUN: yaml2obj %s > %t.obj
+# RUN: llvm-as -o %t.lto.obj %S/Inputs/weak-external2.ll
+# RUN: lld-link /out:%t.exe /entry:g /subsystem:console %t.obj %t.lto.obj
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: [ ]
+sections:
+ - Name: '.text'
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 16
+ SectionData: 00
+symbols:
+ - Name: 'f'
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: 'g'
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_WEAK_EXTERNAL
+ WeakExternal:
+ TagIndex: 0
+ Characteristics: IMAGE_WEAK_EXTERN_SEARCH_LIBRARY
+...
diff --git a/test/COFF/weak-external3.test b/test/COFF/weak-external3.test
new file mode 100644
index 0000000000000..9ba32982d505f
--- /dev/null
+++ b/test/COFF/weak-external3.test
@@ -0,0 +1,32 @@
+# RUN: yaml2obj %s > %t.obj
+# RUN: llvm-as -o %t.lto.obj %S/Inputs/weak-external3.ll
+# RUN: lld-link /out:%t1.exe /entry:f /subsystem:console /lldmap:%t1.map %t.lto.obj
+# RUN: FileCheck --check-prefix=CHECK1 %s < %t1.map
+# RUN: lld-link /out:%t2.exe /entry:f /subsystem:console /lldmap:%t2.map %t.obj %t.lto.obj
+# RUN: FileCheck --check-prefix=CHECK2 %s < %t2.map
+
+# CHECK1: <lto object>:
+# CHECK1-NOT: :
+# CHECK1: {{ g$}}
+
+# CHECK2: weak-external3{{.*}}:
+# CHECK2-NOT: :
+# CHECK2: {{ f$}}
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: [ ]
+sections:
+ - Name: '.text'
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 16
+ SectionData: 00
+symbols:
+ - Name: 'f'
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...