llvm / llvm/llvm-project

[DebugInfo] Missing frame in gdb backtrace when noinline function tail-calls another noinline function

Open
#201,542 5 comments 0 reactions 0 assignees View on GitHub
debuginfo
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

When a `[[gnu::noinline]]` function tail-calls another noinline function,
the caller is missing from the gdb backtrace. GCC produces the expected
backtrace with all frames present.

## Reproducer

```c
#include
#include
#include

[[gnu::noinline]]
static void crash_here() {
long page_size = sysconf(_SC_PAGESIZE);
if (page_size <= 0) abort();
void* p = mmap(NULL, (size_t)page_size, PROT_NONE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (p == MAP_FAILED) abort();
*(volatile int*)p = 42;
}

[[gnu::noinline]]
static void middle() {
crash_here();
}

int main() {
middle();
return 0;
}
```

## Clang (frame missing)

```
$ clang -g -O2 -o crash crash.c && gdb -batch -ex 'handle SIGSEGV stop' -ex run -ex bt ./crash
#0 crash_here () at crash.c:16
#1 0x... in main () at crash.c:24
```

middle() is missing.

## GCC (all frames present)

```
$ gcc -g -O2 -o crash crash.c && gdb -batch -ex 'handle SIGSEGV stop' -ex run -ex bt ./crash
#0 crash_here () at crash.c:20
#1 0x... in middle () at crash.c:25
#2 0x... in main () at crash.c:29
```

PS: clang version 22

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.