Dwarf errors on Fedora 35 when running perf script

I recently moved a server from Debian Stable to Fedora Server 35. Now, when I try to profile my code with perf, I get these kinds of messages when running perf script:

BFD: DWARF error: could not find variable specification at offset 0x3f74
BFD: DWARF error: could not find variable specification at offset 0x15ce
etc.

This results in a flamegraph that has way more stacks than I would expect and they're just not super useful for finding performance hotspots.

A few random tidbits of information:

  • Rust v1.57.0
  • Linux 5.15
  • Compiled in release mode with lto = thin and debug = 2
  • Command-line for perf record: perf record --call-graph=dwarf -g ./target/release/my-program
  • Command-line for perf script: perf script | inferno-collapse-perf | inferno-flamegraph >flame.svg
  • Interestingly, cargo-flamegraph produces flamegraphs without the error messages and which look fine. I looked at the commands that were run with ps and they're roughly the same as what I do manually.

I'd love to hear back from people who figured how to fix this problem.