Skip to content

llvm-bolt --instrument crash happens #158792

@zhouyu0502

Description

@zhouyu0502
  1. i want to instrument a shared library which is arm64 arch in x86_64 server (i successfully cross-compiler bolt-rt in x86_64 for arm64 and verify bolt instrument feature sucessfully in simple arm64 so), but i come across this crash in a complicated so because of assert ContainingBF && "cannot find function for address in code"
Image

./llvmtest/build_debug/bin/llvm-bolt libduml_fastrtps.so --instrument -o out.so
BOLT-INFO: shared object or position-independent executable detected
BOLT-INFO: Target architecture: aarch64
BOLT-INFO: BOLT version: 6abb626
BOLT-INFO: first alloc address is 0x0
BOLT-INFO: creating new program header table at address 0x800000, offset 0x800000
BOLT-INFO: enabling relocation mode
BOLT-INFO: forcing -jump-tables=move for instrumentation
llvm-bolt: /home/yulia.zhou/code/llvm/llvmtest/llvm-project/bolt/lib/Rewrite/RewriteInstance.cpp:2762: void llvm::bolt::RewriteInstance::handleRelocation(const llvm::object::SectionRef&, const llvm::object::RelocationRef&): Assertion ContainingBF && "cannot find function for address in code"' failed.
#0 0x0000556fbf94bf3a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (.localalias) /home/yulia.zhou/code/llvm/llvmtest/llvm-project/llvm/lib/Support/Unix/Signals.inc:834:22
#1 0x0000556fbf94c3bf PrintStackTraceSignalHandler(void*) /home/yulia.zhou/code/llvm/llvmtest/llvm-project/llvm/lib/Support/Unix/Signals.inc:918:1
#2 0x0000556fbf949650 llvm::sys::RunSignalHandlers() (.localalias) /home/yulia.zhou/code/llvm/llvmtest/llvm-project/llvm/lib/Support/Signals.cpp:104:20
#3 0x0000556fbf94b785 SignalHandler(int, siginfo_t*, void*) /home/yulia.zhou/code/llvm/llvmtest/llvm-project/llvm/lib/Support/Unix/Signals.inc:426:14
#4 0x00007ff55a820420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#5 0x00007ff55a2ed00b raise /build/glibc-B3wQXB/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
#6 0x00007ff55a2cc859 abort /build/glibc-B3wQXB/glibc-2.31/stdlib/abort.c:81:7
#7 0x00007ff55a2cc729 get_sysdep_segment_value /build/glibc-B3wQXB/glibc-2.31/intl/loadmsgcat.c:509:8
#8 0x00007ff55a2cc729 _nl_load_domain /build/glibc-B3wQXB/glibc-2.31/intl/loadmsgcat.c:970:34
#9 0x00007ff55a2ddfd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
#10 0x0000556fbfa9deb2 llvm::bolt::RewriteInstance::handleRelocation(llvm::object::SectionRef const&, llvm::object::RelocationRef const&) (.localalias) /home/yulia.zhou/code/llvm/llvmtest/llvm-project/bolt/lib/Rewrite/RewriteInstance.cpp:2763:9
#11 0x0000556fbfa9d320 llvm::bolt::RewriteInstance::readRelocations(llvm::object::SectionRef const&) (.localalias) /home/yulia.zhou/code/llvm/llvmtest/llvm-project/bolt/lib/Rewrite/RewriteInstance.cpp:2645:55
#12 0x0000556fbfa9b979 llvm::bolt::RewriteInstance::processRelocations() (.localalias) /home/yulia.zhou/code/llvm/llvmtest/llvm-project/bolt/lib/Rewrite/RewriteInstance.cpp:2453:20
#13 0x0000556fbfa95344 llvm::bolt::RewriteInstance::discoverFileObjects() (.localalias) /home/yulia.zhou/code/llvm/llvmtest/llvm-project/bolt/lib/Rewrite/RewriteInstance.cpp:1352:20
#14 0x0000556fbfa911ca llvm::bolt::RewriteInstance::run() /home/yulia.zhou/code/llvm/llvmtest/llvm-project/bolt/lib/Rewrite/RewriteInstance.cpp:709:32
#15 0x0000556fbe79a8fc main /home/yulia.zhou/code/llvm/llvmtest/llvm-project/bolt/tools/driver/llvm-bolt.cpp:267:29
#16 0x00007ff55a2ce083 __libc_start_main /build/glibc-B3wQXB/glibc-2.31/csu/../csu/libc-start.c:342:3
#17 0x0000556fbe79942e _start (./llvmtest/build_debug/bin/llvm-bolt+0x29c42e)

2.i add some logs and find out this happens when exe handleRelocation() in readRelocations() for section rela.init
it cannot find offset rela.init (0x13f904) in BinaryFunctions
Rel.getOffset() = 0x13f904
BinaryFunctions.size() = 12912
BinaryFunctions.firstkey = 0x13f920
BinaryFunctions.lastkey = 0x50da40
so **getBinaryFunctionContainingAddress(**Rel.getOffset()) return nullptr and cause crash

Image

P.S. readelf -r rela.init section shows Offset is 00000013f904

Relocation section '.rela.init' at offset 0x7179b0 contains 1 entry:
Offset Info Type Symbol's Value Symbol's Name + Addend
00000013f904 00010000011b R_AARCH64_CALL26 000000000014eb10 .text + 85d6c

Metadata

Metadata

Assignees

No one assigned

    Labels

    BOLTcrashPrefer [crash-on-valid] or [crash-on-invalid]

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions