Skip to content

Commit 4023625

Browse files
[Orc] Deduplicate GDB JIT Interface declarations (NFC) (#76373)
#76236 introduced the forth copy and it was time to deduplicate. This patch brings it back to 2, one in OrcTargetProcess and one in legacy ExecutionEngine.
1 parent 54378a7 commit 4023625

File tree

5 files changed

+36
-111
lines changed

5 files changed

+36
-111
lines changed

llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,32 @@
1616
#include "llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h"
1717
#include <cstdint>
1818

19+
// Keep in sync with gdb/gdb/jit.h
20+
extern "C" {
21+
22+
typedef enum {
23+
JIT_NOACTION = 0,
24+
JIT_REGISTER_FN,
25+
JIT_UNREGISTER_FN
26+
} jit_actions_t;
27+
28+
struct jit_code_entry {
29+
struct jit_code_entry *next_entry;
30+
struct jit_code_entry *prev_entry;
31+
const char *symfile_addr;
32+
uint64_t symfile_size;
33+
};
34+
35+
struct jit_descriptor {
36+
uint32_t version;
37+
// This should be jit_actions_t, but we want to be specific about the
38+
// bit-width.
39+
uint32_t action_flag;
40+
struct jit_code_entry *relevant_entry;
41+
struct jit_code_entry *first_entry;
42+
};
43+
}
44+
1945
extern "C" llvm::orc::shared::CWrapperFunctionResult
2046
llvm_orc_registerJITLoaderGDBWrapper(const char *Data, uint64_t Size);
2147

llvm/lib/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,8 @@
2121
// First version as landed in August 2009
2222
static constexpr uint32_t JitDescriptorVersion = 1;
2323

24-
// Keep in sync with gdb/gdb/jit.h
2524
extern "C" {
2625

27-
typedef enum {
28-
JIT_NOACTION = 0,
29-
JIT_REGISTER_FN,
30-
JIT_UNREGISTER_FN
31-
} jit_actions_t;
32-
33-
struct jit_code_entry {
34-
struct jit_code_entry *next_entry;
35-
struct jit_code_entry *prev_entry;
36-
const char *symfile_addr;
37-
uint64_t symfile_size;
38-
};
39-
40-
struct jit_descriptor {
41-
uint32_t version;
42-
// This should be jit_actions_t, but we want to be specific about the
43-
// bit-width.
44-
uint32_t action_flag;
45-
struct jit_code_entry *relevant_entry;
46-
struct jit_code_entry *first_entry;
47-
};
48-
4926
// We put information about the JITed function in this global, which the
5027
// debugger reads. Make sure to specify the version statically, because the
5128
// debugger checks the version before we can set it during runtime.

llvm/tools/lli/ExecutionUtils.cpp

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,14 @@
88

99
#include "ExecutionUtils.h"
1010

11+
#include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h"
1112
#include "llvm/Support/FileSystem.h"
1213
#include "llvm/Support/FormatVariadic.h"
1314
#include "llvm/Support/raw_ostream.h"
1415

1516
#include <cstdint>
1617
#include <vector>
1718

18-
// Declarations follow the GDB JIT interface (version 1, 2009) and must match
19-
// those of the DYLD used for testing. See:
20-
//
21-
// llvm/lib/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.cpp
22-
// llvm/lib/ExecutionEngine/GDBRegistrationListener.cpp
23-
//
24-
typedef enum {
25-
JIT_NOACTION = 0,
26-
JIT_REGISTER_FN,
27-
JIT_UNREGISTER_FN
28-
} jit_actions_t;
29-
30-
struct jit_code_entry {
31-
struct jit_code_entry *next_entry;
32-
struct jit_code_entry *prev_entry;
33-
const char *symfile_addr;
34-
uint64_t symfile_size;
35-
};
36-
37-
struct jit_descriptor {
38-
uint32_t version;
39-
// This should be jit_actions_t, but we want to be specific about the
40-
// bit-width.
41-
uint32_t action_flag;
42-
struct jit_code_entry *relevant_entry;
43-
struct jit_code_entry *first_entry;
44-
};
45-
4619
namespace llvm {
4720

4821
template <typename... Ts> static void outsv(const char *Fmt, Ts &&...Vals) {
@@ -61,6 +34,9 @@ static const char *actionFlagToStr(uint32_t ActionFlag) {
6134
return "<invalid action_flag>";
6235
}
6336

37+
// Declarations follow the GDB JIT interface (version 1, 2009) and must match
38+
// those of the DYLD used for testing.
39+
//
6440
// Sample output:
6541
//
6642
// Reading __jit_debug_descriptor at 0x0000000000404048

llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -112,43 +112,16 @@ int openListener(std::string Host, std::string PortStr) {
112112
#endif // LLVM_ON_UNIX
113113
}
114114

115-
// This must be kept in sync with gdb/gdb/jit.h .
116-
extern "C" {
117-
118-
typedef enum {
119-
JIT_NOACTION = 0,
120-
JIT_REGISTER_FN,
121-
JIT_UNREGISTER_FN
122-
} jit_actions_t;
123-
124-
struct jit_code_entry {
125-
struct jit_code_entry *next_entry;
126-
struct jit_code_entry *prev_entry;
127-
const char *symfile_addr;
128-
uint64_t symfile_size;
129-
};
130-
131-
struct jit_descriptor {
132-
uint32_t version;
133-
// This should be jit_actions_t, but we want to be specific about the
134-
// bit-width.
135-
uint32_t action_flag;
136-
struct jit_code_entry *relevant_entry;
137-
struct jit_code_entry *first_entry;
138-
};
139-
140-
// We put information about the JITed function in this global, which the
141-
// debugger reads. Make sure to specify the version statically, because the
142-
// debugger checks the version before we can set it during runtime.
143-
extern struct jit_descriptor __jit_debug_descriptor;
115+
// JITLink debug support plugins put information about JITed code in this GDB
116+
// JIT Interface global from OrcTargetProcess.
117+
extern "C" struct jit_descriptor __jit_debug_descriptor;
144118

145119
static void *findLastDebugDescriptorEntryPtr() {
146120
struct jit_code_entry *Last = __jit_debug_descriptor.first_entry;
147121
while (Last && Last->next_entry)
148122
Last = Last->next_entry;
149123
return Last;
150124
}
151-
}
152125

153126
int main(int argc, char *argv[]) {
154127
#if LLVM_ENABLE_THREADS

llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -512,43 +512,16 @@ TEST_F(OrcCAPITestBase, AddObjectBuffer) {
512512
ASSERT_TRUE(!!SumAddr);
513513
}
514514

515-
// This must be kept in sync with gdb/gdb/jit.h .
516-
extern "C" {
517-
518-
typedef enum {
519-
JIT_NOACTION = 0,
520-
JIT_REGISTER_FN,
521-
JIT_UNREGISTER_FN
522-
} jit_actions_t;
523-
524-
struct jit_code_entry {
525-
struct jit_code_entry *next_entry;
526-
struct jit_code_entry *prev_entry;
527-
const char *symfile_addr;
528-
uint64_t symfile_size;
529-
};
530-
531-
struct jit_descriptor {
532-
uint32_t version;
533-
// This should be jit_actions_t, but we want to be specific about the
534-
// bit-width.
535-
uint32_t action_flag;
536-
struct jit_code_entry *relevant_entry;
537-
struct jit_code_entry *first_entry;
538-
};
539-
540-
// We put information about the JITed function in this global, which the
541-
// debugger reads. Make sure to specify the version statically, because the
542-
// debugger checks the version before we can set it during runtime.
543-
extern struct jit_descriptor __jit_debug_descriptor;
515+
// JITLink debug support plugins put information about JITed code in this GDB
516+
// JIT Interface global from OrcTargetProcess.
517+
extern "C" struct jit_descriptor __jit_debug_descriptor;
544518

545519
static void *findLastDebugDescriptorEntryPtr() {
546520
struct jit_code_entry *Last = __jit_debug_descriptor.first_entry;
547521
while (Last && Last->next_entry)
548522
Last = Last->next_entry;
549523
return Last;
550524
}
551-
}
552525

553526
#if defined(_AIX) or not(defined(__ELF__) or defined(__MACH__))
554527
TEST_F(OrcCAPITestBase, DISABLED_EnableDebugSupport) {

0 commit comments

Comments
 (0)