已开启
AArch64 的 reset_tsv110_option 在交叉编译场景错误依赖宿主机 /proc/cpuinfo #89
super dog.创建于 5月14日
5月14日 添加了label:sig/Compiler
openeuler-ci-bot
5月14日 评论:
5月14日 评论:
Welcome To openEuler Community
Hey @papertager , thanks for your contribution to the community.
Bot Usage Manual
I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands.
Contact Guide
If you have any questions, please contact the SIG: Compiler ,
and any of the maintainers: @SegFault, @alexanderbill, @cf-zhao, @chenzheng1030, @eastb233, @kuenking111_admin, @li-yancheng, @wangqiang95, @wd-gitcode ,
and any of the committers: @huang-xiaoquan, @lin-4682, @xiongzhou4 .


9月9日 关联了pull request:AArch64: avoid host CPU detection for TSV110 defaults
问题描述
在
gcc/common/config/aarch64/aarch64-common.cc中,aarch64_handle_option()会在处理 AArch64 选项时无条件调用reset_tsv110_option()。该函数会读取宿主机/proc/cpuinfo,并在检测到vendor_id == 0x48 && part_id == 0xd01时把默认的aarch64_flag_outline_atomics从2改成0。这意味着在 Kunpeng 宿主机上执行交叉编译时,即使目标 CPU 并不是当前宿主机型号,编译器默认代码生成行为也会被宿主机环境悄悄影响,最终导致同一份命令行在不同构建机上产生不同的默认 AArch64 代码路径。
根因分析
reset_tsv110_option()的调用位置过早且过宽。当前它在aarch64_handle_option()中被无条件执行,而不是只在明确选中了相关目标 CPU 时执行。/proc/cpuinfo,而不是用户通过-mcpu/-march指定的目标 CPU 信息,因此天然不适合交叉编译场景。vendor_id == 0x48 && part_id == 0xd01,就会把默认outline-atomics策略改写为0,从而把“宿主机特征”错误带入“目标机代码生成策略”。修复方向
建议把这段逻辑收敛到真正与目标 CPU 绑定的路径上,避免宿主机状态污染目标代码生成:
/proc/cpuinfo决定目标机默认行为。outline-atomics,建议改为基于-mcpu/-mtune的目标信息做判断,或改成显式开关,而不是隐式宿主机探测。