facebookarchive / BOLT

Binary Optimization and Layout Tool - A linux command-line utility used for optimizing performance of binaries
2.51k stars 176 forks source link

populateJumpTables(): Assertion `0 && "unclaimed PC-relative relocations left in data\n"' failed. #223

Closed SaveTheRbtz closed 2 years ago

SaveTheRbtz commented 2 years ago

I'm using a following command:

perf2bolt -p perf.data -o chia_plot

(both profile and binary can be found here ~1.8Gb)

Traceback:

perf2bolt: BinaryContext.cpp:764: void llvm::bolt::BinaryContext::populateJumpTables(): Assertion `0 && "unclaimed PC-relative relocations left in data\n"' failed.
 #0 0x00005586b20afb01 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x00005586b20ad7be SignalHandler(int) Signals.cpp:0:0
 #2 0x00007fc429ef3870 __restore_rt sigaction.c:0:0
 #3 0x00007fc42993dd22 raise (/usr/lib/libc.so.6+0x3cd22)
 #4 0x00007fc429927862 abort (/usr/lib/libc.so.6+0x26862)
 #5 0x00007fc429927747 _nl_load_domain.cold loadmsgcat.c:0:0
 #6 0x00007fc429936616 (/usr/lib/libc.so.6+0x35616)
 #7 0x00005586b0f8dac0 llvm::bolt::BinaryContext::populateJumpTables() (/home/rbtz/porn/llvm-bolt-build/bin/perf2bolt+0x331ac0)
 #8 0x00005586b1068b71 llvm::bolt::RewriteInstance::disassembleFunctions() (/home/rbtz/porn/llvm-bolt-build/bin/perf2bolt+0x40cb71)
 #9 0x00005586b10c27e5 llvm::bolt::RewriteInstance::run() (/home/rbtz/porn/llvm-bolt-build/bin/perf2bolt+0x4667e5)
#10 0x00005586b0f024ba main (/home/rbtz/porn/llvm-bolt-build/bin/perf2bolt+0x2a64ba)

plot_chia is a PGO/LTO binary build with clang with following notable build/link flags

add_link_options("-fuse-ld=lld")
add_link_options("-Wl,--emit-relocs")
add_link_options("-Wl,--no-rosegment")
add_link_options("-Wl,-Bsymbolic-functions")
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static -lrt -pthread -Wl,--whole-archive -lpthread -Wl,--no-whole-archive")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
SaveTheRbtz commented 2 years ago

As a workaround, assembling BOLT without assertions works: -DLLVM_ENABLE_ASSERTIONS=OFF

maksfb commented 2 years ago

The workaround could cause runtime failures for the app and is not recommended. The issue is likely in one of the statically linked standard libraries. I haven't narrowed it down to any particular function yet.

SaveTheRbtz commented 2 years ago

Yep, the only way how I was able to make this work was to switch from static to dynamic compilation, otherwise processed binaries either crash with "illegal instruction" or segfault in pthread or jemalloc.

As you've mentioned, dynamic compilation works beautifully.

unordered-set commented 2 years ago

How nice for a guy from Yandex trying to optimize Solana and having the same issue, to find another Yandexoid having the same issue with Chia :)