Skip to content

Commit 3f3a3e8

Browse files
authored
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; ^~~ ```
1 parent 9f8ccf5 commit 3f3a3e8

File tree

7 files changed

+322
-170
lines changed

7 files changed

+322
-170
lines changed

llvm/test/ExecutionEngine/OrcLazy/debug-descriptor.ll renamed to llvm/test/ExecutionEngine/OrcLazy/debug-descriptor-elf-minimal.ll

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
1-
; REQUIRES: native && target-x86_64
1+
; REQUIRES: native && x86_64-linux
22

3-
; RUN: lli --jit-linker=rtdyld --orc-lazy-debug=jit-debug-descriptor %s 2>&1 | FileCheck %s
4-
; RUN: lli --jit-linker=jitlink --orc-lazy-debug=jit-debug-descriptor %s 2>&1 | FileCheck %s
3+
; RUN: lli --jit-linker=rtdyld \
4+
; RUN: --generate=__dump_jit_debug_descriptor %s | FileCheck %s
55
;
6-
; Initial entry should be empty:
7-
; CHECK: jit_debug_descriptor 0x0000000000000000
6+
; RUN: lli --jit-linker=jitlink \
7+
; RUN: --generate=__dump_jit_debug_descriptor %s | FileCheck %s
88
;
9-
; After adding the module it must not be empty anymore:
10-
; CHECK: jit_debug_descriptor 0x
11-
; CHECK-NOT: 000000000000000
12-
; CHECK-SAME: {{[048c]}}
9+
; CHECK: Reading __jit_debug_descriptor at 0x{{.*}}
10+
; CHECK: Version: 1
11+
; CHECK: Action: JIT_REGISTER_FN
12+
; CHECK: Entry Symbol File Size Previous Entry
13+
; CHECK: [ 0] 0x{{.*}} 0x{{.*}} {{.*}} 0x0000000000000000
14+
15+
target triple = "x86_64-unknown-unknown-elf"
16+
17+
; Built-in symbol provided by the JIT
18+
declare void @__dump_jit_debug_descriptor(ptr)
19+
20+
; Host-process symbol from the GDB JIT interface
21+
@__jit_debug_descriptor = external global i8, align 1
1322

1423
define i32 @main() !dbg !9 {
24+
%1 = alloca i32, align 4
25+
store i32 0, ptr %1, align 4
26+
call void @__dump_jit_debug_descriptor(ptr @__jit_debug_descriptor), !dbg !13
1527
ret i32 0, !dbg !14
1628
}
1729

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
; REQUIRES: native && x86_64-linux
2+
3+
; In-memory debug-object contains some basic DWARF
4+
;
5+
; RUN: lli --jit-linker=rtdyld \
6+
; RUN: --generate=__dump_jit_debug_objects %s | llvm-dwarfdump --diff - | FileCheck %s
7+
;
8+
; RUN: lli --jit-linker=jitlink \
9+
; RUN: --generate=__dump_jit_debug_objects %s | llvm-dwarfdump --diff - | FileCheck %s
10+
;
11+
; CHECK: -: file format elf64-x86-64
12+
; CHECK: .debug_info contents:
13+
; CHECK: 0x00000000: Compile Unit: length = 0x00000047, format = DWARF32, version = 0x0004, abbr_offset = 0x0000, addr_size = 0x08 (next unit at 0x0000004b)
14+
; CHECK: DW_TAG_compile_unit
15+
; CHECK: DW_AT_producer ("compiler version")
16+
; CHECK: DW_AT_language (DW_LANG_C99)
17+
; CHECK: DW_AT_name ("source-file.c")
18+
; CHECK: DW_AT_stmt_list ()
19+
; CHECK: DW_AT_comp_dir ("/workspace")
20+
; CHECK: DW_AT_low_pc ()
21+
; CHECK: DW_AT_high_pc ()
22+
; CHECK: DW_TAG_subprogram
23+
; CHECK: DW_AT_low_pc ()
24+
; CHECK: DW_AT_high_pc ()
25+
; CHECK: DW_AT_frame_base (DW_OP_reg7 RSP)
26+
; CHECK: DW_AT_name ("main")
27+
; CHECK: DW_AT_decl_file ("/workspace/source-file.c")
28+
; CHECK: DW_AT_decl_line (4)
29+
; CHECK: DW_AT_type ("int")
30+
; CHECK: DW_AT_external (true)
31+
; CHECK: DW_TAG_base_type
32+
; CHECK: DW_AT_name ("int")
33+
; CHECK: DW_AT_encoding (DW_ATE_signed)
34+
; CHECK: DW_AT_byte_size (0x04)
35+
; CHECK: NULL
36+
37+
; Text section of the in-memory debug-object has a non-null load-address
38+
;
39+
; RUN: lli --jit-linker=rtdyld \
40+
; RUN: --generate=__dump_jit_debug_objects %s | llvm-objdump --section-headers - | \
41+
; RUN: FileCheck --check-prefix=CHECK_LOAD_ADDR %s
42+
;
43+
; RUN: lli --jit-linker=jitlink \
44+
; RUN: --generate=__dump_jit_debug_objects %s | llvm-objdump --section-headers - | \
45+
; RUN: FileCheck --check-prefix=CHECK_LOAD_ADDR %s
46+
;
47+
; CHECK_LOAD_ADDR-NOT: {{[0-9]*}} .ltext {{.*}} 0000000000000000 TEXT
48+
49+
target triple = "x86_64-unknown-unknown-elf"
50+
51+
; Built-in symbol provided by the JIT
52+
declare void @__dump_jit_debug_objects(ptr)
53+
54+
; Host-process symbol from the GDB JIT interface
55+
@__jit_debug_descriptor = external global i8, align 1
56+
57+
define i32 @main() !dbg !9 {
58+
%1 = alloca i32, align 4
59+
store i32 0, ptr %1, align 4
60+
call void @__dump_jit_debug_objects(ptr @__jit_debug_descriptor), !dbg !13
61+
ret i32 0, !dbg !14
62+
}
63+
64+
!llvm.module.flags = !{!0, !1, !2, !3, !4}
65+
!llvm.dbg.cu = !{!5}
66+
!llvm.ident = !{!8}
67+
68+
!0 = !{i32 2, !"SDK Version", [3 x i32] [i32 10, i32 15, i32 6]}
69+
!1 = !{i32 7, !"Dwarf Version", i32 4}
70+
!2 = !{i32 2, !"Debug Info Version", i32 3}
71+
!3 = !{i32 1, !"wchar_size", i32 4}
72+
!4 = !{i32 7, !"PIC Level", i32 2}
73+
!5 = distinct !DICompileUnit(language: DW_LANG_C99, file: !6, producer: "compiler version", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !7, nameTableKind: None)
74+
!6 = !DIFile(filename: "source-file.c", directory: "/workspace")
75+
!7 = !{}
76+
!8 = !{!"compiler version"}
77+
!9 = distinct !DISubprogram(name: "main", scope: !6, file: !6, line: 4, type: !10, scopeLine: 4, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !7)
78+
!10 = !DISubroutineType(types: !11)
79+
!11 = !{!12}
80+
!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
81+
!13 = !DILocation(line: 5, column: 3, scope: !9)
82+
!14 = !DILocation(line: 6, column: 3, scope: !9)

llvm/test/ExecutionEngine/OrcLazy/debug-objects.ll

Lines changed: 0 additions & 62 deletions
This file was deleted.

llvm/tools/lli/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ endif( LLVM_USE_PERF )
5353

5454
add_llvm_tool(lli
5555
lli.cpp
56+
ExecutionUtils.cpp
5657

5758
DEPENDS
5859
intrinsics_gen

llvm/tools/lli/ExecutionUtils.cpp

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
//===---- ExecutionUtils.cpp - Utilities for executing functions in lli ---===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "ExecutionUtils.h"
10+
11+
#include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h"
12+
#include "llvm/Support/FileSystem.h"
13+
#include "llvm/Support/FormatVariadic.h"
14+
#include "llvm/Support/raw_ostream.h"
15+
16+
#include <cstdint>
17+
#include <vector>
18+
19+
namespace llvm {
20+
21+
template <typename... Ts> static void outsv(const char *Fmt, Ts &&...Vals) {
22+
outs() << formatv(Fmt, Vals...);
23+
}
24+
25+
static const char *actionFlagToStr(uint32_t ActionFlag) {
26+
switch (ActionFlag) {
27+
case JIT_NOACTION:
28+
return "JIT_NOACTION";
29+
case JIT_REGISTER_FN:
30+
return "JIT_REGISTER_FN";
31+
case JIT_UNREGISTER_FN:
32+
return "JIT_UNREGISTER_FN";
33+
}
34+
return "<invalid action_flag>";
35+
}
36+
37+
// Declarations follow the GDB JIT interface (version 1, 2009) and must match
38+
// those of the DYLD used for testing.
39+
//
40+
// Sample output:
41+
//
42+
// Reading __jit_debug_descriptor at 0x0000000000404048
43+
//
44+
// Version: 0
45+
// Action: JIT_REGISTER_FN
46+
//
47+
// Entry Symbol File Size Previous Entry
48+
// [ 0] 0x0000000000451290 0x0000000000002000 200 0x0000000000000000
49+
// [ 1] 0x0000000000451260 0x0000000000001000 100 0x0000000000451290
50+
// ...
51+
//
52+
static void dumpDebugDescriptor(void *Addr) {
53+
outsv("Reading __jit_debug_descriptor at {0}\n\n", Addr);
54+
55+
jit_descriptor *Descriptor = reinterpret_cast<jit_descriptor *>(Addr);
56+
outsv("Version: {0}\n", Descriptor->version);
57+
outsv("Action: {0}\n\n", actionFlagToStr(Descriptor->action_flag));
58+
outsv("{0,11} {1,24} {2,15} {3,14}\n", "Entry", "Symbol File", "Size",
59+
"Previous Entry");
60+
61+
unsigned Idx = 0;
62+
for (auto *Entry = Descriptor->first_entry; Entry; Entry = Entry->next_entry)
63+
outsv("[{0,2}] {1:X16} {2:X16} {3,8:D} {4}\n", Idx++, Entry,
64+
reinterpret_cast<const void *>(Entry->symfile_addr),
65+
Entry->symfile_size, Entry->prev_entry);
66+
}
67+
68+
static LLIBuiltinFunctionGenerator *Generator = nullptr;
69+
70+
static void dumpDebugObjects(void *Addr) {
71+
jit_descriptor *Descriptor = reinterpret_cast<jit_descriptor *>(Addr);
72+
for (auto *Entry = Descriptor->first_entry; Entry; Entry = Entry->next_entry)
73+
Generator->appendDebugObject(Entry->symfile_addr, Entry->symfile_size);
74+
}
75+
76+
LLIBuiltinFunctionGenerator::LLIBuiltinFunctionGenerator(
77+
std::vector<BuiltinFunctionKind> Enabled, orc::MangleAndInterner &Mangle)
78+
: TestOut(nullptr) {
79+
Generator = this;
80+
for (BuiltinFunctionKind F : Enabled) {
81+
switch (F) {
82+
case BuiltinFunctionKind::DumpDebugDescriptor:
83+
expose(Mangle("__dump_jit_debug_descriptor"), &dumpDebugDescriptor);
84+
break;
85+
case BuiltinFunctionKind::DumpDebugObjects:
86+
expose(Mangle("__dump_jit_debug_objects"), &dumpDebugObjects);
87+
TestOut = createToolOutput();
88+
break;
89+
}
90+
}
91+
}
92+
93+
Error LLIBuiltinFunctionGenerator::tryToGenerate(
94+
orc::LookupState &LS, orc::LookupKind K, orc::JITDylib &JD,
95+
orc::JITDylibLookupFlags JDLookupFlags,
96+
const orc::SymbolLookupSet &Symbols) {
97+
orc::SymbolMap NewSymbols;
98+
for (const auto &NameFlags : Symbols) {
99+
auto It = BuiltinFunctions.find(NameFlags.first);
100+
if (It != BuiltinFunctions.end())
101+
NewSymbols.insert(*It);
102+
}
103+
104+
if (NewSymbols.empty())
105+
return Error::success();
106+
107+
return JD.define(absoluteSymbols(std::move(NewSymbols)));
108+
}
109+
110+
// static
111+
std::unique_ptr<ToolOutputFile>
112+
LLIBuiltinFunctionGenerator::createToolOutput() {
113+
std::error_code EC;
114+
auto TestOut = std::make_unique<ToolOutputFile>("-", EC, sys::fs::OF_None);
115+
if (EC) {
116+
errs() << "Error creating tool output file: " << EC.message() << '\n';
117+
exit(1);
118+
}
119+
return TestOut;
120+
}
121+
122+
} // namespace llvm

llvm/tools/lli/ExecutionUtils.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//===- ExecutionUtils.h - Utilities for executing code in lli ---*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// Contains utilities for executing code in lli.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef LLVM_TOOLS_LLI_EXECUTIONUTILS_H
14+
#define LLVM_TOOLS_LLI_EXECUTIONUTILS_H
15+
16+
#include "llvm/ExecutionEngine/JITSymbol.h"
17+
#include "llvm/ExecutionEngine/Orc/Core.h"
18+
#include "llvm/ExecutionEngine/Orc/Mangling.h"
19+
#include "llvm/Support/Error.h"
20+
#include "llvm/Support/ToolOutputFile.h"
21+
22+
#include <memory>
23+
#include <utility>
24+
25+
namespace llvm {
26+
27+
enum class BuiltinFunctionKind {
28+
DumpDebugDescriptor,
29+
DumpDebugObjects,
30+
};
31+
32+
// Utility class to expose symbols for special-purpose functions to the JIT.
33+
class LLIBuiltinFunctionGenerator : public orc::DefinitionGenerator {
34+
public:
35+
LLIBuiltinFunctionGenerator(std::vector<BuiltinFunctionKind> Enabled,
36+
orc::MangleAndInterner &Mangle);
37+
38+
Error tryToGenerate(orc::LookupState &LS, orc::LookupKind K,
39+
orc::JITDylib &JD, orc::JITDylibLookupFlags JDLookupFlags,
40+
const orc::SymbolLookupSet &Symbols) override;
41+
42+
void appendDebugObject(const char *Addr, size_t Size) {
43+
TestOut->os().write(Addr, Size);
44+
}
45+
46+
private:
47+
orc::SymbolMap BuiltinFunctions;
48+
std::unique_ptr<ToolOutputFile> TestOut;
49+
50+
template <typename T> void expose(orc::SymbolStringPtr Name, T *Handler) {
51+
BuiltinFunctions[Name] = {orc::ExecutorAddr::fromPtr(Handler),
52+
JITSymbolFlags::Exported};
53+
}
54+
55+
static std::unique_ptr<ToolOutputFile> createToolOutput();
56+
};
57+
58+
} // end namespace llvm
59+
60+
#endif // LLVM_TOOLS_LLI_EXECUTIONUTILS_H

0 commit comments

Comments
 (0)