[LinkerScript.18] SECTION命令: Input Section Description : 输入section的基础

来源:互联网 发布:非诚勿扰灭灯软件逗拍 编辑:程序博客网 时间:2024/06/17 03:12

An input section description consists of a file name optionally followed by a list of section names in parentheses.

The file name and the section name may be wildcard patterns, which we describe further below (see Input Section Wildcards).

一个输入section描述由一个文件名,后面加上在大括号里的可选的一组section名称所组成.


The most common input section description is to include all input sections with a particular name in the output section. For example, to include all input ‘.text’ sections, you would write:

大多数公共输入section描述会在输出section中使用一个特殊的名称来包含所有输入section. 比如, 包含所有输入'.text'section,你可以这样写:

     *(.text)

Here the ‘*’ is a wildcard which matches any file name. To exclude a list of files from matching the file name wildcard, EXCLUDE_FILE may be used to match all files except the ones specified in the EXCLUDE_FILE list. For example:

这里的'*'是一个用于匹配所有文件名的通配符. 要从配置文件名的通配符中排除一组文件, 使用EXCLUDE_FILE可以在所有匹配文件中排除EXCLUDE_FILE列表中指定的文件. 比如:

     *(EXCLUDE_FILE (*crtend.o *otherfile.o) .ctors)

will cause all .ctors sections from all files except crtend.o and otherfile.o to be included.

There are two ways to include more than one section:

在所有文件中,使.ctors sections不会包含crtend.o和otherfile.o.

有两种方法用于包含多于一个section:

     *(.text .rdata)     *(.text) *(.rdata)

The difference between these is the order in which the ‘.text’ and ‘.rdata’ input sections will appear in the output section. In the first example, they will be intermingled, appearing in the same order as they are found in the linker input. In the second example, all ‘.text’ input sections will appear first, followed by all ‘.rdata’ input sections.

它们之间的不同是在输出section中'.text'和'.rdata'输入section出现的顺序. 第一个例子中,这两个section将被混合一起,按照链接器输入的顺序排布.在第二个例子中, 所有'.text'输入section将先出现, 随后跟上所有'.rdata'输入section.


You can specify a file name to include sections from a particular file. You would do this if one or more of your files contain special data that needs to be at a particular location in memory. For example:

你可以指定一个文件名来实现中包含一个特定文件的section. 如果一个或多个文件的特殊数据需要被放在存储中的指定位置, 你就应该这样做.比如

     data.o(.data)

To refine the sections that are included based on the section flags of an input section, INPUT_SECTION_FLAGS may be used.

基于输入section的section flags改善被包含的section, INPUT_SECTION_FLAGS可以被使用.


Here is a simple example for using Section header flags for ELF sections:

这是一个关于使用ELF section的section头部flags的简单实例:

     SECTIONS {       .text : { INPUT_SECTION_FLAGS (SHF_MERGE & SHF_STRINGS) *(.text) }       .text2 :  { INPUT_SECTION_FLAGS (!SHF_WRITE) *(.text) }     }

In this example, the output section ‘.text’ will be comprised of any input section matching the name *(.text) whose section header flags SHF_MERGE and SHF_STRINGS are set. The output section ‘.text2’ will be comprised of any input section matching the name *(.text) whose section header flag SHF_WRITE is clear.

在这个例子中, 输出section '.text'将由匹配了*(.text)并且section头部标志SHF_MERGE和SHF_STGRINGS被设置的输入section组成. 输出section '.text2'将由匹配了*(.text)并且section头部标志SHF_WRITE被清除的输入section组成.


You can also specify files within archives by writing a pattern matching the archive, a colon, then the pattern matching the file, with no whitespace around the colon.

你也可以通过写一个模式匹配档案包,一个冒号, 然后模式匹配文件,并且冒号旁边不能带空格, 来实现指定档案包中的文件.

archive:file
matches file within archive 
匹配档案包中的文件
archive:
matches the whole archive
匹配整个档案包.
:file
matches file but not one in an archive
匹配一个文件,除了空的档案包

Either one or both of ‘archive’ and ‘file’ can contain shell wildcards. On DOS based file systems, the linker will assume that a single letter followed by a colon is a drive specifier, so ‘c:myfile.o’ is a simple file specification, not ‘myfile.o’ within an archive called ‘c’. ‘archive:file’ filespecs may also be used within an EXCLUDE_FILE list, but may not appear in other linker script contexts. For instance, you cannot extract a file from an archive by using ‘archive:file’ in an INPUTcommand.

'archive'和'file'都是可以包含shell通配符.在基于DOS文件系统上,链接器会认为单个字母后跟一个冒号是一个驱动符,因此'c:myfile.o' 是一个简单的文件文档,而不是所谓'c'档案包的文件'myfile.o'. 'archive:file'文件规范也可能被用在一个EXCLUDE_FILE列表里面,但是不能出现在其它链接器脚本的上下文中. 例如, 你不能在INPUT命令中使用'archive:file'从一个档案包中解压一个文件.


If you use a file name without a list of sections, then all sections in the input file will be included in the output section. This is not commonly done, but it may by useful on occasion. For example:

如果你使用一个没有带一组section的文件名称,那么输入文件中的所有section将被包含到输出section中. 这是不常用的做法,但是在某个场合中可能是很有用的.比如

     data.o

When you use a file name which is not an ‘archive:file’ specifier and does not contain any wild card characters, the linker will first see if you also specified the file name on the linker command line or in an INPUT command. If you did not, the linker will attempt to open the file as an input file, as though it appeared on the command line. Note that this differs from an INPUT command, because the linker will not search for the file in the archive search path.

当你使用一个不是"archive:file'标识的文件名称,并且没有包含任何通配符, 链接器将首先看你是否也在链接器命令行中或输入命令中指定文件名称.如果你没有, 链接器将尝试去以输入文件打开该文件, 就象它出现在命令行一样.  注: 这是与输入命令不同的, 因为链接器将不会在档案搜索路径中搜索文件的.



0 0
原创粉丝点击