链接脚本:将特定文件放在稍后的位置 [英] Linker Script: Put a particular file at a later position
问题描述
我想编写一个链接描述文件,如下所示:
I'd like to write a linker script looking something like this:
SECTIONS {
. = 0x0;
.startup . : { startup.o(.text) }
.text : { *(.text) }
.data : { *(.data) }
.bss : { *(.bss COMMON) }
. = 0x4000;
other.text : { other.o(.text) }
other.data : { other.o(.data) }
other.bss : { other.o(.bss) }
}
我的意图是按以下顺序:
My intention here is to have, in this order:
- 从
startup.o $中的
.text
c $ c> -
.text
,.data
和.bss
除了other.o
$ b还包含所有其他输入文件中的这些部分$ b -
.text
,.data
和.bss
节从other.o
- a section with the
.text
fromstartup.o
.text
,.data
and.bss
containing those sections from all other input files besidesother.o
- the
.text
,.data
and.bss
sections fromother.o
当然有问题与我给出的脚本: other.o
包含在以前使用的 *
通配符中,输入部分其他
。
Of course there is a problem with the script I've given: other.o
is included in the *
wildcards used previously, so it doesn't get put in the output section other
.
除了手动列出所有输入对象文件栏 other.o
代替 *
s,有没有办法可以实现我想要的?
Besides manually listing all the input object files bar other.o
in place of the *
s, is there a way I can achieve what I want here?
推荐答案
您可以使用部分属性来解决此问题。假设您在该文件(或任何其他文件)中声明函数时添加以下属性:
You can use section attributes to solve this. Suppose you add the following attribute when declaring functions in that file (or any other file):
void foo() __attribute__ ((section(".specialmem")));
链接描述文件中有一个类似的部分定义:
And a similar section definition in your linker script:
.specialmem:
{
*(.specialmem)
}
你也可以使用data / bss(全局变量)做同样的事情。
假设您希望某些文件/函数最终在特定的内存位置,那么在链接器文件中定义这些内存块也是一个很好的做法,然后将它们放在那里,如:
You can do the same thing with data/bss (global variables) as well. Assuming you want some files/functions to end up in a specific memory location, it is a good practice to define these memory blocks in your linker file as well and then place them there like:
.specialmem:
{
*(.specialmem)
} >specialMemBlock
这篇关于链接脚本:将特定文件放在稍后的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!