Introduction to the objcopy command

Source: Internet
Author: User
Tags srec

ObjcopyCopy the content of a target file to another type of target file.

(1)Compile the image into an executable fileQ: How can I directly link a binary file, slice, or dictionary to an executable file as a. o file? A:
$ Objcopy-I Binary-O elf32-i386-B i386 14_95_13.jpg image. o
$ GCC image. o tt. O-o tt
$ Nm TT | grep 14_95
0805d6c7 D _ binary_14_95_13_jpg_end
00014213 A _ binary_14_95_13_jpg_size
080494b4 D _ binary_14_95_13_jpg_start

(2) Remove unnecessary information using objcopy: $ objcopy-R. comment-R. Note halo. Min

(3)
$ Objcopy-R. Note-R. comment-S-O binary xyb. Bin
-R. Note-R. Comment indicates that the. Note and. Comment segments are removed.
-S indicates removing all flag and relocation Information
-O binary xyb. Bin indicates that the binary file xyb. Bin is generated by xyb.ObjcopyTool User Guide
Objcopy Utility
Objcopy [-F bfdname | -- target = bfdname]
[-I bfdname | -- input-target = bfdname]
[-O bfdname | -- output-target = bfdname]
[-S | -- strip-all] [-G | -- strip-Debug]
[-K symbolname | -- keep-symbol = symbolname]
[-N symbolname | -- strip-symbol = symbolname]
[-L symbolname | -- localize-symbol = symbolname]
[-W symbolname | -- weaken-symbol = symbolname]
[-X | -- discard-all] [-x | -- discard-locals]
[-B byte | -- byte = byte]
[-I interleave | -- interleave = interleave]
[-R sectionname | -- remove-Section = sectionname]
[-P | -- preserve-dates] [-- debugging]
[-- Gap-fill = Val] [-- pad-To = address]
[-- Set-Start = Val] [-- Adjust-Start = incr]
[-- Change-address = incr]
[-- Change-section-address = Section {=, +,-} Val]
[-- Change-warnings] [-- no-change-warnings]
[-- Set-section-flags = Section = flags]
[-- Add-Section = sectionname = filename]
[-- Change-leading char] [-- remove-leading-Char]
[-- Weaken]
[-V | -- verbose] [-v | -- version] [-- help]
Input-file [OUTFILE]
The GNU utility program objcopy is used to copy the content of a target file to another target file. Objcopy uses the gnu bfd library to read or write the target file. Objcopy can be used to write the target file in a format different from that of the source target file (that is, the target file in one format can be converted to a target file in another format ). You can use the above command line options to control the specific operations of objcopy.
When converting the target file, objcopy will generate a temporary file. After the conversion is completed, the temporary file will be deleted. Objcopy uses BFD for conversion. If there is no explicit format requirement, objcopy will access all the formats that have been described in the BFD library and can be recognized by it, see "BFD library" and "target file format standardized in BFD library" in "using lD" chapter in "gnupro decelopment Tools.
By using SREC as the output target (using command line option-o srec), objcopy can generate s record format files.
By using binary as the output destination (using the command line option-O binary), objcopy can generate the original binary file. The use of objcopy to generate an original binary file is essentially a memory transfer to storage of the content of the input target file. All symbols and relocation information will be discarded. The memory dump starts from the smallest virtual address in the input target file that will be copied to the output target file.
During the generation of s record format files or original binary files using objcopy, the-s option and-R option may be more useful. The-s option is used to delete the part that contains debugging information, and the-r option is used to delete the part that contains the content that is not required by the binary file. Input-File
OUTFILE
Parameter input-file and OUTFILE indicate the input target file (source target file) and output target file (target file) respectively ). If OUTFILE is not explicitly specified in the command line, objcopy will create a temporary file to store the target result, and then rename the temporary file using the input-file name (at this time, the original input-file will be overwritten ). -I bfdname
-- Input-target = bfdname
Clearly tell objcopy what the source file format is, And bfdname is the standard format name described in the BFD library. This method is much more efficient than "Let objcopy analyze the source file format and compare it with the various formats described in BFD, and know the target format name of the source file through. -O bfdname
-- Output-target = bfdname
Use the specified format to write the output file (that is, the target file). bfdname is the standard format name described in the BFD library. -F bfdname
-- Target = bfdname
Clearly tell objcopy what the source file format is and use this format to write the output file (that is, the target file ), that is to say, during the process of copying the content of the source target file to the target file, only the file is copied without format conversion. What is the format of the source target file, and what is the format of the target file. -R sectionname
-- Remove-Section = sectionname
Delete all segments named sectionname from the output file. This option can be used multiple times.
Note: Improper use of this option may cause the output file to be unavailable. -S
-- Strip-All (strip stripping and stripping)
The relocation information and symbolic information are not copied from the source file to the output file (destination file. -G
-- Strip-Debug
Do not copy the debugging symbol from the source file to the output file (destination file. -- Strip-undeeded
Removes all the symbols that are not required during the relocation process. -K symbolname
-- Keep-symbol = symbolname
Only the symbolname symbol is copied from the source file. This option can be used multiple times. -N symbolname
-- Strip-symbol = symbolname
Do not copy the symbol symbolname from the source file. This option can be used multiple times. It can be used together with other strip options (except-K symbolname | -- keep-symbol = symbolname ). -L symbolname
-- Localize-symbol = symbolname
Make the symbolname symbol localized in the file so that it is invisible outside the file. This option can be used multiple times. -W symbolname
-Weaken-symbol = symbolname
Weaken the symbol symbolname. This option can be used multiple times. -X
-- Discard-All (discard and discard)
Do not copy non-Global symbols from the source file. -X
-- Discard-locals
Do not copy local symbols generated by the compiler from the source file (these symbols are usually starting with L or ). -B byte
-- Byte = byte
Keep only every byte of the input file (header data is not affected). byte can be
In the range from 0 to interleave-1, where interleave is given by the-I or
-- Interleave option, or the default of 4. This option is useful for creating files
Program Rom. It is typically used with an SREC output target.-I interleave
-- Interleave = interleave (Interleave)
Only copy one out of every interleave bytes. Select which byte to copy with
-B or -- byte option. The default is 4. objcopy ignores this option if you do not
Specify either-B or -- byte.-P
-- Preserve-dates (preserve save and keep)
Set the access and modification date of the output file to be the same as that of the input file. [-- Debugging]
If possible, convert the debugging information. This option is not the default one because only the specified debugging format is supported and the conversion process takes some time.
-- Gap-fill = Val
Fill in the gap between segments with the content Val. By adding the segment size and filling the content Val in the additional space of the segment with a lower address, this option is enabled. -- Pad-To = address
Fill in the output file to the Virtual Address. By increasing the size of the last segment in the output file, in the additional space between the end of the last segment and the address of the output file, fill in with the content Val specified in the -- gap-fill = Val option (the default content is 0, that is, if the -- gap-fill = Val option is not used ). -- Set-Start = Val
Set a new file (should it be an output file ?) The starting address of is Val. Not all target file formats support starting address setting. -- Change-Start = incr
-- Adjust-Start = incr
Change the starting address by adding incr. Not all target file formats support starting address setting. -- Change-addresses incr
-- Adjust-VMA incr
Change the VMA and LMA addresses of all sections, section., as well as
Start address, by adding incr. Some object file formats do not permit Section
Addresses to be changed arbitrarily. Add a value of incr to change the VMA (virtual memory address runtime address) and LMA (load memory address loading address) of all segments and the starting address. Some target file formats do not allow you to change the segment address. -- Change-section-address section {=, +,-} Val
-- Adjust-section-VMA section {=, +,-} Val
Set or change the VMA (virtual memory address runtime address) and LMA (load memory address loading address) of the section ). If "=" is used in this option, then the VMA (virtual memory address runtime address) and LMA (load memory address loading address) segments named section are) will be set to Val; if "-" or "+" is used in this option ", the preceding two addresses will be set or changed to the current values of the two addresses minus or plus the values after Val. If the section in the input file does not exist, objcopy issues a warning unless the -- no-change-warnings option is used.
Here, the segment address settings and changes are relative to the segment in the output file. For example:
(1) -- change-section-address. Text = 10000
In this example, the name of the input file (that is, the source file) is. after the text segment is copied to the output file. the VMA (virtual memory address runtime address) and LMA (load memory address loading address) in the text segment will be set to 10000.
(2) -- change-section-address. Text + 100
This refers to the name of the input file (that is, the source file. after the text segment is copied to the output file. the VMA (virtual memory address runtime address) and LMA (load memory address loading address) in the text segment will be set to the previous input file. add the value after 100 to the address (current address) of the text segment. -- Change-section-LMA section {=, +,-} Val
Only set or change the LMA (load memory address load address) of the section ). When a program is loaded, the LMA of a segment is the first address of the segment of memory space to be loaded. Generally, LMA and VMA (virtual memory address runtime address) are the same, but LMA and VMA are different in some systems, especially in those systems where programs are stored in Rom. If "=" is used in this option, the LMA (load memory address load address) of the section is set to Val; if "-" or "+" is used in this option, LMA will be set or changed to the current value of the two addresses minus or plus the value after Val. If the section in the input file does not exist, objcopy issues a warning unless the -- no-change-warnings option is used. -- Change-section-VMA section {=, +,-} Val
Set or change only the VMA (load memory address load address) of the section ). The VMA of a segment is the location address of the segment when the program is running. Generally, VMA and LMA (virtual memory address runtime address) are the same, but LMA and VMA are different in some systems, especially in those systems where programs are stored in Rom. If "=" is used in this option, the LMA (load memory address load address) of the section is set to Val; if "-" or "+" is used in this option, LMA will be set or changed to the current value of the two addresses minus or plus the value after Val. If the section in the input file does not exist, objcopy issues a warning unless the -- no-change-warnings option is used. -- Change-Warnings
-- Adjust-Warnings
If -- change-section-address section {=, +,-} Val or -- Adjust-section-VMA section {=, +,-} Val is used in the command line, or -- change-section-LMA section {=, +,-} Val, or -- change-section-VMA section {=, +,-} Val, if the section in the input file does not exist, objcopy issues a warning. This is the default option. -- No-chagne-Warnings
-- No-adjust-Warnings
If -- change-section-address section {=, +,-} Val or -- Adjust-section-VMA section {=, +,-} Val is used in the command line, or -- change-section-LMA section {=, +,-} Val, or -- change-section-VMA section {=, +,-} Val, even if the section in the input file does not exist, objcopy will not issue a warning. -- Set-section-flags section = flags
Set an identifier for the Section section. The flags variable can be separated by commas (,). Valid identifiers include alloc, load, readonly, code, data and Rom.
You can set the contents flag for a section which does not havecontents, but it is not meaningful to clear the contents flag of a section which does have contents; just remove the section instead. not all flags are meaningful for all object file formats. -- add-section sectionname = filename
When copying the target file, add a new segment named sectionname to the output file. The content of the newly added segment is obtained from the file filename. The size of the file filename is the size of the newly added segment. This option is available only when the format of the output file allows the file segment to have any segment name (the segment name is not standard and fixed. -- 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 will add
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. This option will remove a leading underscore from all
Global symbols. This can be useful if you want to link together objects of different
File formats with different conventions for symbol names. -- weaken
Change all global symbols in the file to be weak. This can be useful when building
An object that will be linked against other objects using the-r option to the linker.
This option is only valid tive when using an object file format that supports weak
Symbols.-V
-- Version
Show the version number of objcopy.-V
-- Verbose
Verbose output: list all object files modified. In the case of archives, objcopy-V
Lists All members of the archive. -- Help
Show a Summary of the options to objcopy.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.