objcopy用於將object的部分獲全部內容拷貝到另一個object,從而可以實現格式的變換。
objcopy可用用於將文件轉換成S-record格式或者raw二進制格式。<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
例如,
xxxx-elf-objcopy –O srec test.o test.s19
則將test.o轉換成s-record文件中。通常涉及到text段。
xxxx-elf-objcopy –O binary test.o test.bin
則將test.o轉換成raw binary文件格式。
當將object文件轉換成raw binary格式時,通常將去除掉symbols和relocation信息。在生成s-record過程中,有時需要用選項“-S”,“-R”去除掉binary文件,s-record文件不需要的相應信息。
此外,還需要注意到使用objcopy不能夠改變大、小endian。
選項 |
Desc |
infile/outfile |
源文件/目標文件 |
-I bfdname --input-target=bfdname |
輸入文件的bfdname,可取值elf32-little,elf32-big等,可用用objdump –I查看相應的信息 |
-O bfdname --output-target=bfdname |
輸出文件的bfdname |
-F bfdname --target=bfdname |
指定輸入、輸出文件的bfdname,目標文件格式 |
-j sectionname --only-section=sectionname |
只將由sectionname指定的section拷貝到輸出文件 |
-R sectionname --remove-section=sectionname |
去除掉由sectionname指定的section |
-S --strip-all |
去掉源文件的符號信息和relocation信息 |
-g --strip-debug |
去除掉調試符號信息和相關的段 |
-K symbolname --keep-symbol=symbolname |
保留由symbolname指定的符號信息 |
-N symbolname --strip-symbol=symbolname |
去除掉由symbolname指定的符號信息 |
-G symbolname --keep-global-symbol=symbolname -L symbolname --localize-symbol=symbolname -W symbolname --weaken-symbol=symbolname -w --wildcard -x --discard-all -X --discard-locals |
處理符號 |
-b byte --byte=byte |
每byteth byte中保留1 byte |
-i interleave --interleave=interleave |
每隔interleave字節拷貝1 byte |
--gap-fill val |
在section中填充val |
--set-start val |
設定新文件的start address |
--change-start incr --adjust-start incr |
調整start address |
--change-address incr --adjust-vma incr |
調整所有sections的VMA(virtual memory address)和LMA(linear memory address)。 |
--change-section-address section{=,+,-}val --adjust-section-vma section {=,+,-}val |
調整指定section的VMA/LMA地址 |
--set-section-flags section=flag |
指定指定section的flag,flag的取值可以alloc,contents, load, noload, readonly, code, data, rom, share, debug |
--add-section sectionname=filename |
添加一個section,該section的內容爲filenmae的內容 |
--rename-section oldname= newname[,flags] |
更改section的名 |
-V --version |
objcopy的version number |