如何使用GCC创建运行时可见变量 [英] How to create runtime visible variables using GCC

查看:250
本文介绍了如何使用GCC创建运行时可见变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Green Hill编译器,可以在运行时可见的链接器中创建变量。在链接器中:

__ ghs_ramstart = MEMADDR(dram_memory);

在代码中:

if(__ghs_ramstart == 0){do something}

使用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 possible to do the same type of thing when using gcc?

推荐答案

是的,你可以使用GNU ld链接器脚本来做到这一点。 http://sourceware.org/binutils/docs-2.21/ld/Scripts .html#脚本您可以在可从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;

并从C访问,例如

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.

这篇关于如何使用GCC创建运行时可见变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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