python / python/cpython

BOLT issue with Android: annotation value out of range

オープン
#139,245 コメント 5 件 リアクション 0 件 担当者 1 名 GitHub で見る

@corona10 がすでに取り組んでいます。

2025年9月22日 から。

build OS-android pending
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。