Skip to content
This repository has been archived by the owner on Jul 1, 2023. It is now read-only.

Split-functions in large ARM64 binaries #104

Closed
yota9 opened this issue Oct 17, 2020 · 7 comments
Closed

Split-functions in large ARM64 binaries #104

yota9 opened this issue Oct 17, 2020 · 7 comments

Comments

@yota9
Copy link
Contributor

yota9 commented Oct 17, 2020

Hello!
I've faced the problem when tried to use BOLT on big binaries using "-split-functions=2" option. The thing is that when BOLT splits function in to cold/hot sections it creates R_AARCH64_CONDBR19 relocation branch between some of them. This relocation could only be used if the relative distance between the branch place and its target address is smaller then 1Mb (2^20). But using the big binary (>25Mb) the distance is bigger, so we have triggered assert in RuntimeDyldELF.cpp file
case ELF::R_AARCH64_CONDBR19: { ... assert(isInt<21>(BranchImm)); ... }
Is there an easy way to fix this issue?
Thank you!

@yota9 yota9 changed the title Split-functions in big ARM64 binaries Split-functions in large ARM64 binaries Oct 17, 2020
@maksfb
Copy link
Contributor

maksfb commented Oct 18, 2020

Thanks for reporting. We should be inserting stubs in LongJmpPass specifically for cover for short branches. Sounds like a bug in the pass. Could you share the BOLT output?

@ghost
Copy link

ghost commented Oct 18, 2020

Hello @maksfb ! Sure, here it is:
BOLT-INFO: Target architecture: aarch64
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 0x6800000, offset 0x6800000
BOLT-INFO: enabling relocation mode
BOLT-INFO: disabling -align-macro-fusion on non-x86 platform
BOLT-INFO: operating with basic samples profiling data (no LBR).
BOLT-INFO: normalizing samples by instruction count.
BOLT-INFO: 1156 functions out of 43613 simple functions (2.7%) have non-empty execution profile.
BOLT-INFO: 31 non-simple function(s) have profile.
BOLT-INFO: basic block reordering modified layout of 587 (1.31%) functions
BOLT-INFO: UCE removed 1 blocks and 4 bytes of code.
BOLT-INFO: program-wide dynostats after all optimizations before SCTC and FOP:

       252442941 : executed forward branches
        61129408 : taken forward branches
        65882377 : executed backward branches
        91491060 : taken backward branches
        20935230 : executed unconditional branches
        40783446 : all function calls
         3861863 : indirect calls
               0 : PLT calls
      2633654103 : executed instructions
       622982689 : executed load instructions
               0 : executed store instructions
               0 : taken jump table branches
               0 : taken unknown indirect branches
       339260548 : total branches
       173555698 : taken branches
       165704850 : non-taken conditional branches
       152620468 : taken conditional branches
       318325318 : all conditional branches
               0 : linker-inserted veneer calls

       256771272 : executed forward branches (+1.7%)
         8398867 : taken forward branches (-86.3%)
        61554046 : executed backward branches (-6.6%)
        41045295 : taken backward branches (-55.1%)
        54634181 : executed unconditional branches (+161.0%)
        40783446 : all function calls (=)
         3861863 : indirect calls (=)
               0 : PLT calls (=)
      2639262130 : executed instructions (+0.2%)
       622982689 : executed load instructions (=)
               0 : executed store instructions (=)
               0 : taken jump table branches (=)
               0 : taken unknown indirect branches (=)
       372959499 : total branches (+9.9%)
       104078343 : taken branches (-40.0%)
       268881156 : non-taken conditional branches (+62.3%)
        49444162 : taken conditional branches (-67.6%)
       318325318 : all conditional branches (=)
               0 : linker-inserted veneer calls (=)

BOLT-INFO: Starting stub-insertion pass
BOLT-INFO: Inserted 664 stubs in the hot area and 232 stubs in the cold area. Shared 0 times, iterated 3 times.
llvm-bolt: ../lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp:416: void llvm::RuntimeDyldELF::resolveAArch64Relocation(const llvm::SectionEntry&, uint64_t, uint64_t, uint32_t, int64_t): Assertion `isInt<21>(BranchImm)' failed.
#0 0x00005555563974ba llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/media/src/llvm-bolt/install/bin/llvm-bolt+0xe434ba)
#1 0x0000555556395216 llvm::sys::RunSignalHandlers() (/media/src/llvm-bolt/install/bin/llvm-bolt+0xe41216)
#2 0x00005555563955b5 SignalHandler(int) (/media/src/llvm-bolt/install/bin/llvm-bolt+0xe415b5)
#3 0x00007ffff77bb890 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12890)
#4 0x00007ffff646ce97 gsignal /build/glibc-OTsEL5/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
#5 0x00007ffff646e801 abort /build/glibc-OTsEL5/glibc-2.27/stdlib/abort.c:81:0
#6 0x00007ffff645e39a __assert_fail_base /build/glibc-OTsEL5/glibc-2.27/assert/assert.c:89:0
#7 0x00007ffff645e412 (/lib/x86_64-linux-gnu/libc.so.6+0x30412)
#8 0x000055555688ad3d llvm::RuntimeDyldELF::resolveAArch64Relocation(llvm::SectionEntry const&, unsigned long, unsigned long, unsigned int, long) (/media/src/llvm-bolt/install/bin/llvm-bolt+0x1336d3d)
#9 0x000055555688bcb1 llvm::RuntimeDyldELF::resolveRelocation(llvm::RelocationEntry const&, unsigned long) (/media/src/llvm-bolt/install/bin/llvm-bolt+0x1337cb1)
#10 0x000055555687a0bc llvm::RuntimeDyldImpl::resolveRelocationList(llvm::SmallVector<llvm::RelocationEntry, 64u> const&, unsigned long) (/media/src/llvm-bolt/install/bin/llvm-bolt+0x13260bc)
#11 0x000055555687ee5f llvm::RuntimeDyldImpl::resolveRelocations() (/media/src/llvm-bolt/install/bin/llvm-bolt+0x132ae5f)
#12 0x000055555687f21a llvm::RuntimeDyld::finalizeWithMemoryManagerLocking() (/media/src/llvm-bolt/install/bin/llvm-bolt+0x132b21a)
#13 0x00005555558b050c llvm::orc::RTDyldObjectLinkingLayer::ConcreteLinkedObject<std::shared_ptrllvm::RuntimeDyld::MemoryManager >::finalize() (/media/src/llvm-bolt/install/bin/llvm-bolt+0x35c50c)
#14 0x0000555555871c5e llvm::orc::RTDyldObjectLinkingLayer::emitAndFinalize(unsigned long) (/media/src/llvm-bolt/install/bin/llvm-bolt+0x31dc5e)
#15 0x00005555558b2928 llvm::bolt::RewriteInstance::emitAndLink() (/media/src/llvm-bolt/install/bin/llvm-bolt+0x35e928)
#16 0x00005555558b6034 llvm::bolt::RewriteInstance::run() (/media/src/llvm-bolt/install/bin/llvm-bolt+0x362034)
#17 0x0000555555738dc0 main (/media/src/llvm-bolt/install/bin/llvm-bolt+0x1e4dc0)
#18 0x00007ffff644fb97 __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:344:0
#19 0x000055555578031a _start (/media/src/llvm-bolt/install/bin/llvm-bolt+0x22c31a)
Stack dump:
0. Program arguments: /media/src/llvm-bolt/install/bin/llvm-bolt file -o file.bolt -data perf.fdata -reorder-blocks=cache+ -reorder-functions=hfsort -split-functions=2 -split-all-cold -split-eh -dyno-stats
Aborted (core dumped)
Thank you!

@maksfb
Copy link
Contributor

maksfb commented Oct 19, 2020

The log shows that the pass creates stubs, but apparently it's missing some. I'll check if we can repro the scenario internally. If you can share the binary that would be helpful too (I understand if you cannot).

@yota9
Copy link
Contributor Author

yota9 commented Oct 19, 2020

I'm sorry, but it is not possible :( But if I comment-out this assert all the symbols are in placed in binary normally, but there will be something like beq #junk_address And the place where it really should branch to will be located further than 1Mb boundary.
Thank you!

@yota9 yota9 closed this as completed Nov 17, 2020
@yota9 yota9 reopened this Nov 18, 2020
@OpenStacksh
Copy link

Hello! @maksfb @yota9
Has this problem been solved?
If it has been resolved, could you provide the solution?
Thank you!

@yota9
Copy link
Contributor Author

yota9 commented Jun 25, 2021

@OpenStacksh As I know the problem is not resolver yet. Thank you!

@yota9
Copy link
Contributor Author

yota9 commented Oct 16, 2021

@OpenStacksh I believe the problem is solved and I will close the issue now. If you will have similar problem please open new issue

@yota9 yota9 closed this as completed Oct 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants