llvm-project
169 строк · 6.8 Кб
1# REQUIRES: x86
2
3# RUN: rm -rf %t; split-file %s %t
4
5## ld64 ignores the __objc_imageinfo section entirely if there is no actual
6## ObjC class + category data in the file. LLD doesn't yet do this check, but
7## to make this test work for both linkers, I am inserting an appropriate class
8## definition into each test file.
9# RUN: cat %t/no-category-cls.s %t/foo-cls.s > %t/no-category-cls-1.s
10# RUN: cat %t/with-category-cls.s %t/foo-cls.s > %t/with-category-cls-1.s
11# RUN: cat %t/ignored-flags.s %t/foo-cls.s > %t/ignored-flags-1.s
12# RUN: cat %t/invalid-version.s %t/foo-cls.s > %t/invalid-version-1.s
13# RUN: cat %t/invalid-size.s %t/foo-cls.s > %t/invalid-size-1.s
14# RUN: cat %t/swift-version-1.s %t/foo-cls.s > %t/swift-version-1-1.s
15# RUN: cat %t/swift-version-2.s %t/foo-cls.s > %t/swift-version-2-1.s
16
17# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/no-category-cls-1.s -o %t/no-category-cls.o
18# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/with-category-cls-1.s -o %t/with-category-cls.o
19# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/ignored-flags-1.s -o %t/ignored-flags.o
20# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/invalid-version-1.s -o %t/invalid-version.o
21# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/swift-version-1-1.s -o %t/swift-version-1.o
22# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/swift-version-2-1.s -o %t/swift-version-2.o
23# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/invalid-size-1.s -o %t/invalid-size.o
24
25# RUN: %lld -dylib -lSystem %t/with-category-cls.o -o %t/test-with-cat
26# RUN: llvm-objdump --macho --section="__DATA_CONST,__objc_imageinfo" --syms \
27# RUN: %t/test-with-cat | FileCheck %s --check-prefix=HAS-CAT-CLS \
28# RUN: --implicit-check-not=_discard_me
29
30# RUN: %lld -dylib -lSystem %t/no-category-cls.o -o %t/test-no-cat
31# RUN: llvm-objdump --macho --section="__DATA_CONST,__objc_imageinfo" --syms \
32# RUN: %t/test-no-cat | FileCheck %s --check-prefix=NO-CAT-CLS \
33# RUN: --implicit-check-not=_discard_me
34
35# RUN: %lld -dylib -lSystem %t/no-category-cls.o %t/with-category-cls.o -o %t/test1
36# RUN: llvm-objdump --macho --section="__DATA_CONST,__objc_imageinfo" %t/test1 \
37# RUN: | FileCheck %s --check-prefix=NO-CAT-CLS
38
39# RUN: %lld -dylib -lSystem %t/with-category-cls.o %t/ignored-flags.o -o %t/test2
40# RUN: llvm-objdump --macho --section="__DATA_CONST,__objc_imageinfo" %t/test2 \
41# RUN: | FileCheck %s --check-prefix=HAS-CAT-CLS
42
43# RUN: %lld -dylib -lSystem %t/no-category-cls.o %t/ignored-flags.o -o %t/test3
44# RUN: llvm-objdump --macho --section="__DATA_CONST,__objc_imageinfo" %t/test3 \
45# RUN: | FileCheck %s --check-prefix=NO-CAT-CLS
46
47# RUN: %no-fatal-warnings-lld -dylib -lSystem %t/with-category-cls.o \
48# RUN: %t/invalid-version.o -o %t/test4 2>&1 | FileCheck %s \
49# RUN: --check-prefix=IMAGE-VERSION
50# RUN: llvm-objdump --macho --section="__DATA_CONST,__objc_imageinfo" %t/test4 \
51# RUN: | FileCheck %s --check-prefix=NO-CAT-CLS
52
53# RUN: %no-fatal-warnings-lld -dylib -lSystem %t/no-category-cls.o \
54# RUN: %t/invalid-version.o -o %t/test5 2>&1 | FileCheck %s \
55# RUN: --check-prefix=IMAGE-VERSION
56# RUN: llvm-objdump --macho --section="__DATA_CONST,__objc_imageinfo" %t/test5 \
57# RUN: | FileCheck %s --check-prefix=NO-CAT-CLS
58
59# RUN: %no-fatal-warnings-lld -dylib -lSystem %t/with-category-cls.o \
60# RUN: %t/invalid-size.o -o %t/test6 2>&1 | FileCheck %s \
61# RUN: --check-prefix=INVALID-SIZE
62# RUN: llvm-objdump --macho --section="__DATA_CONST,__objc_imageinfo" %t/test6 \
63# RUN: | FileCheck %s --check-prefix=NO-CAT-CLS
64
65# RUN: not %lld -dylib -lSystem %t/swift-version-1.o %t/swift-version-2.o -o \
66# RUN: /dev/null 2>&1 | FileCheck %s --check-prefix=SWIFT-MISMATCH-12
67# RUN: not %lld -dylib -lSystem %t/swift-version-2.o %t/swift-version-1.o -o \
68# RUN: /dev/null 2>&1 | FileCheck %s --check-prefix=SWIFT-MISMATCH-21
69
70## with-category-cls.o does not have a Swift version (it's set to zero) and
71## should be compatible with any Swift version.
72# RUN: %lld -dylib -lSystem %t/with-category-cls.o %t/swift-version-1.o -o %t/swift-v1
73# RUN: llvm-objdump --macho --section="__DATA_CONST,__objc_imageinfo" \
74# RUN: %t/swift-v1 | FileCheck %s --check-prefix=SWIFT-V1
75# RUN: %lld -dylib -lSystem %t/with-category-cls.o %t/swift-version-2.o -o %t/swift-v2
76# RUN: llvm-objdump --macho --section="__DATA_CONST,__objc_imageinfo" \
77# RUN: %t/swift-v2 | FileCheck %s --check-prefix=SWIFT-V2
78
79# HAS-CAT-CLS: Contents of (__DATA_CONST,__objc_imageinfo) section
80# HAS-CAT-CLS: 00 00 00 40 00 00 00
81# HAS-CAT-CLS-EMPTY:
82
83# NO-CAT-CLS: Contents of (__DATA_CONST,__objc_imageinfo) section
84# NO-CAT-CLS: 00 00 00 00 00 00 00
85# NO-CAT-CLS-EMPTY:
86
87# SWIFT-V1: Contents of (__DATA_CONST,__objc_imageinfo) section
88# SWIFT-V1: 00 00 00 40 01 00 00
89# SWIFT-V1-EMPTY:
90
91# SWIFT-V2: Contents of (__DATA_CONST,__objc_imageinfo) section
92# SWIFT-V2: 00 00 00 40 02 00 00
93# SWIFT-V2-EMPTY:
94
95# IMAGE-VERSION: warning: {{.*}}invalid-version.o: invalid __objc_imageinfo version
96
97# INVALID-SIZE: warning: {{.*}}invalid-size.o: invalid __objc_imageinfo size
98
99# SWIFT-MISMATCH-12: error: Swift version mismatch: {{.*}}swift-version-1.o has version 1.0 but {{.*}}swift-version-2.o has version 1.1
100# SWIFT-MISMATCH-21: error: Swift version mismatch: {{.*}}swift-version-2.o has version 1.1 but {{.*}}swift-version-1.o has version 1.0
101
102#--- no-category-cls.s
103.section __DATA,__objc_imageinfo,regular,no_dead_strip
104## ld64 discards any symbols in this section; we follow suit.
105_discard_me:
106.long 0
107.long 0
108
109#--- with-category-cls.s
110.section __DATA,__objc_imageinfo,regular,no_dead_strip
111_discard_me:
112.long 0
113.long 0x40 ## "has category class properties" flag
114
115#--- ignored-flags.s
116.section __DATA,__objc_imageinfo,regular,no_dead_strip
117.long 0
118## Only the 0x40 flag is carried through to the output binary.
119.long (0x40 | 0x20 | 0x4 | 0x2)
120
121#--- invalid-version.s
122.section __DATA,__objc_imageinfo,regular,no_dead_strip
123.long 1 ## only 0 is valid; the flag field below will not be parsed.
124.long 0x40
125
126#--- invalid-size.s
127.section __DATA,__objc_imageinfo
128.long 0
129
130#--- swift-version-1.s
131.section __DATA,__objc_imageinfo,regular,no_dead_strip
132.long 0
133.byte 0x40
134.byte 0x1 ## Swift version
135.short 0
136
137#--- swift-version-2.s
138.section __DATA,__objc_imageinfo,regular,no_dead_strip
139.long 0
140.byte 0x40
141.byte 0x2 ## Swift version
142.short 0
143
144#--- foo-cls.s
145.section __TEXT,__objc_classname,cstring_literals
146L_CAT_NAME:
147.asciz "barcat"
148
149.section __DATA,__objc_data
150.p2align 3
151_OBJC_CLASS_$_FooClass:
152.space 40
153
154.section __DATA,__objc_const
155.p2align 3
156__OBJC_$_CATEGORY_FooClass_$_barcat:
157.quad L_CAT_NAME
158.quad _OBJC_CLASS_$_FooClass
159.quad 0
160.quad 0
161.quad 0
162.quad 0
163.quad 0
164.long 64
165.space 4
166
167.section __DATA,__objc_catlist,regular,no_dead_strip
168.p2align 3
169.quad __OBJC_$_CATEGORY_FooClass_$_barcat
170