试图加载位置无关code上的Cortex-M3 [英] Trying to load position independent code on cortex-m3

查看:324
本文介绍了试图加载位置无关code上的Cortex-M3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个嵌入式应用里面会有一个引导程序,这将决定直接从内部闪存的两个应用程序的运行1。我试图让这些应用与位置无关的,这样它们都可以为相同的基地址进行编译。没有操作系统,所以没有动态连接器是可用的。到目前为止,我已经尝试用不太多的成功-fPIE选项(使用gcc)建设。函数调用似乎是正确的,但全局数据不具有正确的地址。本地定义的全局数据似乎有它的地址通过应用从原来的基地址的偏移量抵消。这是在其他文件中声明的全局数据有一个完全错误的地址(如果我建立与-fpic那么无论是局部声明全局数据和全局数据在其他文件是完全错误的)。我怀疑我需要做我的应用程序启动时,GOT节的一些处理,但我不知道。

I have an embedded application which will have a bootloader which will decide to run 1 of two applications directly from internal flash. I am trying to make these apps position independent so that they both can be compiled for the same base address. There is no operating system, so no dynamic linker is available. So far I have tried building with -fpie option (using gcc) with not too much success. The function calls appear to be correct but the global data does not have the correct address. The locally defined global data seems to have it's address offset by the amount that the app is offset from its original base address. The global data which is declared in other files has a completely wrong address(and if I build with -fpic then both the locally declared global data and global data in other files are completely wrong). I suspect I need to do some manipulation of the GOT section when my app starts but I am not sure.

推荐答案

我终于得到了它的工作。它看起来像我需要做到以下几点:
所有code需要与-fpic(previously我试图-fPIE)

I finally got it working. It looks like I need to do the following: All code needs to be complied with -fpic (previously I was trying -fpie)

另外我有我的链接脚本修改程序。我被强迫坐进SRAM部分,它位于动力部分,它在闪光后。看起来如果GOT部分之前在flash动态部分位于就像一切工作正常。不知道为什么这个问题,但它似乎解决一切 - 在此之前,这是因为如果code没有正确定位GOT因为GOT有存储在其中的正确的价值观,但我的所有变量的地址是不正确的。

Also I had my linker script needed modification. I was forcing the GOT into the sram section and it was located after the dynamic section which was in flash. Looks like everything works properly if the GOT section is located prior to the dynamic section in the flash. Not sure why this matters but it seemed to fix everything - prior to this it was as if the code did not locate the GOT properly since the GOT had the correct values stored in it but the address of all my variables were incorrect.

这篇关于试图加载位置无关code上的Cortex-M3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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