我想将一些函数放在名为" .xip.text"的特定部分中, 但只读数据不能放入该部分。
以下是我的测试代码:
#include <stdio.h>
void foo(void) __attribute__((section (".xip.text")));
void foo(void)
{
printf("hello world\n");
}
在链接描述文件中:
MEMORY
{
RAM (rwx) : ORIGIN = 0x00010000, LENGTH = 448K
FLASH (rx) : ORIGIN = 0x10000000, LENGTH = 1024K
}
SECTIONS
{
.xip :
{
*(.xip.text .xip.text.*)
*(.xip.rodata .xip.rodata.*)
} > FLASH
.text :
{
*(.text*)
} > RAM
}
链接后,功能文本放在&#34; .xip&#34;部分,但字符串 &#34;你好世界\ n&#34;不属于同一部分。怎么解决?
我可以将整个文件放在&#34; .xip&#34;部分解决了这个问题。但是我 有很多文件,我只想把一些功能放到&#34; .xip&#34;部分,不是 整个文件。
在地图文件中,foo()的文本放在右侧部分, 但字符串&#34;你好世界\ n&#34; (.rodata.str1.1)放在另一个区域。
*(.xip.text .xip.text.*)
.xip.text 0x1002f7b0 0xc ../foo.o
0x1002f7b0 foo
*fill* 0x1002f7bc 0x4
.rodata.str1.1
0x00025515 0xc ../foo.o
*fill* 0x00025521 0x3
反汇编后,
1002f7b0 <foo>:
void foo(void) __attribute__((section (".xip.text")));
void foo(void)
{
printf("hello world\n");
1002f7b0: 4801 ldr r0, [pc, #4] ; (1002f7b8 <foo+0x8>)
1002f7b2: f000 b95d b.w 1002fa70 <__puts_veneer>
1002f7b6: bf00 nop
1002f7b8: 00025515 .word 0x00025515
1002f7bc: 00000000 .word 0x00000000
gcc版本:gcc-arm-none-eabi-7-2017-q4-major,gcc版本7.2.1 20170904(发布)[ARM / embedded-7-branch revision 255204](用于ARM嵌入式处理器的GNU工具7 -2017-Q4-主要)
答案 0 :(得分:1)
功能文本放在&#34; .xip&#34;部分,但字符串&#34;你好世界\ n&#34;没有放在同一部分。
只读数据不是.text
,因此不应该放入同一部分。
如果要控制只读数据的哪个部分,则需要自己执行此操作。这样的事情应该有效:
__attribute__((section(".xip.rodata")))
const char my_xip_data[] = "hello, world\n";
void foo(void)
{
printf(my_xip_data);
}