【u-boot-2018.11】源码分析之sections.c

本文介绍ARM架构下特定C文件中的内存段配置方法。通过定义零大小数组并将其放置在特定段中,确保链接器使用R_ARM_RELATIVE重定位。这种方法避免了编译器对void类型的支持限制,并解决了gcc4.4及以下版本的别名问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

arch/arm/lib/sections.c:

/*
这两个符号在一个C文件中声明,因此链接器使用R_ARM_RELATIVE重定位,而不是在链接器文件中定义符号时
使用的R_ARM_ABS32。仅使用R_ARM_RELATIVE重新定位可确保对符号的引用在重新定位之后和之前都是正确
的。
对于这些符号,我们需要一个0字节大小的类型,而编译器不允许定义C类型的对象“void”。编译器允许使用空
结构,但这会导致gcc 4.4及以下版本出现别名问题。因此,我们使用下一个最好的东西:零大小的数组,它既
是0字节大小的,又不受别名警告的影响。
*/

char __bss_start[0] __attribute__((section(".__bss_start")));
char __bss_end[0] __attribute__((section(".__bss_end")));
char __image_copy_start[0] __attribute__((section(".__image_copy_start")));
char __image_copy_end[0] __attribute__((section(".__image_copy_end")));
char __rel_dyn_start[0] __attribute__((section(".__rel_dyn_start")));
char __rel_dyn_end[0] __attribute__((section(".__rel_dyn_end")));
char __secure_start[0] __attribute__((section(".__secure_start")));
char __secure_end[0] __attribute__((section(".__secure_end")));
char __secure_stack_start[0] __attribute__((section(".__secure_stack_start")));
char __secure_stack_end[0] __attribute__((section(".__secure_stack_end")));
char __efi_runtime_start[0] __attribute__((section(".__efi_runtime_start")));
char __efi_runtime_stop[0] __attribute__((section(".__efi_runtime_stop")));
char __efi_runtime_rel_start[0] __attribute__((section(".__efi_runtime_rel_start")));
char __efi_runtime_rel_stop[0] __attribute__((section(".__efi_runtime_rel_stop")));
char _end[0] __attribute__((section(".__end")));

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值