NAME

objcopy - copy and translate object files

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] [-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] [-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] [--keep-file-symbols] [--only-keep-debug] [--strip-dwo] [--extract-dwo] [--extract-symbol] [--writable-text] [--readonly-text] [--pure] [--impure] [--file-alignment=num] [--heap=size] [--image-base=address] [--section-alignment=num] [--stack=size] [--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

The GNU objcopy utility copies the contents of an object file to another. objcopy uses the GNU BFD Library to read and write the object files. It can write the destination object file in a format different from that of the source object file. The exact behavior of objcopy is controlled by command-line options. Note that 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.

objcopy creates temporary files to do its translations and deletes them afterward. objcopy 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.

objcopy can be used to generate S-records by using an output target of srec (e.g., use -O srec).

objcopy can be used 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.

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.)

OPTIONS

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.

Consider the source file's object format to be bfdname, rather than attempting to deduce it.

Write the output file using the object format 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.

Useful when transforming a 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.

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 sectinos maching '.text.*' but not the section '.text.foo'.

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. 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'.

Do not copy relocation and symbol information from the source file.

Do not copy debugging symbols or sections from the source file.

When stripping symbols, keep symbol symbolname even if it would normally be stripped. This option may be given more than once.

Do not copy symbol symbolname from the source file. This option may be given more than once.

Keep only symbol symbolname global. Make all other symbols local to the file, so that they are not visible externally. This option may be given more than once. Note: this option cannot be used in conjunction with the --globalize-symbol or --globalize-symbols options.

Convert a global or weak symbol called symbolname into a local symbol, so that it is not visible externally. This option may be given more than once. Note - unique symbols are not converted.

Make symbol symbolname weak. This option may be given more than once.

Permit regular expressions in symbolnames used in other command line options. The question mark (?), asterisk (*), backslash (\) and square brackets ([]) operators can be used anywhere in the symbol name. If the first character of the symbol name is the exclamation point (!) then the sense of the switch is reversed for that symbol. For example: -w -W !foo -W fo* would cause objcopy to weaken all symbols that start with fo except for the symbol foo.

Do not copy non-global symbols from the source file.

Do not copy compiler-generated local symbols. (These usually start with L or ..)

If interleaving has been enabled via the --interleave option then start the range of bytes to keep at the byteth byte. byte can be in the range from 0 to breadth-1, where breadth is the value given by the --interleave option.

Only copy a range out of every breadth bytes. (Header data is not affected). Select which byte in the range begins the copy with the --byte option. Select the width of the range with the --interleave-width option. This option is useful for creating files to program ROM. It is typically used with an srec output target. Note that objcopy will complain if you do not specify the --byte option as well. 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.

Set the access and modification dates of the output file to be the same as those of the input file.

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. If binutils was configured with --enable-deterministic-archives, then this mode is on by default. It can be disabled with the -U option, below.

Do not operate in deterministic mode. This is the inverse of the -D option, 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.

Change the start address (also known as the entry address) by adding incr. Not all object file formats support setting the start address.

Change the VMA and LMA addresses of all sections, as well as the start address, by adding incr. Some object file formats do not permit section addresses to be changed arbitrarily. Note that this does not relocate the sections; if the program expects sections to be loaded at a certain address, and this option is used to change the sections such that they are loaded at a different address, the program may fail.

Set or change 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. If sectionpattern does not match any sections in the input file, a warning will be issued, unless --no-change-warnings is used.

If --change-section-address or --change-section-lma or --change-section-vma is used, and the section pattern does not match any sections, issue a warning. This is the default.

Do not issue a warning if --change-section-address or --adjust-section-lma or --adjust-section-vma is used, even if the section pattern does not match any sections.

Specify 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.]

Specify 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.]

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 also. Numeric values are also accepted for which. [This option is specific to PE targets.]

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 zlib. The debug sections are renamed to begin with .zdebug instead of .debug. Note - if compression would actually make a section larger, then it is not compressed nor renamed.

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.

For ELF files, attempt (or do not attempt) to reduce the size of any SHT_NOTE type sections by removing duplicate notes.

Show the version number of objcopy.

Verbose output: list all object files modified. In the case of archives, objcopy -V lists all members of the archive.

  1. Read 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

ld (1), objdump (1), and the Info entries for binutils.

COPYRIGHT

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

Permission is granted 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, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled GNU Free Documentation License.