gpt4 book ai didi

gcc - "load address"和 "relocation address"有什么区别?

转载 作者:行者123 更新时间:2023-12-01 05:05:30 31 4
gpt4 key购买 nike

关于AT (...) ld 的指令, this source状态:
AT ( ldadr )
The expression ldadr that follows the AT keyword specifies the load address of the section. The default (if you do not use the AT keyword) is to make the load address the same as the relocation address. This feature is designed to make it easy to build a ROM image.

我一直在搜索,但没有找到“加载地址”和“重定位地址”的明确定义。

我知道当目标文件链接在一起时,代码在跳转地址中被“重新定位”,等等被重写以指向组合机器代码中的正确偏移量。那么,“重定位地址”是一个部分开始的结果目标代码中的偏移量吗?如果是这样,一个部分的“加载地址”怎么可能有所不同?

如果这两个地址不同,链接器的输出将如何受到影响?

最佳答案

差异至关重要。重定位地址添加到节中的所有重定位。因此,如果它与加载地址不同,则在此部分中什么都不会真正起作用 - 部分内的所有 reloc 都将被解析为错误的值。

那么为什么我们需要这样的技术呢?应用程序不多,但假设 ( from here ) 您的架构上确实有 0x1000 的极快内存

那么你可以取两个部分来获得重定位地址 0x1000:

.text0 0x1000 : AT (0x4000) { o1/*.o(.text) }
__load_start_text0 = LOADADDR (.text0);
__load_stop_text0 = LOADADDR (.text0) + SIZEOF (.text0);
.text1 0x1000 : AT (0x4000 + SIZEOF (.text0)) { o2/*.o(.text) }
__load_start_text1 = LOADADDR (.text1);
__load_stop_text1 = LOADADDR (.text1) + SIZEOF (.text1);
. = 0x1000 + MAX (SIZEOF (.text0), SIZEOF (.text1));

现在在运行时继续,当你需要 text1 时,自己管理它从它的实际加载地址复制到正确的地址:
extern char __load_start_text1, __load_stop_text1;
memcpy ((char *) 0x1000, &__load_start_text1,
&__load_stop_text1 - &__load_start_text1);

然后用它, 加载时 这里自然。这种技术称为叠加。

我认为,例子很清楚。

关于gcc - "load address"和 "relocation address"有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29271886/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com