[llvm-dev] Question regarding correctness of debug information generated by LLC

Dwight Guth via llvm-dev llvm-dev at lists.llvm.org
Wed Nov 24 14:24:56 PST 2021


I have a program I am developing that is exhibiting some undesirable
behavior, and I'm not entirely sure whether this constitutes a bug in
LLVM or not, so I wanted to ask.

I have managed to construct a minimized program that exhibits the same
issue I am dealing with; it can be found at
https://gist.github.com/dwightguth/75988aa998471a83d5dd198fac5ef02a

For a little background of what I am working on, I am developing a
garbage collector for a language that compiles down to LLVM IR, making
use of the garbage collection safepoints infrastructure in LLVM in
order to find references to heap objects on the stack. The language is
a functional language that relies on tail call optimizations to avoid
unbounded stack growth, so it makes use of the tailcc calling
convention (which is in turn based on the older fastcc calling
convention with -tailcallopt passed to llc).

The issue I am having is that it would appear that the debug
information generated for my program indicates a different value for
the $rsp register within the `apply_rule_6870` call frame at each of
the two different call sites of `scanStackRoots`. The value seems
correct at the first call site. However, at the second call site, the
value appears incorrect and gdb actually cannot find the `main` stack
frame when it tries to do a backtrace.

This is actually a matter of correctness for me because I use
libunwind to find the stack pointer at each call frame in order to be
able to interpret the stack map generated by the LLVM GC safepoints.
When run in the full example, the code sees an incorrect address for
one or more local variables, attempts to read memory incorrectly, and
eventually segfaults as a result.

My question is: is this a bug in LLVM? My gut feeling is yes, because
the compiler ought to generate the necessary cfi declarations in order
to be able to correctly unwind the stack. But I'm not entirely sure
because I'm not completely clear on what guarantees LLVM provides with
respect to debug information on non-standard calling conventions.

So, my question to the list is, should I report this program as a bug
in LLVM? Or do I need to find another means by which to reconstruct
the canonical frame address when looking for garbage collection roots
on the stack. And if so, what means might be available?

Thanks,

-- 
Dwight Guth
Chief Information Officer
Runtime Verification, Inc.

Email: dwight.guth at runtimeverification.com


More information about the llvm-dev mailing list