objcopy
copies the contents of an object file to another, optionally transforming it
TLDR
Copy data to another file
SYNOPSIS
objcopy [-F bfdname | --target=bfdname] [-I bfdname | --input-target=bfdname] [-O bfdname | --output-target=bfdname] [options] infile [outfile]
DESCRIPTION
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.
PARAMETERS
-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 .gnudebuglink 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
CAVEATS
Cannot change the endianness of input files; target format must match source endianness or have no endianness (like S-records). Copying relocatable object files between formats may not preserve all information correctly. Fully linked executables copy more reliably across formats.
HISTORY
Part of GNU Binutils, first released in 1991 alongside other binary utilities like objdump and nm. Developed to complement the GNU toolchain (GCC, GAS, ld) for cross-platform development and embedded systems programming.
