python / python/cpython

BOLT issue with Android: annotation value out of range

未關閉
#139,245 5 則留言 0 個 reaction 已指派 1 人 在 GitHub 檢視

@corona10 已經在處理了。

開始於 2025年9月22日。

build OS-android pending
主要語言
Python
星號
77.2k
分支
36k
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. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。