内部搬迁未修复 [英] internal relocation not fixed up

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

问题描述

我最近开始为 arm 内核编写汇编程序.我的第一个小演示,只有 .text 部分,运行没有任何问题.

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

作为一个逻辑扩展,我想将汇编代码组织成通常的部分:.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.

虽然我找到了一种正确组装代码的方法,但通过替换

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

 .section .data

 .org .

这不是一个令人满意的解决方案.特别是考虑到gas文档突出了本节的意义.

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 相对访问来说太远了怎么办?由于编译器(不进行链接)不知道数据部分与文本部分的距离有多远,它会拒绝编译该代码,以防万一它不可访问.

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).

代码改编自 http://www.zap.org.au/elec2041-cdrom/examples/intro/pseudo.s

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

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