Gcc:匿名字符串的内存区域

发布于 2024-11-28 14:27:44 字数 312 浏览 1 评论 0原文

我使用 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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

因为看清所以看轻 2024-12-05 14:27:44

您可以将 -fdata-sections 与 gcc 一起使用。这将为目标文件中的每个全局变量创建一个唯一的部分。

然后您可以创建一个 LdScript 文件,该文件将告诉链接器 (ld) 将这些节放入所需的内存区域。

匿名字符串位于目标文件的 .rodata 部分中。 LdScript 示例片段:

.memregion1.rodata :
{ 
    Startup.c.obj(.rodata.str1.8)
}

将 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:

.memregion1.rodata :
{ 
    Startup.c.obj(.rodata.str1.8)
}

will put the str1.8 from Startup.c into the memregion1.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文