@@ -103,6 +103,43 @@ createClangInterpreter(std::vector<const char*>& args) {
103
103
bool CudaEnabled = !gpu_args.empty ();
104
104
#endif
105
105
106
+ #ifdef __APPLE__
107
+ // Define a minimal mach header for JIT'd code.
108
+ static MachO::mach_header_64 fake_mach_header = {
109
+ .magic = MachO::MH_MAGIC_64,
110
+ .cputype = MachO::CPU_TYPE_ARM64,
111
+ .cpusubtype = MachO::CPU_SUBTYPE_ARM64_ALL,
112
+ .filetype = MachO::MH_DYLIB,
113
+ .ncmds = 0 ,
114
+ .sizeofcmds = 0 ,
115
+ .flags = 0 ,
116
+ .reserved = 0 };
117
+
118
+ // Declare libunwind SPI types and functions.
119
+ struct unw_dynamic_unwind_sections {
120
+ uintptr_t dso_base;
121
+ uintptr_t dwarf_section;
122
+ size_t dwarf_section_length;
123
+ uintptr_t compact_unwind_section;
124
+ size_t compact_unwind_section_length;
125
+ };
126
+
127
+ int find_dynamic_unwind_sections (uintptr_t addr,
128
+ unw_dynamic_unwind_sections * info) {
129
+ info->dso_base = (uintptr_t )&fake_mach_header;
130
+ info->dwarf_section = 0 ;
131
+ info->dwarf_section_length = 0 ;
132
+ info->compact_unwind_section = 0 ;
133
+ info->compact_unwind_section_length = 0 ;
134
+ return 1 ;
135
+ }
136
+
137
+ // Typedef for callback above.
138
+ typedef int (*unw_find_dynamic_unwind_sections)(
139
+ uintptr_t addr, struct unw_dynamic_unwind_sections * info);
140
+
141
+ #endif
142
+
106
143
clang::IncrementalCompilerBuilder CB;
107
144
CB.SetCompilerArgs ({args.begin (), it});
108
145
@@ -151,6 +188,15 @@ createClangInterpreter(std::vector<const char*>& args) {
151
188
return std::move (*innerOrErr);
152
189
}
153
190
191
+ #ifdef __APPLE__
192
+ inline void removeFindDynamicUnwindSections () {
193
+ if (auto * unw_remove_find_dynamic_unwind_sections = (int (*)(
194
+ unw_find_dynamic_unwind_sections find_dynamic_unwind_sections))
195
+ dlsym (RTLD_DEFAULT, " __unw_remove_find_dynamic_unwind_sections" ))
196
+ unw_remove_find_dynamic_unwind_sections (find_dynamic_unwind_sections);
197
+ }
198
+ #endif
199
+
154
200
inline void maybeMangleDeclName (const clang::GlobalDecl& GD,
155
201
std::string& mangledName) {
156
202
// copied and adapted from CodeGen::CodeGenModule::getMangledName
0 commit comments