[BOLT][perf2bolt] Bolt optimizes coremark and reports errors under static link conditions
@LiqinWeng: can you please add a debug log produced by adding -debug-only=bolt? The interesting line is the last relocation information.
@mtvec: the backtrace suggests the issue is inside this block: https://github.com/llvm/llvm-project/blob/33d5f4314f4fd83be21e22054e662220a62fe40b/bolt/lib/Rewrite/RewriteInstance.cpp#L2529-L2536 added in f873029386dd415cd9caa78f600a593d9570c9ae, can you please take a look?
@mtvec: the backtrace suggests the issue is inside this block:
https://github.com/llvm/llvm-project/blob/33d5f4314f4fd83be21e22054e662220a62fe40b/bolt/lib/Rewrite/RewriteInstance.cpp#L2529-L2536 added in f873029, can you please take a look?
Sure. @LiqinWeng is it possible for you to share the coremark executable you used and x86-dyn.data?
- command && script for cormark
NOTES: **static link**
// script for cormark
#!/bin/bash
set -x
make clean
[ x"$GCC_PATH" == x"" ] && GCC_PATH=/home/wengliqin/tool/gcc-linux
[ x"$LLVM_PATH" == x"" ] && LLVM_PATH=/home/wengliqin/tool/llvm18-x86
# -fprofile-instr-generate=coremark.profraw -flto -mllvm -enable-loop-int-wrap-predication -march=rv64gc
LLVM_CFLAGS="-Wl,--emit-relocs -mllvm -enable-dfa-jump-thread -menable-experimental-extensions -mllvm -enable-post-misched -mllvm -misched-postra -O3"
export PORT_DIR="posix"
export CC="$LLVM_PATH/bin/clang $LLVM_CFLAGS"
make link
mv coremark.exe coremark-rel-x86-dyn.exe
1. ./build-x86.sh
2. perf record -e cpu-clock:u -o x86-dyn.data -- ./coremark-rel-x86-dyn.exe
3. perf2bolt -p x86-dyn.data -o x86-dyn.fdata ./coremark-rel-x86-dyn.exe -nl
4. llvm-bolt ./coremark-rel-x86-dyn.exe -o ./coremark-rel-x86-dyn.exe.bolt x86-dyn.data -data=x86-dyn.fdata -reorder-blocks=ext-tsp -reorder-functions=hfsort -split-functions -split-all-cold -split-eh -dyno-stats
- exe file && data file Uploading x86-static-bolt.zip…
This is triggered by the following relocation:
Relocation section '.rela.data.rel.ro' at offset 0x103090 contains 1029 entries:
Offset Info Type Symbol's Value Symbol's Name + Addend
...
00000000002c4140 0000084a00000001 R_X86_64_64 0000000000000002 _nl_current_LC_CTYPE_used + 0
Since it's a data relocation, ContainingBF is null which causes the crash.
Should be fixed by #76026.