summaryrefslogtreecommitdiffstats
path: root/lld/test/COFF/crt-dyn-initializer-order.test
blob: 019f1bdf484b1f8bd1c3578021d855c522002a07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# // a.cpp
# #include <iostream>
# #include <vector>
#
# template <int Magic> struct TemplatedObject {
#   static std::vector<TemplatedObject<Magic> *> Instances;
#   TemplatedObject() { Instances.push_back(this); }
# };
#
# using Object = TemplatedObject<0>;
# template <> std::vector<Object *> Object::Instances{};
# Object idle{};
#
# int main() {
#   if (Object::Instances.size() == 0)
#     std::cout << "It's broken" << std::endl;
#   else
#     std::cout << "It works!" << std::endl;
#   return 0;
# }
# // using `clang-cl /c a.cpp | lld-link a.obj` works
# // using `cl /c a.cpp | lld-link a.obj` fails without lld/COFF/Writer.cpp/Writer::sortSectionChunks()

# RUN: yaml2obj %s > %t.obj
# RUN: yaml2obj %S/Inputs/crt-dyn-initializer-order_1.yaml > %t1.obj
# RUN: yaml2obj %S/Inputs/crt-dyn-initializer-order_2.yaml > %t2.obj

# CHECK: Name: .CRT
# CHECK: Characteristics [
# CHECK-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA
# CHECK-NEXT: IMAGE_SCN_MEM_READ
# CHECK-NEXT: ]
# CHECK-NEXT: SectionData (

# RUN: lld-link /out:%t.dll /entry:__ImageBase /dll %t.obj %t1.obj %t2.obj
# RUN: llvm-readobj --sections --section-data %t.dll | FileCheck %s --check-prefixes CHECK,CASE1
# CASE1-NEXT: 01020304 55701011 1205

# RUN: lld-link /out:%t.dll /entry:__ImageBase /dll %t.obj %t2.obj %t1.obj
# RUN: llvm-readobj --sections --section-data %t.dll | FileCheck %s --check-prefixes CHECK,CASE2
# CASE2-NEXT: 01020304 10111255 7005

# RUN: lld-link /out:%t.dll /entry:__ImageBase /dll %t1.obj %t2.obj %t.obj
# RUN: llvm-readobj --sections --section-data %t.dll | FileCheck %s --check-prefixes CHECK,CASE3
# CASE3-NEXT: 01557010 11120203 0405

# RUN: lld-link /out:%t.dll /entry:__ImageBase /dll %t1.obj %t.obj %t2.obj
# RUN: llvm-readobj --sections --section-data %t.dll | FileCheck %s --check-prefixes CHECK,CASE4
# CASE4-NEXT: 01557002 03041011 1205

# RUN: lld-link /out:%t.dll /entry:__ImageBase /dll %t2.obj %t1.obj %t.obj
# RUN: llvm-readobj --sections --section-data %t.dll | FileCheck %s --check-prefixes CHECK,CASE5
# CASE5-NEXT: 01101112 55700203 0405

# RUN: lld-link /out:%t.dll /entry:__ImageBase /dll %t2.obj %t.obj %t1.obj
# RUN: llvm-readobj --sections --section-data %t.dll | FileCheck %s --check-prefixes CHECK,CASE6
# CASE6-NEXT: 01101112 02030455 7005

# CHECK-NEXT: )

--- !COFF
header:
  Machine:         IMAGE_FILE_MACHINE_AMD64
  Characteristics: [  ]
sections:
  - Name:            '.CRT$XCA'
    Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
    Alignment:       1
    SectionData:     01
  - Name:            '.CRT$XCU'
    Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
    Alignment:       1
    SectionData:     02
  - Name:            '.CRT$XCU'
    Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_LNK_COMDAT ]
    Alignment:       1
    SectionData:     03
  - Name:            '.CRT$XCU'
    Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
    Alignment:       1
    SectionData:     04
  - Name:            '.CRT$XCZ'
    Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
    Alignment:       1
    SectionData:     05
symbols:
  - Name:            '.CRT$XCU'
    Value:           0
    SectionNumber:   3
    SimpleType:      IMAGE_SYM_TYPE_NULL
    ComplexType:     IMAGE_SYM_DTYPE_NULL
    StorageClass:    IMAGE_SYM_CLASS_STATIC
    SectionDefinition:
      Length:          1
      NumberOfRelocations: 0
      NumberOfLinenumbers: 0
      CheckSum:        1
      Number:          2
      Selection:       IMAGE_COMDAT_SELECT_ASSOCIATIVE
...
OpenPOWER on IntegriCloud