llvm / llvm/llvm-project

[BOLT] Core dump whilst oprimising linux kernel with BOLT

Open
#206,028 1 comment 0 reactions 0 assignees View on GitHub
BOLT
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Note, this occurs both on the latest version of LLVM and the latest git commit (as of 18:00 UTC, 25-6-26).

#### Steps to reproduce:

OS: Custom built cachyos-based kernel...

Generate perf profile using `sudo perf record -a -e cycles -j any,k -F 1000 -o ~/kernelbuild/bolt/perf.data -- sleep 600`. I do recieve `Warning: Processed 15514204 events and lost 229 chunks!`, however `perf report -i ~/kernelbuild/bolt/perf.data --stats 2>&1 | grep -i lost` shows a negligable amount of lost events:
``` LOST events: 229 ( 0.0%)
LOST_SAMPLES events: 44 ( 0.0%)
LOST_SAMPLES events: 67810
LOST_SAMPLES events: 87978
LOST_SAMPLES events: 186
```

Run perf2bolt on a cachyos kernel generated using corrected kernel patches from [here](https://github.com/llvm/llvm-project/blob/main/bolt/docs/OptimizingLinux.md).

You should recieve the following panic:
```
BOLT-INFO: Linux kernel version is 7.1.0
perf2bolt: /home/suitablymysterious/dev/llvm-project/bolt/lib/Rewrite/LinuxKernelRewriter.cpp:479: void {anonymous}::LinuxKernelRewriter::processLKKSymtab(bool): Assertion `SectionOrError && "__ksymtab[_gpl] section not found in Linux Kernel binary"' failed.
#0 0x000056526f118392 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/suitablymysterious/dev/build/bin/perf2bolt+0x106d392)
#1 0x000056526f115149 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#2 0x00007f4cfb244db0 (/usr/lib/libc.so.6+0x44db0)
#3 0x00007f4cfb2adfbb pthread_kill (/usr/lib/libc.so.6+0xadfbb)
#4 0x00007f4cfb244c88 raise (/usr/lib/libc.so.6+0x44c88)
#5 0x00007f4cfb225795 abort (/usr/lib/libc.so.6+0x25795)
#6 0x00007f4cfb226a31 (/usr/lib/libc.so.6+0x26a31)
#7 0x00007f4cfb23b552 __assert_fail (/usr/lib/libc.so.6+0x3b552)
#8 0x000056526f271c29 (anonymous namespace)::LinuxKernelRewriter::processLKKSymtab(bool) LinuxKernelRewriter.cpp:0:0
#9 0x000056526f290760 (anonymous namespace)::LinuxKernelRewriter::preCFGInitializer() LinuxKernelRewriter.cpp:0:0
#10 0x000056526f2930cf llvm::bolt::MetadataManager::runInitializersPreCFG() (/home/suitablymysterious/dev/build/bin/perf2bolt+0x11e80cf)
#11 0x000056526f237e91 llvm::bolt::RewriteInstance::run() (/home/suitablymysterious/dev/build/bin/perf2bolt+0x118ce91)
#12 0x000056526e459bb8 main (/home/suitablymysterious/dev/build/bin/perf2bolt+0x3aebb8)
#13 0x00007f4cfb227c8e (/usr/lib/libc.so.6+0x27c8e)
#14 0x00007f4cfb227dcb __libc_start_main (/usr/lib/libc.so.6+0x27dcb)
#15 0x000056526e508945 _start (/home/suitablymysterious/dev/build/bin/perf2bolt+0x45d945)
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0. Program arguments: /home/suitablymysterious/dev/build/bin/perf2bolt -p /home/suitablymysterious/kernelbuild/bolt/perf_overall.data -o /mnt/wdr/bolt-work/perf_overall.fdata /usr/src/debug/linux-archbishop/vmlinux
[1] 1970 abort (core dumped) ~/dev/build/bin/perf2bolt -p ~/kernelbuild/bolt/perf_overall.data -o
```

From what I understand `__ksymtab_GPL` is a build/temporary thing and is put into a `.export_symbol`, however I don't understand why it was ever a requirement in BOLT - if anyone could correct me if I'm wrong that would be great!

I've tried the following fix to `bolt/lib/Rewrite/LinuxKernelRewriter.cpp`:
```cpp
SectionName = "__ksymtab_gpl"; // line 479
ErrorOr SectionOrError =
BC.getUniqueSectionByName(SectionName);
// assert(SectionOrError &&
// "__ksymtab[_gpl] section not found in Linux Kernel binary");
if (!SectionOrError)
return;
const uint64_t SectionSize = SectionOrError->get
Size();
const uint64_t SectionAddress = SectionOrError->
getAddress();
assert((SectionSize % 4) == 0 && // line 483

```

I suppose this isn't the correct way to fix this, yet it works for me down the line when combined with my fix for #206027 ; if anyone thinks of a better solution, I'm happy to make a pr.

Thanks for any support.

Contributor guide

Open the contributing guide

Research direction

Start with bolt/lib/Rewrite/LinuxKernelRewriter.cpp, especially processLKKSymtab and its caller preCFGInitializer, then reproduce with perf2bolt using the provided perf data and vmlinux command. Compare the kernel's exported-symbol sections with the section lookup at the assertion and verify behavior with the reported corrected kernel patches. Done means perf2bolt handles this kernel without aborting while preserving the subsequent BOLT processing.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, linux
Domain
compilers, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.