摘自GNU官方網站:(http://sourceware.org/binutils/docs/ld/Options.html#Options)
--oformat output-format
ld 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-format
ld 可以通過配置來支援多於一種的目標檔案。如果你的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