13
13
#include " llvm/ADT/SmallString.h"
14
14
#include " llvm/ADT/StringRef.h"
15
15
#include " llvm/ADT/Twine.h"
16
+ #include " llvm/BinaryFormat/MachO.h"
16
17
#include " llvm/Config/llvm-config.h"
17
18
#include " llvm/ExecutionEngine/JITSymbol.h"
18
19
#include " llvm/ExecutionEngine/Orc/LLJIT.h"
20
+ #include " llvm/Object/MachO.h"
19
21
#include " llvm/Support/Casting.h"
20
22
#include " llvm/Support/Path.h"
21
23
24
+ /home/maximus/cppyy-interop-dev/CppInterOp/llvm-project/compiler-rt/lib/orc/macho_platform.cpp
25
+
22
26
#ifdef USE_CLING
23
27
24
28
#include " cling/Interpreter/DynamicLibraryManager.h"
@@ -36,6 +40,45 @@ namespace compat {
36
40
37
41
using Interpreter = cling::Interpreter;
38
42
43
+ #ifdef __APPLE__
44
+ #include < mach-o/dyld.h>
45
+ #include < sys/stat.h>
46
+ // Define a minimal mach header for JIT'd code.
47
+ static MachO::mach_header_64 fake_mach_header = {
48
+ .magic = MachO::MH_MAGIC_64,
49
+ .cputype = MachO::CPU_TYPE_ARM64,
50
+ .cpusubtype = MachO::CPU_SUBTYPE_ARM64_ALL,
51
+ .filetype = MachO::MH_DYLIB,
52
+ .ncmds = 0 ,
53
+ .sizeofcmds = 0 ,
54
+ .flags = 0 ,
55
+ .reserved = 0 };
56
+
57
+ // Declare libunwind SPI types and functions.
58
+ struct unw_dynamic_unwind_sections {
59
+ uintptr_t dso_base;
60
+ uintptr_t dwarf_section;
61
+ size_t dwarf_section_length;
62
+ uintptr_t compact_unwind_section;
63
+ size_t compact_unwind_section_length;
64
+ };
65
+
66
+ int find_dynamic_unwind_sections (uintptr_t addr,
67
+ unw_dynamic_unwind_sections* info) {
68
+ info->dso_base = (uintptr_t )&fake_mach_header;
69
+ info->dwarf_section = 0 ;
70
+ info->dwarf_section_length = 0 ;
71
+ info->compact_unwind_section = 0 ;
72
+ info->compact_unwind_section_length = 0 ;
73
+ return 1 ;
74
+ }
75
+
76
+ // Typedef for callback above.
77
+ typedef int (*unw_find_dynamic_unwind_sections)(
78
+ uintptr_t addr, struct unw_dynamic_unwind_sections * info);
79
+
80
+ #endif
81
+
39
82
inline void maybeMangleDeclName (const clang::GlobalDecl& GD,
40
83
std::string& mangledName) {
41
84
cling::utils::Analyze::maybeMangleDeclName (GD, mangledName);
@@ -151,6 +194,15 @@ createClangInterpreter(std::vector<const char*>& args) {
151
194
return std::move (*innerOrErr);
152
195
}
153
196
197
+ #ifdef __APPLE__
198
+ inline void removeFindDynamicUnwindSections () {
199
+ if (auto * unw_remove_find_dynamic_unwind_sections = (int (*)(
200
+ unw_find_dynamic_unwind_sections find_dynamic_unwind_sections))
201
+ dlsym (RTLD_DEFAULT, " __unw_remove_find_dynamic_unwind_sections" ))
202
+ unw_remove_find_dynamic_unwind_sections (find_dynamic_unwind_sections);
203
+ }
204
+ #endif
205
+
154
206
inline void maybeMangleDeclName (const clang::GlobalDecl& GD,
155
207
std::string& mangledName) {
156
208
// copied and adapted from CodeGen::CodeGenModule::getMangledName
0 commit comments