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 |