-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "[lli] Revisit Orc debug output tests" (#79055)
Reverts #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<llvm::MemoryBuffer>’ to ‘llvm::Expected<std::unique_ptr<llvm::MemoryBuffer> >’ return Obj; ^~~ ```
- Loading branch information
Showing
7 changed files
with
322 additions
and
170 deletions.
There are no files selected for viewing
30 changes: 21 additions & 9 deletions
30
...ecutionEngine/OrcLazy/debug-descriptor.ll → ...e/OrcLazy/debug-descriptor-elf-minimal.ll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
llvm/test/ExecutionEngine/OrcLazy/debug-objects-elf-minimal.ll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,7 @@ endif( LLVM_USE_PERF ) | |
|
||
add_llvm_tool(lli | ||
lli.cpp | ||
ExecutionUtils.cpp | ||
|
||
DEPENDS | ||
intrinsics_gen | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <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 |
Oops, something went wrong.