且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用GCC创建运行时可见变量

更新时间:2021-08-18 03:22:51

是的,你可以使用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.