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-mc -filetype=obj -triple=x86_64-apple-darwin %t/has-swift-proto.s -o %t/has-swift-proto.o
9 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/no-objc.s -o %t/no-objc.o
10 ## Make sure we don't mis-parse a 32-bit file as 64-bit
11 # RUN: llvm-mc -filetype=obj -triple=armv7-apple-watchos %t/no-objc.s -o %t/wrong-arch.o
12 # 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/wrong-arch.o
13 # 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/wrong-arch.o
15 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o
17 # RUN: %lld -lSystem %t/test.o -o %t/test -L%t -lHasSomeObjC -ObjC
18 # RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s --check-prefix=OBJC
20 # RUN: %lld -lSystem %t/test.o -o %t/test -L%t -lHasSomeObjC2 -ObjC
21 # RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s --check-prefix=OBJC
23 # 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/wrong-arch.o --end-lib -ObjC 2>&1 \
24 # RUN: | FileCheck -check-prefix=WARNING %s
25 # RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s --check-prefix=OBJC
27 # WARNING: {{.+}}wrong-arch.o has architecture armv7 which is incompatible with target architecture x86_64
31 # OBJC-NEXT: Idx Name Size VMA Type
32 # OBJC-NEXT: 0 __text {{.*}} TEXT
33 # OBJC-NEXT: 1 __swift {{.*}} DATA
34 # OBJC-NEXT: 2 __swift5_fieldmd{{.*}} DATA
35 # OBJC-NEXT: 3 __objc_catlist {{.*}} DATA
36 # OBJC-NEXT: 4 has_objc_symbol {{.*}} DATA
38 # OBJC-NEXT: SYMBOL TABLE:
39 # OBJC-DAG: g F __TEXT,__text _main
40 # OBJC-DAG: g F __TEXT,__text _OBJC_CLASS_$_MyObject
41 # OBJC-DAG: g O __TEXT,__swift5_fieldmd $s7somelib4Blah_pMF
43 # RUN: %lld -lSystem %t/test.o -o %t/test -L%t -lHasSomeObjC
44 # RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s --check-prefix=NO-OBJC
47 # NO-OBJC-NEXT: Idx Name Size VMA Type
48 # NO-OBJC-NEXT: 0 __text {{.*}} TEXT
50 # NO-OBJC-NEXT: SYMBOL TABLE:
51 # NO-OBJC-NEXT: g F __TEXT,__text _main
52 # NO-OBJC-NEXT: g F __TEXT,__text __mh_execute_header
53 # NO-OBJC-NEXT: *UND* dyld_stub_binder
56 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/refs-dup.s -o %t/refs-dup.o
57 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/refs-objc.s -o %t/refs-objc.o
59 ## Check that -ObjC causes has-objc-symbol.o to be loaded first, prior to symbol
60 ## resolution. This matches ld64's behavior.
61 # RUN: %lld -dylib %t/refs-dup.o %t/refs-objc.o -o %t/refs-dup -L%t -lHasSomeObjC -ObjC
62 # RUN: llvm-objdump --macho --syms %t/refs-dup | FileCheck %s --check-prefix=DUP-FROM-OBJC
63 # DUP-FROM-OBJC: g O __DATA,has_objc_symbol _has_dup
65 ## Without -ObjC, no-objc.o gets loaded first during symbol resolution, causing
66 ## a duplicate symbol error.
67 # RUN: not %lld -dylib %t/refs-dup.o %t/refs-objc.o -o %t/refs-dup -L%t \
68 # RUN: -lHasSomeObjC 2>&1 | FileCheck %s --check-prefix=DUP-ERROR
69 # DUP-ERROR: error: duplicate symbol: _has_dup
71 ## TODO: Load has-objc-symbol.o prior to symbol resolution to match the archive behavior.
72 # RUN: not %lld -dylib %t/refs-dup.o %t/refs-objc.o -o %t/refs-dup --start-lib %t/no-objc.o \
73 # RUN: %t/has-objc-symbol.o %t/has-objc-category.o %t/has-swift.o %t/wrong-arch.o --end-lib \
74 # RUN: -ObjC 2>&1 | FileCheck %s --check-prefix=DUP-ERROR
76 #--- has-objc-symbol.s
77 .globl _OBJC_CLASS_$_MyObject, _has_dup
78 _OBJC_CLASS_$_MyObject
:
80 .section __DATA,has_objc_symbol
83 #--- has-objc-category.s
84 .section __DATA,__objc_catlist
87 #--- has-objc-symbol-and-category.s
88 ## Make sure we load this archive member exactly once (i.e. no duplicate symbol
90 .globl _OBJC_CLASS_$_MyObject, _has_dup
91 _OBJC_CLASS_$_MyObject
:
93 .section __DATA,has_objc_symbol
96 .section __DATA,__objc_catlist
100 .section __TEXT,__swift
103 #--- has-swift-proto.s
104 .section __TEXT,__swift5_fieldmd
105 .globl $s7somelib4Blah_pMF
109 ## This archive member should not be pulled in by -ObjC since it does not
110 ## contain any ObjC-related data.
114 .section __DATA,no_objc
128 .quad _OBJC_CLASS_$_MyObject