[llvm] [llvm-jitlink-executor] Drop else block after noreturn-if (NFC) (PR #76689)
Stefan Gränitz via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 1 10:35:05 PST 2024
https://github.com/weliveindetail created https://github.com/llvm/llvm-project/pull/76689
[llvm-jitlink-executor] Drop else block after noreturn-if (NFC)
Following up from https://github.com/llvm/llvm-project/pull/76236/files#r1435159528
>From 5f134a740bfab1421a5b2caa1853cf61d3879563 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= <stefan.graenitz at gmail.com>
Date: Fri, 22 Dec 2023 11:43:18 +0100
Subject: [PATCH 1/7] [Orc][examples] Drop manual TargetMachineBuilder setup
---
.../LLJITWithRemoteDebugging.cpp | 15 ---------------
1 file changed, 15 deletions(-)
diff --git a/llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/LLJITWithRemoteDebugging.cpp b/llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/LLJITWithRemoteDebugging.cpp
index 9001125060583f..3d626e0ed9ab77 100644
--- a/llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/LLJITWithRemoteDebugging.cpp
+++ b/llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/LLJITWithRemoteDebugging.cpp
@@ -174,25 +174,10 @@ int main(int argc, char *argv[]) {
TSMs.push_back(ExitOnErr(parseExampleModuleFromFile(Path)));
}
- std::string TT;
- StringRef MainModuleName;
- TSMs.front().withModuleDo([&MainModuleName, &TT](Module &M) {
- MainModuleName = M.getName();
- TT = M.getTargetTriple();
- if (TT.empty())
- TT = sys::getProcessTriple();
- });
-
- // Create a target machine that matches the input triple.
- JITTargetMachineBuilder JTMB((Triple(TT)));
- JTMB.setCodeModel(CodeModel::Small);
- JTMB.setRelocationModel(Reloc::PIC_);
-
// Create LLJIT and destroy it before disconnecting the target process.
outs() << "Initializing LLJIT for remote executor\n";
auto J = ExitOnErr(LLJITBuilder()
.setExecutorProcessControl(std::move(EPC))
- .setJITTargetMachineBuilder(std::move(JTMB))
.setObjectLinkingLayerCreator([&](auto &ES, const auto &TT) {
return std::make_unique<ObjectLinkingLayer>(ES);
})
>From 1477b90e8d7e5fb4790833dc6fbdfd3ba95cfcee Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= <stefan.graenitz at gmail.com>
Date: Fri, 22 Dec 2023 16:08:34 +0100
Subject: [PATCH 2/7] [Orc][examples] Drop addDebugSupport() in favor of Orc's
enableDebuggerSupport()
---
.../LLJITWithRemoteDebugging/CMakeLists.txt | 1 +
.../LLJITWithRemoteDebugging.cpp | 11 ++++-------
.../LLJITWithRemoteDebugging/RemoteJITUtils.cpp | 16 ----------------
.../LLJITWithRemoteDebugging/RemoteJITUtils.h | 2 --
4 files changed, 5 insertions(+), 25 deletions(-)
diff --git a/llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/CMakeLists.txt b/llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/CMakeLists.txt
index 576603c47f593e..51b3925f4a9e79 100644
--- a/llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/CMakeLists.txt
+++ b/llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/CMakeLists.txt
@@ -3,6 +3,7 @@ set(LLVM_LINK_COMPONENTS
ExecutionEngine
IRReader
JITLink
+ OrcDebugging
OrcJIT
OrcShared
OrcTargetProcess
diff --git a/llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/LLJITWithRemoteDebugging.cpp b/llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/LLJITWithRemoteDebugging.cpp
index 3d626e0ed9ab77..1f69415649e84e 100644
--- a/llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/LLJITWithRemoteDebugging.cpp
+++ b/llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/LLJITWithRemoteDebugging.cpp
@@ -77,6 +77,7 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/ExecutionEngine/Orc/Debugging/DebuggerSupport.h"
#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
@@ -176,15 +177,11 @@ int main(int argc, char *argv[]) {
// Create LLJIT and destroy it before disconnecting the target process.
outs() << "Initializing LLJIT for remote executor\n";
- auto J = ExitOnErr(LLJITBuilder()
- .setExecutorProcessControl(std::move(EPC))
- .setObjectLinkingLayerCreator([&](auto &ES, const auto &TT) {
- return std::make_unique<ObjectLinkingLayer>(ES);
- })
- .create());
+ auto J = ExitOnErr(
+ LLJITBuilder().setExecutorProcessControl(std::move(EPC)).create());
// Add plugin for debug support.
- ExitOnErr(addDebugSupport(J->getObjLinkingLayer()));
+ ExitOnErr(enableDebuggerSupport(*J));
// Load required shared libraries on the remote target and add a generator
// for each of it, so the compiler can lookup their symbols.
diff --git a/llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/RemoteJITUtils.cpp b/llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/RemoteJITUtils.cpp
index 49f5fcdbef8dfe..a5c06367d639b5 100644
--- a/llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/RemoteJITUtils.cpp
+++ b/llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/RemoteJITUtils.cpp
@@ -27,22 +27,6 @@
using namespace llvm;
using namespace llvm::orc;
-Error addDebugSupport(ObjectLayer &ObjLayer) {
- ExecutionSession &ES = ObjLayer.getExecutionSession();
- auto Registrar = createJITLoaderGDBRegistrar(ES);
- if (!Registrar)
- return Registrar.takeError();
-
- auto *ObjLinkingLayer = cast<ObjectLinkingLayer>(&ObjLayer);
- if (!ObjLinkingLayer)
- return createStringError(inconvertibleErrorCode(),
- "No debug support for given object layer type");
-
- ObjLinkingLayer->addPlugin(std::make_unique<DebugObjectManagerPlugin>(
- ES, std::move(*Registrar), true, true));
- return Error::success();
-}
-
Expected<std::unique_ptr<DefinitionGenerator>>
loadDylib(ExecutionSession &ES, StringRef RemotePath) {
if (auto Handle = ES.getExecutorProcessControl().loadDylib(RemotePath.data()))
diff --git a/llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/RemoteJITUtils.h b/llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/RemoteJITUtils.h
index e7cad9facdea6e..3663307109bdb7 100644
--- a/llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/RemoteJITUtils.h
+++ b/llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/RemoteJITUtils.h
@@ -36,8 +36,6 @@ launchLocalExecutor(llvm::StringRef ExecutablePath);
llvm::Expected<std::unique_ptr<llvm::orc::SimpleRemoteEPC>>
connectTCPSocket(llvm::StringRef NetworkAddress);
-llvm::Error addDebugSupport(llvm::orc::ObjectLayer &ObjLayer);
-
llvm::Expected<std::unique_ptr<llvm::orc::DefinitionGenerator>>
loadDylib(llvm::orc::ExecutionSession &ES, llvm::StringRef RemotePath);
>From 3462b5d7bf5529018903047ee5ceae124a82b364 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= <stefan.graenitz at gmail.com>
Date: Fri, 22 Dec 2023 14:36:02 +0100
Subject: [PATCH 3/7] [Orc][examples] Check that debug support plugins append
jit_code_entry
---
.../RemoteJITUtils.cpp | 9 ++-
.../lljit-with-remote-debugging.test | 12 +++-
.../llvm-jitlink-executor.cpp | 55 ++++++++++++++++++-
3 files changed, 70 insertions(+), 6 deletions(-)
diff --git a/llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/RemoteJITUtils.cpp b/llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/RemoteJITUtils.cpp
index a5c06367d639b5..b11d875c6f2d06 100644
--- a/llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/RemoteJITUtils.cpp
+++ b/llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/RemoteJITUtils.cpp
@@ -95,11 +95,15 @@ launchLocalExecutor(StringRef ExecutablePath) {
close(FromExecutor[ReadEnd]);
// Execute the child process.
- std::unique_ptr<char[]> ExecPath, FDSpecifier;
+ std::unique_ptr<char[]> ExecPath, FDSpecifier, TestOutputFlag;
{
ExecPath = std::make_unique<char[]>(ExecutablePath.size() + 1);
strcpy(ExecPath.get(), ExecutablePath.data());
+ const char *TestOutputFlagStr = "test-jitloadergdb";
+ TestOutputFlag = std::make_unique<char[]>(strlen(TestOutputFlagStr) + 1);
+ strcpy(TestOutputFlag.get(), TestOutputFlagStr);
+
std::string FDSpecifierStr("filedescs=");
FDSpecifierStr += utostr(ToExecutor[ReadEnd]);
FDSpecifierStr += ',';
@@ -108,7 +112,8 @@ launchLocalExecutor(StringRef ExecutablePath) {
strcpy(FDSpecifier.get(), FDSpecifierStr.c_str());
}
- char *const Args[] = {ExecPath.get(), FDSpecifier.get(), nullptr};
+ char *const Args[] = {ExecPath.get(), TestOutputFlag.get(),
+ FDSpecifier.get(), nullptr};
int RC = execvp(ExecPath.get(), Args);
if (RC != 0)
return make_error<StringError>(
diff --git a/llvm/test/Examples/OrcV2Examples/lljit-with-remote-debugging.test b/llvm/test/Examples/OrcV2Examples/lljit-with-remote-debugging.test
index b0b33503a1eece..ac12341c3ce646 100644
--- a/llvm/test/Examples/OrcV2Examples/lljit-with-remote-debugging.test
+++ b/llvm/test/Examples/OrcV2Examples/lljit-with-remote-debugging.test
@@ -1,15 +1,21 @@
-# This test makes sure that the example builds and executes as expected.
+# Check that the debug support plugin appends a jit_code_entry to the
+# jit_descriptor of the child process.
+
# Instructions for debugging can be found in LLJITWithRemoteDebugging.cpp
# REQUIRES: default_triple
# UNSUPPORTED: target=powerpc64{{.*}}
-# RUN: LLJITWithRemoteDebugging %p/Inputs/argc_sub1_elf.ll | FileCheck --check-prefix=CHECK0 %s
+# RUN: LLJITWithRemoteDebugging %p/Inputs/argc_sub1_elf.ll 2>&1 | FileCheck --check-prefix=CHECK0 %s
+# CHECK0: __jit_debug_descriptor.last_entry = [[BEFORE0:0x[0-9a-f]+]]
+# CHECK0-NOT: __jit_debug_descriptor.last_entry = [[BEFORE0]]
# CHECK0: Parsing input IR code from: {{.*}}/Inputs/argc_sub1_elf.ll
# CHECK0: Running: main()
# CHECK0: Exit code: 0
-# RUN: LLJITWithRemoteDebugging %p/Inputs/argc_sub1_elf.ll --args 2nd 3rd 4th | FileCheck --check-prefix=CHECK3 %s
+# RUN: LLJITWithRemoteDebugging %p/Inputs/argc_sub1_elf.ll --args 2nd 3rd 4th 2>&1 | FileCheck --check-prefix=CHECK3 %s
+# CHECK3: __jit_debug_descriptor.last_entry = [[BEFORE3:0x[0-9a-f]+]]
+# CHECK3-NOT: __jit_debug_descriptor.last_entry = [[BEFORE3]]
# CHECK3: Parsing input IR code from: {{.*}}/Inputs/argc_sub1_elf.ll
# CHECK3: Running: main("2nd", "3rd", "4th")
# CHECK3: Exit code: 3
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
index 71c83f2badb8ff..3a05c9b5be24dc 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
@@ -112,6 +112,44 @@ int openListener(std::string Host, std::string PortStr) {
#endif // LLVM_ON_UNIX
}
+// This must be kept in sync with gdb/gdb/jit.h .
+extern "C" {
+
+typedef enum {
+ JIT_NOACTION = 0,
+ JIT_REGISTER_FN,
+ JIT_UNREGISTER_FN
+} jit_actions_t;
+
+struct jit_code_entry {
+ struct jit_code_entry *next_entry;
+ struct jit_code_entry *prev_entry;
+ const char *symfile_addr;
+ uint64_t symfile_size;
+};
+
+struct jit_descriptor {
+ uint32_t version;
+ // This should be jit_actions_t, but we want to be specific about the
+ // bit-width.
+ uint32_t action_flag;
+ struct jit_code_entry *relevant_entry;
+ struct jit_code_entry *first_entry;
+};
+
+// We put information about the JITed function in this global, which the
+// debugger reads. Make sure to specify the version statically, because the
+// debugger checks the version before we can set it during runtime.
+extern struct jit_descriptor __jit_debug_descriptor;
+
+static void *findLastDebugDescriptorEntryPtr() {
+ struct jit_code_entry *Last = __jit_debug_descriptor.first_entry;
+ while (Last && Last->next_entry)
+ Last = Last->next_entry;
+ return Last;
+}
+}
+
int main(int argc, char *argv[]) {
#if LLVM_ENABLE_THREADS
@@ -121,10 +159,11 @@ int main(int argc, char *argv[]) {
int InFD = 0;
int OutFD = 0;
+ std::vector<StringRef> TestOutputFlags;
+
if (argc < 2)
printErrorAndExit("insufficient arguments");
else {
-
StringRef ConnectArg = argv[FirstProgramArg++];
#ifndef NDEBUG
if (ConnectArg == "debug") {
@@ -133,6 +172,11 @@ int main(int argc, char *argv[]) {
}
#endif
+ while (ConnectArg.starts_with("test-")) {
+ TestOutputFlags.push_back(ConnectArg);
+ ConnectArg = argv[FirstProgramArg++];
+ }
+
StringRef SpecifierType, Specifier;
std::tie(SpecifierType, Specifier) = ConnectArg.split('=');
if (SpecifierType == "filedescs") {
@@ -156,6 +200,10 @@ int main(int argc, char *argv[]) {
printErrorAndExit("invalid specifier type \"" + SpecifierType + "\"");
}
+ if (llvm::is_contained(TestOutputFlags, "test-jitloadergdb"))
+ fprintf(stderr, "__jit_debug_descriptor.last_entry = 0x%016" PRIx64 "\n",
+ pointerToJITTargetAddress(findLastDebugDescriptorEntryPtr()));
+
auto Server =
ExitOnErr(SimpleRemoteEPCServer::Create<FDSimpleRemoteEPCTransport>(
[](SimpleRemoteEPCServer::Setup &S) -> Error {
@@ -173,6 +221,11 @@ int main(int argc, char *argv[]) {
InFD, OutFD));
ExitOnErr(Server->waitForDisconnect());
+
+ if (llvm::is_contained(TestOutputFlags, "test-jitloadergdb"))
+ fprintf(stderr, "__jit_debug_descriptor.last_entry = 0x%016" PRIx64 "\n",
+ pointerToJITTargetAddress(findLastDebugDescriptorEntryPtr()));
+
return 0;
#else
>From 3451693e8fbfefab5f705d20ceba64aa698d943c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= <stefan.graenitz at gmail.com>
Date: Fri, 22 Dec 2023 15:58:35 +0100
Subject: [PATCH 4/7] [Orc][examples] Update and reduce sample input
---
.../OrcV2Examples/Inputs/argc_sub1.ll | 16 ++++++
.../OrcV2Examples/Inputs/argc_sub1_elf.ll | 51 -------------------
.../lljit-with-remote-debugging.test | 8 +--
3 files changed, 20 insertions(+), 55 deletions(-)
create mode 100644 llvm/test/Examples/OrcV2Examples/Inputs/argc_sub1.ll
delete mode 100644 llvm/test/Examples/OrcV2Examples/Inputs/argc_sub1_elf.ll
diff --git a/llvm/test/Examples/OrcV2Examples/Inputs/argc_sub1.ll b/llvm/test/Examples/OrcV2Examples/Inputs/argc_sub1.ll
new file mode 100644
index 00000000000000..97317710a60a17
--- /dev/null
+++ b/llvm/test/Examples/OrcV2Examples/Inputs/argc_sub1.ll
@@ -0,0 +1,16 @@
+define i32 @sub1(i32 %0) {
+ %2 = add i32 %0, -1
+ ret i32 %2
+}
+
+define i32 @main(i32 %0) {
+ %2 = call i32 @sub1(i32 %0)
+ ret i32 %2
+}
+
+!llvm.module.flags = !{!0}
+!llvm.dbg.cu = !{!1}
+
+!0 = !{i32 2, !"Debug Info Version", i32 3}
+!1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang 18.0.0git", emissionKind: FullDebug)
+!2 = !DIFile(filename: "argc_sub1.c", directory: ".")
diff --git a/llvm/test/Examples/OrcV2Examples/Inputs/argc_sub1_elf.ll b/llvm/test/Examples/OrcV2Examples/Inputs/argc_sub1_elf.ll
deleted file mode 100644
index 0cdc5e7de844db..00000000000000
--- a/llvm/test/Examples/OrcV2Examples/Inputs/argc_sub1_elf.ll
+++ /dev/null
@@ -1,51 +0,0 @@
-; ModuleID = 'argc_sub1.c'
-
-define i32 @sub1(i32) !dbg !8 {
- call void @llvm.dbg.value(metadata i32 %0, metadata !13, metadata !DIExpression()), !dbg !14
- %2 = add nsw i32 %0, -1, !dbg !15
- ret i32 %2, !dbg !16
-}
-
-define i32 @main(i32, i8** nocapture readnone) !dbg !17 {
- call void @llvm.dbg.value(metadata i32 %0, metadata !24, metadata !DIExpression()), !dbg !26
- call void @llvm.dbg.value(metadata i8** %1, metadata !25, metadata !DIExpression()), !dbg !27
- %3 = tail call i32 @sub1(i32 %0), !dbg !28
- ret i32 %3, !dbg !29
-}
-
-declare void @llvm.dbg.value(metadata, metadata, metadata)
-
-!llvm.dbg.cu = !{!0}
-!llvm.module.flags = !{!3, !4, !5, !6}
-!llvm.ident = !{!7}
-
-!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 7.0.1-8+deb10u2 (tags/RELEASE_701/final)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
-!1 = !DIFile(filename: "argc_sub1.c", directory: "Inputs/")
-!2 = !{}
-!3 = !{i32 2, !"Dwarf Version", i32 4}
-!4 = !{i32 2, !"Debug Info Version", i32 3}
-!5 = !{i32 1, !"wchar_size", i32 4}
-!6 = !{i32 7, !"PIC Level", i32 2}
-!7 = !{!"clang version 7.0.1-8+deb10u2 (tags/RELEASE_701/final)"}
-!8 = distinct !DISubprogram(name: "sub1", scope: !1, file: !1, line: 1, type: !9, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !12)
-!9 = !DISubroutineType(types: !10)
-!10 = !{!11, !11}
-!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
-!12 = !{!13}
-!13 = !DILocalVariable(name: "x", arg: 1, scope: !8, file: !1, line: 1, type: !11)
-!14 = !DILocation(line: 1, column: 14, scope: !8)
-!15 = !DILocation(line: 1, column: 28, scope: !8)
-!16 = !DILocation(line: 1, column: 19, scope: !8)
-!17 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 2, type: !18, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !23)
-!18 = !DISubroutineType(types: !19)
-!19 = !{!11, !11, !20}
-!20 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !21, size: 64)
-!21 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !22, size: 64)
-!22 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
-!23 = !{!24, !25}
-!24 = !DILocalVariable(name: "argc", arg: 1, scope: !17, file: !1, line: 2, type: !11)
-!25 = !DILocalVariable(name: "argv", arg: 2, scope: !17, file: !1, line: 2, type: !20)
-!26 = !DILocation(line: 2, column: 14, scope: !17)
-!27 = !DILocation(line: 2, column: 27, scope: !17)
-!28 = !DILocation(line: 2, column: 42, scope: !17)
-!29 = !DILocation(line: 2, column: 35, scope: !17)
diff --git a/llvm/test/Examples/OrcV2Examples/lljit-with-remote-debugging.test b/llvm/test/Examples/OrcV2Examples/lljit-with-remote-debugging.test
index ac12341c3ce646..83dbf6249cfa1a 100644
--- a/llvm/test/Examples/OrcV2Examples/lljit-with-remote-debugging.test
+++ b/llvm/test/Examples/OrcV2Examples/lljit-with-remote-debugging.test
@@ -6,16 +6,16 @@
# REQUIRES: default_triple
# UNSUPPORTED: target=powerpc64{{.*}}
-# RUN: LLJITWithRemoteDebugging %p/Inputs/argc_sub1_elf.ll 2>&1 | FileCheck --check-prefix=CHECK0 %s
+# RUN: LLJITWithRemoteDebugging %p/Inputs/argc_sub1.ll 2>&1 | FileCheck --check-prefix=CHECK0 %s
# CHECK0: __jit_debug_descriptor.last_entry = [[BEFORE0:0x[0-9a-f]+]]
# CHECK0-NOT: __jit_debug_descriptor.last_entry = [[BEFORE0]]
-# CHECK0: Parsing input IR code from: {{.*}}/Inputs/argc_sub1_elf.ll
+# CHECK0: Parsing input IR code from: {{.*}}/Inputs/argc_sub1.ll
# CHECK0: Running: main()
# CHECK0: Exit code: 0
-# RUN: LLJITWithRemoteDebugging %p/Inputs/argc_sub1_elf.ll --args 2nd 3rd 4th 2>&1 | FileCheck --check-prefix=CHECK3 %s
+# RUN: LLJITWithRemoteDebugging %p/Inputs/argc_sub1.ll --args 2nd 3rd 4th 2>&1 | FileCheck --check-prefix=CHECK3 %s
# CHECK3: __jit_debug_descriptor.last_entry = [[BEFORE3:0x[0-9a-f]+]]
# CHECK3-NOT: __jit_debug_descriptor.last_entry = [[BEFORE3]]
-# CHECK3: Parsing input IR code from: {{.*}}/Inputs/argc_sub1_elf.ll
+# CHECK3: Parsing input IR code from: {{.*}}/Inputs/argc_sub1.ll
# CHECK3: Running: main("2nd", "3rd", "4th")
# CHECK3: Exit code: 3
>From ecd54d3e073713b3dc4b655dbfac15ce193877e2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= <stefan.graenitz at gmail.com>
Date: Mon, 25 Dec 2023 22:12:50 +0100
Subject: [PATCH 5/7] [Orc] Deduplicate GDB JIT Interface declarations (NFC)
---
.../Orc/TargetProcess/JITLoaderGDB.h | 26 +++++++++++++++
.../Orc/TargetProcess/JITLoaderGDB.cpp | 23 -------------
llvm/tools/lli/ExecutionUtils.cpp | 32 +++---------------
.../llvm-jitlink-executor.cpp | 33 ++-----------------
.../ExecutionEngine/Orc/OrcCAPITest.cpp | 33 ++-----------------
5 files changed, 36 insertions(+), 111 deletions(-)
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h
index 99175d79697475..9f91a64e95ce99 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h
@@ -16,6 +16,32 @@
#include "llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h"
#include <cstdint>
+// Keep in sync with gdb/gdb/jit.h
+extern "C" {
+
+typedef enum {
+ JIT_NOACTION = 0,
+ JIT_REGISTER_FN,
+ JIT_UNREGISTER_FN
+} jit_actions_t;
+
+struct jit_code_entry {
+ struct jit_code_entry *next_entry;
+ struct jit_code_entry *prev_entry;
+ const char *symfile_addr;
+ uint64_t symfile_size;
+};
+
+struct jit_descriptor {
+ uint32_t version;
+ // This should be jit_actions_t, but we want to be specific about the
+ // bit-width.
+ uint32_t action_flag;
+ struct jit_code_entry *relevant_entry;
+ struct jit_code_entry *first_entry;
+};
+}
+
extern "C" llvm::orc::shared::CWrapperFunctionResult
llvm_orc_registerJITLoaderGDBWrapper(const char *Data, uint64_t Size);
diff --git a/llvm/lib/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.cpp b/llvm/lib/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.cpp
index 8eca874c48b870..8a4145a6b02a26 100644
--- a/llvm/lib/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.cpp
@@ -21,31 +21,8 @@
// First version as landed in August 2009
static constexpr uint32_t JitDescriptorVersion = 1;
-// Keep in sync with gdb/gdb/jit.h
extern "C" {
-typedef enum {
- JIT_NOACTION = 0,
- JIT_REGISTER_FN,
- JIT_UNREGISTER_FN
-} jit_actions_t;
-
-struct jit_code_entry {
- struct jit_code_entry *next_entry;
- struct jit_code_entry *prev_entry;
- const char *symfile_addr;
- uint64_t symfile_size;
-};
-
-struct jit_descriptor {
- uint32_t version;
- // This should be jit_actions_t, but we want to be specific about the
- // bit-width.
- uint32_t action_flag;
- struct jit_code_entry *relevant_entry;
- struct jit_code_entry *first_entry;
-};
-
// We put information about the JITed function in this global, which the
// debugger reads. Make sure to specify the version statically, because the
// debugger checks the version before we can set it during runtime.
diff --git a/llvm/tools/lli/ExecutionUtils.cpp b/llvm/tools/lli/ExecutionUtils.cpp
index 55370ed40f2b6f..b6cc3bb174d3c3 100644
--- a/llvm/tools/lli/ExecutionUtils.cpp
+++ b/llvm/tools/lli/ExecutionUtils.cpp
@@ -8,6 +8,7 @@
#include "ExecutionUtils.h"
+#include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/raw_ostream.h"
@@ -15,34 +16,6 @@
#include <cstdint>
#include <vector>
-// Declarations follow the GDB JIT interface (version 1, 2009) and must match
-// those of the DYLD used for testing. See:
-//
-// llvm/lib/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.cpp
-// llvm/lib/ExecutionEngine/GDBRegistrationListener.cpp
-//
-typedef enum {
- JIT_NOACTION = 0,
- JIT_REGISTER_FN,
- JIT_UNREGISTER_FN
-} jit_actions_t;
-
-struct jit_code_entry {
- struct jit_code_entry *next_entry;
- struct jit_code_entry *prev_entry;
- const char *symfile_addr;
- uint64_t symfile_size;
-};
-
-struct jit_descriptor {
- uint32_t version;
- // This should be jit_actions_t, but we want to be specific about the
- // bit-width.
- uint32_t action_flag;
- struct jit_code_entry *relevant_entry;
- struct jit_code_entry *first_entry;
-};
-
namespace llvm {
template <typename... Ts> static void outsv(const char *Fmt, Ts &&...Vals) {
@@ -61,6 +34,9 @@ static const char *actionFlagToStr(uint32_t ActionFlag) {
return "<invalid action_flag>";
}
+// Declarations follow the GDB JIT interface (version 1, 2009) and must match
+// those of the DYLD used for testing.
+//
// Sample output:
//
// Reading __jit_debug_descriptor at 0x0000000000404048
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
index 3a05c9b5be24dc..034c43f9352a58 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
@@ -112,35 +112,9 @@ int openListener(std::string Host, std::string PortStr) {
#endif // LLVM_ON_UNIX
}
-// This must be kept in sync with gdb/gdb/jit.h .
-extern "C" {
-
-typedef enum {
- JIT_NOACTION = 0,
- JIT_REGISTER_FN,
- JIT_UNREGISTER_FN
-} jit_actions_t;
-
-struct jit_code_entry {
- struct jit_code_entry *next_entry;
- struct jit_code_entry *prev_entry;
- const char *symfile_addr;
- uint64_t symfile_size;
-};
-
-struct jit_descriptor {
- uint32_t version;
- // This should be jit_actions_t, but we want to be specific about the
- // bit-width.
- uint32_t action_flag;
- struct jit_code_entry *relevant_entry;
- struct jit_code_entry *first_entry;
-};
-
-// We put information about the JITed function in this global, which the
-// debugger reads. Make sure to specify the version statically, because the
-// debugger checks the version before we can set it during runtime.
-extern struct jit_descriptor __jit_debug_descriptor;
+// JITLink debug support plugins put information about JITed code in this GDB
+// JIT Interface global from OrcTargetProcess.
+extern "C" struct jit_descriptor __jit_debug_descriptor;
static void *findLastDebugDescriptorEntryPtr() {
struct jit_code_entry *Last = __jit_debug_descriptor.first_entry;
@@ -148,7 +122,6 @@ static void *findLastDebugDescriptorEntryPtr() {
Last = Last->next_entry;
return Last;
}
-}
int main(int argc, char *argv[]) {
#if LLVM_ENABLE_THREADS
diff --git a/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp b/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp
index d62973f30add90..5bc21b1971365f 100644
--- a/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp
@@ -512,35 +512,9 @@ TEST_F(OrcCAPITestBase, AddObjectBuffer) {
ASSERT_TRUE(!!SumAddr);
}
-// This must be kept in sync with gdb/gdb/jit.h .
-extern "C" {
-
-typedef enum {
- JIT_NOACTION = 0,
- JIT_REGISTER_FN,
- JIT_UNREGISTER_FN
-} jit_actions_t;
-
-struct jit_code_entry {
- struct jit_code_entry *next_entry;
- struct jit_code_entry *prev_entry;
- const char *symfile_addr;
- uint64_t symfile_size;
-};
-
-struct jit_descriptor {
- uint32_t version;
- // This should be jit_actions_t, but we want to be specific about the
- // bit-width.
- uint32_t action_flag;
- struct jit_code_entry *relevant_entry;
- struct jit_code_entry *first_entry;
-};
-
-// We put information about the JITed function in this global, which the
-// debugger reads. Make sure to specify the version statically, because the
-// debugger checks the version before we can set it during runtime.
-extern struct jit_descriptor __jit_debug_descriptor;
+// JITLink debug support plugins put information about JITed code in this GDB
+// JIT Interface global from OrcTargetProcess.
+extern "C" struct jit_descriptor __jit_debug_descriptor;
static void *findLastDebugDescriptorEntryPtr() {
struct jit_code_entry *Last = __jit_debug_descriptor.first_entry;
@@ -548,7 +522,6 @@ static void *findLastDebugDescriptorEntryPtr() {
Last = Last->next_entry;
return Last;
}
-}
#if defined(_AIX) or not(defined(__ELF__) or defined(__MACH__))
TEST_F(OrcCAPITestBase, DISABLED_EnableDebugSupport) {
>From 7161b40c26a20207317af95ced91ee87cd7b8d0b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= <stefan.graenitz at gmail.com>
Date: Mon, 1 Jan 2024 19:25:59 +0100
Subject: [PATCH 6/7] [llvm-jitlink-executor] Drop else block after noreturn-if
(NFC)
---
.../llvm-jitlink-executor.cpp | 65 +++++++++----------
1 file changed, 31 insertions(+), 34 deletions(-)
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
index 034c43f9352a58..69f34167fcf8ce 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
@@ -132,51 +132,48 @@ int main(int argc, char *argv[]) {
int InFD = 0;
int OutFD = 0;
- std::vector<StringRef> TestOutputFlags;
-
if (argc < 2)
printErrorAndExit("insufficient arguments");
- else {
- StringRef ConnectArg = argv[FirstProgramArg++];
+
+ StringRef NextArg = argv[FirstProgramArg++];
#ifndef NDEBUG
- if (ConnectArg == "debug") {
- DebugFlag = true;
- ConnectArg = argv[FirstProgramArg++];
- }
+ if (NextArg == "debug") {
+ DebugFlag = true;
+ NextArg = argv[FirstProgramArg++];
+ }
#endif
- while (ConnectArg.starts_with("test-")) {
- TestOutputFlags.push_back(ConnectArg);
- ConnectArg = argv[FirstProgramArg++];
- }
-
- StringRef SpecifierType, Specifier;
- std::tie(SpecifierType, Specifier) = ConnectArg.split('=');
- if (SpecifierType == "filedescs") {
- StringRef FD1Str, FD2Str;
- std::tie(FD1Str, FD2Str) = Specifier.split(',');
- if (FD1Str.getAsInteger(10, InFD))
- printErrorAndExit(FD1Str + " is not a valid file descriptor");
- if (FD2Str.getAsInteger(10, OutFD))
- printErrorAndExit(FD2Str + " is not a valid file descriptor");
- } else if (SpecifierType == "listen") {
- StringRef Host, PortStr;
- std::tie(Host, PortStr) = Specifier.split(':');
-
- int Port = 0;
- if (PortStr.getAsInteger(10, Port))
- printErrorAndExit("port number '" + PortStr +
- "' is not a valid integer");
-
- InFD = OutFD = openListener(Host.str(), PortStr.str());
- } else
- printErrorAndExit("invalid specifier type \"" + SpecifierType + "\"");
+ std::vector<StringRef> TestOutputFlags;
+ while (NextArg.starts_with("test-")) {
+ TestOutputFlags.push_back(NextArg);
+ NextArg = argv[FirstProgramArg++];
}
if (llvm::is_contained(TestOutputFlags, "test-jitloadergdb"))
fprintf(stderr, "__jit_debug_descriptor.last_entry = 0x%016" PRIx64 "\n",
pointerToJITTargetAddress(findLastDebugDescriptorEntryPtr()));
+ StringRef SpecifierType, Specifier;
+ std::tie(SpecifierType, Specifier) = NextArg.split('=');
+ if (SpecifierType == "filedescs") {
+ StringRef FD1Str, FD2Str;
+ std::tie(FD1Str, FD2Str) = Specifier.split(',');
+ if (FD1Str.getAsInteger(10, InFD))
+ printErrorAndExit(FD1Str + " is not a valid file descriptor");
+ if (FD2Str.getAsInteger(10, OutFD))
+ printErrorAndExit(FD2Str + " is not a valid file descriptor");
+ } else if (SpecifierType == "listen") {
+ StringRef Host, PortStr;
+ std::tie(Host, PortStr) = Specifier.split(':');
+
+ int Port = 0;
+ if (PortStr.getAsInteger(10, Port))
+ printErrorAndExit("port number '" + PortStr + "' is not a valid integer");
+
+ InFD = OutFD = openListener(Host.str(), PortStr.str());
+ } else
+ printErrorAndExit("invalid specifier type \"" + SpecifierType + "\"");
+
auto Server =
ExitOnErr(SimpleRemoteEPCServer::Create<FDSimpleRemoteEPCTransport>(
[](SimpleRemoteEPCServer::Setup &S) -> Error {
>From 68daa456f01124d7e106cfc939ea3d2018e864c8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= <stefan.graenitz at gmail.com>
Date: Mon, 1 Jan 2024 19:32:49 +0100
Subject: [PATCH 7/7] [llvm-jitlink-executor] Add test-jitloadergdb option in
help output
---
.../llvm-jitlink-executor/llvm-jitlink-executor.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
index 69f34167fcf8ce..20205eed82aa79 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
@@ -54,9 +54,9 @@ void printErrorAndExit(Twine ErrMsg) {
errs() << "error: " << ErrMsg.str() << "\n\n"
<< "Usage:\n"
<< " llvm-jitlink-executor " << DebugOption
- << "filedescs=<infd>,<outfd> [args...]\n"
+ << "[test-jitloadergdb] filedescs=<infd>,<outfd> [args...]\n"
<< " llvm-jitlink-executor " << DebugOption
- << "listen=<host>:<port> [args...]\n";
+ << "[test-jitloadergdb] listen=<host>:<port> [args...]\n";
exit(1);
}
More information about the llvm-commits
mailing list