← 返回命令列表

Linux command

objcopy 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Copy

objcopy [path/to/source_file] [path/to/target_file]

Example

objcopy --input-target=[input_format] --output-target [output_format] [path/to/source_file] [path/to/target_file]

Strip all symbol

objcopy --strip-all [path/to/source_file] [path/to/target_file]

Example

objcopy --strip-debug [path/to/source_file] [path/to/target_file]

Example

objcopy --only-section [section] [path/to/source_file] [path/to/target_file]

说明

objcopy copies the contents of an object file to another, optionally transforming it in the process. It uses the GNU BFD library to read and write object files in various formats including ELF, COFF, S-records, and raw binary. Common uses include: stripping symbols to reduce binary size, extracting debug information to separate files, converting between executable formats (e.g., ELF to raw binary for embedded systems), and copying or removing specific sections from object files.

参数

-I _bfdname_, --input-target=_bfdname_
Consider the source file's object format to be _bfdname_
-O _bfdname_, --output-target=_bfdname_
Write the output file using the object format _bfdname_
-F _bfdname_, --target=_bfdname_
Use _bfdname_ as the format for both input and output
-j _name_, --only-section=_name_
Copy only the specified section to the output
-R _name_, --remove-section=_name_
Remove the specified section from the output
-S, --strip-all
Remove all symbol and relocation information
-g, --strip-debug
Remove debugging symbols only
--only-keep-debug
Strip everything except debugging information
--add-gnu-debuglink=_file_
Add a .gnu_debuglink section linking to _file_
--dump-section _name_=_file_
Dump contents of section _name_ to _file_
--rename-section _old_=_new_,_flags_
Rename section _old_ to _new_ with optional flags
-B _bfdarch_, --binary-architecture=_bfdarch_
Set architecture when input is binary format
-i, --info
List all available BFD target formats

FAQ

What is the objcopy command used for?

objcopy copies the contents of an object file to another, optionally transforming it in the process. It uses the GNU BFD library to read and write object files in various formats including ELF, COFF, S-records, and raw binary. Common uses include: stripping symbols to reduce binary size, extracting debug information to separate files, converting between executable formats (e.g., ELF to raw binary for embedded systems), and copying or removing specific sections from object files.

How do I run a basic objcopy example?

Run `objcopy [path/to/source_file] [path/to/target_file]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -I _bfdname_, --input-target=_bfdname_ do in objcopy?

Consider the source file's object format to be _bfdname_