How to create runtime visible variables using GCC

时光总嘲笑我的痴心妄想 提交于 2019-12-11 12:03:08

问题


With the Green Hill compiler it is possible to create variables in the linker that is visible at runtime. In the linker:
__ghs_ramstart = MEMADDR(dram_memory);
In the code:
if (__ghs_ramstart == 0) {do something}
Is it possible to do the same type of thing when using gcc?


回答1:


Yes, you can do that using GNU ld linker scripting. http://sourceware.org/binutils/docs-2.21/ld/Scripts.html#Scripts You can defined symbols in scripts that are accessible from gcc. I've also used scripts to create data tables (an array of addresses, for example).

In the linker script, you can say something like

__ghs_ramstart = dram_memory;

and access it from C, e.g.

extern char __ghs_ramstart[];

...

You may need to add or remove a leading underscore, depending on your target. Some targets add them to symbols, some do not.




回答2:


You can define a macro using -D option.



来源:https://stackoverflow.com/questions/6278219/how-to-create-runtime-visible-variables-using-gcc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!