[LinkerScript.5] 简单的链接器脚本命令: 文件命令 - Simple Linker Script Commands: File Commands


Several linker script commands deal with files.
与文件处理相关的一些链接器脚本命令


INCLUDE filename
---------------------------------------------------------------

Include the linker script filename at this point. The file will be searched for in the current directory, and in any directory specified with the -L option. 

You can nest calls to INCLUDE up to 10 levels deep.

You can place INCLUDE directives at the top level, in MEMORY or SECTIONS commands, or in output section descriptions. 

包含文件名到这个点上。链接器将在当前目录和“-L”选项指定的目录下搜索该文件。

你可以嵌套调用INCLUDE高达10级之深.

你可以把INCLUDE指令放置在文件的最顶端,或在MEMORY或SECTIONS命令中,或者在输出section描述中.


INPUT(file, file, ...)
INPUT(file file ...)

-------------------------------------------------

The INPUT command directs the linker to include the named files in the link, as though they were named on the command line.
For example, if you always want to include subr.o any time you do a link, but you can't be bothered to put it on every link command line, then you can put ‘INPUT (subr.o)’ in your linker script.
In fact, if you like, you can list all of your input files in the linker script, and then invoke the linker with nothing but a ‘-T’ option.


INPUT命令可以使链接器包含链接中的文件,就好像它们在命令行中直接被命名一样.

比如,如果你总是想要在任何时候做一个链接来包含subr.o,但是你又不想每次写一次链接命令行,那么你可以把'INPUT(subr.o)'放在你的链接脚本中.

其实,如果你喜欢,你可以在链接器脚本中链接所有你的输入文件,然后调用只带'-T‘选项的链接器


In case a sysroot prefix is configured, and the filename starts with the ‘/’ character, and the script being processed was located inside the sysroot prefix, the filename will be looked for in the sysroot prefix. Otherwise, the linker will try to open the file in the current directory. If it is not found, the linker will search through the archive library search path. See the description of ‘-L’ in Command Line Options.

万一sysroot前缀被配置了,则文件名是以'/'开始的,执行脚本会被定位在sysroot前缀中,并在sysroot前缀中搜索文件. 否则,链接器将尝试在当前目录中打开文件。如果没有发现,链接器将通过档案库搜索路径搜索。请查看命令行选项‘-L’的描述。


If you use ‘INPUT (-lfile)’, ld will transform the name to libfile.a, as with the command line argument ‘-l’.

如果你使用‘ INPUT(-lfile)',那么ld将转换名称为libfile.a,如同命令行参数'-l'一样.


When you use the INPUT command in an implicit linker script, the files will be included in the link at the point at which the linker script file is included. This can affect archive searching. 

当你在隐式链接器脚本中使用INPUT命令时,这些文件将被包含到的链接位置就是链接器脚本文件被包含的位置。这会影响档案搜索.


GROUP(file, file, ...)
GROUP(file file ...)

-------------------------------------------------
The GROUP command is like INPUT, except that the named files should all be archives, and they are searched repeatedly until no new undefined references are created. See the description of ‘ -( ’ in Command Line Options. 

GROUP命令是象INPUT,除了命名的文件都必须是档案外,这些文件将被重复地搜索直到没有新的未定义引用被创建。

请查看命令行选项‘-(‘的描述。


AS_NEEDED(file, file, ...)
AS_NEEDED(file file ...)

-------------------------------------
This construct can appear only inside of the INPUT or GROUP commands, among other filenames. The files listed will be handled as if they appear directly in the INPUT or GROUP commands, with the exception of ELF shared libraries, that will be added only when they are actually needed. This construct essentially enables --as-needed option for all the files listed inside of it and restores previous --as-needed resp. --no-as-needed setting afterwards. 

在其它文件名之中,这个结构仅仅出现在INPUT或GROUP命令里面.文件列表将被处理,就好像它们直接出现在INPUT或GROUP命令当中一样,唯有ELF共享库例外,仅当真正需要它们时共享才会被添加。这个结构本来就为在它里面的文件使能了 --as-needed 选项,并且在--no-as-needed配置之后恢复先前的--as-needed.


OUTPUT(filename)

--------------------------------
The OUTPUT command names the output file. Using OUTPUT(filename) in the linker script is exactly like using ‘-o filename’ on the command line (see Command Line Options). If both are used, the command line option takes precedence.
You can use the OUTPUT command to define a default name for the output file other than the usual default of a.out. 


OUTPUT命令定义了输出文件. 在链接器脚本中使用OUTPUT(filename),其实就是命令行中使用“-o filename"(请查看命令行选项)。如果两者都使用了,优先使用命令行选项。除了通常默认的a.out之外,你可以使用OUTPUT命令去定义一个的默认的输出文件名.




SEARCH_DIR(path)

-----------------------------------
The SEARCH_DIR command adds path to the list of paths where ld looks for archive libraries. Using SEARCH_DIR(path) is exactly like using ‘-L path’ on the command line (see Command Line Options). If both are used, then the linker will search both paths. Paths specified using the command line option are searched first. 

SEARCH_DIR命令添加路径到ld搜索档案库的路径列表. 其实使用SEARCH_DIR(path)就是使肉用命令行选项“-L path"(请参考命令行选项)。如果两者都被使用,链接器将搜索这两个配置的路径。使用命令行选项指定的路径会被优先搜索。



STARTUP(filename)

------------------------------------
The STARTUP command is just like the INPUT command, except that filename will become the first input file to be linked, as though it were specified first on the command line. This may be useful when using a system in which the entry point is always the start of the first file.

STARTUP命令非常象INPUT命令,但它的文件名称将成为第一个被链接的输入文件,就象在命令行中第一个被指定链接的文件.这可能是很有用的,当使用系统时,入口总是被放在第一个文件的开始






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值