您的位置:首页 > 其它

使用连接器ld生成不同格式的二进制目标文件

2009-09-20 14:25 423 查看
摘自GNU官方网站:(http://sourceware.org/binutils/docs/ld/Options.html#Options

--oformat output-formatld may be configured to support more than one kind of object
file. If your ld is configured this way, you can use the
`--oformat' option to specify the binary format for the output
object file. Even when ld is configured to support alternative
object formats, you don't usually need to specify this, as ld
should be configured to produce as a default output format the most
usual format on each machine. output-format is a text string, the
name of a particular format supported by the BFD libraries. (You can
list the available binary formats with `objdump -i'.) The script
command
OUTPUT_FORMAT
can also specify the output format, but
this option overrides it. See BFD.

我试着拙劣地翻译一下:

--oformat output-formatld 可以通过配置来支持多于一种的目标文件。如果你的ld进行了这样的配置,你就可以使用`--oformat'选项来指定输出目标文件的二进制格式。即使ld配置了支持不同的目标格式,你一般也不需要指定此选项,因为ld的缺省输出格式配置为各个机器上最常用的格式。output-format是一个字符串,一个BFD库所支持的格式名称。(你可以使用命令`objdump -i'列出所有可用的二进制格式。)脚本命令
OUTPUT_FORMAT
也可以指定输出格式,但这个选项会覆盖它。参见BFD

下面是我机器上的`objdump -i'输出:

$ objdump -i
BFD header file version (GNU Binutils for Debian) 2.19.91.20090910
elf32-i386
(header little endian, data little endian)
i386
a.out-i386-linux
(header little endian, data little endian)
i386
pei-i386
(header little endian, data little endian)
i386
elf32-little
(header little endian, data little endian)
i386
l1om
elf32-big
(header big endian, data big endian)
i386
l1om
elf64-x86-64
(header little endian, data little endian)
i386
pei-x86-64
(header little endian, data little endian)
i386
elf64-l1om
(header little endian, data little endian)
l1om
elf64-little
(header little endian, data little endian)
i386
l1om
elf64-big
(header big endian, data big endian)
i386
l1om
srec
(header endianness unknown, data endianness unknown)
i386
l1om
symbolsrec
(header endianness unknown, data endianness unknown)
i386
l1om
verilog
(header endianness unknown, data endianness unknown)
i386
l1om
tekhex
(header endianness unknown, data endianness unknown)
i386
l1om
binary
(header endianness unknown, data endianness unknown)
i386
l1om
ihex
(header endianness unknown, data endianness unknown)
i386
l1om
trad-core
(header endianness unknown, data endianness unknown)

elf32-i386 a.out-i386-linux pei-i386 elf32-little elf32-big
i386 elf32-i386 a.out-i386-linux pei-i386 elf32-little elf32-big
l1om ---------- ---------------- -------- elf32-little elf32-big

elf64-x86-64 pei-x86-64 elf64-l1om elf64-little elf64-big srec
i386 elf64-x86-64 pei-x86-64 ---------- elf64-little elf64-big srec
l1om ------------ ---------- elf64-l1om elf64-little elf64-big srec

symbolsrec verilog tekhex binary ihex trad-core
i386 symbolsrec verilog tekhex binary ihex ---------
l1om symbolsrec verilog tekhex binary ihex ---------

然后你就可以使用以下命令来编译连接你的源代码来生成.bin文件了:

$ ls

boot.s

$ as -o boot.o boot.s

$ ld -o boot.bin --oformat binary boot.o

$ ls

boot.bin boot.o boot.s
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: