Gcc:匿名字符串的内存区域
我使用 GCC 并且需要定义大的文本数组,就像
const char* myArray[1000] = {"red", "blue", "green", "yellow", ...};
我在内存中有一个指针数组和大堆文本,例如 "red\0blue\0green\0..."
。我想更改该文本的内存区域。我使用了 __attribute__((section(...)))
GCC 指令,但它们仅更改指针的分配。如何更改大文本块的分配?感谢您的回答。
PS 抱歉英语不好。
I used GCC and need to define big array of text, like
const char* myArray[1000] = {"red", "blue", "green", "yellow", ...};
I have a array of pointers and big heap of text like "red\0blue\0green\0..."
somewere in memory. I want to change memory region for that text. I used __attribute__((section(...)))
GCC directive, but they change only allocation of pointers. How can i change allocation of big text chunk? Thanks for answers.
P.S. Sorry for bad English.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将 -fdata-sections 与 gcc 一起使用。这将为目标文件中的每个全局变量创建一个唯一的部分。
然后您可以创建一个 LdScript 文件,该文件将告诉链接器 (ld) 将这些节放入所需的内存区域。
匿名字符串位于目标文件的 .rodata 部分中。 LdScript 示例片段:
将 Startup.c 中的 str1.8 放入 memregion1。
You can use -fdata-sections with gcc. That will create a unique section for each global variable in the object-file.
Then you can create a LdScript-file which will tell the linker (ld) to put the sections into the desired memory region.
Anonymous strings are in the .rodata-section of the object-file. An LdScript-example snippet:
will put the str1.8 from Startup.c into the memregion1.