Skip to content

Commit 467b3bb

Browse files
mshockwavec-rhodes
authored andcommitted
[ELFDebugObjectPlugin] Do not wait for std::future in post-fixup phase in the absent of debug info (#178541)
If there is no debug information, we wouldn't call `DebugObject::collectTargetAlloc` in the post-allocation phase. Therefore, when it's in the post-fixup phase, `DebugObject::awaitTargetMem` will fail with _"std::future_error: No associated state"_ because the std::future was not even populated. (cherry picked from commit 696ea11)
1 parent 5bebd32 commit 467b3bb

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

llvm/lib/ExecutionEngine/Orc/Debugging/ELFDebugObjectPlugin.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,14 @@ class DebugObject {
7575

7676
void trackFinalizedAlloc(FinalizedAlloc FA) { Alloc = std::move(FA); }
7777

78-
Expected<ExecutorAddrRange> awaitTargetMem() { return FinalizeFuture.get(); }
78+
bool hasPendingTargetMem() const { return FinalizeFuture.valid(); }
79+
80+
Expected<ExecutorAddrRange> awaitTargetMem() {
81+
assert(FinalizeFuture.valid() &&
82+
"FinalizeFuture is not valid. Perhaps there is no pending target "
83+
"memory transaction?");
84+
return FinalizeFuture.get();
85+
}
7986

8087
void reportTargetMem(ExecutorAddrRange TargetMem) {
8188
FinalizePromise.set_value(TargetMem);
@@ -342,6 +349,12 @@ void ELFDebugObjectPlugin::modifyPassConfig(MaterializationResponsibility &MR,
342349
// register the memory range with the GDB JIT Interface in an allocation
343350
// action of the LinkGraph's own allocation
344351
DebugObject *DebugObj = getPendingDebugObj(MR);
352+
assert(DebugObj && "Don't inject passes if we have no debug object");
353+
// Post-allocation phases would bail out if there is no debug section,
354+
// in which case we wouldn't collect target memory and therefore shouldn't
355+
// wait for the transaction to finish.
356+
if (!DebugObj->hasPendingTargetMem())
357+
return Error::success();
345358
Expected<ExecutorAddrRange> R = DebugObj->awaitTargetMem();
346359
if (!R)
347360
return R.takeError();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# REQUIRES: native && x86_64-linux
2+
3+
# RUN: rm -rf %t && mkdir %t
4+
# RUN: llvm-mc -triple=x86_64-unknown-linux \
5+
# RUN: -filetype=obj -o %t/ELF_x86-64_no_debug_info.o %s
6+
# RUN: llvm-jitlink %t/ELF_x86-64_no_debug_info.o
7+
8+
# Check if everything works in the absent of any debug information.
9+
10+
.text
11+
.globl main # -- Begin function main
12+
.p2align 4
13+
.type main,@function
14+
main: # @main
15+
pushq %rbp
16+
movq %rsp, %rbp
17+
movl $0, -4(%rbp)
18+
movl $0, %eax
19+
popq %rbp
20+
retq

0 commit comments

Comments
 (0)