譯文
NAME
objcopy - copy and translate object files
概要
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]
[--localize-hidden]
[-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 [breadth]|--interleave[=breadth]]
[--interleave-width=width]
[-j sectionpattern|--only-section=sectionpattern]
[-R sectionpattern|--remove-section=sectionpattern]
[-p|--preserve-dates]
[-D|--enable-deterministic-archives]
[-U|--disable-deterministic-archives]
[--debugging]
[--gap-fill=val]
[--pad-to=address]
[--set-start=val]
[--adjust-start=incr]
[--change-addresses=incr]
[--change-section-address sectionpattern{=,+,-}val]
[--change-section-lma sectionpattern{=,+,-}val]
[--change-section-vma sectionpattern{=,+,-}val]
[--change-warnings] [--no-change-warnings]
[--set-section-flags sectionpattern=flags]
[--add-section sectionname=filename]
[--dump-section sectionname=filename]
[--update-section sectionname=filename]
[--rename-section oldname=newname[,flags]]
[--long-section-names {enable,disable,keep}]
[--change-leading-char] [--remove-leading-char]
[--reverse-bytes=num]
[--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]
[--add-symbol name=[section:]value[,flags]
[--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]
[--strip-dwo]
[--extract-dwo]
[--extract-symbol]
[--writable-text]
[--readonly-text]
[--pure]
[--impure]
[--file-alignment=num]
[--heap=size]
[--image-base=address]
[--section-alignment=num]
[--stack=size]
[--subsystem=which:major.minor]
[--compress-debug-sections]
[--decompress-debug-sections]
[--elf-stt-common=val]
[-v|--verbose]
[-V|--version]
[--help] [--info]
infile [outfile]
描述
GNU objcopy實用程序將一個對象文件的內容復制到另一個文件中。 objcopy使用 GNU BFD庫讀取和寫入目標文件。它可以寫目的地 目標文件的格式與源目標文件的格式不同。確切行為
的objcopy把由命令行選項來控制。請注意,objcopy應該能夠 在任何兩種格式之間復制完全鏈接的文件。但是,復制可重定位的對象
兩種格式之間的文件可能無法正常工作。
objcopy創建臨時文件以進行翻譯,然后將其刪除。
objcopy使用BFD進行所有翻譯工作;它可以訪問所有格式
在BFD中進行了描述,因此無需明確說明就可以識別大多數格式。
objcopy可用於通過使用srec的輸出目標(例如,使用-O
srec)來生成S記錄。
objcopy可用於通過使用二進制輸出目標 (例如,使用-O binary)來生成原始二進制文件。當objcopy生成原始二進制文件時,它將基本上 產生輸入目標文件內容的內存轉儲。所有符號和 重定位信息將被丟棄。內存轉儲將從加載地址開始
復制到輸出文件的最低部分的。
生成S記錄或原始二進制文件時,使用-S刪除可能會有所幫助 包含調試信息的部分。在某些情況下,-R對刪除很有用
包含二進制文件不需要的信息的部分。
注意--- objcopy無法更改其輸入文件的字節序。如果輸入
格式具有字節序(某些格式沒有),objcopy只能將輸入復制到文件中
具有相同字節序或不具有字節序的格式(例如srec)。(然而,
請參閱--reverse-bytes選項。)
選項
infile
outfile 分別是輸入文件和輸出文件。如果未指定outfile,則objcopy將
創建一個臨時文件,並以infile的名稱破壞性地重命名結果。
-I bfdname
--input-target = bfdname
認為源文件的對象格式為bfdname,而不是嘗試
推論它。
-O bfdname
--output-target = bfdname
使用對象格式bfdname寫入輸出文件。
-F bfdname
--target = bfdname
使用bfdname作為輸入文件和輸出文件的對象格式;即,簡單地
無需翻譯即可將數據從源傳輸到目標。
-B bfdarch
--binary-architecture = bfdarch 將無架構的輸入文件轉換為目標文件時很有用。在這個
可以將輸出體系結構設置為bfdarch的情況。如果此選項將被忽略
輸入文件具有已知的bfdarch。您可以在程序中訪問此二進制數據 通過引用轉換過程中創建的特殊符號。這些
符號稱為_binary_ objfile _start,_binary_ objfile _end和
_binary_ objfile _size。例如,您可以將圖片文件轉換為目標文件,然后
然后使用這些符號在您的代碼中對其進行訪問。
-j sectionpattern
--only-section = sectionpattern 僅將指示的部分從輸入文件復制到輸出文件。這個選項 可能會被多次給予。請注意,不當使用此選項可能會使
輸出文件不可用。sectionpattern中接受通配符。
-R sectionpattern
--remove截面= sectionpattern
刪除任何部分匹配sectionpattern從輸出文件。此選項可能是 給予不止一次。請注意,不當使用此選項可能會使輸出
文件無法使用。sectionpattern中接受通配符。同時使用-j
和-R選項會導致未定義的行為。
-S-
全部
不要從源文件復制重定位和符號信息。
-g
--strip-調試
不要從源文件中復制調試符號或節。
-不需要條紋
去除重定位處理不需要的所有符號。
-K symbolname
--keep-symbol = symbolname 剝離符號時,即使通常會剝離,也要保留符號symbolname。
可以多次給此選項。
-N symbolname
--strip-symbol = symbolname 不復制源文件中的symbol symbolname。可以給這個選項更多
不止一次。
--strip-unneeded-symbol = symbolname除非源文件需要,否則 不要從源文件中復制符號symbolname。 搬遷。可以多次給此選項。
-G symbolname
--keep-global-symbol = symbolname
僅保留全局符號symbolname。使所有其他符號位於文件本地,以便 它們在外部不可見。可以多次給此選項。
--localize-hidden
在ELF對象中,將所有具有隱藏或內部可見性的符號標記為局部。
此選項適用於特定於符號的本地化選項(例如-L)。
-L symbolname
--localize-symbol = symbolname
將符號symbolname設置為文件本地,以使其在外部不可見。這
選項可能會多次給出。
-W symbolname
--weaken-symbol = symbolname
使符號symbolname變弱。可以多次給此選項。
--globalize-symbol = symbolname
賦予符號symbolname全局作用域,以便在文件的外部可見 它是定義的。可以多次給此選項。
-w
--wildcard 允許在其他命令行選項中使用的symbolname中的正則表達式。這
問號(?),星號(*),反斜杠(\)和方括號([])運算符可以 可在符號名稱中的任何位置使用。如果符號名稱的第一個字符是 感嘆號(!),則該符號的開關方向相反。為了
例子:
-w -W!foo -W fo *
會導致objcopy削弱所有以“ fo”開頭的符號,除了該符號
“ foo”。
-x
--discard,所有
不要從源文件復制非全局符號。
-X
--discard-locals 不要復制編譯器生成的本地符號。(這些通常以L或。開頭。)
-b 字節
--byte =字節
如果通過--interleave選項啟用了交錯,則開始范圍
字節保持在字節個字節。 字節的范圍可以從0到寬度-1,其中
寬度是--interleave選項給出的值。
-i [廣度]
--interleave [=廣度]
只復制的范圍超出每廣度字節。(標題數據不受影響)。選擇
范圍中的哪個字節以--byte選項開始復制。選擇寬度--interleave-width選項 的范圍。
此選項對於創建要編程ROM的文件很有用。通常與 “ srec”輸出目標。請注意,如果您也未指定--byte選項,則objcopy將抱怨 。
默認的交錯寬度為4,因此當--byte設置為0時,objcopy將復制
從輸入到輸出的每四個字節中的第一個字節。
--interleave-width = width
與--interleave選項一起使用時,一次復制寬度字節。的開始
要復制的字節范圍由--byte選項設置,范圍的范圍
使用--interleave選項設置。
此選項的默認值是1的值寬度加上字節值集合通過
該--byte選項必須不被超過交錯廣度集--interleave
選項。
此選項可用於為兩個交錯的16位閃光燈創建圖像。
通過將-b 0 -i 4 --interleave-width = 2和-b 2 -i 4
--interleave-width = 2傳遞給兩個objcopy命令來實現32位總線。如果輸入為“ 12345678”,則
輸出分別為“ 1256”和“ 3478”。
-p
--preserve-日期
將輸出文件的訪問和修改日期設置為與
輸入文件。
-D-
啟用確定性歸檔
以確定性模式運行。復制檔案成員並寫入檔案時
索引,將UID,GID,時間戳記為零,並將所有文件使用一致的文件模式
文件。
如果binutils配置了--enable-deterministic-archives,則此模式為開 默認情況下。可以使用下面的-U選項禁用它。
-U
--disable確定性的存檔
千萬不能在運行確定性模式。這與上面的-D選項相反。
復制存檔成員並寫入存檔索引時,請使用其實際的UID,GID,
時間戳記和文件模式值。
這是默認設置,除非binutils配置了
--enable-deterministic-archives。
- 調試 盡可能轉換調試信息。這不是默認值,因為
支持某些調試格式,轉換過程可能很耗時
消耗。
--gap填充 VAL
與段之間填補空白VAL。此操作適用於加載 地址(LMA) 部分。這是通過增加該部分的大小來降低的
地址,並填充使用val創建的額外空間。
--pad-to address
將輸出文件填充到加載地址address。這是通過增加 最后一節的大小。多余的空間用以下值指定
--gap-fill(默認為零)。
--set-start val
將新文件的起始地址設置為val。並非所有目標文件格式都支持
設置起始地址。
--change-start incr
--adjust-start incr
通過添加incr更改起始地址。並非所有目標文件格式都支持設置
起始地址。
--change- addresss增量
--adjust-vma 增量
通過以下方法更改所有部分的VMA和LMA地址以及起始地址
添加incr。某些目標文件格式不允許更改節地址 任意地。請注意,這不會重定位這些部分;如果程序期望
節將加載到某個地址,並且此選項用於更改
如果將它們裝入不同的地址,則程序可能會失敗。
--change-section-address sectionpattern {=,+,-} val
--adjust-section-vma sectionpattern {=,+,-} val
設置或更改任何匹配部分的VMA地址和LMA地址
節模式。如果使用=,則段地址設置為val。否則,val為 添加到節地址或從節地址中減去。請參閱下面的評論
--change-addresses,上面。如果sectionpattern與輸入中的任何部分都不匹配
文件,將發出警告,除非使用--no-change-warnings。
--change-section-lma sectionpattern {=,+,-} val
設置或更改與sectionpattern匹配的任何節的LMA地址。LMA
address是在程序加載時該段將被加載到內存中的地址 時間。通常,這與VMA地址相同,即VMA的地址。
部分在程序運行時進行,但在某些系統上,尤其是在其中有程序的系統 保存在ROM中,兩者可以不同。如果使用=,則段地址設置為
val。否則,將val添加到節地址或從節地址中減去。見上面--change-addresses 下的注釋。如果sectionpattern不匹配
輸入文件中的節,將發出警告,除非--no-change-warnings為
用過的。
--change-section-vma sectionpattern {=,+,-} val
設置或更改任何與sectionpattern匹配的節的VMA地址。VMA地址
是程序啟動后該部分將位於的地址 執行。通常,這與LMA地址相同,即
該部分將被加載到內存中,但是在某些系統上,尤其是那些 程序保存在ROM中,兩者可以不同。如果使用=,則段地址
設置為val。否則,將val添加到節地址或從節地址中減去。 請參閱上方--change-addresses下的注釋。如果sectionpattern不匹配
輸入文件中的任何部分,都會發出警告,除非--no-change-warnings
用來。
--change-warnings
--adjust-warnings
如果使用--change-section-address或--change-section-lma或--change-section-vma, 並且節模式與任何節都不匹配,請發出警告。這是
默認。
--no-change-warnings
--no-adjust-warnings
如果使用--change-section-address或--adjust-section-lma或
--adjust-section-vma,即使該節位於模式與任何部分都不匹配。
--set-section-flags sectionpattern =標志
設置與sectionpattern匹配的任何部分的標志。該標志參數是一個逗號 標記名稱的分隔字符串。可識別的名稱是alloc,內容,load,
noload,readonly,代碼,data,rom,share和debug。您可以設置內容標志
對於沒有內容的部分,但清除該部分沒有意義
具有內容的部分的內容標志-只需刪除該部分即可。
並非所有標志對於所有目標文件格式都有意義。
--add-section sectionname = filename復制文件時 添加一個名為sectionname的新部分。新內容
部分取自文件filename。該部分的大小將是 文件。此選項僅適用於支持以下格式的文件格式: 任意名稱。注意-可能需要使用--set-section-flags選項
設置新創建的部分的屬性。
--dump-section sectionname = filename
將名為sectionname的節的內容放入文件filename中,覆蓋 以前可能在那里的任何內容。此選項是
--add-section。該選項類似於--only-section選項,除了它
不創建格式化文件,它只是將內容轉儲為原始二進制數據, 而不應用任何重定位。可以多次指定該選項。
--update截面 sectionname =文件名
替換已命名的節中的現有內容sectionname與文件的內容
的文件名。該部分的大小將調整為文件的大小。這sectionname的 section標志將保持不變。對於ELF格式的文件,請參閱
段映射也將保持不變,這是無法使用的
--remove-section和--add-section。該選項可以指定多個
一次。
注意-可以使用--rename-section和--update-section來更新和 從一個命令行重命名節。在這種情況下,請傳遞原始節名稱
到--update-section,原始和新的部分名稱到--rename-section。
--add-symbol name = [ section :] value [,flags ]在復制文件時 添加一個名為name的新符號。可以指定此選項 多次。如果給出了該部分,則該符號將與和 相對於該部分,否則將是ABS符號。指定一個未定義 部分將導致致命錯誤。沒有檢查該值,它將是 按指定采取。可以指定符號標志,並非所有標志都可以 對於所有目標文件格式都有意義。默認情況下,該符號為全局符號。這
特殊標志'before = othersym '將在指定的elseym之前插入新符號 ,否則將在符號表的末尾添加符號。
他們出現的順序。
--rename-section oldname = newname [,flags ]
將一個節從oldname重命名為newname,可以選擇在此過程中將該節的標志更改為 flags。與使用鏈接程序腳本執行以下操作相比,這具有優勢
重命名,因為輸出將保留為目標文件,並且不會成為鏈接文件
可執行文件。
當輸入格式為二進制時,此選項特別有用,因為它將 始終創建一個名為.data的節。例如,如果您想創建一個
包含二進制數據的名為.rodata的部分,您可以使用以下命令行
實現它:
objcopy -I二進制-O <輸出格式> -B <體系結構> \
--rename-section .data = .rodata,alloc,load,readonly,data,contents \
<輸入二進制文件> <輸出對象文件>
--long-section-names {啟用,禁用,保留}
處理“ COFF”和“ PE-COFF”時控制長節名稱的處理 對象格式。默認行為keep,是保留長節名稱(如果有) 在輸入文件中。在啟用和禁用選項強制啟用或 禁止在輸出對象中使用長節名稱;當禁用生效時, 輸入對象中的任何長節名稱都將被截斷。在啟用選項 如果輸入中存在長節名,則僅發出長節名;這大致相同
與keep一樣,但是使能選項是否可能強制創建仍未定義
輸出文件中的空字符串表。
--change-lead-char 某些目標文件格式在符號開頭使用特殊字符。最多
下划線通常是此類字符,編譯器通常在每個符號前添加下划線。
此選項告訴objcopy更改每個符號的前導字符 在目標文件格式之間轉換。如果目標文件格式使用相同的前導 字符,此選項無效。否則,它將添加一個字符,或刪除一個
字符,或酌情更改字符。
-刪除領先的字符
如果全局符號的第一個字符是使用的特殊符號前導字符 通過目標文件格式,刪除字符。最常見的符號領先 字符是下划線。此選項將從全球范圍內刪除領先的下划線 符號。如果要將不同文件的對象鏈接在一起,這將很有用。 符號名稱使用不同約定的格式。這不同於
--change-leading-char,因為它總是在適當的時候更改符號名稱,
無論輸出文件的目標文件格式如何。
--reverse-bytes = num 反轉具有輸出內容的節中的字節。截面長度必須均勻 被給定值整除以便能夠進行交換。倒車
發生在執行交織之前。
此選項通常用於為有問題的目標系統生成ROM映像。
例如,在某些目標板上,將從8位ROM讀取的32位字重新 不論CPU字節順序如何,都以低位字節順序匯編。根據
在編程模型中,可能需要修改ROM的字節序。
考慮一個簡單的文件,該文件的節包含以下八個字節:12345678。
對於上面的示例, 使用--reverse-bytes = 2,輸出文件中的字節為
訂購21436587。
對於上面的示例, 使用--reverse-bytes = 4,輸出文件中的字節為
訂購43218765。
通過使用--reverse字節= 2的以上示例中,接着--reverse字節= 4上的
輸出文件,第二個輸出文件中的字節將被排序34127856。
--srec-len = ival 僅對srec輸出有意義。設置Srecords的最大長度為
生產到節日。該長度涵蓋地址,數據和crc字段。
--srec-forceS3 僅對srec輸出有意義。避免生成S1 / S2記錄,僅創建S3
記錄格式。
--redefine-sym old = new
將符號old的名稱更改為new。當人們嘗試鏈接時,這可能會很有用
兩件事在一起,你沒有源頭,並且有名字沖突。
--redefine-SYMS =文件名
應用--redefine -均每個符號對“舊 新”的文件中列出的文件名。
filename是簡單的平面文件,每行一對符號。行注釋可能是 由井號字符引入。可以多次給此選項。
- 削弱 將文件中的所有全局符號更改為弱。在構建一個 使用鏈接器的-R選項與其他對象鏈接的對象。
僅當使用支持弱文件格式的目標文件格式時,此選項才有效。
符號。
--keep-symbols = filename
將--keep-symbol選項應用於文件filename中列出的每個符號。 文件名是 只是一個平面文件,每行一個符號名稱。行注釋可以通過以下方式引入 哈希字符。可以多次給此選項。
--strip-symbols = filename
將--strip-symbol選項應用於文件filename中列出的每個符號。 文件名是 只是一個平面文件,每行一個符號名稱。行注釋可以通過以下方式引入 哈希字符。可以多次給此選項。
--strip-unneeded-symbols = filename
將--strip-unneeded-symbol選項應用於文件filename中列出的每個符號。 filename是簡單的平面文件,每行一個符號名稱。行注釋可能是 由井號字符引入。可以多次給此選項。
--keep-global-symbols = filename
將--keep-global-symbol選項應用於文件filename中列出的每個符號。 filename是簡單的平面文件,每行一個符號名稱。行注釋可能是 由井號字符引入。可以多次給此選項。
--localize-symbols = filename
將--localize-symbol選項應用於文件filename中列出的每個符號。 文檔名稱 只是一個平面文件,每行一個符號名稱。可能會引入行注釋 通過井號字符。可以多次給此選項。
--globalize-symbols = filename
將--globalize-symbol選項應用於文件filename中列出的每個符號。 文檔名稱 只是一個平面文件,每行一個符號名稱。可能會引入行注釋 通過井號字符。可以多次給此選項。
--weaken-symbols = filename
將--weaken-symbol選項應用於文件filename中列出的每個符號。 文件名是 只是一個平面文件,每行一個符號名稱。行注釋可以通過以下方式引入 哈希字符。可以多次給此選項。
--alt-machine-code = index
如果輸出體系結構具有備用機器代碼,請改用index th代碼 默認之一。如果為機器分配了官方代碼,並且
工具鏈采用了新代碼,但其他應用程序仍依賴於 正在使用原始代碼。對於基於ELF的體系結構,如果使用索引替代項
不存在,則將該值視為要存儲在
ELF標頭的e_machine字段。
-可寫文本 將輸出文本標記為可寫。此選項對所有目標文件都沒有意義
格式。
--readonly-text 使輸出文本具有寫保護。此選項對所有對象都沒有意義
文件格式。
- 純的 將輸出文件標記為按需分頁。此選項對所有對象都沒有意義
文件格式。
-不純 將輸出文件標記為不純。此選項對所有目標文件都沒有意義
格式。
--prefix符號=串
前綴與輸出文件中的所有符號串。
--prefix-sections = string
使用string將輸出文件中的所有節名稱前綴。
--prefix-alloc-sections = string
使用string將輸出文件中所有已分配節的所有名稱前綴。
--add-gnu-debuglink =文件路徑
創建一個.gnu_debuglink節,其中包含對文件路徑的引用並添加 它到輸出文件。注意:指向文件路徑的文件必須存在。的一部分
添加.gnu_debuglink節的過程涉及嵌入以下文件的校驗和:
將調試信息文件的內容放入該部分。
如果調試信息文件建在一個位置,但要安裝在一個位置
稍后進入另一個位置,則不要使用安裝路徑 地點。該--add-GNU-debuglink因為安裝文件執行選項將失敗 還不存在。而是將調試信息文件放在當前目錄中,並使用
--add-gnu-debuglink選項,不包含任何目錄組件,例如:
objcopy --add-gnu-debuglink = foo.debug
在調試時,調試器將嘗試在以下位置查找單獨的調試信息文件: 一組已知位置。這些位置的確切集合取決於
使用的發行版,但通常包括:
“ *與可執行文件相同的目錄。”
“ *包含可執行文件的目錄的子目錄”
叫做.debug
“ *全局調試目錄,例如/ usr / lib / debug。
只要之前將調試信息文件安裝到這些位置之一中,
調試器正在運行,一切應該正常工作。
--keep-file-symbols
剝離文件時,可能使用--strip-debug或--strip-unneeded時,保留任何
指定源文件名的符號,否則將被剝離。
--only-keep-debug
剝離文件,刪除不會被剝離的任何節的內容
--strip-debug並保持調試部分完整無缺。在ELF文件中,此保留
輸出中的所有注釋部分。
注意-保留已刪除部分的部分標題,包括它們的標題 大小,但該部分的內容將被丟棄。節標題是
保留,以便其他工具可以將debuginfo文件與實際
可執行文件,即使該可執行文件已重定位到其他地址空間。
目的是將此選項與--add-gnu-debuglink結合使用 創建一個兩部分的可執行文件。一個剝離的二進制文件,它將占用較少的空間
在RAM和分發中,第二個是調試信息文件 如果需要調試功能,則需要。建議的程序來創建這些
文件如下:
1. <正常鏈接可執行文件。假設被稱為>
然后是“ foo”
1. <運行“ objcopy --only-keep-debug foo foo.dbg”到>
創建一個包含調試信息的文件。
1. <運行“ objcopy --strip-debug foo”創建一個>
剝離的可執行文件。
1. <運行“ objcopy --add-gnu-debuglink = foo.dbg foo”>
將調試信息的鏈接添加到剝離的可執行文件中。
注意---選擇“ .dbg”作為調試信息文件的擴展名是任意的。 同樣,“-only-keep-debug”步驟是可選的。您可以改為:
1. <正常鏈接可執行文件。
1. <將“ foo”復制到“ foo.full”
1. <運行“ objcopy --strip-debug foo”>
1. <運行“ objcopy --add-gnu-debuglink = foo.full foo”>
即,-- add-gnu-debuglink指向的文件可以是完整的可執行文件。它
不必是--only-keep-debug開關創建的文件。
注意-此開關僅適用於完全鏈接的文件。它不會
在調試信息可能不完整的目標文件上使用它是有意義的。
此外,gnu_debuglink功能目前僅支持存在一個文件名
包含調試信息,而不是每個對象一個文件包含多個文件名
基礎。
--strip-dwo
刪除所有DWARF .dwo節的內容,保留其余調試信息 部分和所有符號完整無缺。此選項供編譯器使用-gsplit-dwarf選項的 一部分,該選項在.o文件之間拆分調試信息 和一個單獨的.dwo文件。編譯器在同一時間生成所有調試信息
文件,然后使用--extract-dwo選項將.dwo部分復制到.dwo文件中,
然后使用--strip-dwo選項從原始.o文件中刪除這些部分。
--extract-dwo 提取所有DWARF .dwo節的內容。有關更多信息,請參見--strip-dwo選項
信息。
--file-alignment num 指定文件對齊方式。文件中的節將始終以文件偏移量開始 是此數字的倍數。默認值為512。[此選項特定
PE目標。]
--heap reserve
--heap reserve ,提交
指定要保留(和可選地)用作的內存字節數 該程序的堆。[此選項特定於PE目標。]
--image-base value
使用value作為程序或dll的基址。這是最低的內存 加載程序或dll時將使用的位置。減少需要
遷移並提高dll的性能,每個dll都應具有唯一的基址 並且不與任何其他dll重疊。可執行文件的默認值為0x400000,並且 dll為0x10000000。[此選項特定於PE目標。]
--section-alignment num 設置截面對齊方式。內存中的部分將始終從以下地址開始 是此數字的倍數。預設為0x1000。[此選項特定於PE
目標。]
--stack 儲備
--stack 儲備,提交
指定要保留(和可選地)用作的內存字節數 該程序的堆棧。[此選項特定於PE目標。]
--subsystem 其中
--subsystem 其中:major
--subsystem 其中:major 。次要的 指定程序將在其下執行的子系統。的法律價值
分別是“本機”,“窗口”,“控制台”,“ posix”,“ efi-app”,“ efi-bsd”,“ efi-rtd”, “ sal-rtd”和“ xbox”。您也可以選擇設置子系統版本。數字
還接受其中的值。[此選項特定於PE目標。]
--extract-符號 保留文件的節標記和符號,但刪除所有節數據。具體來說,
選項:
* <刪除所有部分的內容;> * <將每個部分的大小設置為零;和>
* <將文件的起始地址設置為零。
此選項用於為VxWorks內核構建.sym文件。也可以是
減小--just-symbols鏈接器輸入文件大小的有用方法。
--compress-debug-sections 使用zlib和ELF ABI的SHF_COMPRESSED壓縮DWARF調試節。筆記 -
如果壓縮實際上會使一個部分變大,則它不會被壓縮。
--compress-debug-sections =無
--compress-debug-sections = zlib
--compress-debug-sections = zlib-gnu
--compress-debug-sections = zlib-gabi
對於ELF文件,這些選項控制DWARF調試節的壓縮方式。
--compress-debug-sections = none等效於--decompress-debug-sections。
--compress-debug-sections = zlib和--compress-debug-sections = zlib-gabi是等效的
到--compress調試截面。 --compress-debug-sections = zlib-gnu壓縮DWARF 使用zlib調試部分。將調試部分重命名為以.zdebug
而不是.debug開頭。注意-如果壓縮實際上會使部分變大,則
它沒有壓縮也沒有重命名。
--decompress-debug-sections 使用zlib解壓縮DWARF調試部分。的原始部分名稱
壓縮的節將恢復。
--elf-stt-common =是
--elf-stt-common =否
對於ELF文件,這些選項控制是否應將通用符號轉換為
“ STT_COMMON”或“ STT_OBJECT”類型。 --elf-stt-common = yes轉換常用符號類型
到“ STT_COMMON”。--elf-stt-common = no將常用符號類型轉換為“ STT_OBJECT”。
-V
--version
顯示objcopy的版本號。
-v
--verbose 詳細輸出:列出所有已修改的目標文件。對於檔案,使用objcopy -V
列出存檔的所有成員。
--help
顯示objcopy選項的摘要。
- 信息
顯示一個列表,其中列出了所有可用的體系結構和對象格式。
@ file
從file中讀取命令行選項。讀取的選項將插入
原始@文件選項。如果文件不存在或無法讀取,則該選項
將按字面意義處理,並且不會刪除。
文件中的 選項用空格分隔。可能包含空格字符 在選項中將整個選項括在單引號或雙引號中。任何
字符(包括反斜杠)可以通過在字符前面加上 包含反斜杠。該文件本身可能包含其他@文件選項;任何
這樣的選項將被遞歸處理。
另請參見
ld(1), objdump(1)和binutils的Info條目。
版權
版權所有(c)1991-2016 Free Software Foundation,Inc.
根據以下條款授予復制,分發和/或修改本文檔的權限
GNU Free Documentation License版本1.3或Free發布的任何更高版本 軟件基礎;沒有不變的部分,沒有封面的文本,也沒有 封底文本。許可證的副本包含在標題為“ GNU Free
文檔許可證”。
原文
NAME
objcopy - copy and translate object files
SYNOPSIS
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]
[--strip-unneeded]
[-K symbolname|--keep-symbol=symbolname]
[-N symbolname|--strip-symbol=symbolname]
[--strip-unneeded-symbol=symbolname]
[-G symbolname|--keep-global-symbol=symbolname]
[--localize-hidden]
[-L symbolname|--localize-symbol=symbolname]
[--globalize-symbol=symbolname]
[--globalize-symbols=filename]
[-W symbolname|--weaken-symbol=symbolname]
[-w|--wildcard]
[-x|--discard-all]
[-X|--discard-locals]
[-b byte|--byte=byte]
[-i [breadth]|--interleave[=breadth]]
[--interleave-width=width]
[-j sectionpattern|--only-section=sectionpattern]
[-R sectionpattern|--remove-section=sectionpattern]
[--keep-section=sectionpattern]
[--remove-relocations=sectionpattern]
[-p|--preserve-dates]
[-D|--enable-deterministic-archives]
[-U|--disable-deterministic-archives]
[--debugging]
[--gap-fill=val]
[--pad-to=address]
[--set-start=val]
[--adjust-start=incr]
[--change-addresses=incr]
[--change-section-address sectionpattern{=,+,-}val]
[--change-section-lma sectionpattern{=,+,-}val]
[--change-section-vma sectionpattern{=,+,-}val]
[--change-warnings] [--no-change-warnings]
[--set-section-flags sectionpattern=flags]
[--set-section-alignment sectionpattern=align]
[--add-section sectionname=filename]
[--dump-section sectionname=filename]
[--update-section sectionname=filename]
[--rename-section oldname=newname[,flags]]
[--long-section-names {enable,disable,keep}]
[--change-leading-char] [--remove-leading-char]
[--reverse-bytes=num]
[--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]
[--weaken-symbols=filename]
[--add-symbol name=[section:]value[,flags]]
[--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]
[--strip-dwo]
[--extract-dwo]
[--extract-symbol]
[--writable-text]
[--readonly-text]
[--pure]
[--impure]
[--file-alignment=num]
[--heap=size]
[--image-base=address]
[--section-alignment=num]
[--stack=size]
[--subsystem=which:major.minor]
[--compress-debug-sections]
[--decompress-debug-sections]
[--elf-stt-common=val]
[--merge-notes]
[--no-merge-notes]
[--verilog-data-width=val]
[-v|--verbose]
[-V|--version]
[--help] [--info]
infile [outfile]
DESCRIPTION
The GNU objcopy utility copies the contents of an object file to another. objcopy uses
the GNU BFD Library to read and write the object files. It can write the destination
object file in a format different from that of the source object file. The exact behavior
of objcopy is controlled by command-line options. Note that objcopy should be able to
copy a fully linked file between any two formats. However, copying a relocatable object
file between any two formats may not work as expected.
objcopy creates temporary files to do its translations and deletes them afterward.
objcopy uses BFD to do all its translation work; it has access to all the formats
described in BFD and thus is able to recognize most formats without being told explicitly.
objcopy can be used to generate S-records by using an output target of srec (e.g., use -O
srec).
objcopy can be used to generate a raw binary file by using an output target of binary
(e.g., use -O binary). When objcopy generates a raw binary file, it will essentially
produce a memory dump of the contents of the input object file. All symbols and
relocation information will be discarded. The memory dump will start at the load address
of the lowest section copied into the output file.
When generating an S-record or a raw binary file, it may be helpful to use -S to remove
sections containing debugging information. In some cases -R will be useful to remove
sections which contain information that is not needed by the binary file.
Note---objcopy is not able to change the endianness of its input files. If the input
format has an endianness (some formats do not), objcopy can only copy the inputs into file
formats that have the same endianness or which have no endianness (e.g., srec). (However,
see the --reverse-bytes option.)
OPTIONS
infile
outfile
The input and output files, respectively. If you do not specify outfile, objcopy
creates a temporary file and destructively renames the result with the name of infile.
-I bfdname
--input-target=bfdname
Consider the source file's object format to be bfdname, rather than attempting to
deduce it.
-O bfdname
--output-target=bfdname
Write the output file using the object format bfdname.
-F bfdname
--target=bfdname
Use bfdname as the object format for both the input and the output file; i.e., simply
transfer data from source to destination with no translation.
-B bfdarch
--binary-architecture=bfdarch
Useful when transforming a architecture-less input file into an object file. In this
case the output architecture can be set to bfdarch. This option will be ignored if
the input file has a known bfdarch. You can access this binary data inside a program
by referencing the special symbols that are created by the conversion process. These
symbols are called _binary_objfile_start, _binary_objfile_end and
_binary_objfile_size. e.g. you can transform a picture file into an object file and
then access it in your code using these symbols.
-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'.
-R sectionpattern
--remove-section=sectionpattern
Remove any section matching sectionpattern from 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. Using both the -j
and -R options together results in undefined behaviour.
If the first character of sectionpattern is the exclamation point (!) then matching
sections will not be removed even if an earlier use of --remove-section on the same
command line would otherwise remove it. For example:
--remove-section=.text.* --remove-section=!.text.foo
will remove all sections matching the pattern '.text.*', but will not remove the
section '.text.foo'.
--keep-section=sectionpattern
When removing sections from the output file, keep sections that match sectionpattern.
--remove-relocations=sectionpattern
Remove non-dynamic relocations from the output file for any section matching
sectionpattern. This option may be given more than once. Note that using this option
inappropriately may make the output file unusable, and attempting to remove a dynamic
relocation section such as .rela.plt from an executable or shared library with
--remove-relocations=.plt will not work. Wildcard characters are accepted in
sectionpattern. For example:
--remove-relocations=.text.*
will remove the relocations for all sections matching the pattern '.text.*'.
If the first character of sectionpattern is the exclamation point (!) then matching
sections will not have their relocation removed even if an earlier use of
--remove-relocations on the same command line would otherwise cause the relocations to
be removed. For example:
--remove-relocations=.text.* --remove-relocations=!.text.foo
will remove all relocations for sections matching the pattern '.text.*', but will not
remove relocations for the section '.text.foo'.
-S
--strip-all
Do not copy relocation and symbol information from the source file.
-g
--strip-debug
Do not copy debugging symbols or sections from the source file.
--strip-unneeded
Strip all symbols that are not needed for relocation processing.
-K symbolname
--keep-symbol=symbolname
When stripping symbols, keep symbol symbolname even if it would normally be stripped.
This option may be given more than once.
-N symbolname
--strip-symbol=symbolname
Do not copy symbol symbolname from the source file. This option may be given more
than once.
--strip-unneeded-symbol=symbolname
Do not copy symbol symbolname from the source file unless it is needed by a
relocation. This option may be given more than once.
-G symbolname
--keep-global-symbol=symbolname
Keep only symbol symbolname global. Make all other symbols local to the file, so that
they are not visible externally. This option may be given more than once. Note: this
option cannot be used in conjunction with the --globalize-symbol or
--globalize-symbols options.
--localize-hidden
In an ELF object, mark all symbols that have hidden or internal visibility as local.
This option applies on top of symbol-specific localization options such as -L.
-L symbolname
--localize-symbol=symbolname
Convert a global or weak symbol called symbolname into a local symbol, so that it is
not visible externally. This option may be given more than once. Note - unique
symbols are not converted.
-W symbolname
--weaken-symbol=symbolname
Make symbol symbolname weak. This option may be given more than once.
--globalize-symbol=symbolname
Give symbol symbolname global scoping so that it is visible outside of the file in
which it is defined. This option may be given more than once. Note: this option
cannot be used in conjunction with the -G or --keep-global-symbol options.
-w
--wildcard
Permit regular expressions in symbolnames used in other command line options. The
question mark (?), asterisk (*), backslash (\) and square brackets ([]) operators can
be used anywhere in the symbol name. If the first character of the symbol name is the
exclamation point (!) then the sense of the switch is reversed for that symbol. For
example:
-w -W !foo -W fo*
would cause objcopy to weaken all symbols that start with "fo" except for the symbol
"foo".
-x
--discard-all
Do not copy non-global symbols from the source file.
-X
--discard-locals
Do not copy compiler-generated local symbols. (These usually start with L or ..)
-b byte
--byte=byte
If interleaving has been enabled via the --interleave option then start the range of
bytes to keep at the byteth byte. byte can be in the range from 0 to breadth-1, where
breadth is the value given by the --interleave option.
-i [breadth]
--interleave[=breadth]
Only copy a range out of every breadth bytes. (Header data is not affected). Select
which byte in the range begins the copy with the --byte option. Select the width of
the range with the --interleave-width option.
This option is useful for creating files to program ROM. It is typically used with an
"srec" output target. Note that objcopy will complain if you do not specify the
--byte option as well.
The default interleave breadth is 4, so with --byte set to 0, objcopy would copy the
first byte out of every four bytes from the input to the output.
--interleave-width=width
When used with the --interleave option, copy width bytes at a time. The start of the
range of bytes to be copied is set by the --byte option, and the extent of the range
is set with the --interleave option.
The default value for this option is 1. The value of width plus the byte value set by
the --byte option must not exceed the interleave breadth set by the --interleave
option.
This option can be used to create images for two 16-bit flashes interleaved in a
32-bit bus by passing -b 0 -i 4 --interleave-width=2 and -b 2 -i 4
--interleave-width=2 to two objcopy commands. If the input was '12345678' then the
outputs would be '1256' and '3478' respectively.
-p
--preserve-dates
Set the access and modification dates of the output file to be the same as those of
the input file.
-D
--enable-deterministic-archives
Operate in deterministic mode. When copying archive members and writing the archive
index, use zero for UIDs, GIDs, timestamps, and use consistent file modes for all
files.
If binutils was configured with --enable-deterministic-archives, then this mode is on
by default. It can be disabled with the -U option, below.
-U
--disable-deterministic-archives
Do not operate in deterministic mode. This is the inverse of the -D option, above:
when copying archive members and writing the archive index, use their actual UID, GID,
timestamp, and file mode values.
This is the default unless binutils was configured with
--enable-deterministic-archives.
--debugging
Convert debugging information, if possible. This is not the default because only
certain debugging formats are supported, and the conversion process can be time
consuming.
--gap-fill val
Fill gaps between sections with val. This operation applies to the load address (LMA)
of the sections. It is done by increasing the size of the section with the lower
address, and filling in the extra space created with val.
--pad-to address
Pad the output file up to the load address address. This is done by increasing the
size of the last section. The extra space is filled in with the value specified by
--gap-fill (default zero).
--set-start val
Set the start address of the new file to val. Not all object file formats support
setting the start address.
--change-start incr
--adjust-start incr
Change the start address by adding incr. Not all object file formats support setting
the start address.
--change-addresses incr
--adjust-vma incr
Change the VMA and LMA addresses of all sections, as well as the start address, by
adding incr. Some object file formats do not permit section addresses to be changed
arbitrarily. Note that this does not relocate the sections; if the program expects
sections to be loaded at a certain address, and this option is used to change the
sections such that they are loaded at a different address, the program may fail.
--change-section-address sectionpattern{=,+,-}val
--adjust-section-vma sectionpattern{=,+,-}val
Set or change both the VMA address and the LMA address of any section matching
sectionpattern. If = is used, the section address is set to val. Otherwise, val is
added to or subtracted from the section address. See the comments under
--change-addresses, above. If sectionpattern does not match any sections in the input
file, a warning will be issued, unless --no-change-warnings is used.
--change-section-lma sectionpattern{=,+,-}val
Set or change the LMA address of any sections matching sectionpattern. The LMA
address is the address where the section will be loaded into memory at program load
time. Normally this is the same as the VMA address, which is the address of the
section at program run time, but on some systems, especially those where a program is
held in ROM, the two can be different. If = is used, the section address is set to
val. Otherwise, val is added to or subtracted from the section address. See the
comments under --change-addresses, above. If sectionpattern does not match any
sections in the input file, a warning will be issued, unless --no-change-warnings is
used.
--change-section-vma sectionpattern{=,+,-}val
Set or change the VMA address of any section matching sectionpattern. The VMA address
is the address where the section will be located once the program has started
executing. Normally this is the same as the LMA address, which is the address where
the section will be loaded into memory, but on some systems, especially those where a
program is held in ROM, the two can be different. If = is used, the section address
is set to val. Otherwise, val is added to or subtracted from the section address.
See the comments under --change-addresses, above. If sectionpattern does not match
any sections in the input file, a warning will be issued, unless --no-change-warnings
is used.
--change-warnings
--adjust-warnings
If --change-section-address or --change-section-lma or --change-section-vma is used,
and the section pattern does not match any sections, issue a warning. This is the
default.
--no-change-warnings
--no-adjust-warnings
Do not issue a warning if --change-section-address or --adjust-section-lma or
--adjust-section-vma is used, even if the section pattern does not match any sections.
--set-section-flags sectionpattern=flags
Set the flags for any sections matching sectionpattern. The flags argument is a comma
separated string of flag names. The recognized names are alloc, contents, load,
noload, readonly, code, data, rom, share, and debug. You can set the contents flag
for a section which does not have contents, 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.
--set-section-alignment sectionpattern=align
Set the alignment for any sections matching sectionpattern. align specifies the
alignment in bytes and must be a power of two, i.e. 1, 2, 4, 8....
--add-section sectionname=filename
Add a new section named sectionname while copying the file. The contents of the new
section are taken from the file filename. The size of the section will be the size of
the file. This option only works on file formats which can support sections with
arbitrary names. Note - it may be necessary to use the --set-section-flags option to
set the attributes of the newly created section.
--dump-section sectionname=filename
Place the contents of section named sectionname into the file filename, overwriting
any contents that may have been there previously. This option is the inverse of
--add-section. This option is similar to the --only-section option except that it
does not create a formatted file, it just dumps the contents as raw binary data,
without applying any relocations. The option can be specified more than once.
--update-section sectionname=filename
Replace the existing contents of a section named sectionname with the contents of file
filename. The size of the section will be adjusted to the size of the file. The
section flags for sectionname will be unchanged. For ELF format files the section to
segment mapping will also remain unchanged, something which is not possible using
--remove-section followed by --add-section. The option can be specified more than
once.
Note - it is possible to use --rename-section and --update-section to both update and
rename a section from one command line. In this case, pass the original section name
to --update-section, and the original and new section names to --rename-section.
--add-symbol name=[section:]value[,flags]
Add a new symbol named name while copying the file. This option may be specified
multiple times. If the section is given, the symbol will be associated with and
relative to that section, otherwise it will be an ABS symbol. Specifying an undefined
section will result in a fatal error. There is no check for the value, it will be
taken as specified. Symbol flags can be specified and not all flags will be
meaningful for all object file formats. By default, the symbol will be global. The
special flag 'before=othersym' will insert the new symbol in front of the specified
othersym, otherwise the symbol(s) will be added at the end of the symbol table in the
order they appear.
--rename-section oldname=newname[,flags]
Rename a section from oldname to newname, optionally changing the section's flags to
flags in the process. This has the advantage over using a linker script to perform
the rename in that the output stays as an object file and does not become a linked
executable.
This option is particularly helpful when the input format is binary, since this will
always create a section called .data. If for example, you wanted instead to create a
section called .rodata containing binary data you could use the following command line
to achieve it:
objcopy -I binary -O <output_format> -B <architecture> \
--rename-section .data=.rodata,alloc,load,readonly,data,contents \
<input_binary_file> <output_object_file>
--long-section-names {enable,disable,keep}
Controls the handling of long section names when processing "COFF" and "PE-COFF"
object formats. The default behaviour, keep, is to preserve long section names if any
are present in the input file. The enable and disable options forcibly enable or
disable the use of long section names in the output object; when disable is in effect,
any long section names in the input object will be truncated. The enable option will
only emit long section names if any are present in the inputs; this is mostly the same
as keep, but it is left undefined whether the enable option might force the creation
of an empty string table in the output file.
--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. This is different from
--change-leading-char because it always changes the symbol name when appropriate,
regardless of the object file format of the output file.
--reverse-bytes=num
Reverse the bytes in a section with output contents. A section length must be evenly
divisible by the value given in order for the swap to be able to take place. Reversing
takes place before the interleaving is performed.
This option is used typically in generating ROM images for problematic target systems.
For example, on some target boards, the 32-bit words fetched from 8-bit ROMs are re-
assembled in little-endian byte order regardless of the CPU byte order. Depending on
the programming model, the endianness of the ROM may need to be modified.
Consider a simple file with a section containing the following eight bytes: 12345678.
Using --reverse-bytes=2 for the above example, the bytes in the output file would be
ordered 21436587.
Using --reverse-bytes=4 for the above example, the bytes in the output file would be
ordered 43218765.
By using --reverse-bytes=2 for the above example, followed by --reverse-bytes=4 on the
output file, the bytes in the second output file would be ordered 34127856.
--srec-len=ival
Meaningful only for srec output. Set the maximum length of the Srecords being
produced to ival. This length covers both address, data and crc fields.
--srec-forceS3
Meaningful only for srec output. Avoid generation of S1/S2 records, creating S3-only
record format.
--redefine-sym old=new
Change the name of a symbol old, to new. This can be useful when one is trying link
two things together for which you have no source, and there are name collisions.
--redefine-syms=filename
Apply --redefine-sym to each symbol pair "old new" listed in the file filename.
filename is simply a flat file, with one symbol pair per line. Line comments may be
introduced by the hash character. This option may be given more than once.
--weaken
Change all global symbols in the file to be weak. This can be useful when building an
object which will be linked against other objects using the -R option to the linker.
This option is only effective when using an object file format which supports weak
symbols.
--keep-symbols=filename
Apply --keep-symbol option to each symbol listed in the file filename. filename is
simply a flat file, with one symbol name per line. Line comments may be introduced by
the hash character. This option may be given more than once.
--strip-symbols=filename
Apply --strip-symbol option to each symbol listed in the file filename. filename is
simply a flat file, with one symbol name per line. Line comments may be introduced by
the hash character. This option may be given more than once.
--strip-unneeded-symbols=filename
Apply --strip-unneeded-symbol option to each symbol listed in the file filename.
filename is simply a flat file, with one symbol name per line. Line comments may be
introduced by the hash character. This option may be given more than once.
--keep-global-symbols=filename
Apply --keep-global-symbol option to each symbol listed in the file filename.
filename is simply a flat file, with one symbol name per line. Line comments may be
introduced by the hash character. This option may be given more than once.
--localize-symbols=filename
Apply --localize-symbol option to each symbol listed in the file filename. filename
is simply a flat file, with one symbol name per line. Line comments may be introduced
by the hash character. This option may be given more than once.
--globalize-symbols=filename
Apply --globalize-symbol option to each symbol listed in the file filename. filename
is simply a flat file, with one symbol name per line. Line comments may be introduced
by the hash character. This option may be given more than once. Note: this option
cannot be used in conjunction with the -G or --keep-global-symbol options.
--weaken-symbols=filename
Apply --weaken-symbol option to each symbol listed in the file filename. filename is
simply a flat file, with one symbol name per line. Line comments may be introduced by
the hash character. This option may be given more than once.
--alt-machine-code=index
If the output architecture has alternate machine codes, use the indexth code instead
of the default one. This is useful in case a machine is assigned an official code and
the tool-chain adopts the new code, but other applications still depend on the
original code being used. For ELF based architectures if the index alternative does
not exist then the value is treated as an absolute number to be stored in the
e_machine field of the ELF header.
--writable-text
Mark the output text as writable. This option isn't meaningful for all object file
formats.
--readonly-text
Make the output text write protected. This option isn't meaningful for all object
file formats.
--pure
Mark the output file as demand paged. This option isn't meaningful for all object
file formats.
--impure
Mark the output file as impure. This option isn't meaningful for all object file
formats.
--prefix-symbols=string
Prefix all symbols in the output file with string.
--prefix-sections=string
Prefix all section names in the output file with string.
--prefix-alloc-sections=string
Prefix all the names of all allocated sections in the output file with string.
--add-gnu-debuglink=path-to-file
Creates a .gnu_debuglink section which contains a reference to path-to-file and adds
it to the output file. Note: the file at path-to-file must exist. Part of the
process of adding the .gnu_debuglink section involves embedding a checksum of the
contents of the debug info file into the section.
If the debug info file is built in one location but it is going to be installed at a
later time into a different location then do not use the path to the installed
location. The --add-gnu-debuglink option will fail because the installed file does
not exist yet. Instead put the debug info file in the current directory and use the
--add-gnu-debuglink option without any directory components, like this:
objcopy --add-gnu-debuglink=foo.debug
At debug time the debugger will attempt to look for the separate debug info file in a
set of known locations. The exact set of these locations varies depending upon the
distribution being used, but it typically includes:
"* The same directory as the executable."
"* A sub-directory of the directory containing the executable"
called .debug
"* A global debug directory such as /usr/lib/debug."
As long as the debug info file has been installed into one of these locations before
the debugger is run everything should work correctly.
--keep-file-symbols
When stripping a file, perhaps with --strip-debug or --strip-unneeded, retain any
symbols specifying source file names, which would otherwise get stripped.
--only-keep-debug
Strip a file, removing contents of any sections that would not be stripped by
--strip-debug and leaving the debugging sections intact. In ELF files, this preserves
all note sections in the output.
Note - the section headers of the stripped sections are preserved, including their
sizes, but the contents of the section are discarded. The section headers are
preserved so that other tools can match up the debuginfo file with the real
executable, even if that executable has been relocated to a different address space.
The intention is that this option will be used in conjunction with --add-gnu-debuglink
to create a two part executable. One a stripped binary which will occupy less space
in RAM and in a distribution and the second a debugging information file which is only
needed if debugging abilities are required. The suggested procedure to create these
files is as follows:
1.<Link the executable as normal. Assuming that it is called>
"foo" then...
1.<Run "objcopy --only-keep-debug foo foo.dbg" to>
create a file containing the debugging info.
1.<Run "objcopy --strip-debug foo" to create a>
stripped executable.
1.<Run "objcopy --add-gnu-debuglink=foo.dbg foo">
to add a link to the debugging info into the stripped executable.
Note---the choice of ".dbg" as an extension for the debug info file is arbitrary.
Also the "--only-keep-debug" step is optional. You could instead do this:
1.<Link the executable as normal.>
1.<Copy "foo" to "foo.full">
1.<Run "objcopy --strip-debug foo">
1.<Run "objcopy --add-gnu-debuglink=foo.full foo">
i.e., the file pointed to by the --add-gnu-debuglink can be the full executable. It
does not have to be a file created by the --only-keep-debug switch.
Note---this switch is only intended for use on fully linked files. It does not make
sense to use it on object files where the debugging information may be incomplete.
Besides the gnu_debuglink feature currently only supports the presence of one filename
containing debugging information, not multiple filenames on a one-per-object-file
basis.
--strip-dwo
Remove the contents of all DWARF .dwo sections, leaving the remaining debugging
sections and all symbols intact. This option is intended for use by the compiler as
part of the -gsplit-dwarf option, which splits debug information between the .o file
and a separate .dwo file. The compiler generates all debug information in the same
file, then uses the --extract-dwo option to copy the .dwo sections to the .dwo file,
then the --strip-dwo option to remove those sections from the original .o file.
--extract-dwo
Extract the contents of all DWARF .dwo sections. See the --strip-dwo option for more
information.
--file-alignment num
Specify the file alignment. Sections in the file will always begin at file offsets
which are multiples of this number. This defaults to 512. [This option is specific
to PE targets.]
--heap reserve
--heap reserve,commit
Specify the number of bytes of memory to reserve (and optionally commit) to be used as
heap for this program. [This option is specific to PE targets.]
--image-base value
Use value as the base address of your program or dll. This is the lowest memory
location that will be used when your program or dll is loaded. To reduce the need to
relocate and improve performance of your dlls, each should have a unique base address
and not overlap any other dlls. The default is 0x400000 for executables, and
0x10000000 for dlls. [This option is specific to PE targets.]
--section-alignment num
Sets the section alignment field in the PE header. Sections in memory will always
begin at addresses which are a multiple of this number. Defaults to 0x1000. [This
option is specific to PE targets.]
--stack reserve
--stack reserve,commit
Specify the number of bytes of memory to reserve (and optionally commit) to be used as
stack for this program. [This option is specific to PE targets.]
--subsystem which
--subsystem which:major
--subsystem which:major.minor
Specifies the subsystem under which your program will execute. The legal values for
which are "native", "windows", "console", "posix", "efi-app", "efi-bsd", "efi-rtd",
"sal-rtd", and "xbox". You may optionally set the subsystem version also. Numeric
values are also accepted for which. [This option is specific to PE targets.]
--extract-symbol
Keep the file's section flags and symbols but remove all section data. Specifically,
the option:
*<removes the contents of all sections;>
*<sets the size of every section to zero; and>
*<sets the file's start address to zero.>
This option is used to build a .sym file for a VxWorks kernel. It can also be a
useful way of reducing the size of a --just-symbols linker input file.
--compress-debug-sections
Compress DWARF debug sections using zlib with SHF_COMPRESSED from the ELF ABI. Note -
if compression would actually make a section larger, then it is not compressed.
--compress-debug-sections=none
--compress-debug-sections=zlib
--compress-debug-sections=zlib-gnu
--compress-debug-sections=zlib-gabi
For ELF files, these options control how DWARF debug sections are compressed.
--compress-debug-sections=none is equivalent to --decompress-debug-sections.
--compress-debug-sections=zlib and --compress-debug-sections=zlib-gabi are equivalent
to --compress-debug-sections. --compress-debug-sections=zlib-gnu compresses DWARF
debug sections using zlib. The debug sections are renamed to begin with .zdebug
instead of .debug. Note - if compression would actually make a section larger, then
it is not compressed nor renamed.
--decompress-debug-sections
Decompress DWARF debug sections using zlib. The original section names of the
compressed sections are restored.
--elf-stt-common=yes
--elf-stt-common=no
For ELF files, these options control whether common symbols should be converted to the
"STT_COMMON" or "STT_OBJECT" type. --elf-stt-common=yes converts common symbol type
to "STT_COMMON". --elf-stt-common=no converts common symbol type to "STT_OBJECT".
--merge-notes
--no-merge-notes
For ELF files, attempt (or do not attempt) to reduce the size of any SHT_NOTE type
sections by removing duplicate notes.
-V
--version
Show the version number of objcopy.
--verilog-data-width=bytes
For Verilog output, this options controls the number of bytes converted for each
output data element. The input target controls the endianness of the conversion.
-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.
--info
Display a list showing all architectures and object formats available.
@file
Read command-line options from file. The options read are inserted in place of the
original @file option. If file does not exist, or cannot be read, then the option
will be treated literally, and not removed.
Options in file are separated by whitespace. A whitespace character may be included
in an option by surrounding the entire option in either single or double quotes. Any
character (including a backslash) may be included by prefixing the character to be
included with a backslash. The file may itself contain additional @file options; any
such options will be processed recursively.
SEE ALSO
ld(1), objdump(1), and the Info entries for binutils.
COPYRIGHT
Copyright (c) 1991-2020 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document under the terms of
the GNU Free Documentation License, Version 1.3 or any later version published by the Free
Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no
Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free
Documentation License".
【來源】