[llvm] cd6ed95 - Reland "[lli] Revisit Orc debug output tests (#79055)"
Stefan Gränitz via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 22 13:47:38 PST 2024
Author: Stefan Gränitz
Date: 2024-01-22T22:46:27+01:00
New Revision: cd6ed95e48354d14e59871f3c3f3a8665def22c8
URL: https://github.com/llvm/llvm-project/commit/cd6ed95e48354d14e59871f3c3f3a8665def22c8
DIFF: https://github.com/llvm/llvm-project/commit/cd6ed95e48354d14e59871f3c3f3a8665def22c8.diff
LOG: Reland "[lli] Revisit Orc debug output tests (#79055)"
Integrate in-memory debug-info dumps into the `--orc-lazy-debug`
command-line option instead of exposing built-in functions to be called
from JITed code. This reduces overall amount of code (removing
`ExecutionUtils.cpp`) and seems cleaner anyway.
All existing items of `OrcDumpKind` work on IR level and run in the
IR-transform step of the JIT. The newly added `DumpDebugDescriptor` and
`DumpDebugObjects` must run after debug-registration and thus are
deferred to the Object-transform step of the JIT. This separation is the
major side-effect of the patch.
The original commit 263efb044add93b9 was reverted in #79055, because
the gcc 7.5 bot had found a missing std::move().
Added:
llvm/test/ExecutionEngine/OrcLazy/debug-descriptor.ll
llvm/test/ExecutionEngine/OrcLazy/debug-objects.ll
Modified:
llvm/tools/lli/CMakeLists.txt
llvm/tools/lli/lli.cpp
Removed:
llvm/test/ExecutionEngine/OrcLazy/debug-descriptor-elf-minimal.ll
llvm/test/ExecutionEngine/OrcLazy/debug-objects-elf-minimal.ll
llvm/tools/lli/ExecutionUtils.cpp
llvm/tools/lli/ExecutionUtils.h
################################################################################
diff --git a/llvm/test/ExecutionEngine/OrcLazy/debug-descriptor-elf-minimal.ll b/llvm/test/ExecutionEngine/OrcLazy/debug-descriptor.ll
similarity index 53%
rename from llvm/test/ExecutionEngine/OrcLazy/debug-descriptor-elf-minimal.ll
rename to llvm/test/ExecutionEngine/OrcLazy/debug-descriptor.ll
index 9bac3897864f723..bf7f13fb5439f72 100644
--- a/llvm/test/ExecutionEngine/OrcLazy/debug-descriptor-elf-minimal.ll
+++ b/llvm/test/ExecutionEngine/OrcLazy/debug-descriptor.ll
@@ -1,29 +1,17 @@
-; REQUIRES: native && x86_64-linux
+; REQUIRES: native && target-x86_64
-; RUN: lli --jit-linker=rtdyld \
-; RUN: --generate=__dump_jit_debug_descriptor %s | FileCheck %s
+; RUN: lli --jit-linker=rtdyld --orc-lazy-debug=jit-debug-descriptor %s 2>&1 | FileCheck %s
+; RUN: lli --jit-linker=jitlink --orc-lazy-debug=jit-debug-descriptor %s 2>&1 | FileCheck %s
;
-; RUN: lli --jit-linker=jitlink \
-; RUN: --generate=__dump_jit_debug_descriptor %s | FileCheck %s
+; Initial entry should be empty:
+; CHECK: jit_debug_descriptor 0x0000000000000000
;
-; CHECK: Reading __jit_debug_descriptor at 0x{{.*}}
-; CHECK: Version: 1
-; CHECK: Action: JIT_REGISTER_FN
-; CHECK: Entry Symbol File Size Previous Entry
-; CHECK: [ 0] 0x{{.*}} 0x{{.*}} {{.*}} 0x0000000000000000
-
-target triple = "x86_64-unknown-unknown-elf"
-
-; Built-in symbol provided by the JIT
-declare void @__dump_jit_debug_descriptor(ptr)
-
-; Host-process symbol from the GDB JIT interface
- at __jit_debug_descriptor = external global i8, align 1
+; After adding the module it must not be empty anymore:
+; CHECK: jit_debug_descriptor 0x
+; CHECK-NOT: 000000000000000
+; CHECK-SAME: {{[048c]}}
define i32 @main() !dbg !9 {
- %1 = alloca i32, align 4
- store i32 0, ptr %1, align 4
- call void @__dump_jit_debug_descriptor(ptr @__jit_debug_descriptor), !dbg !13
ret i32 0, !dbg !14
}
diff --git a/llvm/test/ExecutionEngine/OrcLazy/debug-objects-elf-minimal.ll b/llvm/test/ExecutionEngine/OrcLazy/debug-objects-elf-minimal.ll
deleted file mode 100644
index 31fe730b740366a..000000000000000
--- a/llvm/test/ExecutionEngine/OrcLazy/debug-objects-elf-minimal.ll
+++ /dev/null
@@ -1,82 +0,0 @@
-; REQUIRES: native && x86_64-linux
-
-; In-memory debug-object contains some basic DWARF
-;
-; RUN: lli --jit-linker=rtdyld \
-; RUN: --generate=__dump_jit_debug_objects %s | llvm-dwarfdump --
diff - | FileCheck %s
-;
-; RUN: lli --jit-linker=jitlink \
-; RUN: --generate=__dump_jit_debug_objects %s | llvm-dwarfdump --
diff - | FileCheck %s
-;
-; CHECK: -: file format elf64-x86-64
-; CHECK: .debug_info contents:
-; CHECK: 0x00000000: Compile Unit: length = 0x00000047, format = DWARF32, version = 0x0004, abbr_offset = 0x0000, addr_size = 0x08 (next unit at 0x0000004b)
-; CHECK: DW_TAG_compile_unit
-; CHECK: DW_AT_producer ("compiler version")
-; CHECK: DW_AT_language (DW_LANG_C99)
-; CHECK: DW_AT_name ("source-file.c")
-; CHECK: DW_AT_stmt_list ()
-; CHECK: DW_AT_comp_dir ("/workspace")
-; CHECK: DW_AT_low_pc ()
-; CHECK: DW_AT_high_pc ()
-; CHECK: DW_TAG_subprogram
-; CHECK: DW_AT_low_pc ()
-; CHECK: DW_AT_high_pc ()
-; CHECK: DW_AT_frame_base (DW_OP_reg7 RSP)
-; CHECK: DW_AT_name ("main")
-; CHECK: DW_AT_decl_file ("/workspace/source-file.c")
-; CHECK: DW_AT_decl_line (4)
-; CHECK: DW_AT_type ("int")
-; CHECK: DW_AT_external (true)
-; CHECK: DW_TAG_base_type
-; CHECK: DW_AT_name ("int")
-; CHECK: DW_AT_encoding (DW_ATE_signed)
-; CHECK: DW_AT_byte_size (0x04)
-; CHECK: NULL
-
-; Text section of the in-memory debug-object has a non-null load-address
-;
-; RUN: lli --jit-linker=rtdyld \
-; RUN: --generate=__dump_jit_debug_objects %s | llvm-objdump --section-headers - | \
-; RUN: FileCheck --check-prefix=CHECK_LOAD_ADDR %s
-;
-; RUN: lli --jit-linker=jitlink \
-; RUN: --generate=__dump_jit_debug_objects %s | llvm-objdump --section-headers - | \
-; RUN: FileCheck --check-prefix=CHECK_LOAD_ADDR %s
-;
-; CHECK_LOAD_ADDR-NOT: {{[0-9]*}} .ltext {{.*}} 0000000000000000 TEXT
-
-target triple = "x86_64-unknown-unknown-elf"
-
-; Built-in symbol provided by the JIT
-declare void @__dump_jit_debug_objects(ptr)
-
-; Host-process symbol from the GDB JIT interface
- at __jit_debug_descriptor = external global i8, align 1
-
-define i32 @main() !dbg !9 {
- %1 = alloca i32, align 4
- store i32 0, ptr %1, align 4
- call void @__dump_jit_debug_objects(ptr @__jit_debug_descriptor), !dbg !13
- ret i32 0, !dbg !14
-}
-
-!llvm.module.flags = !{!0, !1, !2, !3, !4}
-!llvm.dbg.cu = !{!5}
-!llvm.ident = !{!8}
-
-!0 = !{i32 2, !"SDK Version", [3 x i32] [i32 10, i32 15, i32 6]}
-!1 = !{i32 7, !"Dwarf Version", i32 4}
-!2 = !{i32 2, !"Debug Info Version", i32 3}
-!3 = !{i32 1, !"wchar_size", i32 4}
-!4 = !{i32 7, !"PIC Level", i32 2}
-!5 = distinct !DICompileUnit(language: DW_LANG_C99, file: !6, producer: "compiler version", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !7, nameTableKind: None)
-!6 = !DIFile(filename: "source-file.c", directory: "/workspace")
-!7 = !{}
-!8 = !{!"compiler version"}
-!9 = distinct !DISubprogram(name: "main", scope: !6, file: !6, line: 4, type: !10, scopeLine: 4, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !7)
-!10 = !DISubroutineType(types: !11)
-!11 = !{!12}
-!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
-!13 = !DILocation(line: 5, column: 3, scope: !9)
-!14 = !DILocation(line: 6, column: 3, scope: !9)
diff --git a/llvm/test/ExecutionEngine/OrcLazy/debug-objects.ll b/llvm/test/ExecutionEngine/OrcLazy/debug-objects.ll
new file mode 100644
index 000000000000000..1f48bd9a2318ad3
--- /dev/null
+++ b/llvm/test/ExecutionEngine/OrcLazy/debug-objects.ll
@@ -0,0 +1,62 @@
+; REQUIRES: native && x86_64-linux
+
+; In-memory debug-objects contain DWARF
+;
+; RUN: lli --jit-linker=rtdyld --orc-lazy-debug=jit-debug-objects %s | llvm-dwarfdump --
diff - | FileCheck %s
+; RUN: lli --jit-linker=jitlink --orc-lazy-debug=jit-debug-objects %s | llvm-dwarfdump --
diff - | FileCheck %s
+;
+; CHECK: -: file format elf64-x86-64
+; TODO: Synthesized Mach-O objects error out with:
+; truncated or malformed object (offset field of section 8 in
+; LC_SEGMENT_64 command 0 extends past the end of the file)
+;
+; CHECK: .debug_info contents:
+; CHECK: format = DWARF32
+; CHECK: DW_TAG_compile_unit
+; CHECK: DW_AT_producer ("clang version 18.0.0git")
+; CHECK: DW_AT_language (DW_LANG_C11)
+; CHECK: DW_AT_name ("source-file.c")
+; CHECK: DW_AT_comp_dir ("/workspace")
+; CHECK: DW_TAG_subprogram
+; CHECK: DW_AT_frame_base (DW_OP_reg7 RSP)
+; CHECK: DW_AT_name ("main")
+; CHECK: DW_AT_decl_file ("/workspace/source-file.c")
+; CHECK: DW_AT_decl_line (1)
+; CHECK: DW_AT_type ("int")
+; CHECK: DW_AT_external (true)
+; CHECK: DW_TAG_base_type
+; CHECK: DW_AT_name ("int")
+; CHECK: DW_AT_encoding (DW_ATE_signed)
+; CHECK: DW_AT_byte_size (0x04)
+; CHECK: NULL
+
+; Text section of the in-memory debug-objects have non-null load-address
+;
+; RUN: lli --jit-linker=rtdyld --orc-lazy-debug=jit-debug-objects %s | \
+; RUN: llvm-objdump --section-headers - | \
+; RUN: FileCheck --check-prefix=CHECK_LOAD_ADDR %s
+; RUN: lli --jit-linker=jitlink --orc-lazy-debug=jit-debug-objects %s | \
+; RUN: llvm-objdump --section-headers - | \
+; RUN: FileCheck --check-prefix=CHECK_LOAD_ADDR %s
+;
+; CHECK_LOAD_ADDR: .text
+; CHECK_LOAD_ADDR-NOT: 0000000000000000
+; CHECK_LOAD_ADDR-SAME: TEXT
+
+define i32 @main() !dbg !3 {
+entry:
+ ret i32 0, !dbg !8
+}
+
+!llvm.module.flags = !{!0}
+!llvm.dbg.cu = !{!2}
+
+!0 = !{i32 2, !"Debug Info Version", i32 3}
+!1 = !DIFile(filename: "source-file.c", directory: "/workspace")
+!2 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 18.0.0git", emissionKind: FullDebug)
+!3 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 1, type: !4, scopeLine: 1, unit: !2, retainedNodes: !7)
+!4 = !DISubroutineType(types: !5)
+!5 = !{!6}
+!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!7 = !{}
+!8 = !DILocation(line: 1, column: 14, scope: !3)
diff --git a/llvm/tools/lli/CMakeLists.txt b/llvm/tools/lli/CMakeLists.txt
index 315de28e12b57cc..e3fca225a22754b 100644
--- a/llvm/tools/lli/CMakeLists.txt
+++ b/llvm/tools/lli/CMakeLists.txt
@@ -53,7 +53,6 @@ endif( LLVM_USE_PERF )
add_llvm_tool(lli
lli.cpp
- ExecutionUtils.cpp
DEPENDS
intrinsics_gen
diff --git a/llvm/tools/lli/ExecutionUtils.cpp b/llvm/tools/lli/ExecutionUtils.cpp
deleted file mode 100644
index b6cc3bb174d3c30..000000000000000
--- a/llvm/tools/lli/ExecutionUtils.cpp
+++ /dev/null
@@ -1,122 +0,0 @@
-//===---- ExecutionUtils.cpp - Utilities for executing functions in lli ---===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#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"
-
-#include <cstdint>
-#include <vector>
-
-namespace llvm {
-
-template <typename... Ts> static void outsv(const char *Fmt, Ts &&...Vals) {
- outs() << formatv(Fmt, Vals...);
-}
-
-static const char *actionFlagToStr(uint32_t ActionFlag) {
- switch (ActionFlag) {
- case JIT_NOACTION:
- return "JIT_NOACTION";
- case JIT_REGISTER_FN:
- return "JIT_REGISTER_FN";
- case JIT_UNREGISTER_FN:
- return "JIT_UNREGISTER_FN";
- }
- 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
-//
-// Version: 0
-// Action: JIT_REGISTER_FN
-//
-// Entry Symbol File Size Previous Entry
-// [ 0] 0x0000000000451290 0x0000000000002000 200 0x0000000000000000
-// [ 1] 0x0000000000451260 0x0000000000001000 100 0x0000000000451290
-// ...
-//
-static void dumpDebugDescriptor(void *Addr) {
- outsv("Reading __jit_debug_descriptor at {0}\n\n", Addr);
-
- jit_descriptor *Descriptor = reinterpret_cast<jit_descriptor *>(Addr);
- outsv("Version: {0}\n", Descriptor->version);
- outsv("Action: {0}\n\n", actionFlagToStr(Descriptor->action_flag));
- outsv("{0,11} {1,24} {2,15} {3,14}\n", "Entry", "Symbol File", "Size",
- "Previous Entry");
-
- unsigned Idx = 0;
- for (auto *Entry = Descriptor->first_entry; Entry; Entry = Entry->next_entry)
- outsv("[{0,2}] {1:X16} {2:X16} {3,8:D} {4}\n", Idx++, Entry,
- reinterpret_cast<const void *>(Entry->symfile_addr),
- Entry->symfile_size, Entry->prev_entry);
-}
-
-static LLIBuiltinFunctionGenerator *Generator = nullptr;
-
-static void dumpDebugObjects(void *Addr) {
- jit_descriptor *Descriptor = reinterpret_cast<jit_descriptor *>(Addr);
- for (auto *Entry = Descriptor->first_entry; Entry; Entry = Entry->next_entry)
- Generator->appendDebugObject(Entry->symfile_addr, Entry->symfile_size);
-}
-
-LLIBuiltinFunctionGenerator::LLIBuiltinFunctionGenerator(
- std::vector<BuiltinFunctionKind> Enabled, orc::MangleAndInterner &Mangle)
- : TestOut(nullptr) {
- Generator = this;
- for (BuiltinFunctionKind F : Enabled) {
- switch (F) {
- case BuiltinFunctionKind::DumpDebugDescriptor:
- expose(Mangle("__dump_jit_debug_descriptor"), &dumpDebugDescriptor);
- break;
- case BuiltinFunctionKind::DumpDebugObjects:
- expose(Mangle("__dump_jit_debug_objects"), &dumpDebugObjects);
- TestOut = createToolOutput();
- break;
- }
- }
-}
-
-Error LLIBuiltinFunctionGenerator::tryToGenerate(
- orc::LookupState &LS, orc::LookupKind K, orc::JITDylib &JD,
- orc::JITDylibLookupFlags JDLookupFlags,
- const orc::SymbolLookupSet &Symbols) {
- orc::SymbolMap NewSymbols;
- for (const auto &NameFlags : Symbols) {
- auto It = BuiltinFunctions.find(NameFlags.first);
- if (It != BuiltinFunctions.end())
- NewSymbols.insert(*It);
- }
-
- if (NewSymbols.empty())
- return Error::success();
-
- return JD.define(absoluteSymbols(std::move(NewSymbols)));
-}
-
-// static
-std::unique_ptr<ToolOutputFile>
-LLIBuiltinFunctionGenerator::createToolOutput() {
- std::error_code EC;
- auto TestOut = std::make_unique<ToolOutputFile>("-", EC, sys::fs::OF_None);
- if (EC) {
- errs() << "Error creating tool output file: " << EC.message() << '\n';
- exit(1);
- }
- return TestOut;
-}
-
-} // namespace llvm
diff --git a/llvm/tools/lli/ExecutionUtils.h b/llvm/tools/lli/ExecutionUtils.h
deleted file mode 100644
index 6bf9cd58e031b80..000000000000000
--- a/llvm/tools/lli/ExecutionUtils.h
+++ /dev/null
@@ -1,60 +0,0 @@
-//===- ExecutionUtils.h - Utilities for executing code in lli ---*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Contains utilities for executing code in lli.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_TOOLS_LLI_EXECUTIONUTILS_H
-#define LLVM_TOOLS_LLI_EXECUTIONUTILS_H
-
-#include "llvm/ExecutionEngine/JITSymbol.h"
-#include "llvm/ExecutionEngine/Orc/Core.h"
-#include "llvm/ExecutionEngine/Orc/Mangling.h"
-#include "llvm/Support/Error.h"
-#include "llvm/Support/ToolOutputFile.h"
-
-#include <memory>
-#include <utility>
-
-namespace llvm {
-
-enum class BuiltinFunctionKind {
- DumpDebugDescriptor,
- DumpDebugObjects,
-};
-
-// Utility class to expose symbols for special-purpose functions to the JIT.
-class LLIBuiltinFunctionGenerator : public orc::DefinitionGenerator {
-public:
- LLIBuiltinFunctionGenerator(std::vector<BuiltinFunctionKind> Enabled,
- orc::MangleAndInterner &Mangle);
-
- Error tryToGenerate(orc::LookupState &LS, orc::LookupKind K,
- orc::JITDylib &JD, orc::JITDylibLookupFlags JDLookupFlags,
- const orc::SymbolLookupSet &Symbols) override;
-
- void appendDebugObject(const char *Addr, size_t Size) {
- TestOut->os().write(Addr, Size);
- }
-
-private:
- orc::SymbolMap BuiltinFunctions;
- std::unique_ptr<ToolOutputFile> TestOut;
-
- template <typename T> void expose(orc::SymbolStringPtr Name, T *Handler) {
- BuiltinFunctions[Name] = {orc::ExecutorAddr::fromPtr(Handler),
- JITSymbolFlags::Exported};
- }
-
- static std::unique_ptr<ToolOutputFile> createToolOutput();
-};
-
-} // end namespace llvm
-
-#endif // LLVM_TOOLS_LLI_EXECUTIONUTILS_H
diff --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp
index 8a7ea2d3d0c5822..905ec23de45b967 100644
--- a/llvm/tools/lli/lli.cpp
+++ b/llvm/tools/lli/lli.cpp
@@ -12,7 +12,6 @@
//
//===----------------------------------------------------------------------===//
-#include "ExecutionUtils.h"
#include "ForwardingMemoryManager.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Bitcode/BitcodeReader.h"
@@ -33,6 +32,7 @@
#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
+#include "llvm/ExecutionEngine/Orc/ObjectTransformLayer.h"
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
#include "llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h"
#include "llvm/ExecutionEngine/Orc/SymbolStringPool.h"
@@ -62,6 +62,7 @@
#include "llvm/Support/Program.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/TargetSelect.h"
+#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Support/WithColor.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TargetParser/Triple.h"
@@ -254,35 +255,29 @@ namespace {
NoDump,
DumpFuncsToStdOut,
DumpModsToStdOut,
- DumpModsToDisk
+ DumpModsToDisk,
+ DumpDebugDescriptor,
+ DumpDebugObjects,
};
cl::opt<DumpKind> OrcDumpKind(
"orc-lazy-debug", cl::desc("Debug dumping for the orc-lazy JIT."),
cl::init(DumpKind::NoDump),
- cl::values(clEnumValN(DumpKind::NoDump, "no-dump",
- "Don't dump anything."),
- clEnumValN(DumpKind::DumpFuncsToStdOut, "funcs-to-stdout",
- "Dump function names to stdout."),
- clEnumValN(DumpKind::DumpModsToStdOut, "mods-to-stdout",
- "Dump modules to stdout."),
- clEnumValN(DumpKind::DumpModsToDisk, "mods-to-disk",
- "Dump modules to the current "
- "working directory. (WARNING: "
- "will overwrite existing files).")),
- cl::Hidden);
-
- cl::list<BuiltinFunctionKind> GenerateBuiltinFunctions(
- "generate",
- cl::desc("Provide built-in functions for access by JITed code "
- "(jit-kind=orc-lazy only)"),
- cl::values(clEnumValN(BuiltinFunctionKind::DumpDebugDescriptor,
- "__dump_jit_debug_descriptor",
- "Dump __jit_debug_descriptor contents to stdout"),
- clEnumValN(BuiltinFunctionKind::DumpDebugObjects,
- "__dump_jit_debug_objects",
- "Dump __jit_debug_descriptor in-memory debug "
- "objects as tool output")),
+ cl::values(
+ clEnumValN(DumpKind::NoDump, "no-dump", "Don't dump anything."),
+ clEnumValN(DumpKind::DumpFuncsToStdOut, "funcs-to-stdout",
+ "Dump function names to stdout."),
+ clEnumValN(DumpKind::DumpModsToStdOut, "mods-to-stdout",
+ "Dump modules to stdout."),
+ clEnumValN(DumpKind::DumpModsToDisk, "mods-to-disk",
+ "Dump modules to the current "
+ "working directory. (WARNING: "
+ "will overwrite existing files)."),
+ clEnumValN(DumpKind::DumpDebugDescriptor, "jit-debug-descriptor",
+ "Dump __jit_debug_descriptor contents to stdout"),
+ clEnumValN(DumpKind::DumpDebugObjects, "jit-debug-objects",
+ "Dump __jit_debug_descriptor in-memory debug "
+ "objects as tool output")),
cl::Hidden);
ExitOnError ExitOnErr;
@@ -756,9 +751,41 @@ int main(int argc, char **argv, char * const *envp) {
return Result;
}
-static std::function<void(Module &)> createDebugDumper() {
+// 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 struct jit_code_entry *
+findNextDebugDescriptorEntry(struct jit_code_entry *Latest) {
+ if (Latest == nullptr)
+ return __jit_debug_descriptor.first_entry;
+ if (Latest->next_entry)
+ return Latest->next_entry;
+ return nullptr;
+}
+
+static ToolOutputFile &claimToolOutput() {
+ static std::unique_ptr<ToolOutputFile> ToolOutput = nullptr;
+ if (ToolOutput) {
+ WithColor::error(errs(), "lli")
+ << "Can not claim stdout for tool output twice\n";
+ exit(1);
+ }
+ std::error_code EC;
+ ToolOutput = std::make_unique<ToolOutputFile>("-", EC, sys::fs::OF_None);
+ if (EC) {
+ WithColor::error(errs(), "lli")
+ << "Failed to create tool output file: " << EC.message() << "\n";
+ exit(1);
+ }
+ return *ToolOutput;
+}
+
+static std::function<void(Module &)> createIRDebugDumper() {
switch (OrcDumpKind) {
case DumpKind::NoDump:
+ case DumpKind::DumpDebugDescriptor:
+ case DumpKind::DumpDebugObjects:
return [](Module &M) {};
case DumpKind::DumpFuncsToStdOut:
@@ -800,6 +827,43 @@ static std::function<void(Module &)> createDebugDumper() {
llvm_unreachable("Unknown DumpKind");
}
+static std::function<void(MemoryBuffer &)> createObjDebugDumper() {
+ switch (OrcDumpKind) {
+ case DumpKind::NoDump:
+ case DumpKind::DumpFuncsToStdOut:
+ case DumpKind::DumpModsToStdOut:
+ case DumpKind::DumpModsToDisk:
+ return [](MemoryBuffer &) {};
+
+ case DumpKind::DumpDebugDescriptor: {
+ // Dump the empty descriptor at startup once
+ fprintf(stderr, "jit_debug_descriptor 0x%016" PRIx64 "\n",
+ pointerToJITTargetAddress(__jit_debug_descriptor.first_entry));
+ return [](MemoryBuffer &) {
+ // Dump new entries as they appear
+ static struct jit_code_entry *Latest = nullptr;
+ while (auto *NewEntry = findNextDebugDescriptorEntry(Latest)) {
+ fprintf(stderr, "jit_debug_descriptor 0x%016" PRIx64 "\n",
+ pointerToJITTargetAddress(NewEntry));
+ Latest = NewEntry;
+ }
+ };
+ }
+
+ case DumpKind::DumpDebugObjects: {
+ return [](MemoryBuffer &Obj) {
+ static struct jit_code_entry *Latest = nullptr;
+ static ToolOutputFile &ToolOutput = claimToolOutput();
+ while (auto *NewEntry = findNextDebugDescriptorEntry(Latest)) {
+ ToolOutput.os().write(NewEntry->symfile_addr, NewEntry->symfile_size);
+ Latest = NewEntry;
+ }
+ };
+ }
+ }
+ llvm_unreachable("Unknown DumpKind");
+}
+
Error loadDylibs() {
for (const auto &Dylib : Dylibs) {
std::string ErrMsg;
@@ -1001,8 +1065,7 @@ int runOrcJIT(const char *ProgName) {
if (PerModuleLazy)
J->setPartitionFunction(orc::CompileOnDemandLayer::compileWholeModule);
- auto Dump = createDebugDumper();
-
+ auto IRDump = createIRDebugDumper();
J->getIRTransformLayer().setTransform(
[&](orc::ThreadSafeModule TSM,
const orc::MaterializationResponsibility &R) {
@@ -1011,18 +1074,18 @@ int runOrcJIT(const char *ProgName) {
dbgs() << "Bad module: " << &M << "\n";
exit(1);
}
- Dump(M);
+ IRDump(M);
});
return TSM;
});
- if (GenerateBuiltinFunctions.size() > 0) {
- // Add LLI builtins.
- orc::MangleAndInterner Mangle(J->getExecutionSession(), J->getDataLayout());
- J->getMainJITDylib().addGenerator(
- std::make_unique<LLIBuiltinFunctionGenerator>(GenerateBuiltinFunctions,
- Mangle));
- }
+ auto ObjDump = createObjDebugDumper();
+ J->getObjTransformLayer().setTransform(
+ [&](std::unique_ptr<MemoryBuffer> Obj)
+ -> Expected<std::unique_ptr<MemoryBuffer>> {
+ ObjDump(*Obj);
+ return std::move(Obj);
+ });
// If this is a Mingw or Cygwin executor then we need to alias __main to
// orc_rt_int_void_return_0.
More information about the llvm-commits
mailing list