From 3f3a3e873a684e924d9d873f9e094e217e323f2a Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Mon, 22 Jan 2024 12:54:30 -0800 Subject: [PATCH] Revert "[lli] Revisit Orc debug output tests" (#79055) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Reverts llvm/llvm-project#76822 This fails to build with gcc 7.5: ``` llvm/tools/lli/lli.cpp:1087:16: error: could not convert ‘Obj’ from ‘std::unique_ptr’ to ‘llvm::Expected >’ return Obj; ^~~ ``` --- ...scriptor.ll => debug-descriptor-elf-minimal.ll} | 30 +++-- .../OrcLazy/debug-objects-elf-minimal.ll | 82 +++++++++++++ llvm/test/ExecutionEngine/OrcLazy/debug-objects.ll | 62 ---------- llvm/tools/lli/CMakeLists.txt | 1 + llvm/tools/lli/ExecutionUtils.cpp | 122 +++++++++++++++++++ llvm/tools/lli/ExecutionUtils.h | 60 +++++++++ llvm/tools/lli/lli.cpp | 135 ++++++--------------- 7 files changed, 322 insertions(+), 170 deletions(-) rename llvm/test/ExecutionEngine/OrcLazy/{debug-descriptor.ll => debug-descriptor-elf-minimal.ll} (53%) create mode 100644 llvm/test/ExecutionEngine/OrcLazy/debug-objects-elf-minimal.ll delete mode 100644 llvm/test/ExecutionEngine/OrcLazy/debug-objects.ll create mode 100644 llvm/tools/lli/ExecutionUtils.cpp create mode 100644 llvm/tools/lli/ExecutionUtils.h diff --git a/llvm/test/ExecutionEngine/OrcLazy/debug-descriptor.ll b/llvm/test/ExecutionEngine/OrcLazy/debug-descriptor-elf-minimal.ll similarity index 53% rename from llvm/test/ExecutionEngine/OrcLazy/debug-descriptor.ll rename to llvm/test/ExecutionEngine/OrcLazy/debug-descriptor-elf-minimal.ll index bf7f13fb5439..9bac3897864f 100644 --- a/llvm/test/ExecutionEngine/OrcLazy/debug-descriptor.ll +++ b/llvm/test/ExecutionEngine/OrcLazy/debug-descriptor-elf-minimal.ll @@ -1,17 +1,29 @@ -; REQUIRES: native && target-x86_64 +; REQUIRES: native && x86_64-linux -; 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=rtdyld \ +; RUN: --generate=__dump_jit_debug_descriptor %s | FileCheck %s ; -; Initial entry should be empty: -; CHECK: jit_debug_descriptor 0x0000000000000000 +; RUN: lli --jit-linker=jitlink \ +; RUN: --generate=__dump_jit_debug_descriptor %s | FileCheck %s ; -; After adding the module it must not be empty anymore: -; CHECK: jit_debug_descriptor 0x -; CHECK-NOT: 000000000000000 -; CHECK-SAME: {{[048c]}} +; 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 +@__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_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 new file mode 100644 index 000000000000..31fe730b7403 --- /dev/null +++ b/llvm/test/ExecutionEngine/OrcLazy/debug-objects-elf-minimal.ll @@ -0,0 +1,82 @@ +; 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 +@__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 deleted file mode 100644 index 1f48bd9a2318..000000000000 --- a/llvm/test/ExecutionEngine/OrcLazy/debug-objects.ll +++ /dev/null @@ -1,62 +0,0 @@ -; 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 e3fca225a227..315de28e12b5 100644 --- a/llvm/tools/lli/CMakeLists.txt +++ b/llvm/tools/lli/CMakeLists.txt @@ -53,6 +53,7 @@ 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 new file mode 100644 index 000000000000..b6cc3bb174d3 --- /dev/null +++ b/llvm/tools/lli/ExecutionUtils.cpp @@ -0,0 +1,122 @@ +//===---- 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 +#include + +namespace llvm { + +template 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 ""; +} + +// 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(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(Entry->symfile_addr), + Entry->symfile_size, Entry->prev_entry); +} + +static LLIBuiltinFunctionGenerator *Generator = nullptr; + +static void dumpDebugObjects(void *Addr) { + jit_descriptor *Descriptor = reinterpret_cast(Addr); + for (auto *Entry = Descriptor->first_entry; Entry; Entry = Entry->next_entry) + Generator->appendDebugObject(Entry->symfile_addr, Entry->symfile_size); +} + +LLIBuiltinFunctionGenerator::LLIBuiltinFunctionGenerator( + std::vector 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 +LLIBuiltinFunctionGenerator::createToolOutput() { + std::error_code EC; + auto TestOut = std::make_unique("-", 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 new file mode 100644 index 000000000000..6bf9cd58e031 --- /dev/null +++ b/llvm/tools/lli/ExecutionUtils.h @@ -0,0 +1,60 @@ +//===- 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 +#include + +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 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 TestOut; + + template void expose(orc::SymbolStringPtr Name, T *Handler) { + BuiltinFunctions[Name] = {orc::ExecutorAddr::fromPtr(Handler), + JITSymbolFlags::Exported}; + } + + static std::unique_ptr 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 15acf6d38dba..8a7ea2d3d0c5 100644 --- a/llvm/tools/lli/lli.cpp +++ b/llvm/tools/lli/lli.cpp @@ -12,6 +12,7 @@ // //===----------------------------------------------------------------------===// +#include "ExecutionUtils.h" #include "ForwardingMemoryManager.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Bitcode/BitcodeReader.h" @@ -32,7 +33,6 @@ #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,7 +62,6 @@ #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" @@ -255,29 +254,35 @@ namespace { NoDump, DumpFuncsToStdOut, DumpModsToStdOut, - DumpModsToDisk, - DumpDebugDescriptor, - DumpDebugObjects, + DumpModsToDisk }; cl::opt 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)."), - 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::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 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::Hidden); ExitOnError ExitOnErr; @@ -751,41 +756,9 @@ int main(int argc, char **argv, char * const *envp) { return Result; } -// 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 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("-", 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 createIRDebugDumper() { +static std::function createDebugDumper() { switch (OrcDumpKind) { case DumpKind::NoDump: - case DumpKind::DumpDebugDescriptor: - case DumpKind::DumpDebugObjects: return [](Module &M) {}; case DumpKind::DumpFuncsToStdOut: @@ -827,43 +800,6 @@ static std::function createIRDebugDumper() { llvm_unreachable("Unknown DumpKind"); } -static std::function 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; @@ -1065,7 +1001,8 @@ int runOrcJIT(const char *ProgName) { if (PerModuleLazy) J->setPartitionFunction(orc::CompileOnDemandLayer::compileWholeModule); - auto IRDump = createIRDebugDumper(); + auto Dump = createDebugDumper(); + J->getIRTransformLayer().setTransform( [&](orc::ThreadSafeModule TSM, const orc::MaterializationResponsibility &R) { @@ -1074,18 +1011,18 @@ int runOrcJIT(const char *ProgName) { dbgs() << "Bad module: " << &M << "\n"; exit(1); } - IRDump(M); + Dump(M); }); return TSM; }); - auto ObjDump = createObjDebugDumper(); - J->getObjTransformLayer().setTransform( - [&](std::unique_ptr Obj) - -> Expected> { - ObjDump(*Obj); - return Obj; - }); + if (GenerateBuiltinFunctions.size() > 0) { + // Add LLI builtins. + orc::MangleAndInterner Mangle(J->getExecutionSession(), J->getDataLayout()); + J->getMainJITDylib().addGenerator( + std::make_unique(GenerateBuiltinFunctions, + Mangle)); + } // If this is a Mingw or Cygwin executor then we need to alias __main to // orc_rt_int_void_return_0. -- 2.11.4.GIT