Section: GNU Development Tools (1)
objcopy [-F bfdname|--target=bfdname]
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.)
-w -W !foo -W fo*
would cause objcopy to weaken all symbols that start with ``fo except for the symbol ``foo.
"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.
The default value for this option is 1. The value of width plus the byte value set by the --byte option must not exceed the interleave breadth set by the --interleave option.
This option can be used to create 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.
If binutils was configured with --enable-deterministic-archives, then this mode is on by default. It can be disabled with the -U option, below.
This is the default unless binutils was configured with --enable-deterministic-archives.
This option is particularly helpful when the input format is binary, since this will always create a section called .data. If for example, you wanted instead to create a section called .rodata containing binary data 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>:
"PE-COFF"object formats. The default behaviour, keep, is to preserve long section names if any are present in the input file. The enable and disable options 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 the enable option might force the creation of an empty string table in the output file.:
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
The intention is that this option will be used in conjunction with --add-gnu-debuglink to create a two part executable. One a stripped binary which will occupy less space in RAM and in a distribution and the second a debugging information file which is only needed if debugging abilities are required. The suggested procedure to create these files is as follows:
: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.>
:1.<Copy "foo" to "foo.full">
:1.<Run "objcopy --strip-debug foo">
:1.<Run "objcopy --add-gnu-debuglink=foo.full foo">
i.e., the file pointed to by the --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.
"xbox". You may optionally set the subsystem version also. Numeric values are also accepted for which. [This option is specific to PE targets.]:
:*<removes the contents of all sections;>
:*<sets the size of every section to zero; and>
:*<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.
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.
Copyright (c) 1991-2014 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''.
Tutoriais de Tecnologia Web