2 # RUN: rm -rf %t; split-file %s %t
4 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/has-objc-symbol.s -o %t/has-objc-symbol.o
5 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/has-objc-category.s -o %t/has-objc-category.o
6 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/has-objc-symbol-and-category.s -o %t/has-objc-symbol-and-category.o
7 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/has-swift.s -o %t/has-swift.o
8 # RUN: llvm-as %t/has-swift-ir-loaded.ll -o %t/has-swift-ir-loaded.o
9 # RUN: llvm-as %t/has-swift-ir-not-loaded.ll -o %t/has-swift-ir-not-loaded.o
10 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/has-swift-proto.s -o %t/has-swift-proto.o
11 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/no-objc.s -o %t/no-objc.o
12 ## Make sure we don't mis-parse a 32-bit file as 64-bit
13 # RUN: llvm-mc -filetype=obj -triple=armv7-apple-watchos %t/no-objc.s -o %t/wrong-arch.o
14 # RUN: llvm-ar rcs %t/libHasSomeObjC.a %t/no-objc.o %t/has-objc-symbol.o %t/has-objc-category.o %t/has-swift.o %t/has-swift-proto.o %t/has-swift-ir-loaded.o %t/has-swift-ir-not-loaded.o %t/wrong-arch.o
15 # RUN: llvm-ar rcs %t/libHasSomeObjC2.a %t/no-objc.o %t/has-objc-symbol-and-category.o %t/has-swift.o %t/has-swift-proto.o %t/has-swift-ir-loaded.o %t/has-swift-ir-not-loaded.o %t/wrong-arch.o
17 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o
19 # RUN: %lld -lSystem %t/test.o -o %t/test -L%t -lHasSomeObjC -ObjC
20 # RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s --check-prefix=OBJC
22 # RUN: %lld -lSystem %t/test.o -o %t/test -L%t -lHasSomeObjC2 -ObjC
23 # RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s --check-prefix=OBJC
25 # RUN: %no-fatal-warnings-lld -lSystem %t/test.o -o %t/test --start-lib %t/no-objc.o %t/has-objc-symbol.o %t/has-objc-category.o %t/has-swift.o %t/has-swift-proto.o %t/has-swift-ir-loaded.o %t/has-swift-ir-not-loaded.o %t/wrong-arch.o --end-lib -ObjC 2>&1 \
26 # RUN: | FileCheck -check-prefix=WARNING %s
27 # RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s --check-prefix=OBJC
29 # WARNING: {{.+}}wrong-arch.o has architecture armv7 which is incompatible with target architecture x86_64
33 # OBJC-NEXT: Idx Name Size VMA Type
34 # OBJC-NEXT: 0 __text {{.*}} TEXT
35 # OBJC-NEXT: 1 __swift {{.*}} DATA
36 # OBJC-NEXT: 2 __swift5_fieldmd{{.*}} DATA
37 # OBJC-NEXT: 3 __objc_catlist {{.*}} DATA
38 # OBJC-NEXT: 4 has_objc_symbol {{.*}} DATA
40 # OBJC-NEXT: SYMBOL TABLE:
41 # OBJC-DAG: g O __TEXT,__swift _foo
42 # OBJC-DAG: g F __TEXT,__text _main
43 # OBJC-DAG: g F __TEXT,__text _OBJC_CLASS_$_MyObject
44 # OBJC-DAG: g O __TEXT,__swift5_fieldmd $s7somelib4Blah_pMF
46 # RUN: %lld -lSystem %t/test.o -o %t/test -L%t -lHasSomeObjC
47 # RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s --check-prefix=NO-OBJC
50 # NO-OBJC-NEXT: Idx Name Size VMA Type
51 # NO-OBJC-NEXT: 0 __text {{.*}} TEXT
53 # NO-OBJC-NEXT: SYMBOL TABLE:
54 # NO-OBJC-NEXT: g F __TEXT,__text _main
55 # NO-OBJC-NEXT: g F __TEXT,__text __mh_execute_header
56 # NO-OBJC-NEXT: *UND* dyld_stub_binder
59 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/refs-dup.s -o %t/refs-dup.o
60 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/refs-objc.s -o %t/refs-objc.o
62 ## Check that -ObjC causes has-objc-symbol.o to be loaded first, prior to symbol
63 ## resolution. This matches ld64's behavior.
64 # RUN: %lld -dylib %t/refs-dup.o %t/refs-objc.o -o %t/refs-dup -L%t -lHasSomeObjC -ObjC
65 # RUN: llvm-objdump --macho --syms %t/refs-dup | FileCheck %s --check-prefix=DUP-FROM-OBJC
66 # DUP-FROM-OBJC: g O __DATA,has_objc_symbol _has_dup
68 ## Without -ObjC, no-objc.o gets loaded first during symbol resolution, causing
69 ## a duplicate symbol error.
70 # RUN: not %lld -dylib %t/refs-dup.o %t/refs-objc.o -o %t/refs-dup -L%t \
71 # RUN: -lHasSomeObjC 2>&1 | FileCheck %s --check-prefix=DUP-ERROR
72 # DUP-ERROR: error: duplicate symbol: _has_dup
74 ## TODO: Load has-objc-symbol.o prior to symbol resolution to match the archive behavior.
75 # RUN: not %lld -dylib %t/refs-dup.o %t/refs-objc.o -o %t/refs-dup --start-lib %t/no-objc.o \
76 # RUN: %t/has-objc-symbol.o %t/has-objc-category.o %t/has-swift.o %t/wrong-arch.o --end-lib \
77 # RUN: -ObjC 2>&1 | FileCheck %s --check-prefix=DUP-ERROR
79 #--- has-objc-symbol.s
80 .globl _OBJC_CLASS_$_MyObject, _has_dup
81 _OBJC_CLASS_$_MyObject
:
83 .section __DATA,has_objc_symbol
86 #--- has-objc-category.s
87 .section __DATA,__objc_catlist
90 #--- has-objc-symbol-and-category.s
91 ## Make sure we load this archive member exactly once (i.e. no duplicate symbol
93 .globl _OBJC_CLASS_$_MyObject, _has_dup
94 _OBJC_CLASS_$_MyObject
:
96 .section __DATA,has_objc_symbol
99 .section __DATA,__objc_catlist
103 .section __TEXT,__swift
106 #--- has-swift-ir-loaded.ll
107 target datalayout
= "e-m:o-i64:64-i128:128-n32:64-S128"
108 target triple
= "x86_64-apple-darwin"
110 @foo
= global i64
1234, section
"__TEXT,__swift"
111 @llvm.used
= appending global
[1 x ptr
] [ptr @foo
]
113 #--- has-swift-ir-not-loaded.ll
114 target datalayout
= "e-m:o-i64:64-i128:128-n32:64-S128"
115 target triple
= "x86_64-apple-darwin"
117 @bar
= global i64
1234
118 @llvm.used
= appending global
[1 x ptr
] [ptr @bar
]
120 #--- has-swift-proto.s
121 .section __TEXT,__swift5_fieldmd
122 .globl $s7somelib4Blah_pMF
126 ## This archive member should not be pulled in by -ObjC since it does not
127 ## contain any ObjC-related data.
131 .section __DATA,no_objc
145 .quad _OBJC_CLASS_$_MyObject