How to add a raw binary image to linker output
The GNU objcopy utility copies the contents of an object file to another. 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. 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 notobjcopy can only copy the inputs into file formats that have the same endianness or which have no endianness e.
However, see the --reverse-bytes option. The input and output files, respectively. If you do not specify outfileobjcopy creates a temporary file and destructively renames the result with the name of infile. See Target Selectionfor more information. Write the output file using the object format bfdname. Use bfdname as the object format for both the input and the output file; how to add a raw binary image to linker output. 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.
Copy only the indicated how to add a raw binary image to linker output 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!
Remove any section matching sectionpattern from the output file. Using both the -j and -R options together results in undefined behaviour. Remove relocations from the output file for any section matching sectionpattern. When stripping symbols, keep symbol symbolname even if it would normally be stripped. Do not copy symbol symbolname from the source file. Do not copy symbol symbolname from the source file unless it is needed by a relocation. Keep only symbol symbolname global.
Make all other symbols local to the file, so that they are not visible externally. In an ELF object, mark all symbols that have hidden or internal visibility as local. This option applies on top of symbol-specific localization options such as -L.
Convert a global or weak symbol called symbolname into a local symbol, so that it is not visible externally. Note - unique symbols are not converted. Give symbol symbolname global scoping so that it is visible outside of the file in which it is defined. Permit regular expressions in symbolname s used in other command line options. If the first character of the symbol name is the exclamation point!
Do not copy compiler-generated local symbols. If interleaving has been enabled via the --interleave option then start the range of bytes to keep at the byte th byte. 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. When used with the --interleave option, copy width bytes at a time. The start of the range of bytes to be copied is set by the --byte option, and the extent of the range is set with the --interleave option. 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. 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-archivesthen this mode is on by default.
Do not operate in deterministic mode. This is the inverse of the -D option, above: This is the default unless binutils was configured with --enable-deterministic-archives. Convert debugging information, if possible. This is not the default how to add a raw binary image to linker output only certain debugging formats are supported, and the conversion process can be time consuming.
Fill gaps between sections with val. This operation applies to the load address LMA of the sections. It is done by increasing the size of the section how to add a raw binary image to linker output the lower address, and filling in the extra space created with val.
Pad the output file up to the load address address. This is done by increasing the size of the last section. The extra space is filled in with the value specified by --gap-fill default zero. Set the start address of the new file how to add a raw binary image to linker output val. Not all object file formats support setting the start address. Change 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. Otherwise, val is added to or subtracted from the section address. See the comments under how to add a raw binary image to linker outputabove. If sectionpattern does not match any sections in the input file, a warning will be issued, unless --no-change-warnings is used.
Set or change the LMA address of any sections matching sectionpattern. The LMA address is the address where the section will be loaded into memory at program load time. Normally this is the same as the VMA address, which is the address of the section at program run time, but on some systems, especially those where a program is held in ROM, the two can be different.
Set or change the VMA address of any section matching sectionpattern. The VMA address is the address where the section will be located once the program has started executing. Normally this is the same as the LMA address, which is the address where the section will be loaded into memory, but on some systems, especially those where a program is held in ROM, the two can be different.
If --change-section-address or --change-section-lma or how to add a raw binary image to linker output 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.
Set the flags for any sections matching sectionpattern. The flags argument is a comma separated string of flag names. Not all flags are meaningful for all object file formats. Add a new section named sectionname while copying the file. The contents of the new section are taken from the file filename. The size of the section will be the size of the file.
This option only works on file formats which can support sections with arbitrary names. Note - it may be necessary to use the --set-section-flags option to set the attributes of the newly created section. Place the contents of section named sectionname into the file filenameoverwriting any contents that may have been there previously. This option is the inverse of --add-section. This option 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.