日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

objcopy的详细说明

發(fā)布時間:2025/3/21 编程问答 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 objcopy的详细说明 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
objcopy把一種目標文件中的內容復制到另一種類型的目標文件中.?

(1)將圖像編譯到可執(zhí)行文件內 Q: 如何將一個二進制文件,比如圖片,詞典一類的東西做為.o文件,直接鏈接到可執(zhí)行文件內部呢? A:?
$ objcopy -I binary -O elf32-i386 -B i386 14_95_13.jpg image.o?
$ gcc image.o tt.o -o tt?
$ nm tt | grep 14_95?
0805d6c7 D _binary_14_95_13_jpg_end?
00014213 A _binary_14_95_13_jpg_size?
080494b4 D _binary_14_95_13_jpg_start?

(2)使用objcopy把不用的信息去掉: $ objcopy?-R?.comment?-R?.note?halo?halo.min?

(3)?
$ objcopy?-R?.note?-R?.comment?-S?-O?binary?xyb?xyb.bin?
-R?.note?-R?.comment?表示移掉?.note?與?.comment?段?
-S?表示移出所有的標志及重定位信息?
-O?binary?xyb?xyb.bin?表示由xyb生成二進制文件xyb.bin objcopy工具使用指南
objcopy Utility
objcopy [ -F bfdname | --target=bfdname ]
[ -I bfdname | --input-target=bfdname ]
[ -O bfdname | --output-target= bfdname ]
[ -S | --strip-all ] [ -g | --strip-debug ]
[ -K symbolname | --keep-symbol= symbolname ]
[ -N symbolname | --strip-symbol= symbolname ]
[ -L symbolname | --localize-symbol= symbolname ]
[ -W symbolname | --weaken-symbol= symbolname ]
[ -x | --discard-all ] [ -X | --discard-locals ]
[ -b byte | --byte= byte ]
[ -i interleave | --interleave= interleave ]
[ -R sectionname | --remove-section= sectionname ]
[ -p | --preserve-dates ] [ --debugging ]
[ --gap-fill= val ] [ --pad-to= address ]
[ --set-start= val ] [ --adjust-start= incr ]
[ --change-address= incr ]
[ --change-section-address= section{=,+,-} val ]
[ --change-warnings ] [ --no-change-warnings ]
[ --set-section-flags= section= flags ]
[ --add-section= sectionname= filename ]
[ --change-leading char ] [--remove-leading-char ]
[ --weaken ]
[ -v | --verbose ] [ -V | --version ] [ --help ]
input-file [ outfile ]?
? GNU實用工具程序objcopy的作用是拷貝一個目標文件的內容到另一個目標文件中。Objcopy使用GNU BFD庫去讀或寫目標文件。Objcopy可以使用不同于源目標文件的格式來寫目的目標文件(也即是說可以將一種格式的目標文件轉換成另一種格式的目標文件)。通過以上命令行選項可以控制Objcopy的具體操作。
Objcopy在進行目標文件的轉換時,將生成一個臨時文件,轉換完成后就將這個臨時文件刪掉。Objcopy使用BFD做轉換工作。如果沒有明確地格式要求,則Objcopy將訪問所有在BFD庫中已經描述了的并且它可以識別的格式,請參見《GNUpro Decelopment Tools》中“using ld”一章中“BFD庫”部分和“BFD庫中規(guī)范的目標文件格式”部分。
通過使用srec作為輸出目標(使用命令行選項-o srec),Objcopy可以產生S記錄格式文件。
通過使用binary作為輸出目標(使用命令行選項-o binary),Objcopy可以產生原始的二進制文件。使用Objcopy產生一個原始的二進制文件,實質上是進行了一回輸入目標文件內容的內存轉儲。所有的符號和重定位信息都將被丟棄。內存轉儲起始于輸入目標文件中那些將要拷貝到輸出目標文件去的部分的最小虛地址處。
使用Objcopy生成S記錄格式文件或者原始的二進制文件的過程中,-S選項和-R選項可能會比較有用。-S選項是用來刪掉包含調試信息的部分,-R選項是用來刪掉包含了二進制文件不需要的內容的那些部分。 input-file
outfile
參數(shù)input-file和outfile分別表示輸入目標文件(源目標文件)和輸出目標文件(目的目標文件)。如果在命令行中沒有明確地指定outfile,那么Objcopy將創(chuàng)建一個臨時文件來存放目標結果,然后使用input-file的名字來重命名這個臨時文件(這時候,原來的input-file將被覆蓋)。 -I bfdname?
--input-target=bfdname
明確告訴Objcopy,源文件的格式是什么,bfdname是BFD庫中描述的標準格式名。這樣做要比“讓Objcopy自己去分析源文件的格式,然后去和BFD中描述的各種格式比較,通過而得知源文件的目標格式名”的方法要高效得多。 -O bfdname?
--output-target= bfdname
使用指定的格式來寫輸出文件(即目標文件),bfdname是BFD庫中描述的標準格式名。 -F bfdname
--target= bfdname
明確告訴Objcopy,源文件的格式是什么,同時也使用這個格式來寫輸出文件(即目標文件),也就是說將源目標文件中的內容拷貝到目的目標文件的過程中,只進行拷貝不做格式轉換,源目標文件是什么格式,目的目標文件就是什么格式。 -R sectionname
--remove-section= sectionname
從輸出文件中刪掉所有名為sectionname的段。這個選項可以多次使用。
注意:不恰當?shù)厥褂眠@個選項可能會導致輸出文件不可用。 -S
--strip-all (strip 剝去、剝)
不從源文件中拷貝重定位信息和符號信息到輸出文件(目的文件)中去。 -g
--strip-debug
不從源文件中拷貝調試符號到輸出文件(目的文件)中去。 --strip-undeeded
剝去所有在重定位處理時所不需要的符號。 -K symbolname
--keep-symbol= symbolname
僅從源文件中拷貝名為symbolname的符號。這個選項可以多次使用。 -N symbolname
--strip-symbol= symbolname
不從源文件中拷貝名為symbolname的符號。這個選項可以多次使用。它可以和其他的strip選項聯(lián)合起來使用(除了-K symbolname | --keep-symbol= symbolname外)。 -L symbolname
--localize-symbol= symbolname
使名為symbolname的符號在文件內局部化,以便該符號在該文件外部是不可見的。這個選項可以多次使用。 -W symbolname
-weaken-symbol= symbolname
弱化名為symbolname的符號。這個選項可以多次使用。 -x
--discard-all (discard 丟棄、拋棄)
不從源文件中拷貝非全局符號。 -X
--discard-locals
不從源文件中拷貝又編譯器生成的局部符號(這些符號通常是L或 . 開頭的)。 -b byte
--byte= byte?
Keep only every byte of the input file (header data is not affected). byte can be
in the range from 0 to interleave-1, where interleave is given by the -i or
--interleave option, or the default of 4. This option is useful for creating files to
program ROM . It is typically used with an srec output target. -i interleave
--interleave= interleave (interleave 隔行、交叉)
Only copy one out of every interleave bytes. Select which byte to copy with the
-b or --byte option. The default is 4. objcopy ignores this option if you do not
specify either -b or --byte. -p
--preserve-dates (preserve 保存、保持)
設置輸出文件的訪問和修改日期和輸入文件相同。 [ --debugging ]
如果可能的話,轉換調試信息。因為只有特定的調試格式被支持,以及這個轉換過程要耗費一定的時間,所以這個選項不是默認的。
--gap-fill= val
使用內容val填充段與段之間的空隙。通過增加段的大小,在地址較低的一段附加空間中填充內容val來完成這一選項的功能。 --pad-to= address
填充輸出文件到虛擬地址address。通過增加輸出文件中最后一個段的大小,在輸出文件中最后一段的末尾和address之間的這段附加空間中,用--gap-fill= val選項中指定的內容val來填充(默認內容是0,即沒有使用--gap-fill= val選項的情況下)。 --set-start= val
設置新文件(應該是輸出文件吧?)的起始地址為val。不是所有的目標文件格式都支持設置起始地址。 --change-start = incr
--adjust-start= incr
通過增加值incr來改變起始地址。不是所有的目標文件格式都支持設置起始地址。 --change-addresses incr
--adjust-vma incr
Change the VMA and LMA addresses of all sections, section., as well as the
start address, by adding incr. Some object file formats do not permit section
addresses to be changed arbitrarily. 通過加上一個值incr,改變所有段的VMA(Virtual Memory Address運行時地址)和LMA(Load Memory Address裝載地址),以及起始地址。某些目標文件格式不允許隨便更改段的地址。 --change-section-address section{=,+,-} val
--adjust-section-vma section{=,+,-} val
設置或者改變名為section的段的VMA(Virtual Memory Address運行時地址)和LMA(Load Memory Address裝載地址)。如果這個選項中使用的是“=”,那么名為section的段的VMA(Virtual Memory Address運行時地址)和LMA(Load Memory Address裝載地址)將被設置成val;如果這個選項中使用的是“-”或者“+”,那么上述兩個地址將被設置或者改變成這兩個地址的當前值減去或加上val后的值。如果在輸入文件中名為section的段不存在,那么Objcopy將發(fā)出一個警告,除非--no-change-warnings選項被使用。
這里的段地址設置和改變都是輸出文件中的段相對于輸入文件中的段而言的。例如:
(1)--change-section-address .text = 10000
這里是指將輸入文件(即源文件)中名為.text的段拷貝到輸出文件中后,輸出文件中的.text段的VMA(Virtual Memory Address運行時地址)和LMA(Load Memory Address裝載地址)將都被設置成10000。
(2)--change-section-address .text + 100
這里是指將輸入文件(即源文件)中名為.text的段拷貝到輸出文件中后,輸出文件中的.text段的VMA(Virtual Memory Address運行時地址)和LMA(Load Memory Address裝載地址)將都被設置成以前輸入文件中.text段的地址(當前地址)加上100后的值。 --change-section-lma section{=,+,-} val
僅設置或者改變名為section的段的LMA(Load Memory Address裝載地址)。一個段的LMA是程序被加載時,該段將被加載到的一段內存空間的首地址。通常LMA和VMA(Virtual Memory Address運行時地址)是相同的,但是在某些系統(tǒng)中,特別是在那些程序放在ROM的系統(tǒng)中,LMA和VMA是不相同的。如果這個選項中使用的是“=”,那么名為section的段的LMA(Load Memory Address裝載地址)將被設置成val;如果這個選項中使用的是“-”或者“+”,那么LMA將被設置或者改變成這兩個地址的當前值減去或加上val后的值。如果在輸入文件中名為section的段不存在,那么Objcopy將發(fā)出一個警告,除非--no-change-warnings選項被使用。 --change-section-vma section{=,+,-} val
僅設置或者改變名為section的段的VMA(Load Memory Address裝載地址)。一個段的VMA是程序運行時,該段的定位地址。通常VMA和LMA(Virtual Memory Address運行時地址)是相同的,但是在某些系統(tǒng)中,特別是在那些程序放在ROM的系統(tǒng)中,LMA和VMA是不相同的。如果這個選項中使用的是“=”,那么名為section的段的LMA(Load Memory Address裝載地址)將被設置成val;如果這個選項中使用的是“-”或者“+”,那么LMA將被設置或者改變成這兩個地址的當前值減去或加上val后的值。如果在輸入文件中名為section的段不存在,那么Objcopy將發(fā)出一個警告,除非--no-change-warnings選項被使用。 --change-warnings
--adjust-warnings
如果命令行中使用了--change-section-address section{=,+,-} val或者--adjust-section-vma section{=,+,-} val,又或者--change-section-lma section{=,+,-} val,又或者--change-section-vma section{=,+,-} val,并且輸入文件中名為section的段不存在,則Objcopy發(fā)出警告。這是默認的選項。 --no-chagne-warnings
--no-adjust-warnings
如果命令行中使用了--change-section-address section{=,+,-} val或者--adjust-section-vma section{=,+,-} val,又或者--change-section-lma section{=,+,-} val,又或者--change-section-vma section{=,+,-} val,即使輸入文件中名為section的段不存在, Objcopy也不會發(fā)出警告。 --set-section-flags section=flags
為為section的段設置一個標識。這個flags變量的可以取逗號分隔的多個標識名字符串(這些標識名字符串是能夠被Objcopy程序所識別的),合法的標識名有alloc,load,readonly,code,data和rom。
You can set the contents flag for a section which does not havecontents, but it is not meaningful to clear the contents flag of a section which does have contents; just remove the section instead. Not all flags are meaningful for all object file formats. --add-section sectionname=filename
進行目標文件拷貝的過程中,在輸出文件中增加一個名為sectionname的新段。這個新增加的段的內容從文件filename得到。這個新增加的段的大小就是這個文件filename的大小。只要輸出文件的格式允許該文件的段可以有任意的段名(段名不是標準的,固定的),這個選項才能使用。 --change-leading-char
Some object file formats use special characters at the start of symbols. The most
common such character is underscore, which compilers often add before every
symbol. This option tells objcopy to change the leading character of every
symbol when it converts between object file formats. If the object file formats use
the same leading character, this option has no effect. Otherwise, it will add a
character, or remove a character, or change a character, as appropriate. --remove-leading-char
If the first character of a global symbol is a special symbol leading character used
by the object file format, remove the character. The most common symbol leading
character is underscore. This option will remove a leading underscore from all
global symbols. This can be useful if you want to link together objects of different
file formats with different conventions for symbol names. --weaken
Change all global symbols in the file to be weak. This can be useful when building
an object that will be linked against other objects using the -R option to the linker.
This option is only effective when using an object file format that supports weak
symbols. -V
--version
Show the version number of objcopy. -v
--verbose
Verbose output: list all object files modified. In the case of archives, objcopy -V
lists all members of the archive. --help
Show a summary of the options to objcopy.

總結

以上是生活随笔為你收集整理的objcopy的详细说明的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。