链接脚本为什么会有多个部分命令? [英] Why would a linker script have multiple section commands?
问题描述
我一直在阅读部分文档ld 并不清楚.
I have been reading the sections documentation for ld and something isn't clear.
给出部分链接脚本:
MEMORY
{
FLASH1 (rx) : ORIGIN = 0x000FB000, LENGTH = 0x05000
FLASH2 (r) : ORIGIN = 0x000FA000, LENGTH = 0x01000
}
SECTIONS
{
.some_code :
{
KEEP(*(SORT(.some_code*)))
} > FLASH1
}
SECTIONS
{
.my_page :
{
KEEP(*(SORT(.my_page*)))
} > FLASH2
}
是否有理由在单个链接程序脚本中包含两个以上的分区命令,而不是在下面的一个分区命令中全部包含这些命令?
Is there ever a reason to have 2 section commands in a single linker script as above rather than having it all in 1 section commands as below?
SECTIONS
{
.some_code :
{
KEEP(*(SORT(.some_code*)))
} > FLASH1
.my_page :
{
KEEP(*(SORT(.my_page*)))
} > FLASH2
}
或者它们是等效的.还有其他情况需要将其拆分吗?
Or are they equivalent. Are there other cases where you'd want to split it up like that?
其他说明:我要问的是要有单独的"SECTIONS"命令(每个命令都有自己的节定义块),而不是在问为什么要有单独的节.
Additional clarification: I am asking for a reason to have separate "SECTIONS" commands (each with their own block of section definitions) not asking for the reason for having separate sections in general.
推荐答案
从来没有不可避免地需要编写多个SECTIONS
命令,
或MEMORY
命令(在链接描述文件中).
There isn't ever an unavoidable need to write more than one SECTIONS
command,
or MEMORY
command, in a linker script.
SECTIONS
{
/* Commands... */
}
SECTIONS
{
/* More commands... */
}
等效于:
SECTIONS
{
/* Commands... */
/* More commands... */
}
,对于MEMORY
同样.
但是,平凡的链接描述文件的可维护性是
如果链接描述文件可以包含多个SECTIONS
或MEMORY
,则将为您提供帮助
命令.例如.如果:
However, the maintainability of a non-trivial body of linker-scripts is
assisted if a linker script can include multiple SECTIONS
or MEMORY
commands. E.g. if:
foobar.lds(1)
MEMORY
{
FOOMEM (rx) : ORIGIN = 0x000FB000, LENGTH = 0x05000
BARMEM (r) : ORIGIN = 0x000FA000, LENGTH = 0x01000
}
SECTIONS
{
.foo : {
*(.foo)
} > FOOMEM
.bar : {
*(.bar)
} > BARMEM
}
有些琐碎的事情,它可能会更好地重构为:
were something much less trivial than it is, it might be better refactored as:
foobar.lds(2)
INCLUDE ./foo.lds
INCLUDE ./bar.lds
foo.lds
MEMORY
{
FOOMEM (rx) : ORIGIN = 0x000FB000, LENGTH = 0x05000
}
SECTIONS
{
.foo : {
*(.foo)
} > FOOMEM
}
bar.lds
MEMORY
{
BARMEM (r) : ORIGIN = 0x000FA000, LENGTH = 0x01000
}
SECTIONS
{
.bar : {
*(.bar)
} > BARMEM
}
,以便foobar.lds
(2)被链接器扩展为
so that foobar.lds
(2) is expanded by the linker to
foobar.lds(3)
MEMORY
{
FOOMEM (rx) : ORIGIN = 0x000FB000, LENGTH = 0x05000
}
SECTIONS
{
.foo : {
*(.foo)
} > FOOMEM
}
MEMORY
{
BARMEM (r) : ORIGIN = 0x000FA000, LENGTH = 0x01000
}
SECTIONS
{
.bar : {
*(.bar)
} > BARMEM
}
历史记录:在过去的这个过时的GNU ld
手册,
我们可以找到约束条件:
An historical note: In this obselete GNU ld
manual from bygone days,
we can find the constraints:
您可以在一个脚本文件中最多使用一个SECTIONS命令,但是您可以根据需要在其中包含许多语句.
You may use at most one SECTIONS command in a script file, but you can have as many statements within it as you wish.
和:
一个命令文件最多可以包含MEMORY命令的一种用法;但是,您可以在其中定义任意数量的内存块.
A command file may contain at most one use of the MEMORY command; however, you can define as many blocks of memory within it as you wish.
当前手册中没有的
这篇关于链接脚本为什么会有多个部分命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!