内部搬迁不固定起来 [英] internal relocation not fixed up

查看:480
本文介绍了内部搬迁不固定起来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我开始对ARM内核的汇编程序。我的第一个小演示,只有.text段,运行没有任何问题。

i recently started assembler programming for arm cores. My first little demos, only with the .text section, ran without any problems.

作为一个合乎逻辑的延伸我想构造汇编code到常见的段:.text段,.data和.bss

As a logical extension i wanted to structure the assembler code into the usual sections: .text, .data, .bss .

所以我写了下面的简单程序:

So i wrote the following simple program:

 .globl _start

 .section .text

 _start:
     b   main
     b   .
     b   .
     b   .
     b   .
     b   .
     b   .
     b   .  


 main:
    ldr r0, x
    nop

 .section .data

 x:  .word  0xf0f0f0f0

 .end

  /opt/arm/bin/arm-as -ggdb -mcpu=arm7tdmi demo.s -o demo.o

与错误退出

 prog.s: Assembler messages:
 prog.s:17: Error: internal_relocation (type: OFFSET_IMM) not fixed up
 make: *** [prog.o] Error 1

我不知道为什么汇编抱怨搬迁,因为我认为这是链接器的任务。我能想象,我要告诉我的.data段不位于在组装阶段的最后记忆现在的位置汇编程序,但我找不到任何相关。

I have no clue why the assembler complains about relocation, because i thought that's the task of the linker. I could imagine that i have to tell the assembler that my .data section isn't located at the final memory postion at the assembling stage, but i can't find anything related.

虽然我找到了一种方法来获取code正确组装,通过更换

Although i found a way to get the code assembled correctly, by replacing

 .section .data

 .org .

这并不是一个令人满意的解决方案。特别是鉴于这样的事实,该气体文档突出该部分的感

that is not a satisfying solution. Especially in view of the fact that the gas documentation highlight the sense of this section.

也许你专家有人能帮助我获得一些智慧

Maybe someone of you experts can help me to gain some wisdom

推荐答案

看来你可以做到这一点是通过抓取变量的地址并加载来自该地址的值的唯一途径。

It seems the only way you can do it is by grabbing the address of the variable and load a value from that address.

ldr r1,=x    ; get address of x
ldr r0,[r1]  ; load from that address

在某种程度上,这也是一种很有意义。毕竟,如果x(链接后)的地址是太远了PC相对接?由于编译器(不进行链接)不知道数据的部分可多远从文本部分,它会拒绝编译code以防万一它不可达。

In a way, this also kind of makes sense. After all, what if the address of x (after linking) is too far away for a PC relative access? Since the compiler (which doesn't do the linking) does not know how far away the data section may be from the text section, it would refuse to compile that code just in case it isn't reachable.

通过使用访问一个变量的这种间接的方式,可以保证变量将是可到达(或至少编译器可以确保该变量是否可达与否)。

By using this indirect way of accessing a variable, it is guaranteed that the variable will be reachable (or at least the compiler can be sure whether the variable is reachable or not).

code改编自<一个href=\"http://www.zap.org.au/elec2041-cdrom/examples/intro/pseudo.s\">http://www.zap.org.au/elec2041-cdrom/examples/intro/pseudo.s

这篇关于内部搬迁不固定起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆