A couple of linker script commands deal with object file formats.
处理对象文件格式的一对链接器脚本命令
OUTPUT_FORMAT(
bfdname)
OUTPUT_FORMAT(
default,
big,
little)
--------------------------------------------------------------------
The OUTPUT_FORMAT
command names the BFD format to use for the output file (see BFD). Using OUTPUT_FORMAT(
bfdname)
is exactly like using ‘--oformat bfdname’ on the command line (see Command Line Options). If both are used, the command line option takes precedence.
You can use OUTPUT_FORMAT
with three arguments to use different formats based on the ‘-EB’ and ‘-EL’ command line options. This permits the linker script to set the output format based on the desired endianness.
If neither ‘-EB’ nor ‘-EL’ are used, then the output format will be the first argument, default. If ‘-EB’ is used, the output format will be the second argument, big. If ‘-EL’ is used, the output format will be the third argument, little.
OUTPUT_FORMAT命令指定BFD格式用于定义输出文件(参看BFD).
使用OUTPUT_FORMAT(bfdname)就象使用命令行“--oformat bfdname'(参看命令行选项)。如果两者都使用,命令行选项优先。
你可以使用带三个参数的OUTPUT_FORMAT指定基于'-EB'和'-EL'命令行选项的不同格式。这样可以允许链接器脚本去设置基于某个端格式的输出格式。
如果'-EB'和'-EL'都没被使用,那么输出格式将是第一个参数,default。如果'-EB'被使用,输出格式将使用第二参数,big。如果'-EL'被使用,输出格式将是第三个参数,little。
For example, the default linker script for the MIPS ELF target uses this command:
OUTPUT_FORMAT(elf32-bigmips, elf32-bigmips, elf32-littlemips)
This says that the default format for the output file is ‘elf32-bigmips’, but if the user uses the ‘-EL’ command line option, the output file will be created in the ‘elf32-littlemips’ format.
OUTPUT_FORMAT(elf32-bigmips, elf32-bigmips, elf32-littlemips)
这说明了输出文件的默认格式是'elf32-bigmips',但是如果用户使用了‘-EL'命令行选项,输出文件将在'elf32-littlemips'格式中被创建。
TARGET(
bfdname)
----------------------------------------
The TARGET
command names the BFD format to use when reading input files. It affects subsequent INPUT
and GROUP
commands. This command is like using ‘-b bfdname’ on the command line (see Command Line Options). If the TARGET
command is used but OUTPUT_FORMAT
is not, then the last TARGET
command is also used to set the format for the output file. See BFD.
TARGET命令用于指定读取输入文件时所使用的BFD格式。它影响了随后的INPUT和GROUP命令。这条命令如同使用‘-b bfdname’命令行(参看命令行选项)。如果使用TARGET命令,而没有使用OUTPUT_FORMAT,则上一次TARGET命令也会被用于设置输出文件的格式。(参看BFD)
意思是:TARGET主要负责输入文件的格式,而OUTPUT_FORMAT只负责输出文件的格式,但是如果OUTPUT_FORMAT不提供输出文件的格式,就默认使用TARGET提供输出文件的格式。