编译arm64架构linux-imx内核遇对齐错误及警告求助
交叉编译ARM64内核的编译错误与警告处理
使用CROSS_COMPILE=arm-none-eabi-交叉编译linux-imx仓库的ARM64架构内核时,执行make命令出现以下警告与编译错误:
linux-imx$ make warning: ld does not support --fix-cortex-a53-843419; kernel may be susceptible to erratum warning: LSE atomics not supported by binutils In file included from ././include/linux/compiler_types.h:65, from <command-line>: ./include/linux/smp.h:34:26: error: requested alignment '20' is not a positive power of 2 34 | __aligned(sizeof(struct __call_single_data)); | ^~~~~~~~~~~~~~~~~~ ./include/linux/compiler_attributes.h:33:68: note: in definition of macro '__aligned' 33 | #define __aligned(x) __attribute__((__aligned__(x))) | ^ In file included from ./arch/arm64/include/asm/thread_info.h:17, from ./include/linux/thread_info.h:60, from ./arch/arm64/include/asm/preempt.h:5, from ./include/linux/preempt.h:78, from ./include/linux/smp.h:110, from ./include/linux/lockdep.h:14, from ./include/linux/mutex.h:17, from ./include/linux/kernfs.h:12, from ./include/linux/sysfs.h:16, from ./include/linux/kobject.h:20, from ./include/linux/of.h:17, from ./include/linux/irqdomain.h:35, from ./include/linux/acpi.h:13, from ./include/acpi/apei.h:9, from ./include/acpi/ghes.h:5, from ./include/linux/arm_sdei.h:8, from arch/arm64/kernel/asm-offsets.c:10: ./arch/arm64/include/asm/memory.h: In function 'kaslr_offset': ./arch/arm64/include/asm/memory.h:62:33: warning: left shift count >= width of type [-Wshift-count-overflow] 62 | #define _PAGE_END(va) (-(UL(1) << ((va) - 1))) | ^~
以下是针对性的解决方法:
1. 核心编译错误:对齐值非2的幂
错误根源是使用了32位ARM工具链编译ARM64内核:arm-none-eabi-是针对32位ARM(AArch32)的工具链,计算struct __call_single_data大小为20字节,而ARM64要求内存对齐值必须是2的幂,直接触发编译失败。
解决步骤:
- 替换为64位ARM交叉编译工具链,例如
aarch64-none-linux-gnu-(专门针对ARM64架构的工具链)。 - 重新设置环境变量:
export ARCH=arm64 export CROSS_COMPILE=aarch64-none-linux-gnu- - 清理旧编译残留并重新编译:
make distclean make <你的_defconfig文件名> # 例如 make imx8mp_var_defconfig make -j$(nproc)
2. ld不支持Cortex-A53 843419补丁警告
该警告表示当前链接器版本过旧,无法处理Cortex-A53的843419硬件漏洞补丁,内核运行时可能受该漏洞影响。
解决方法:
- 优先方案:更新交叉编译工具链到GCC 8及以上版本,新版本binutils默认支持该补丁选项。
- 临时方案:禁用内核的该补丁支持:
执行make menuconfig,进入Kernel Features->ARM errata,取消勾选Cortex-A53: 843419选项,保存配置后重新编译。
3. LSE原子操作不支持警告
LSE是ARM64的原子操作扩展,旧版本binutils不支持该特性,导致编译警告。
解决方法:
- 优先方案:更新到支持LSE的工具链(GCC 7及以上版本的
aarch64-none-linux-gnu-)。 - 临时方案:禁用LSE支持:
执行make menuconfig,进入Kernel Features->Enable LSE atomics,取消勾选该选项,保存配置后重新编译。
4. 左移计数溢出警告
该警告是32位工具链编译ARM64代码导致的:UL(1)被识别为32位无符号长整型,左移位数超过32位宽度触发溢出。切换到64位工具链后,UL(1)会被解析为64位类型,此警告自动消失。
内容的提问来源于stack exchange,提问作者Mars Z'uh
相关产品推荐
相关产品推荐

