Skip to content

Commit 9d701c8

Browse files
committed
[ORC] Fix fallout from switch to _objc_map/load_images-based registration.
In f448d44 we switched to calling _objc_map_images and _objc_load_images for MachO language metadata registration. This patch fixes some bugs arising from that change: (1) __objc_imageinfo processing was moved to a post-allocation pass, but this prevents us from discarding the redundant copies. This commit moves processing back to a pre-prune pass and inserts a symbol for the uniqued __objc_image section. Runtime objects use an edge pointing to this symbol to access the address. (2) We were assuming that _objc_map_images & _objc_load_images were available in the Objective-C runtime on 10.15, but these functions didn't become available until later. This commit bumps the macOS version requirement to 13.1 where the functions should be available. (3) The ORC-RT trivial-swift-types-section.S test was missing an __objc_unwindinfo section, which triggered an assert that should have been an error. The assert has been turned into an error, and the testcase has been updated to include an __objc_imageinfo. rdar://107846455
1 parent 9d9a773 commit 9d701c8

File tree

5 files changed

+216
-117
lines changed

5 files changed

+216
-117
lines changed

compiler-rt/lib/orc/macho_platform.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,8 @@ Error MachOPlatformRuntimeState::deregisterEHFrames(
859859

860860
Error MachOPlatformRuntimeState::registerObjCRegistrationObjects(
861861
JITDylibState &JDS) {
862+
ORC_RT_DEBUG(printdbg("Registering Objective-C / Swift metadata.\n"));
863+
862864
if (!_objc_map_images || !_objc_load_image)
863865
return make_error<StringError>(
864866
"Could not register Objective-C / Swift metadata: _objc_map_images / "

compiler-rt/test/lit.common.cfg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,8 @@ def get_ios_commands_dir():
403403
if osx_version >= (10, 11):
404404
config.available_features.add('osx-autointerception')
405405
config.available_features.add('osx-ld64-live_support')
406-
if osx_version >= (10, 15):
407-
config.available_features.add('osx-swift-runtime')
406+
if osx_version >= (13, 1):
407+
config.available_features.add('jit-compatible-osx-swift-runtime')
408408
except subprocess.CalledProcessError:
409409
pass
410410

Lines changed: 112 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,129 @@
11
# RUN: %clang -c -o %t %s
22
# RUN: %llvm_jitlink -preload /usr/lib/swift/libswiftCore.dylib %t
33

4-
# REQUIRES: osx-swift-runtime
4+
# REQUIRES: jit-compatible-osx-swift-runtime
55

66
# Check that _typeByName is able to find a type registered by metadata in
77
# the __swift5_types section.
88

9-
.section __TEXT,__text,regular,pure_instructions
10-
.globl _main
11-
.p2align 4, 0x90
9+
.section __TEXT,__text,regular,pure_instructions
10+
.build_version macos, 14, 0 sdk_version 14, 0
11+
.globl _main
12+
.p2align 4, 0x90
1213
_main:
13-
.cfi_startproc
14-
pushq %rbp
15-
.cfi_def_cfa_offset 16
16-
.cfi_offset %rbp, -16
17-
movq %rsp, %rbp
18-
.cfi_def_cfa_register %rbp
19-
# Constant String for "4Test3FooV"
20-
movabsq $8018152761824990260, %rdi
21-
movabsq $-1585267068834392465, %rsi
22-
callq _$ss11_typeByNameyypXpSgSSF
23-
xorl %edi, %edi
24-
testq %rax, %rax
25-
sete %dil
26-
callq _exit
27-
.cfi_endproc
28-
29-
.private_extern _$s4Test3FooVMa
30-
.globl _$s4Test3FooVMa
31-
.p2align 4, 0x90
14+
.cfi_startproc
15+
pushq %rbp
16+
.cfi_def_cfa_offset 16
17+
.cfi_offset %rbp, -16
18+
movq %rsp, %rbp
19+
.cfi_def_cfa_register %rbp
20+
# Constant String for "4Test3FooV"
21+
movabsq $8018152761824990260, %rdi
22+
movabsq $-1585267068834392465, %rsi
23+
callq _$ss11_typeByNameyypXpSgSSF
24+
xorl %edi, %edi
25+
testq %rax, %rax
26+
sete %dil
27+
callq _exit
28+
.cfi_endproc
29+
30+
.private_extern _$s4Test3FooVACycfC
31+
.globl _$s4Test3FooVACycfC
32+
.p2align 4, 0x90
33+
_$s4Test3FooVACycfC:
34+
pushq %rbp
35+
movq %rsp, %rbp
36+
popq %rbp
37+
retq
38+
39+
.private_extern _$s4Test3FooVMa
40+
.globl _$s4Test3FooVMa
41+
.p2align 4, 0x90
3242
_$s4Test3FooVMa:
33-
leaq _$s4Test3FooVMf+8(%rip), %rax
34-
xorl %edx, %edx
35-
retq
36-
37-
.section __TEXT,__const
38-
l___unnamed_1:
39-
.asciz "Test"
40-
41-
.private_extern _$s4TestMXM
42-
.globl _$s4TestMXM
43-
.weak_definition _$s4TestMXM
44-
.p2align 2
43+
leaq _$s4Test3FooVMf+8(%rip), %rax
44+
xorl %edx, %edx
45+
retq
46+
47+
.section __TEXT,__swift5_entry,regular,no_dead_strip
48+
.p2align 2
49+
l_entry_point:
50+
.long _main-l_entry_point
51+
.long 0
52+
53+
.section __TEXT,__const
54+
l_.str.4.Test:
55+
.asciz "Test"
56+
57+
.private_extern _$s4TestMXM
58+
.globl _$s4TestMXM
59+
.weak_definition _$s4TestMXM
60+
.p2align 2
4561
_$s4TestMXM:
46-
.long 0
47-
.long 0
48-
.long (l___unnamed_1-_$s4TestMXM)-8
62+
.long 0
63+
.long 0
64+
.long (l_.str.4.Test-_$s4TestMXM)-8
4965

50-
l___unnamed_2:
51-
.asciz "Foo"
66+
l_.str.3.Foo:
67+
.asciz "Foo"
5268

53-
.private_extern _$s4Test3FooVMn
54-
.globl _$s4Test3FooVMn
55-
.p2align 2
69+
.private_extern _$s4Test3FooVMn
70+
.globl _$s4Test3FooVMn
71+
.p2align 2
5672
_$s4Test3FooVMn:
57-
.long 81
58-
.long (_$s4TestMXM-_$s4Test3FooVMn)-4
59-
.long (l___unnamed_2-_$s4Test3FooVMn)-8
60-
.long (_$s4Test3FooVMa-_$s4Test3FooVMn)-12
61-
.long (_$s4Test3FooVMF-_$s4Test3FooVMn)-16
62-
.long 0
63-
.long 2
64-
65-
.section __DATA,__const
66-
.p2align 3
73+
.long 81
74+
.long (_$s4TestMXM-_$s4Test3FooVMn)-4
75+
.long (l_.str.3.Foo-_$s4Test3FooVMn)-8
76+
.long (_$s4Test3FooVMa-_$s4Test3FooVMn)-12
77+
.long (_$s4Test3FooVMF-_$s4Test3FooVMn)-16
78+
.long 0
79+
.long 2
80+
81+
.section __DATA,__const
82+
.p2align 3
6783
_$s4Test3FooVMf:
68-
.quad _$sytWV
69-
.quad 512
70-
.quad _$s4Test3FooVMn
71-
72-
.private_extern "_symbolic _____ 4Test3FooV"
73-
.section __TEXT,__swift5_typeref,regular,no_dead_strip
74-
.globl "_symbolic _____ 4Test3FooV"
75-
.weak_definition "_symbolic _____ 4Test3FooV"
76-
.p2align 1
84+
.quad _$sytWV
85+
.quad 512
86+
.quad _$s4Test3FooVMn
87+
88+
.private_extern "_symbolic _____ 4Test3FooV"
89+
.section __TEXT,__swift5_typeref
90+
.globl "_symbolic _____ 4Test3FooV"
91+
.weak_definition "_symbolic _____ 4Test3FooV"
92+
.p2align 1
7793
"_symbolic _____ 4Test3FooV":
78-
.byte 1
79-
.long (_$s4Test3FooVMn-"_symbolic _____ 4Test3FooV")-1
80-
.byte 0
94+
.byte 1
95+
.long (_$s4Test3FooVMn-"_symbolic _____ 4Test3FooV")-1
96+
.byte 0
8197

82-
.section __TEXT,__swift5_fieldmd,regular,no_dead_strip
83-
.p2align 2
98+
.section __TEXT,__swift5_fieldmd
99+
.p2align 2
84100
_$s4Test3FooVMF:
85-
.long "_symbolic _____ 4Test3FooV"-_$s4Test3FooVMF
86-
.long 0
87-
.short 0
88-
.short 12
89-
.long 0
90-
91-
.section __TEXT,__swift5_types,regular,no_dead_strip
92-
.p2align 2
93-
l_type_metadata_table:
94-
.long _$s4Test3FooVMn-l_type_metadata_table
101+
.long "_symbolic _____ 4Test3FooV"-_$s4Test3FooVMF
102+
.long 0
103+
.short 0
104+
.short 12
105+
.long 0
106+
107+
.section __TEXT,__swift5_types
108+
.p2align 2
109+
l_$s4Test3FooVHn:
110+
.long _$s4Test3FooVMn-l_$s4Test3FooVHn
111+
112+
.private_extern ___swift_reflection_version
113+
.section __TEXT,__const
114+
.globl ___swift_reflection_version
115+
.weak_definition ___swift_reflection_version
116+
.p2align 1
117+
___swift_reflection_version:
118+
.short 3
119+
120+
.section __DATA,__objc_imageinfo,regular,no_dead_strip
121+
L_OBJC_IMAGE_INFO:
122+
.long 0
123+
.long 84477760
124+
125+
.globl _$s4Test3FooVN
126+
.private_extern _$s4Test3FooVN
127+
.alt_entry _$s4Test3FooVN
128+
.set _$s4Test3FooVN, _$s4Test3FooVMf+8
129+
.subsections_via_symbols

llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ class MachOPlatform : public Platform {
159159
struct ObjCImageInfo {
160160
uint32_t Version = 0;
161161
uint32_t Flags = 0;
162-
ExecutorAddr Addr;
163162
};
164163

165164
Error bootstrapPipelineStart(jitlink::LinkGraph &G);

0 commit comments

Comments
 (0)