Skip to content

BOLT issue with Android: annotation value out of range #139245

@mgxhhg

Description

@mgxhhg

A third party has an Android NDK for arm64 linux, so I configured it into an Android chroot container. In order to run pgo (--enable-optimizations), I configured Android's linker64 into the container, but I found that Bolt would crash once it encountered the annotation/relocation section of the dynamic library.

Checked 111 modules (31 built-in, 74 shared, 1 n/a on linux-aarch64, 0 disabled, 5 missing, 0 failed on import)
make[2]: 离开目录“/home/sed/cpython/build”
make[1]: 离开目录“/home/sed/cpython/build”                                         
make profile-bolt-stamp                                                            
make[1]: 进入目录“/home/sed/cpython/build”                                         
# Ensure a pristine, pre-BOLT copy of the binary and no profile data from last run.for bin in python libpython3.12.so.1.0; do \                                         prebolt="${bin}.prebolt"; \                                                        
if [ -e "${prebolt}" ]; then \                                                       
echo "Restoring pre-BOLT binary ${prebolt}"; \                                     
mv "${bin}.prebolt" "${bin}"; \                                                  
fi; \                                                                              
cp "${bin}" "${prebolt}"; \                                                        
rm -f ${bin}.bolt.*.fdata ${bin}.fdata; \                                        
done                                                                               
# Instrument each binary.                                                          
for bin in python libpython3.12.so.1.0; do \                                         
/home/sed/android-ndk-r29-beta2/toolchains/llvm/prebuilt/linux-arm64/bin/aarch64-linux-android-llvm-bolt "${bin}" -instrument -instrumentation-file-append-pid -instrumentation-file=/home/sed/cpython/build/${bin}.bolt -o ${bin}.bolt_inst -update-debug-sections -skip-funcs=_PyEval_EvalFrameDefault,sre_ucs1_match/1,sre_ucs2_match/1,sre_ucs4_match/1 ;
 \                                                                
mv "${bin}.bolt_inst" "${bin}"; \                                                
done                                                                               
BOLT-INFO: shared object or position-independent executable detected               
BOLT-INFO: Target architecture: aarch64                                            
BOLT-INFO: BOLT version: <unknown>                                                 
BOLT-INFO: first alloc address is 0x0                                              
BOLT-INFO: creating new program header table at address 0x200000, offset 0x200000  
BOLT-INFO: enabling relocation mode                                                
BOLT-INFO: forcing -jump-tables=move for instrumentation 
LLVM ERROR: annotation value out of range                                          
LLVM ERROR: annotation value out of range                                          
LLVM ERROR: annotation value out of range                                          
Aborted    
make[1]: *** [Makefile:848:profile-bolt-stamp] 错误 134                           
make[1]: 离开目录“/home/sed/cpython/build”                                         
make: *** [Makefile:877:bolt-opt] 错误 2

AI:

Cause:

ELF layout in Android/PIE mode

Your llvm-bolt is in PIE + relocation mode.

The Android64 linker parses the .note / .annotation section slightly differently than GNU ld/ld.lld, causing BOLT to insert an invalid value for the annotation counter.

"annotation value out of range" means the profile counter number is outside the range it can encode.

aarch64 relocation mode bug

Under AArch64, BOLT's annotation emission does not take into account the alignment/pointer size restrictions of the Android toolchain.

This is a known bug in LLVM upstream (works fine on x86-64, crashes on aarch64/PIE).

libpython3.12.so.1.0 is a PIE shared object.

Therefore, BOLT will definitely trigger relocation mode.

The shared object contains a large number of functions (over 7000). BOLT attempts to write a counter annotation for each function, which causes the annotation section to overflow.

AI:

  1. Bolt is only used for executable programs, dynamic libraries are prohibited from using Bolt
    2.Limiting Bolt Pile Range / Mode

detailed:

https://chatgpt.com/share/68d15677-7658-800c-81a5-504ae7fe874d

Metadata

Metadata

Assignees

Labels

OS-androidbuildThe build process and cross-buildpendingThe issue will be closed if no feedback is provided

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions