objdump
-S,
如果有源程序的话,将源程序与汇编代码混合在一起。
使用该选项时,输入的目标文件需要有调试信息,即用gcc -g生成的目标文件才可以,因为,调试信息中才有源程序信息。
--adjust-vma=offset
对于a.out,似乎没有编码节的地址,因此,dump出来的节内容都是从0开始。用该方法可以将ram起始地址作为偏移,加到节内容地址上。
When dumping information, first add offset to all the section addresses. This is useful if the section addresses do not correspond to the symbol table, which can happen when putting sections at particular addresses when using a format which can not represent section addresses, such as a.out.
objcopy
-O bfdname
--output-target=bfdname
Write the output file using the object format bfdname. See Target Selection, for more information.
设置输出文件为bfdname格式。可以使用objdump -i查看支持的目标文件,如下,其中包括binary
sparc-elf-objdump -i BFD header file version 2.13.2.1 elf32-sparc (header big endian, data big endian) sparc a.out-sunos-big (header big endian, data big endian) sparc elf32-little (header little endian, data little endian) sparc elf32-big (header big endian, data big endian) sparc srec (header endianness unknown, data endianness unknown) sparc symbolsrec (header endianness unknown, data endianness unknown) sparc tekhex (header endianness unknown, data endianness unknown) sparc binary (header endianness unknown, data endianness unknown) sparc ihex (header endianness unknown, data endianness unknown) sparc
该选项可以直接将text,data,bss段都拷贝出来,似乎不需要单独的拷贝各个段。
上面和下面三句效果一样?
sparc-elf-objcopy -O binary -j .text main.elf main.text
sparc-elf-objcopy -O binary -j .data main.elf main.data
sparc-elf-objcopy -O binary -j .bss main.elf main.bss
关于BFD
The BFD data files are related to GNU Binutils. BFD file is a Binary File Descriptor Data. The Binary File Descriptor library (BFD) is the GNU Project's main mechanism for the portable manipulation of object files in a variety of formats.
感觉应该是binutil需要支持许多目标文件格式(objdump -i可以查看支持的目标文件),如果由前端来匹配所有文件格式的话,那么前端会非常复杂。因此,弄了一个BFD,前端只和BFD打交道(相应的有一个BFD格式,internal canonical(简洁的) format),而由BFD和后端的各种目标文件格式打交道。这样,前端接口可以统一。这样增加某种目标文件格式支持也相对比较简单。
-j sectionpattern
--only-section=sectionpattern
只拷贝指定的节
Copy only the indicated sections from the input file to the output file. This option may be given more than once. Note that using this option inappropriately may make the output file unusable. Wildcard characters are accepted in sectionpattern.
If the first character of sectionpattern is the exclamation point (!) then matching sections will not be copied, even if earlier use of --only-section on the same command line would otherwise copy it. For example:
--only-section=.text.* --only-section=!.text.foo
will copy all sectinos maching ’.text.*’ but not the section ’.text.foo’.