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

Assertion failure when using with DSO #81

Open wesleyw72 opened 4 years ago

wesleyw72 commented 4 years ago

I'm trying to use BOLT to optimise a DSO which is loaded by an application. When running perf2bolt I get an assertion failure. The binary is built with emit-relocs. Any ideas what could be wrong?

PERF2BOLT: Starting data aggregation job for perfb.data
PERF2BOLT: spawning perf job to read branch events
PERF2BOLT: spawning perf job to read mem events
PERF2BOLT: spawning perf job to read process events
PERF2BOLT: spawning perf job to read task events
BOLT-INFO: Target architecture: x86_64
BOLT-INFO: shared object or position-independent executable detected
BOLT-INFO: first alloc address is 0x0
BOLT-INFO: creating new program header table at address 0xa00000, offset 0xa00000
BOLT-INFO: enabling relocation mode
BOLT-INFO: binary build-id is:     b7fae7fb8a97aa6be2291185d9bd28270a13abf5
PERF2BOLT: spawning perf job to read buildid list
PERF2BOLT: matched build-id and file name
BOLT-INFO: enabling strict relocation mode for aggregation purposes
perf2bolt: ../tools/llvm-bolt/src/RewriteInstance.cpp:1934: bool llvm::bolt::RewriteInstance::analyzeRelocation(const llvm::object::RelocationRef&, uint64_t, std::__cxx11::string&, bool&, uint64_t&, int64_t&, uint64_t&) const: Assertion `verifyExtractedValue() && "mismatched extracted relocation value"' failed.
#0 0x0000557479ead5fa llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/home/wesley/llvm/build/bin/perf2bolt+0xe385fa)
#1 0x0000557479eab316 llvm::sys::RunSignalHandlers() (/home/wesley/llvm/build/bin/perf2bolt+0xe36316)
#2 0x0000557479eab6b5 SignalHandler(int) (/home/wesley/llvm/build/bin/perf2bolt+0xe366b5)
#3 0x00007f617858e890 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12890)
#4 0x00007f617723fe97 gsignal /build/glibc-OTsEL5/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
#5 0x00007f6177241801 abort /build/glibc-OTsEL5/glibc-2.27/stdlib/abort.c:81:0
#6 0x00007f617723139a __assert_fail_base /build/glibc-OTsEL5/glibc-2.27/assert/assert.c:89:0
#7 0x00007f6177231412 (/lib/x86_64-linux-gnu/libc.so.6+0x30412)
#8 0x000055747939d944 llvm::bolt::RewriteInstance::analyzeRelocation(llvm::object::RelocationRef const&, unsigned long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, bool&, unsigned long&, long&, unsigned long&) const (/home/wesley/llvm/build/bin/perf2bolt+0x328944)
#9 0x000055747939e40c llvm::bolt::RewriteInstance::readRelocations(llvm::object::SectionRef const&) (/home/wesley/llvm/build/bin/perf2bolt+0x32940c)
#10 0x00005574793a0529 llvm::bolt::RewriteInstance::processRelocations() (/home/wesley/llvm/build/bin/perf2bolt+0x32b529)
#11 0x00005574793cb36c llvm::bolt::RewriteInstance::discoverFileObjects() (/home/wesley/llvm/build/bin/perf2bolt+0x35636c)
#12 0x00005574793cc638 llvm::bolt::RewriteInstance::run() (/home/wesley/llvm/build/bin/perf2bolt+0x357638)
#13 0x0000557479259fb0 main (/home/wesley/llvm/build/bin/perf2bolt+0x1e4fb0)
#14 0x00007f6177222b97 __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:344:0
#15 0x00005574792a0e8a _start (/home/wesley/llvm/build/bin/perf2bolt+0x22be8a)
Stack dump:
0.  Program arguments: /home/wesley/llvm/build/bin/perf2bolt -p perfb.data -o perfb.fdata my_lib.so
Aborted
Sameeranjoshi commented 3 years ago

Hi, I am giving a try from the list of issues on GH to see if they are still reproducable. Can you please let me know what DSO is ? Or the steps followed to reproduce this error?

Thank you.

wesleyw72 commented 3 years ago

@Sameeranjoshi A DSO is a Dynamic Shared Object, they commonly have .so extensions on Linux and are sometimes referred to as shared/dynamic libraries.

The steps to reproduce are to build a shared library. Record some perf. Then use perf2bolt with it, eg perf2bolt -p perfb.data -o perfb.fdata my_lib.so.

rafaelauler commented 3 years ago

Building a shared lib is not enough to repro. We do use BOLT on shared libs.