开发者

How to create runtime visible variables using GCC

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 possibl开发者_C百科e to do the same type of thing when using gcc?


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.


You can define a macro using -D option.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜