开发者

.rodata relocation related question

I'm trying to write a C program for a machine with no virtual memory(or O.S. to be more precise), and I'm running into some difficulties with the .rodata section, or more precisely the stuff that goes there. The problem arises that although the sections are positioned at well defined addresses during linking, when the program goes into execution, it is being relocated.

e.g.: Let's say that my program starts is linked to start at 0x1000, when it is being executed it what should be at 0x1000 is relocated at 0xff1000.

These being said, my problem is that the stuff that usually goes into .rodata are开发者_开发知识库 "hardcoded" by the compiler(gcc), and i kinda lose said .rodata constants in memory because of the relocation and the gcc hardcoding their addresses so that they get an absolute offset instead of a relative one.

Is there a way that I can get the .rodata constants to have a relative offset instead of an absolute one. And by relative, I mean relative to any active process registers?


Depending on the architecture, It may be possible that the .rodata is arbitrally relocated to a specific memory area (a ROM for instance). This kind of information can be found in your machine datasheet. If you are in this case, you have to tell the link to put your .rodata section in the right area, using a linker script. A good overview of how GCC linker scripts work can be found here:

http://www.scoberlin.de/content/media/http/informatik/gcc_docs/ld_3.html

Moreover, you can easily find a lot of architecture-specific link scripts on the internet.

Hope that helped!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜