OBJCOPY(1)

๐Ÿ“ฆ version 2.47, in arch rolling

๐ŸŒธ NAME ๐ŸŒธ

okay so bestie, meet objcopy(1) from GNU Development Tools โ€” she literally exists to copy and translate object files. iconic behavior, no cap ๐Ÿ’…

โœจ 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]
        [--keep-file-symbols]
        [--keep-section-symbols]
        [-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]
        [--strip-section-headers]
        [-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]
        [--binary-symbol-prefixstring]
        [--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]
        [--only-keep-debug]
        [--strip-dwo]
        [--extract-dwo]
        [--extract-symbol]
        [--writable-text]
        [--readonly-text]
        [--pure]
        [--impure]
        [--file-alignment=num]
        [--heap=reserve[,commit]]
        [--image-base=address]
        [--section-alignment=num]
        [--stack=reserve[,commit]]
        [--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 ๐Ÿฆ‹

okay so the GNU objcopy utility copies the contents of an object file to another object file. she uses the GNU BFD Library to read and write the object files, and she can write the destination object file in a format that's different from the source object file's format. every little behavior of objcopy is controlled by command-line options, which is very main-character of her.

quick vibe check though: objcopy should be able to copy a fully linked file between any two formats. but copying a relocatable object file between any two formats may not work as expected. so likeโ€ฆ be aware, bestie ๐Ÿซถ

objcopy creates temporary files to do its translations and deletes them afterward. it 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. she just knows ๐Ÿ’…

you can use objcopy to generate S-records by using an output target of srec (e.g., use -O srec). you can also use it 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.

bestie, note this one: 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 ๐Ÿ’…

okay bestie, here's the flag-by-flag runthrough โ€” yes, every single one in this part, no skipping, periodt โœจ

  • 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. yes, destructively. she said what she said ๐Ÿ’€
  • -I bfdname, --input-target=bfdname โ€” treat the source file's object format as bfdname, instead of trying to deduce it. no guessing, just vibes.
  • -O bfdname, --output-target=bfdname โ€” write the output file using the object format bfdname. slay.
  • -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. copy-paste but make it object file ๐ŸŽ€
  • -B bfdarch, --binary-architecture=bfdarch โ€” useful when transforming an 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. iconic little trick, ngl ๐Ÿ–ผ๏ธโœจ
  • -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 sections matching .text.* but not the section .text.foo. the ! is giving โ€œnot herโ€ energy ๐Ÿ’…

  • -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.
undefined behaviour alert: using both the -j and -R options together results in undefined behaviour. do not do this to yourself, bestie ๐Ÿ˜ญ

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. protecting her fave section, honestly ๐Ÿซถ

  • --keep-section=sectionpattern โ€” when removing sections from the output file, keep sections that match sectionpattern. literally โ€œyou can go, but not you, you're stayingโ€ ๐ŸŽ€
  • --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. she's got priorities ๐Ÿ’…

  • --strip-section-headers โ€” strips the section header. this option is specific to ELF files. it implies --strip-all and --merge-notes. ELF girlies only ๐Ÿ’–
  • -S, --strip-all โ€” do not copy relocation and symbol information from the source file. also deletes debug sections. she's cleaning house ๐Ÿงนโœจ
  • -g, --strip-debug โ€” do not copy debugging symbols or sections from the source file. debug info? not invited to the function.
  • --strip-unneeded โ€” remove all symbols that are not needed for relocation processing, in addition to debugging symbols and sections stripped by --strip-debug. ruthless but make it efficient ๐Ÿ’€
  • -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. bestie is on the keep list ๐Ÿซถ
  • -N symbolname, --strip-symbol=symbolname โ€” do not copy symbol symbolname from the source file. this option may be given more than once. blocked. unfollowed. stripped. ๐Ÿ™ˆ
  • --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. not to be dramatic, but it's giving โ€œconditional friendshipโ€ ๐Ÿ˜ญ
  • -G symbolname, --keep-global-symbol=*symbolname* โ€” bestie, this one says: keep only symbolname global. Everything else gets demoted to local so it's not visible externally, periodt. You can drop this option more than once. Heads up tho: you literally cannot combine it with --globalize-symbol or --globalize-symbols โ€” they fight, and the tool will not be having it.
  • --localize-hidden โ€” for ELF objects, this snaps every symbol that has hidden or internal visibility into a local symbol. And it stacks on top of the symbol-specific localization stuff like -L, so it's giving "yes and" energy ๐Ÿ’…
  • -L symbolname, --localize-symbol=*symbolname* โ€” turns a global or weak symbol named symbolname into a local one, so it's not visible externally anymore. You can give this more than once. Note: unique symbols do not get converted โ€” they simply don't play that game.
  • -W symbolname, --weaken-symbol=*symbolname* โ€” makes symbolname weak ๐Ÿฅบ. Can be given more than once.
  • --binary-symbol-prefix=*string* โ€” when you're running it with --input-target=binary, this sets string as the base name for the symbols generated for the input file. The symbols it's talking about are:
<string>_start
<string>_end
<string>_size

By default the binary input handler just derives the prefix symbol name from a mangled version of the input file name plus the _binary prefix. This option lets you say it explicitly instead. No more guessing games โœจ

  • --globalize-symbol=*symbolname* โ€” the glow-up option ๐Ÿ‘‘ gives symbolname global scoping so it's visible outside the file it's defined in. Can be given more than once. Note: this one cannot be used in conjunction with -G or --keep-global-symbol โ€” those two are lowkey enemies.
  • -w, --wildcard โ€” lets you use regular expressions in the symbolnames you pass to other command line options. The ?, *, \ and [] operators can go absolutely anywhere in the symbol name. And if the first character of the symbol name is !, the sense of the switch gets reversed for that symbol. Like, for example:
-w -W !foo -W fo*

would make objcopy weaken all symbols that start with "fo" except for the symbol "foo". Iconic exclusion behaviour, no cap ๐ŸŽ€

  • -x, --discard-all โ€” do not copy non-global symbols from the source file. Bye ๐Ÿ‘‹
  • -X, --discard-locals โ€” do not copy compiler-generated local symbols. (These usually start with L or . โ€” yeah, the compiler's little scribbles.)
  • -b byte, --byte=*byte* โ€” if interleaving is already enabled via --interleave, this sets where the range of bytes to keep starts โ€” at the byteth byte. byte can be anywhere from 0 to breadth-1, where breadth is whatever value you gave to --interleave.
  • -i [breadth], --interleave[=*breadth*] โ€” only copy a range out of every breadth bytes. (Header data is not affected, it's built different.) Which byte in the range kicks off the copy? That's the --byte option's job. How wide is the range? That's --interleave-width.

This is the ROM-programming era option โ€” super useful for making files to program ROM, and it's typically used with an "srec" output target. Just so you know: objcopy will complain at you if you don't also specify --byte. It's not flexible about this.

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. Cute, efficient, slay.

  • --interleave-width=*width* โ€” when used with --interleave, copy width bytes at a time. Where the range starts is set by --byte, and the extent of the range is set with --interleave.

The default value is 1. And here's the catch: width plus the byte value from --byte must not exceed the interleave breadth from --interleave. Math check, bestie ๐Ÿงฎ

You can use this to make 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. Literally splitting the friend group, and both halves ate ๐Ÿ’…

  • -p, --preserve-dates โ€” sets the access and modification dates of the output file to be the same as the input file's. Keeping the timestamps alive, we love to see it ๐Ÿซถ

It also copies the date stored in a PE format file's header โ€” unless the SOURCE_DATE_EPOCH environment variable is defined. If it is defined, then that variable is used as the date stored in the header, interpreted as the number of seconds since the Unix epoch.

  • -D, --enable-deterministic-archives โ€” deterministic mode, engaged โœจ When copying archive members and writing the archive index, it uses zero for UIDs, GIDs, timestamps, and uses consistent file modes for all files. Everything's the same every time, it's giving consistency queen.

If binutils was configured with --enable-deterministic-archives, then this mode is on by default. You can turn it off with the -U option, below.

  • -U, --disable-deterministic-archives โ€” do not operate in deterministic mode. It's the exact inverse of -D: when copying archive members and writing the archive index, it uses their actual UID, GID, timestamp, and file mode values. The real real, no filter ๐Ÿ’€

This is the default unless binutils was configured with --enable-deterministic-archives.

  • --debugging โ€” convert debugging information, if possible. It's not the default because only certain debugging formats are supported, and the conversion process can be time consuming. So it's a "when you need it" vibe, not an "always on" vibe.
  • --gap-fill val โ€” fills the gaps between sections with val. This applies to the load address (LMA) of the sections, and it works by growing the size of the section with the lower address and filling in that extra space with val. Filling the silence ๐Ÿซถ
  • --pad-to address โ€” pads the output file up to the load address address. Done by increasing the size of the last section, and the extra space gets filled in with whatever --gap-fill says (default zero if you never set it).
  • --set-start val โ€” sets the start address (also known as the entry address) of the new file to val. Not all object file formats support setting the start address โ€” some of them are just not built for that.
  • --change-start incr, --adjust-start incr โ€” changes the start address (aka the entry address) by adding incr to it. Again: not all object file formats support setting the start address.
  • --change-addresses incr, --adjust-vma incr โ€” changes the VMA and LMA addresses of all sections, plus the start address, by adding incr. Some object file formats don't permit section addresses to be changed arbitrarily, so don't be shocked. Also, important note: this does not relocate the sections. If the program expects sections to be loaded at a certain address, and you use this option to change them so they load somewhere else, the program may fail. Like, catastrophically. You've been warned ๐Ÿ˜ญ
  • --change-section-address sectionpattern{=,+,-}val, --adjust-section-vma sectionpattern{=,+,-}val โ€” sets or changes 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 (yes, the scary ones). And if sectionpattern doesn't match any sections in the input file, a warning gets issued โ€” unless you used --no-change-warnings.
  • --change-section-lma sectionpattern{=,+,-}val โ€” sets or changes the LMA address of any sections matching sectionpattern. The LMA address is where the section gets loaded into memory at program load time. Normally that's the same as the VMA address (which is where the section is at program run time), but on some systems โ€” especially ones where the program lives in ROM โ€” the two can differ. If = is used, the section address is set to val. Otherwise val is added or subtracted. See the comments under --change-addresses above. If sectionpattern matches nothing in the input file, warning time, unless --no-change-warnings is in play.
  • --change-section-vma sectionpattern{=,+,-}val โ€” sets or changes the VMA address of any section matching sectionpattern. The VMA address is where the section will be located once the program has started executing. Normally same as the LMA address (where it gets loaded into memory), but on some systems โ€” again, ROM situations โ€” they can be different. If = is used, the section address is set to val. Otherwise val is added or subtracted. See the comments under --change-addresses above. No matching sections? Warning, unless --no-change-warnings.
โš ๏ธ Also note: changing the VMA of sections in a fully linked binary can be dangerous, since there may be code that expects the sections to be located at their old address. Do not do this casually, bestie. This is not a vibe-check situation, this is a "you will break the binary" situation ๐Ÿ’€
  • --change-warnings, --adjust-warnings โ€” if --change-section-address or --change-section-lma or --change-section-vma is used and the section pattern doesn't match any sections, issue a warning. This is the default. The tool is looking out for you ๐Ÿซถ
  • --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 matches zero sections. Silence is golden, apparently ๐Ÿ™ˆ
  • --set-section-flags sectionpattern=flags โ€” sets 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, exclude, share, debug, and large.

You can set the contents flag for a section that doesn't have contents, but it's not meaningful โ€” and it's not meaningful to clear the contents flag of a section that does have contents either. Just remove the section instead, it's cleaner. Not all flags are meaningful for all object file formats, obviously. In particular the share flag is only meaningful for COFF format files and not for ELF format files. And the ELF x86-64 specific flag large corresponds to SHF_X86_64_LARGE โœจ

  • --set-section-alignment sectionpattern=align โ€” sets 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.... Powers of two only, the math has to math ๐Ÿงš
๐ŸŽ€ heads up bestie โ€” setting a section's alignment does not magically align its LMA or VMA addresses too. If you need those moved, you gotta reach for --change-section-lma and/or --change-section-vma separately, no cap. And fr, changing VMAs can cause problems in fully linked binaries, because there may be code in there that literally expects the section contents to sit at their old address. so likeโ€ฆ be careful. ๐Ÿ’€

  • --add-section sectionname=filename โ€” bestie, this one adds a brand new section called sectionname while it's copying the file. the contents of the new section come straight from the file filename, and the size of the section will be the size of that file. it only works on file formats that can support sections with arbitrary names, so vibe check your format first. ๐Ÿ’… note: it may be necessary to also use the --set-section-flags option to set the attributes of your freshly created section.
  • --dump-section sectionname=filename โ€” the inverse of --add-section, iconic behavior honestly. it places the contents of the section named sectionname into the file filename, overwriting any contents that may have been there before (sorry, old data ๐Ÿ˜ญ). this one 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. you can specify this option more than once. โœจ
  • --update-section sectionname=filename โ€” replace the existing contents of a section named sectionname with the contents of the file filename. the size of the section will be adjusted to the size of the file, and the section flags for sectionname will stay unchanged. ๐Ÿซถ for ELF format files the section to segment mapping also remains unchanged โ€” something which is literally not possible using --remove-section followed by --add-section. this option can be specified more than once.
๐ŸŒธ note: you can use --rename-section and --update-section together to both update and rename a section from one single command line. in that case, pass the original section name to --update-section, and pass the original and new section names to --rename-section. iykyk.
  • --add-symbol name=[section:]value[,flags] โ€” adds 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'll be an ABS symbol. โญ specifying an undefined section will result in a fatal error โ€” so maybe don't. 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] โ€” renames a section from oldname to newname, optionally changing the section's flags to flags while it's at it. the advantage over using a linker script to do the rename is that the output stays as an object file and does not become a linked executable. ๐Ÿ‘‘ this option accepts the same set of flags as the --set-section-flags option.

this one is particularly helpful when the input format is binary, since that will always create a section called .data. so if, for example, you wanted to create a section called .rodata containing binary data instead, 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. ๐ŸŒˆ enable and disable 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 enable 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'll 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, so this option will remove a leading underscore from all global symbols. super 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. math is mathing ๐Ÿ’…

  • --srec-len=ival โ€” meaningful only for srec output. sets 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. avoids 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 you're trying to link two things together for which you have no source, and there are name collisions. we've all been there ๐Ÿ˜ญ
  • --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. 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. pick a lane bestie.
  • --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. 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 either. โญ
  • --pure โ€” Marks the output file as demand paged. This option isnโ€™t meaningful for every object file format, bestie. ๐Ÿ’…
  • --impure โ€” Marks the output file as impure. Also not meaningful for all object file formats. ๐Ÿซถ
  • --prefix-symbols=string โ€” Prefixes all symbols in the output file with string. Slay.
  • --prefix-sections=string โ€” Prefixes all section names in the output file with string. โœจ
  • --prefix-alloc-sections=string โ€” Prefixes all the names of all allocated sections in the output file with string. ๐ŸŽ€
  • --add-gnu-debuglink=path-to-file โ€” Creates a .gnu_debuglink section that contains a reference to path-to-file, then adds it to the output file. Note: the file at path-to-file must exist. Part 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 is going to be installed later 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 doesnโ€™t 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 on 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-section-symbols โ€” When stripping a file โ€” maybe with --strip-debug or --strip-unneeded โ€” retains any symbols specifying section names, which would otherwise get stripped. ๐Ÿฆ‹
  • --keep-file-symbols โ€” When stripping a file โ€” maybe with --strip-debug or --strip-unneeded โ€” retains any symbols specifying source file names, which would otherwise get stripped. ๐ŸŒธ
  • --only-keep-debug โ€” Strips 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 together with --add-gnu-debuglink to create a two-part executable. One is a stripped binary that takes up less space in RAM and in a distribution, and the second is a debugging information file thatโ€™s only needed if debugging abilities are required. The suggested procedure to create these files is as follows:

  1. Link the executable as normal. Assuming itโ€™s called "foo" thenโ€ฆ
  2. Run "objcopy --only-keep-debug foo foo.dbg" to create a file containing the debugging info.
  3. Run "objcopy --strip-debug foo" to create a stripped executable.
  4. 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.
  2. Copy "foo" to "foo.full".
  3. Run "objcopy --strip-debug foo".
  4. Run "objcopy --add-gnu-debuglink=foo.full foo".

i.e., the file pointed to by --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 doesnโ€™t 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 โ€” Removes 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 โ€” Extracts the contents of all DWARF .dwo sections. See the --strip-dwo option for more info. โญ
  • --file-alignment num โ€” Specifies the file alignment. Sections in the file will always begin at file offsets that are multiples of this number. This defaults to 512. [This option is specific to PE targets.] ๐Ÿ’œ
  • --heap reserve
  • --heap reserve,commit โ€” Specifies 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 โ€” Uses 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 โ€” [This option is specific to PE targets.]

Sets the section alignment field in the PE header โ€” if one is present in the binary. Sections in memory will always begin at addresses that are a multiple of this number. Defaults to 0x1000. โœจ

Note โ€” if a sectionโ€™s LMA or VMA addresses are no longer aligned, and those addresses have not been set via the --set-section-lma or --set-section-vma options, and the file has been fully relocated, then a warning message will be issued. It will then be up to the user to decide if the LMA and VMA need updating. ๐Ÿ˜ญ

  • --stack reserve
  • --stack reserve,commit โ€” Specifies 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 too. Numeric values are also accepted for which. [This option is specific to PE targets.] ๐Ÿ‘‘
  • --extract-symbol โ€” Keeps the fileโ€™s section flags and symbols but removes all section data. Specifically, this option:
    • Removes the contents of all sections.
    • Sets the size of every section to zero.
    • 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 โ€” Compresses 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
  • --compress-debug-sections=zstd โ€” 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 the obsoleted zlib-gnu format. The debug sections are renamed to begin with .zdebug. --compress-debug-sections=zstd compresses DWARF debug sections using zstd. Note โ€” if compression would actually make a section larger, then it is not compressed nor renamed. ๐ŸŒˆ
  • --decompress-debug-sections โ€” Decompresses DWARF debug sections. For a .zdebug section, the original name is 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, attempts (or does not attempt) to reduce the size of any SHT_NOTE type sections by removing duplicate notes. ๐Ÿ”ฅ
  • -V
  • --version โ€” Shows the version number of objcopy. โญ
  • --verilog-data-width=bytes โ€” For Verilog output, this option controls the number of bytes converted for each output data element. The input target controls the endianness of the conversion. ๐Ÿงš
  • -v
  • --verbose โ€” Verbose output: lists all object files modified. In the case of archives, objcopy -V lists all members of the archive. ๐Ÿ’œ
  • --help โ€” Shows a summary of the options to objcopy. ๐Ÿซถ
  • --info โ€” Displays a list showing all architectures and object formats available. ๐ŸŒธ
  • @file โ€” Reads 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 ๐ŸŒธ

okay so when you're done vibing with objcopy and you want more unix besties to hang out with, go check these out:

  • ld(1) โ€” the linker bestie, fr fr. different job, same friend group.
  • objdump(1) โ€” literally the reader to objcopy's writer, the way they're such an iconic duo ๐Ÿ’…
  • and the Info entries for binutils โ€” yes, the whole info system, not just a man page. it's giving deep lore ๐ŸŽ€

okay so the legal bit, and no we can't skip it, it's important:

Copyright (c) 1991-2026 Free Software Foundation, Inc.

and here's the permission part โ€” you are granted permission 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, and this matters:

  • no Invariant Sections โœจ
  • no Front-Cover Texts โœจ
  • no Back-Cover Texts โœจ

and a copy of the license is included in the section entitled "GNU Free Documentation License" โ€” so like, it's right there, go read it, iykyk ๐Ÿ“–


lowkey the whole "no Invariant Sections, no Front-Cover Texts, no Back-Cover Texts" thing is just the license saying you have full freedom to remix this doc โ€” slay ๐Ÿ’…

and that's the whole page bestie, you made it to the end, main character energy fr fr ๐ŸŒˆ๐Ÿ‘‘

this glorious manual page is from binutils-2.47, dated 2026-08-31, and it's the OBJCOPY(1) page โ€” go forth and copy your objects, you absolute icon ๐Ÿฆ‹๐Ÿ’œ

๐Ÿ“ฆ where this page comes from