use*_*048 5 c linux linker gcc ld
我创建了一个内存链接器脚本并将其保存为eclipse中的memory.ld:项目:属性:gcc链接器:杂项:我添加了-M -T memory.ld
memory.ld:
MEMORY
{
ram (rw) : ORIGIN = 0x4000000 , LENGTH = 2M
}
SECTIONS
{
RAM : { *(.myvarloc)
} > ram }
Run Code Online (Sandbox Code Playgroud)
在我的c程序中:我做了一个全局声明:
__attribute__ ((section(".myvarloc")))
uint8 measurements [30];
Run Code Online (Sandbox Code Playgroud)
错误:
/usr/bin/ld: FEBRUARY section `.text' will not fit in region `ram'
/usr/bin/ld: region `ram' overflowed by 20018 bytes
/usr/lib/i386-linux-gnu/libc_nonshared.a(elf-init.oS): In function `__libc_csu_init':
(.text+0x2b): undefined reference to `__init_array_end'
/usr/lib/i386-linux-gnu/libc_nonshared.a(elf-init.oS): In function `__libc_csu_init':
(.text+0x31): undefined reference to `__init_array_start'
/usr/lib/i386-linux-gnu/libc_nonshared.a(elf-init.oS): In function `__libc_csu_init':
(.text+0x57): undefined reference to `__init_array_start'
/usr/bin/ld: FEBRUARY: hidden symbol `__init_array_end' isn't defined
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
根据您使用的编译器(GCC?)和您正在编译的处理器(x86?),编译器将在目标文件中生成多个段引用。最常见的是.text代码段、.data已初始化数据和.bss未初始化数据。您可以通过nm在目标文件上使用该实用程序来查看编译器生成的段。
我假设在您提供自己的链接器脚本之前,环境已经自动和/或隐式提供了一些默认脚本。但既然你已经决定“自己动手”,你就必须自己处理所有细节。
我无法验证详细信息,但您可以从以下部分开始:
SECTIONS
{
.bss : { *(.myvarloc) }
.bss : { *(.bss) }
.data : { *(.data) }
.text : { *(.text) }
}
Run Code Online (Sandbox Code Playgroud)
我不确定这是否是您的 GCC 链接器的确切语法(这在一定程度上取决于版本),但您可以在手册中找到更多信息。
| 归档时间: |
|
| 查看次数: |
1857 次 |
| 最近记录: |