objcopy
developmentLinux/Unix
The objcopy command is one of the most frequently used commands in Linux/Unix-like operating systems. objcopy Copy and translate object files
Quick Reference
Command Name:
objcopy
Category:
development
Platform:
Linux/Unix
Basic Usage:
objcopy [options] [arguments]
Common Use Cases
Syntax
objcopy [options] input-file [output-file]
Options
Option | Description |
---|---|
-I bfdname , --input-target=bfdname |
Set the input file format |
-O bfdname , --output-target=bfdname |
Set the output file format |
-F bfdname , --target=bfdname |
Set both input and output formats to bfdname |
-R sectionname , --remove-section=sectionname |
Remove named section from the output |
-S , --strip-all |
Remove all symbols and relocation information |
-g , --strip-debug |
Remove all debugging symbols |
--strip-unneeded |
Remove all symbols not needed by relocations |
--only-keep-debug |
Keep only debugging information |
--add-gnu-debuglink=file |
Add section .gnu_debuglink linking to file |
--add-section=sectionname=filename |
Add section sectionname with contents from filename |
--rename-section=old=new[,flags] |
Rename section old to new, optionally setting flags |
--set-section-flags=sectionname=flags |
Set section flags for named section |
-K symbolname , --keep-symbol=symbolname |
Keep only symbol symbolname |
-N symbolname , --strip-symbol=symbolname |
Remove symbol symbolname |
--keep-symbols=filename |
Keep only symbols listed in filename |
--strip-symbols=filename |
Remove symbols listed in filename |
--redefine-sym=old=new |
Rename symbol old to new |
--redefine-syms=filename |
Rename symbols listed in filename |
--weaken |
Change all global symbols to weak |
-G symbolname , --keep-global-symbol=symbolname |
Keep only symbol symbolname global |
-W symbolname , --weaken-symbol=symbolname |
Make symbol symbolname weak |
--gap-fill=val |
Fill gaps between sections with val |
--pad-to=address |
Pad the last section to address |
--compress-debug-sections |
Compress DWARF debug sections |
Examples
How to Use These Examples
The examples below show common ways to use the objcopy
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
# Basic Examples Basic
objcopy -O binary input.o output.bin