使用連接器ld產生不同格式的二進位目標檔案

來源:互聯網
上載者:User

 

摘自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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.