GNU Binutils之Objcopy
作者:makethyme
objcopy用于将object的部分獲全部内容拷貝到另一個object,進而可以實作格式的變換。
格式如下:
objcopy [‘-F’ bfdname|‘--target=’bfdname]
[‘-I’ bfdname|‘--input-target=’bfdname]
[‘-O’ bfdname|‘--output-target=’bfdname]
[‘-B’ bfdarch|‘--binary-architecture=’bfdarch]
[‘-S’|‘--strip-all’]
[‘-g’|‘--strip-debug’]
[‘-K’ symbolname|‘--keep-symbol=’symbolname]
[‘-N’ symbolname|‘--strip-symbol=’symbolname]
[‘--strip-unneeded-symbol=’symbolname]
[‘-G’ symbolname|‘--keep-global-symbol=’symbolname]
[‘-L’ symbolname|‘--localize-symbol=’symbolname]
[‘--globalize-symbol=’symbolname]
[‘-W’ symbolname|‘--weaken-symbol=’symbolname]
[‘-w’|‘--wildcard’]
[‘-x’|‘--discard-all’]
[‘-X’|‘--discard-locals’]
[‘-b’ byte|‘--byte=’byte]
[‘-i’ interleave|‘--interleave=’interleave]
[‘-j’ sectionname|‘--only-section=’sectionname]
[‘-R’ sectionname|‘--remove-section=’sectionname]
[‘-p’|‘--preserve-dates’]
[‘--debugging’]
[‘--gap-fill=’val]
[‘--pad-to=’address]
[‘--set-start=’val]
[‘--adjust-start=’incr]
[‘--change-addresses=’incr]
[‘--change-section-address’ section{=,+,-}val]
[‘--change-section-lma’ section{=,+,-}val]
[‘--change-section-vma’ section{=,+,-}val]
[‘--change-warnings’] [‘--no-change-warnings’]
[‘--set-section-flags’ section=flags]
[‘--add-section’ sectionname=filename]
[‘--rename-section’ oldname=newname[,flags]]
[‘--change-leading-char’] [‘--remove-leading-char’]
[‘--srec-len=’ival] [‘--srec-forceS3’]
[‘--redefine-sym’ old=new]
[‘--redefine-syms=’filename]
[‘--weaken’]
[‘--keep-symbols=’filename]
[‘--strip-symbols=’filename]
[‘--strip-unneeded-symbols=’filename]
[‘--keep-global-symbols=’filename]
[‘--localize-symbols=’filename]
[‘--globalize-symbols=’filename]
[‘--weaken-symbols=’filename]
[‘--alt-machine-code=’index]
[‘--prefix-symbols=’string]
[‘--prefix-sections=’string]
[‘--prefix-alloc-sections=’string]
[‘--add-gnu-debuglink=’path-to-file]
[‘--keep-file-symbols’]
[‘--only-keep-debug’]
[‘--writable-text’]
[‘--readonly-text’]
[‘--pure’]
[‘--impure’]
[‘-v’|‘--verbose’]
[‘-V’|‘--version’]
[‘--help’] [‘--info’]
infile [outfile]
objcopy可用用于将檔案轉換成S-record格式或者raw二進制格式。 例如, 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 |