内存映射的 gcc 链接文件,那是什么语法?
当使用 gcc 为 MCU 进行交叉编译时,您向链接器提供链接器脚本文件,以便它知道如何创建最终的目标文件。
我想了解有关此类文件的更多信息,但找不到关于这些文件如何工作、它们使用哪种语法、最佳实践是什么以及应避免什么的好教程。
下面是一个精简链接文件的示例,该文件将通过“-Tlinkfile.ld”选项提供给链接器:
MEMORY
{
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20k
rom (rx) : ORIGIN = 0x00000000, LENGTH = 128K
}
SECTIONS
{
. = 0x0; /* From 0x00000000 */
.text :
{
*(.nvic_vector) /* Vector table */
*(.text.*) /* Program code */
*(.text) /* Program code */
*(.rodata) /* Read only data */
} >rom
. = 0x20000000; /* From 0x20000000 */
.data :
{
*(.data) /* Data memory */
} >ram AT > rom
.bss :
{
*(.bss) /* Zero-filled run time allocate data memory */
} >ram AT > rom
}
/Thanks
When using gcc to cross-compile for an MCU you provide a linker script file to the linker so it knows how to create the final object file.
I would like to learn more about this type of file, but can't find a nice tutorial on how these files work, what kind of syntax they use, what are best practices, and what to avoid.
Here's an example of a stripped-down link file that would be provided to the linker with the "-Tlinkfile.ld" option:
MEMORY
{
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20k
rom (rx) : ORIGIN = 0x00000000, LENGTH = 128K
}
SECTIONS
{
. = 0x0; /* From 0x00000000 */
.text :
{
*(.nvic_vector) /* Vector table */
*(.text.*) /* Program code */
*(.text) /* Program code */
*(.rodata) /* Read only data */
} >rom
. = 0x20000000; /* From 0x20000000 */
.data :
{
*(.data) /* Data memory */
} >ram AT > rom
.bss :
{
*(.bss) /* Zero-filled run time allocate data memory */
} >ram AT > rom
}
/Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该语法记录在 GNU binutils
ld
文档 - 这更像是参考而不是教程,但其中散布着各种示例。The syntax is documented in the GNU binutils
ld
documentation - that's more of a reference than a tutorial, but there are various examples scattered through it.