OBJCOPY(1)

๐Ÿ“ฆ version 2.45.1, in arch rolling

๐Ÿ’… OBJCOPY ๐Ÿ’…

ok so this is objcopy from the GNU Development Tools, and bestieโ€ฆ she is the object-file glow-up machine. Let's get into it ๐Ÿซถ


โœจ NAME โœจ

objcopy โ€” copy and translate object files. that's it. that's the whole vibe. ๐Ÿ”ฅ


๐ŸŽ€ SYNOPSIS ๐ŸŽ€

lowkey a lot going on here but like, just breathe and read it:

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]
        [--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 ๐ŸŒธ

ok so the GNU objcopy utility copies the contents of an object file into another one. iconic behavior honestly. โœจ objcopy uses the GNU BFD Library to read and write the object files, and it can write the destination object file in a format that's different from the source object file's format. the exact behavior of objcopy is controlled by command-line options โ€” she's very "you tell me what you want and I'll do it" energy.

โš ๏ธ heads up bestie: 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. not her fault, it's just how it is ๐Ÿ˜ญ

objcopy creates temporary files to do its translations and deletes them afterward. she uses BFD to do all her translation work โ€” she has access to all the formats described in BFD and thus can recognize most formats without being told explicitly. main character who already knows everyone at the party ๐Ÿ’…

you can use objcopy to generate S-records by using an output target of srec (e.g., use -O srec). and 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, and the memory dump will start at the load address of the lowest section copied into the output file. gone. deleted. she doesn't keep that. ๐Ÿฆ‹

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. just little tips from your girl ๐ŸŽ€

๐Ÿ’€ 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.) so likeโ€ฆ no endian-flipping, that's not her job, but there is a workaround-ish option, iykyk.

โญ OPTIONS โญ

okay this is the big one. buckle up bestie, every single flag is here:

  • 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. ๐Ÿซฃ "destructively renames" like she's not even sorry.
  • -I bfdname, --input-target=bfdname โ€” treat the source file's object format as bfdname, rather than attempting to deduce it. no detective work, you just tell her.
  • -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. like copy-paste but make it binary ๐Ÿ’…
  • -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. literally turning a pic into code, that's so iconic ๐ŸŒˆ
  • -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 ๐Ÿ˜ญ so like, be careful. 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 literally "not you bestie" ๐Ÿ™ˆ

  • -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 โ€” like, genuinely undefined, don't do it, that's a "we don't know what happens" situation ๐Ÿ’€

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. the "no wait not THAT one" flag ๐Ÿซถ
  • --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.

  • --strip-section-headers โ€” strip section header. this option is specific to ELF files. implies --strip-all and --merge-notes. โœจ she takes the whole header section out.
  • -S, --strip-all โ€” do not copy relocation and symbol information from the source file. also deletes debug sections. everything must go ๐Ÿงน
  • -g, --strip-debug โ€” do not copy debugging symbols or sections from the source file.
  • --strip-unneeded โ€” remove all symbols that are not needed for relocation processing, in addition to debugging symbols and sections stripped by --strip-debug. the "if you're not contributing to relocations you're out" flag ๐Ÿ˜ค
  • -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. your fave gets VIP access ๐Ÿ’–
  • -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.

ok that's part 1, and there's so much more where that came fromโ€ฆ ๐Ÿ‘€

  • -G symbolname, **--keep-global-symbol=*symbolname*** โ€” okay so this one keeps *only* symbolnameglobal, and makes literally every other symbol local to the file so they're not visible externally. You can drop this option more than once bestie, it stacks. **But** โš ๏ธ heads up: you cannot use it alongside--globalize-symbolor--globalize-symbols`, they fight.
  • --localize-hidden โ€” in an ELF object, this marks every symbol that has hidden or internal visibility as local. And it stacks โ€” it applies on top of symbol-specific localization options like -L. ๐Ÿ’…
  • -L symbolname, --localize-symbol=*symbolname*** โ€” takes a global or weak symbol called symbolname` and converts it into a local symbol, so it's not visible externally anymore. Repeatable, use it as many times as you want. ๐Ÿ“Œ Small note: unique symbols are **not converted, no cap.
  • -W symbolname, **--weaken-symbol=*symbolname*** โ€” makes symbol symbolname` weak. Also repeatable, go off. ๐Ÿฆ‹
  • **--globalize-symbol=*symbolname*** โ€” gives symbolnameglobal scoping so it's visible outside the file it's defined in. Repeatable. โš ๏ธ But it **cannot** be used in conjunction with-Gor--keep-global-symbol` โ€” pick a side, babe.
  • -w, --wildcard โ€” this one lets you use regular expressions in the symbolnames you pass to other command line options. The ?, *, \ and [] operators can go anywhere in the symbol name. And if the first character of the symbol name is ! then the sense of the switch is flipped for that one symbol. For example:
-w -W !foo -W fo*

would make objcopy weaken all symbols that start with "fo" except for the symbol "foo". The exclusion ate, honestly. โœจ

  • -x, --discard-all โ€” do not copy non-global symbols from the source file. Simple as that, we're leaving them behind. ๐Ÿ’€
  • -X, --discard-locals โ€” do not copy compiler-generated local symbols. Those ones usually start with L or . btw, so you know exactly which ones we're ghosting. ๐Ÿ™ˆ
  • -b byte, **--byte=*byte*** โ€” so *if* interleaving has been enabled via --interleave, this starts the range of bytes to keep at the *byte*th byte. bytecan be anything from0tobreadth-1, where breadth is the value you gave to --interleave`.
  • -i [breadth], --interleave[=*breadth*] โ€” only copies a range out of every breadth bytes. (Header data is not affected, fyi.) You pick which byte in the range starts the copy with --byte, and you pick the width of the range with --interleave-width. ๐ŸŽ€

This one is genuinely iconic for making files to program ROM with, and it's typically used with an "srec" output target. โš ๏ธ Note that objcopy will complain if you don't also specify the --byte option โ€” it needs both, periodt.

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 and efficient. โœจ

  • **--interleave-width=*width*** โ€” when used with the --interleaveoption, this copieswidthbytes at a time. The start of the range is set by--byte, and the extent of the range is set with --interleave`.

Default value is 1. And the math has to work: the value of width plus the byte value set by --byte must not exceed the interleave breadth set by --interleave. ๐Ÿ”ฅ

This is how you make images for two 16-bit flashes interleaved in a 32-bit bus โ€” pass -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. Look at that split, she's beautiful ๐Ÿ˜ญ๐Ÿ’–

  • -p, --preserve-dates โ€” sets the access and modification dates of the output file to be the same as the input file's. Time travel but make it file metadata. ๐Ÿ•ฐ๏ธ

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 gets used as the date stored in the header, interpreted as the number of seconds since the Unix epoch.

  • -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. 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 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. Simple as. โœจ

  • --debugging โ€” converts debugging information, if possible. It's not the default because only certain debugging formats are supported, and ngl the conversion process can be time consuming. ๐Ÿ˜ฎโ€๐Ÿ’จ
  • --gap-fill val โ€” fills the gaps between sections with val. This applies to the load address (LMA) of the sections. How? By increasing the size of the section with the lower address, and filling in the extra space created with val.
  • --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 the value specified by --gap-fill (default is zero). ๐ŸŽ€
  • --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, so vibe check your format first.
  • --change-start incr, --adjust-start incr โ€” changes the start address (again, the entry address) by adding incr. โš ๏ธ Same caveat: 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 do not permit section addresses to be changed arbitrarily.
โš ๏ธ Big one: 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 the sections so they load at a different address, the program may fail. Do not do this casually bestie.
  • --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, including the dangerous part ๐Ÿ’€). And if sectionpattern doesn't match any sections in the input file, a warning gets issued โ€” unless --no-change-warnings is used.
  • --change-section-lma sectionpattern{=,+,-}val โ€” sets or changes the LMA address of any sections matching sectionpattern. So what's LMA? It's the address where the section will be loaded into memory at program load time. Normally it's the same as the VMA address (which is the address at program run time), but on some systems โ€” especially ones 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. And if sectionpattern doesn't match any sections in the input file, a warning gets issued โ€” unless --no-change-warnings is used.

  • --change-section-vma sectionpattern{=,+,-}val โ€” sets or changes the VMA address of any section matching sectionpattern. The VMA is the address where the section will be located once the program has started executing. Normally it's the same as the LMA (the address where the section is loaded into memory), but on some systems โ€” again, especially ones where a program lives in ROM โ€” the two can differ. ๐ŸŒธ

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. And if sectionpattern doesn't match any sections, a warning gets issued โ€” unless --no-change-warnings is used.

โš ๏ธ 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. She said what she said.
  • --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 behavior. ๐Ÿ“ฃ
  • --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 doesn't match any 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, and the recognized ones are alloc, contents, load, noload, readonly, code, data, rom, exclude, share, debug, and large. ๐Ÿท๏ธ

You can set the contents flag for a section which doesn't have contents, but it's not meaningful to clear the contents flag of a section that does have contents โ€” just remove the section instead, babe. ๐Ÿ’…

Not all flags are meaningful for all object file formats. 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.... No chaos allowed, only powers of two โญ
โš ๏ธ Note: setting a section's alignment will not automatically align its LMA or VMA addresses. If those need changing too, use the --change-section-lma and/or --change-section-vma options. Also note that changing VMAs can cause problems in fully linked binaries, where there may be code that expects the contents of the sections to be located at their old address. Yep, again. ๐Ÿ˜ญ
  • --add-section sectionname=filename โ€” okay so this one adds a brand-new section named sectionname while copying the file ๐ŸŽ€. The contents of the new section come straight from filename, and the section size is literally the size of that file. It only works on file formats that can support sections with arbitrary names. Note โ€” it may be necessary to use --set-section-flags to set the attributes of the newly created section.
  • --dump-section sectionname=filename โ€” puts the contents of the section named sectionname into filename, overwriting anything that was already there ๐Ÿ’…. This is the inverse of --add-section. Itโ€™s similar to --only-section except it does not create a formatted file โ€” it just dumps the contents as raw binary data, without applying any relocations. Can be specified more than once.
  • --update-section sectionname=filename โ€” replaces the existing contents of the section named sectionname with the contents of filename. The section size gets adjusted to the size of the file. The section flags for sectionname stay unchanged. For ELF format files, the section-to-segment mapping also remains unchanged โ€” something that is not possible with --remove-section followed by --add-section. Can be specified more than once.

Note โ€” you can use --rename-section and --update-section to both update and rename a section from one command line. In that 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] โ€” adds a new symbol named name while copying the file. May be specified multiple times. If section is given, the symbol will be associated with and relative to that section; otherwise itโ€™s an ABS symbol. Specifying an undefined section results in a fatal error ๐Ÿ˜ญ. There is no check for the value โ€” itโ€™s taken as specified. Symbol flags can be specified, and not all flags will be meaningful for all object file formats. By default, the symbol is global. The special flag 'before=othersym' inserts the new symbol in front of the specified othersym; otherwise the symbol(s) get 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 in the process โœจ. This has the advantage over using a linker script to perform the rename because the output stays as an object file and does not become a linked executable. It accepts the same set of flags as --set-section-flags. This is especially helpful when the input format is binary, since that always creates a section called .data. If, for example, you wanted to create a section called .rodata containing binary data instead, you could use this command line:
                     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 how long section names are handled 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 only emits long section names if any are present in the inputs โ€” 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, and the most common one is an underscore, which compilers often add before every symbol ๐ŸŒธ. This tells objcopy to change the leading character of every symbol when it converts between object file formats. If the formats use the same leading character, this has no effect. Otherwise, it adds a character, removes a character, or changes 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, it removes that character โœ‚๏ธ. The most common leading character is underscore. This removes a leading underscore from all global symbols. Useful if you want to link together objects of different file formats with different conventions for symbol names. Itโ€™s 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 โ€” reverses the bytes in a section with output contents ๐Ÿ”ฅ. A section length must be evenly divisible by the value given for the swap to be able to take place. Reversing happens before interleaving is performed. This is used typically when 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 these 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. 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 โ€” changes the name of a symbol from 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 ๐Ÿ‘‘.
  • --redefine-syms=filename โ€” applies --redefine-sym to each symbol pair "old new" listed in 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 โ€” changes 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 โ€” applies --keep-symbol to each symbol listed in 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 โ€” applies --strip-symbol to each symbol listed in 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 โ€” applies --strip-unneeded-symbol to each symbol listed in 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 โ€” applies --keep-global-symbol to each symbol listed in 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 โ€” applies --localize-symbol to each symbol listed in 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 โ€” applies --globalize-symbol to each symbol listed in 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 โ€” applies --weaken-symbol to each symbol listed in 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 โ€” marks the output text as writable. This option isnโ€™t meaningful for all object file formats.
  • --readonly-text โ€” makes the output text write protected. This option isnโ€™t meaningful for all object file formats.
  • --pure โ€” marks the output file as demand paged. This option isnโ€™t meaningful for all object file formats.
  • --impure โ€” marks the output file as impure. This option isnโ€™t meaningful for all object file formats.
  • --prefix-symbols=string โ€” prefixes all symbols in the output file with string.
  • --prefix-sections=string โ€” prefixes all section names in the output file with string ๐ŸŽ€.
  • --prefix-alloc-sections=string โ€” Slap string onto the front of every allocated section name in the output file. Cute little name tag for sections, periodt. ๐Ÿ’…
  • --add-gnu-debuglink=path-to-file โ€” Makes a .gnu_debuglink section that points at path-to-file and drops it into the output file. Part of this whole process is embedding a checksum of the debug info fileโ€™s contents into that section.
Note: the file at path-to-file absolutely must exist. No ghost files, bestie. ๐Ÿ‘ป

If your debug info file gets built in one place but is gonna be installed later somewhere else, do not use the path to the installed location. --add-gnu-debuglink will fail because the installed file doesnโ€™t exist yet. Instead, put the debug info file in the current directory and use --add-gnu-debuglink with no directory components, like this:

objcopy --add-gnu-debuglink=foo.debug

At debug time, the debugger tries to find the separate debug info file in a set of known locations. The exact set varies by distribution, 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 runs, everything should work correctly. โœจ

  • --keep-section-symbols โ€” When stripping a file โ€” maybe with --strip-debug or --strip-unneeded โ€” keep any symbols that specify section names. Those would otherwise get stripped. Protect the section-name girlies. ๐Ÿซถ
  • --keep-file-symbols โ€” When stripping a file โ€” again, maybe with --strip-debug or --strip-unneeded โ€” keep any symbols that specify source file names. Those would otherwise get stripped too. ๐Ÿ“
  • --only-keep-debug โ€” Strips a file by removing the contents of any sections that would not be stripped by --strip-debug, while 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 headers stay so other tools can match up the debuginfo file with the real executable, even if that executable has been relocated to a different address space. Itโ€™s giving โ€œreceipts but no actual stuff inside.โ€ ๐Ÿ˜ญ

The intention is that this option gets used with --add-gnu-debuglink to create a two-part executable: one stripped binary that takes up less space in RAM and in a distribution, and one debugging information file thatโ€™s only needed if debugging abilities are required. The suggested procedure is:

  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 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. So no, it canโ€™t hold your whole debug harem. ๐Ÿ’€
  • --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. Compiler choreography, honestly. ๐Ÿงš
  • --extract-dwo โ€” Extracts the contents of all DWARF .dwo sections. See the --strip-dwo option for more info, bestie. ๐Ÿ”ฅ
  • --file-alignment num โ€” Sets the file alignment. Sections in the file always begin at file offsets that are multiples of this number. Defaults to 512. This option is specific to PE targets. ๐Ÿ“
  • --heap reserve --heap reserve,commit โ€” Says how many bytes of memory to reserve (and optionally commit) for this programโ€™s heap. This option is specific to PE targets. Heap space secured. ๐Ÿซถ
  • --image-base value โ€” Uses value as the base address of your program or dll. This is the lowest memory location used when your program or dll is loaded. To reduce the need to relocate and improve performance of your dlls, each one 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.

It sets the section alignment field in the PE header โ€” if one is present in the binary. Sections in memory 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. After that itโ€™s up to the user to decide if the LMA and VMA need updating. Youโ€™ve been warned, diva. ๐Ÿšจ
  • --stack reserve --stack reserve,commit โ€” Says how many bytes of memory to reserve (and optionally commit) for this programโ€™s stack. This option is specific to PE targets. Stack snack secured. ๐Ÿฅช
  • --subsystem which --subsystem which:major --subsystem which:major.minor โ€” Specifies the subsystem under which your program will execute. 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, the 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. Minimalist icon behavior. โœจ

  • --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. No glow-up, no squeeze. ๐Ÿ™ˆ
  • --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. The section stays exactly as it is, no forced makeover. ๐Ÿ’…
  • --decompress-debug-sections โ€” Decompresses DWARF debug sections. For a .zdebug section, the original name is restored. Name rehab complete. ๐Ÿฆ‹
  • --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.

Symbol type switch-up, no cap. ๐Ÿ”

  • --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. Duplicate note cleanup, very demure. ๐Ÿงน
  • -V --version โ€” Shows the version number of objcopy. The classic โ€œwho are youโ€ moment. ๐Ÿ‘‘
  • --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. Endianness stays in charge, bestie. ๐ŸŒˆ
  • -v --verbose โ€” Verbose output: lists all object files modified. In the case of archives, objcopy -V lists all members of the archive. Yes, thatโ€™s what the page says โ€” keep it exactly like that. ๐Ÿ‘€
  • --help โ€” Shows a summary of the options to objcopy. The menu, basically. ๐ŸŽ€
  • --info โ€” Displays a list showing all architectures and object formats available. The whole buffet of targets. ๐Ÿ“
  • @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 is 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. Itโ€™s giving options inception, fr fr. ๐ŸŒ€


๐ŸŒˆ SEE ALSO ๐ŸŒˆ

Okay legal besties, gather round, because this part is giving official paperwork energy ๐Ÿ’…

  • Copyright (c) 1991-2025 Free Software Foundation, Inc. โ€” yep, thatโ€™s the exact copyright line, protect it with your life ๐Ÿซถ

The official permission vibes are: youโ€™re allowed 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, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License" โœจ


This iconic little manual page is from binutils-2.45.1, dated 2026-01-23. Byeee, go read your licenses bestie ๐ŸŽ€๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from