我试图理解GCC链接脚本并创建一个小示例进行练习,但是我从ld中收到了“语法错误”。我感谢任何意见或建议。非常感谢!
hello.c
__attribute__((section(".testsection"))) volatile int testVariable;
hello.ld
MEMORY {
TEST_SECTION: ORIGIN = 0x43840000 , LENGTH = 0x50
}
SECTIONS{
.testsection: > TEST_SECTION /* Syntax error here*/
}
编译命令
gcc -T hello.ld -o hello hello.o
c:/gnu/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe:../hello.ld:20: syntax error
collect2.exe: error: ld returned 1 exit status
原始帖子
MEMORY {
TEST_SECTION: ORIGIN = 0x43840000 LENGTH = 0x50
}
SECTIONS{
.testsection: > TEST_SECTION
}
将来请标记工具抱怨的行,至少是第一个错误。
解决方案
MEMORY {
TEST_SECTION: ORIGIN = 0x43840000, LENGTH = 0x50
}
SECTIONS{
.testsection: { *(.testsection*) } > TEST_SECTION
}
我认为它缺少两件事
首先是原始值和LENGTH之间的逗号。
第二节命令丢失。我不认为gnu链接器脚本语法可以做到这一点,无论如何您可能都需要在其中添加一些内容才能使它有用。您可以尝试
.testsection: { } > TEST_SECTION
但是我的猜测是,您最终不会在该内存中存储任何内容。