Red Hat ENTERPRISE LINUX 3 - USING BINUTILS, Enterprise Linux 3 Using Instructions

Red Hat Enterprise Linux 3
Using binutils, the Gnu Binary
Utilities
Red Hat Enterprise Linux 3: Using binutils, the Gnu Binary Utilities
Copyright © 1987, 1989, 1991-2003 by Free Software Foundation, Inc. Copyright © 2003 by Red Hat, Inc.
Red Hat, Inc. 1801 Varsity Drive Raleigh NC 27606-2072 USA Phone: +1 919 754 3700 Phone: 888 733 4281 Fax: +1 919 754 3701
PO Box 13588 Research Triangle Park NC 27709 USA
Manual identifier:
PDF: rhds-binutils-EN-3-PDF-RHI (2003-09-24T01:08)
HTML: rhds-binutils-EN-3-HTML-RHI (2003-09-24T01:08)
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no InvariantSections, 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”. Red Hat, Inc. is not granting permission to any redistributor to use the Red Hat name. Red Hat is a registered trademark and the Red Hat Shadow Man logo, RPM, and the RPM logo are trademarks of Red Hat, Inc. Linux is a registered trademark of Linus Torvalds. All other trademarks and copyrights referred to are the property of their respective owners. HTML, PDF, and RPM versions of the manuals are available on the Documentation CD and online at http://www.redhat.com/docs/. The GPG fingerprint of the security@redhat.com key is: CA 20 86 86 2B D6 9D FC 65 F6 EC C4 21 91 80 CD DB 42 A6 0E
Table of Contents
1. Introduction..................................................................................................................................... 1
2. ar.......................................................................................................................................................3
2.1. Controlling aron the Command Line................................................................................ 3
2.2. Controlling arwith a Script ............................................................................................... 6
3. nm..................................................................................................................................................... 9
4. objcopy........................................................................................................................................... 13
5. objdump......................................................................................................................................... 21
6. ranlib .............................................................................................................................................. 27
7. size ..................................................................................................................................................29
8. strings.............................................................................................................................................31
9. strip................................................................................................................................................. 33
10. c++filt ........................................................................................................................................... 35
11. addr2line ...................................................................................................................................... 37
12. nlmconv........................................................................................................................................ 39
13. windres ......................................................................................................................................... 41
14. Create files needed to build and use DLLs ............................................................................... 45
15. readelf........................................................................................................................................... 49
16. Selecting the Target System ....................................................................................................... 53
16.1. Target Selection.............................................................................................................. 53
16.1.1. objdumpTarget ...............................................................................................53
16.1.2. objcopyand stripInput Target .................................................................... 53
16.1.3. objcopyand stripOutput Target.................................................................. 53
16.1.4. nm, size, and stringsTarget........................................................................ 54
16.2. Architecture Selection.................................................................................................... 54
16.2.1. objdumpArchitecture .....................................................................................54
16.2.2. objcopy, nm, size, stringsArchitecture ...................................................54
17. Reporting Bugs............................................................................................................................55
17.1. Have You Found a Bug? ................................................................................................ 55
17.2. How to Report Bugs....................................................................................................... 55
A. GNU Free Documentation License ............................................................................................. 59
A.1. ADDENDUM: How to use this License for your documents......................................... 63
Index................................................................................................................................................... 65
Chapter 1.
Introduction
This brief manual contains documentation for the gnu binary utilities (collectively version
2.14.90.0.4):
This document is distributed under the terms of the GNU Free Documentation License. A copy of the license is included in the section entitled "GNU Free Documentation License".
2 Chapter 1. Introduction
Chapter 2.
ar
ar [-]p[mod [relpos] [count]] archive [member...] ar -M [
mri-script ]
The gnu ar program creates, modifies, and extracts from archives. An archive is a single file holding a collection of other files in a structure that makes it possible to retrieve the original individual files (called members of the archive).
The original files’ contents, mode (permissions), timestamp, owner, and group are preserved in the archive, and can be restored on extraction.
gnu ar can maintain archives whose members have names of any length; however, depending on how
ar is configured on your system, a limit on member-name length may be imposed for compatibility
with archive formats maintained with other tools. If it exists, the limit is often 15 characters (typical of formats related to a.out) or 16 characters (typical of formats related to coff).
ar is considered a binary utility because archives of this sort are most often used as libraries holding
commonly needed subroutines.
ar creates an index to the symbols defined in relocatable object modules in the archive when you
specify the modifier s. Once created, this index is updated in the archive whenever ar makes a change to its contents (save for the q update operation). An archive with such an index speeds up linking to the library, and allows routines in the library to call each other without regard to their placement in the archive.
You may use nm -s or nm -print-armap to list this index table. If an archive lacks the table, another form of ar called ranlib can be used to add just the table.
gnu ar is designed to be compatible with two different facilities. You can control its activity using command-line options, like the different varieties of ar on Unix systems; or, if you specify the single command-line option -M, you can control it with a script supplied via standard input, like the MRI "librarian" program.
2.1. Controlling aron the Command Line
ar [-X32_64] [-]p[mod [relpos] [count]] archive [member...]
When you use ar in the Unix style, ar insists on at least two arguments to execute: one keyletter specifying the operation (optionally accompanied by other keyletters specifying modifiers), and the archive name to act on.
Most operations can also accept further member arguments, specifying particular files to operate on.
gnu ar allows you to mix the operation code p and modifier flags mod in any order, within the first command-line argument.
If you wish, you may begin the first command-line argument with a dash.
The p keyletter specifies what operation to execute; it may be any of the following, but you must specify only one of them:
4 Chapter 2. ar
d
Delete modules from the archive. Specify the names of modules to be deleted as member. . .; the archive is untouched if you specify no files to delete.
If you specify the v modifier, ar lists each module as it is deleted.
m
Use this operation to move members in an archive.
The ordering of members in an archive can make a difference in how programs are linked using the library, if a symbol is defined in more than one member.
If no modifiers are used with m, any members you name in the member arguments are moved to the end of the archive; you can use the a, b, or i modifiers to move them to a specified place instead.
p
Print the specified members of the archive, to the standard output file. If the v modifier is speci- fied, show the member name before copying its contents to standard output.
If you specify no member arguments, all the files in the archive are printed.
q
Quick append; Historically, add the files member. .. to the end of archive, without checking for replacement.
The modifiers a, b, and i do not affect this operation; new members are always placed at the end of the archive.
The modifier v makes ar list each file as it is appended.
Since the point of this operation is speed, the archive’s symbol table index is not updated, even if it already existed; you can use ar s or ranlib explicitly to update the symbol table index.
However, too many different systems assume quick append rebuilds the index, so gnu ar imple­ments q as a synonym for r.
r
Insert the files member. . . into archive (with replacement). This operation differs from q in that any previously existing members are deleted if their names match those being added.
If one of the files named in member. . . does not exist, ar displays an error message, and leaves undisturbed any existing members of the archive matching that name.
By default, new members are added at the end of the file; but you may use one of the modifiers
a, b, or i to request placement relative to some existing member.
The modifier v used with this operation elicits a line of output for each file inserted, along with one of the letters a or r to indicate whether the file was appended (no old member deleted) or replaced.
t
Display a table listing the contents of archive, or those of the files listed in member. . . that are present in the archive. Normally only the member name is shown; if you also want to see the modes (permissions), timestamp, owner, group, and size, you can request that by also specifying the v modifier.
If you do not specify a member, all files in the archive are listed.
Chapter 2. ar 5
If there is more than one file with the same name (say, fie) in an archive (say b.a), ar t b.a
fie lists only the first instance; to see them all, you must ask for a complete listing--in our
example, ar t b.a.
x
Extract members (named member) from the archive. You can use the v modifier with this opera- tion, to request that ar list each name as it extracts it.
If you do not specify a member, all files in the archive are extracted.
A number of modifiers (mod) may immediately follow the p keyletter, to specify variations on an operation’s behavior:
a
Add new files after an existing member of the archive. If you use the modifier a, the name of an existing archive member must be present as the relpos argument, before the archive specification.
b
Add new files before an existing member of the archive. If you use the modifier b, the name of an existing archive member must be present as the relpos argument, before the archive specification. (same as i).
c
Create the archive. The specified archive is always created if it did not exist, when you request an update. But a warning is issued unless you specify in advance that you expect to create it, by using this modifier.
f
Truncate names in the archive. gnu ar will normally permit file names of any length. This will cause it to create archives which are not compatible with the native ar program on some systems. If this is a concern, the f modifier may be used to truncate file names when putting them in the archive.
i
Insert new files before an existing member of the archive. If you use the modifier i, the name of an existing archive member must be present as the relpos argument, before the archive specification. (same as b).
l
This modifier is accepted but not used.
N
Uses the count parameter. This is used if there are multiple entries in the archive with the same name. Extract or delete instance count of the given name from the archive.
o
Preserve the original dates of members when extracting them. If you do not specify this modifier, files extracted from the archive are stamped with the time of extraction.
P
Use the full path name when matching names in the archive. gnu ar can not create an archive with a full path name (such archives are not POSIX complaint), but other archive creators can.
6 Chapter 2. ar
This option will cause gnu ar to match file names using a complete path name, which can be convenient when extracting a single file from an archive created by another tool.
s
Write an object-file index into the archive, or update an existing one, even if no other change is made to the archive. You may use this modifier flag either with any operation, or alone. Running
ar s on an archive is equivalent to running ranlib on it.
S
Do not generate an archive symbol table. This can speed up building a large library in several steps. The resulting archive can not be used with the linker. In order to build a symbol table, you must omit the S modifier on the last execution of ar, or you must run ranlib on the archive.
u
Normally, ar r. . . inserts all files listed into the archive. If you would like to insert only those of the files you list that are newer than existing members of the same names, use this modifier. The
u modifier is allowed only for the operation r (replace). In particular, the combination qu is not
allowed, since checking the timestamps would lose any speed advantage from the operation q.
v
This modifier requests the verbose version of an operation. Many operations display additional information, such as filenames processed, when the modifier v is appended.
V
This modifier shows the version number of ar.
ar ignores an initial option spelt -X32_64, for compatibility with AIX. The behaviour produced by
this option is the default for gnu ar. ar does not support any of the other -X options; in particular, it does not support -X32 which is the default for AIX ar.
2.2. Controlling arwith a Script
ar -M [
script ]
If you use the single command-line option -M with ar, you can control its operation with a rudimen­tary command language. This form of ar operates interactively if standard input is coming directly from a terminal. During interactive use, ar prompts for input (the prompt is AR), and continues executing even after errors. If you redirect standard input to a script file, no prompts are issued, and
ar abandons execution (with a nonzero exit code) on any error.
The ar command language is not designed to be equivalent to the command-line options; in fact, it provides somewhat less control over archives. The only purpose of the command language is to ease the transition to gnu ar for developers who already have scripts written for the MRI "librarian" program.
The syntax for the ar command language is straightforward:
Commands are recognized in upper or lower case; for example, LIST is the same as list. In the
following descriptions, commands are shown in upper case for clarity.
A single command may appear on each line; it is the first word on the line.
Empty lines are allowed, and have no effect.
Chapter 2. ar 7
Comments are allowed; text after either of the characters * or ; is ignored.
Whenever you use a list of names as part of the argument to an ar command, you can separate the
individual names with either commas or blanks. Commas are shown in the explanations below, for clarity.
+ is used as a line continuation character; if + appears at the end of a line, the text on the following
line is considered part of the current command.
Here are the commands you can use in ar scripts, or when using ar interactively. Three of them have special significance:
OPEN or CREATE specify a current archive, which is a temporary file required for most of the other
commands.
SAVE commits the changes so far specified by the script. Prior to SAVE, commands affect only the
temporary copy of the current archive.
ADDLIB archive ADDLIB archive (module, module, ... module)
Add all the contents of archive (or, if specified, each named module from archive) to the current archive.
Requires prior use of OPEN or CREATE.
ADDMOD member, member, ... member
Add each named member as a module in the current archive.
Requires prior use of OPEN or CREATE.
CLEAR
Discard the contents of the current archive, canceling the effect of any operations since the last
SAVE. May be executed (with no effect) even if no current archive is specified.
CREATE archive
Creates an archive, and makes it the current archive (required for many other commands). The new archive is created with a temporary name; it is not actually saved as archive until you use SAVE. You can overwrite existing archives; similarly, the contents of any existing file named
archive will not be destroyed until SAVE.
DELETE module, module, ... module
Delete each listed module from the current archive; equivalent to ar -d archive module ...
module.
Requires prior use of OPEN or CREATE.
DIRECTORY archive (module, ... module) DIRECTORY archive (module, ... module) outputfile
List each named module present in archive. The separate command VERBOSE specifies the
form of the output: when verbose output is off, output is like that of ar -t archive module....
When verbose output is on, the listing is like ar -tv archive module....
Output normally goes to the standard output stream; however, if you specify outputfile as a final argument, ar directs the output to that file.
8 Chapter 2. ar
END
Exit from ar, with a 0 exit code to indicate successful completion. This command does not save the output file; if you have changed the current archive since the last SAVE command, those changes are lost.
EXTRACT module, module, ... module
Extract each named module from the current archive, writing them into the current directory as
separate files. Equivalent to ar -x archive module....
Requires prior use of OPEN or CREATE.
LIST
Display full contents of the current archive, in "verbose" style regardless of the state of VERBOSE. The effect is like ar tv archive. (This single command is a gnu ar enhancement, rather than present for MRI compatibility.)
Requires prior use of OPEN or CREATE.
OPEN archive
Opens an existing archive for use as the current archive (required for many other commands). Any changes as the result of subsequent commands will not actually affect archive until you next use SAVE.
REPLACE module, module, ... module
In the current archive, replace each existing module (named in the REPLACE arguments) from files in the current working directory. To execute this command without errors, both the file, and the module in the current archive, must exist.
Requires prior use of OPEN or CREATE.
VERBOSE
Toggle an internal flag governing the output from DIRECTORY. When the flag is on, DIRECTORY
output matches output from ar -tv . . . .
SAVE
Commit your changes to the current archive, and actually save it as a file with the name specified in the last CREATE or OPEN command.
Requires prior use of OPEN or CREATE.
Chapter 3.
nm
nm [-a|--debug-syms] [-g|--extern-only]
[-B] [-C|--demangle[=style]] [-D|--dynamic] [-S|--print-size] [-s|--print-armap] [-A|-o|--print-file-name] [-n|-v|--numeric-sort] [-p|--no-sort] [-r|--reverse-sort] [--size-sort] [-u|--undefined-only] [-t radix|--radix=radix] [-P|--portability] [--target=bfdname] [-fformat|--format=format] [--defined-only] [-l|--line-numbers] [--no-demangle] [-V|--version] [-X 32_64] [--help] [objfile...]
gnu nm lists the symbols from object files objfile. . .. If no object files are listed as arguments, nm
assumes the file a.out.
For each symbol, nm shows:
The symbol value, in the radix selected by options (see below), or hexadecimal by default.
The symbol type. At least the following types are used; others are, as well, depending on the object
file format. If lowercase, the symbol is local; if uppercase, the symbol is global (external).
A
The symbol’s value is absolute, and will not be changed by further linking.
B
The symbol is in the uninitialized data section (known as BSS).
C
The symbol is common. Common symbols are uninitialized data. When linking, multiple com­mon symbols may appear with the same name. If the symbol is defined anywhere, the common symbols are treated as undefined references. For more details on common symbols, see the dis­cussion of -warn-common in .
D
The symbol is in the initialized data section.
G
The symbol is in an initialized data section for small objects. Some object file formats permit more efficient access to small data objects, such as a global int variable as opposed to a large global array.
I
The symbol is an indirect reference to another symbol. This is a gnu extension to the a.out object file format that is rarely used.
10 Chapter 3. nm
N
The symbol is a debugging symbol.
R
The symbol is in a read only data section.
S
The symbol is in an uninitialized data section for small objects.
T
The symbol is in the text (code) section.
U
The symbol is undefined.
V
The symbol is a weak object. When a weak defined symbol is linked with a normal defined symbol, the normal defined symbol is used with no error. When a weak undefined symbol is linked and the symbol is not defined, the value of the weak symbol becomes zero with no error.
W
The symbol is a weak symbol that has not been specifically tagged as a weak object symbol. When a weak defined symbol is linked with a normal defined symbol, the normal defined symbol is used with no error. When a weak undefined symbol is linked and the symbol is not defined, the value of the weak symbol becomes zero with no error.
-
The symbol is a stabs symbol in an a.out object file. In this case, the next values printed are the stabs other field, the stabs desc field, and the stab type. Stabs symbols are used to hold debugging information. For more information, see .
?
The symbol type is unknown, or object file format specific.
The symbol name.
The long and short forms of options, shown here as alternatives, are equivalent.
-A
-o
-print-file-name
Precede each symbol by the name of the input file (or archive member) in which it was found, rather than identifying the input file once only, before all of its symbols.
-a
-debug-syms
Display all symbols, even debugger-only symbols; normally these are not listed.
-B
The same as -format=bsd (for compatibility with the MIPS nm).
Chapter 3. nm 11
-C
-demangle[=style]
Decode (demangle) low-level symbol names into user-level names. Besides removing any initial underscore prepended by the system, this makes C++ function names readable. Different com­pilers have different mangling styles. The optional demangling style argument can be used to choose an appropriate demangling style for your compiler. Refer to Chapter 10 c++filt for more information on demangling.
-no-demangle
Do not demangle low-level symbol names. This is the default.
-D
-dynamic
Display the dynamic symbols rather than the normal symbols. This is only meaningful for dy­namic objects, such as certain types of shared libraries.
-f format
-format=format
Use the output format format, which can be bsd, sysv, or posix. The default is bsd. Only the first character of format is significant; it can be either upper or lower case.
-g
-extern-only
Display only external symbols.
-l
-line-numbers
For each symbol, use debugging information to try to find a filename and line number. For a defined symbol, look for the line number of the address of the symbol. For an undefined sym­bol, look for the line number of a relocation entry which refers to the symbol. If line number information can be found, print it after the other symbol information.
-n
-v
-numeric-sort
Sort symbols numerically by their addresses, rather than alphabetically by their names.
-p
-no-sort
Do not bother to sort the symbols in any order; print them in the order encountered.
-P
-portability
Use the POSIX.2 standard output format instead of the default format. Equivalent to -f posix.
-S
-print-size
Print size, not the value, of defined symbols for the bsd output format.
12 Chapter 3. nm
-s
-print-armap
When listing symbols from archive members, include the index: a mapping (stored in the archive by ar or ranlib) of which modules contain definitions for which names.
-r
-reverse-sort
Reverse the order of the sort (whether numeric or alphabetic); let the last come first.
-size-sort
Sort symbols by size. The size is computed as the difference between the value of the symbol and the value of the symbol with the next higher value. If the bsd output format is used the size of the symbol is printed, rather than the value, and -S must be used in order both size and value to be printed.
-t radix
-radix=radix
Use radix as the radix for printing the symbol values. It must be d for decimal, o for octal, or x for hexadecimal.
-target=bfdname
Specify an object code format other than your system’s default format. Refer to Section 16.1 Target Selection for more information.
-u
-undefined-only
Display only undefined symbols (those external to each object file).
-defined-only
Display only defined symbols for each object file.
-V
-version
Show the version number of nm and exit.
-X
This option is ignored for compatibility with the AIX version of nm. It takes one parameter which must be the string 32_64. The default mode of AIX nm corresponds to -X 32, which is not supported by gnu nm.
-help
Show a summary of the options to nm and exit.
Chapter 4.
objcopy
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] [-K symbolname|--keep-symbol=symbolname] [-N symbolname|--strip-symbol=symbolname] [-G symbolname|--keep-global-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] [-j sectionname|--only-section=sectionname] [-R sectionname|--remove-section=sectionname] [-p|--preserve-dates] [--debugging] [--gap-fill=val] [--pad-to=address] [--set-start=val] [--adjust-start=incr] [--change-addresses=incr] [--change-section-address section{=,+,-}val] [--change-section-lma section{=,+,-}val] [--change-section-vma section{=,+,-}val] [--change-warnings] [--no-change-warnings] [--set-section-flags section=flags] [--add-section sectionname=filename] [--rename-section oldname=newname[,flags]] [--change-leading-char ] [--remove-leading-char] [--srec-len=ival ] [--srec-forceS3] [--redefine-sym old=new ] [--weaken] [--keep-symbols=filename] [--strip-symbols=filename] [--keep-global-symbols=filename] [--localize-symbols=filename] [--weaken-symbols=filename] [--alt-machine-code=index] [--prefix-symbols=string] [--prefix-sections=string] [--prefix-alloc-sections=string] [-v|--verbose] [-V|--version] [--help] [--info]
infile [outfile]
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.
14 Chapter 4. objcopy
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).
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.
-I bfdname
-input-target=bfdname
Consider the source file’s object format to be bfdname, rather than attempting to deduce it. Refer to Section 16.1 Target Selection for more information.
-O bfdname
-output-target=bfdname
Write the output file using the object format bfdname. Refer to Section 16.1 Target Selection for more information.
-F bfdname
-target=bfdname
Use bfdname as the object format for both the input and the output file; that is, simply transfer data from source to destination with no translation. Refer to Section 16.1 Target Selection for more information.
-B bfdarch
-binary-architecture=bfdarch
Useful when transforming a raw binary 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.
-j sectionname
-only-section=sectionname
Copy only the named section 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.
Chapter 4. objcopy 15
-R sectionname
-remove-section=sectionname
Remove any section named sectionname from the output file. This option may be given more than once. Note that using this option inappropriately may make the output file unusable.
-S
-strip-all
Do not copy relocation and symbol information from the source file.
-g
-strip-debug
Do not copy debugging symbols from the source file.
-strip-unneeded
Strip all symbols that are not needed for relocation processing.
-K symbolname
-keep-symbol=symbolname
Copy only symbol symbolname from the source file. This option may be given more than once.
-N symbolname
-strip-symbol=symbolname
Do not copy symbol symbolname from the source file. This option may be given more than once.
-G symbolname
-keep-global-symbol=symbolname
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.
-L symbolname
-localize-symbol=symbolname
Make symbol symbolname local to the file, so that it is not visible externally. This option may be given more than once.
-W symbolname
-weaken-symbol=symbolname
Make symbol symbolname weak. This option may be given more than once.
-x
-discard-all
Do not copy non-global symbols from the source file.
-X
-discard-locals
Do not copy compiler-generated local symbols. (These usually start with L or ..)
-b byte
-byte=byte
Keep only every byteth 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,
16 Chapter 4. objcopy
or the default of 4. This option is useful for creating files to program rom. It is typically used with an srec output target.
-i interleave
-interleave=interleave
Only copy one out of every interleave bytes. Select which byte to copy with the -b or -byte option. The default is 4. objcopy ignores this option if you do not specify either -b or -byte.
-p
-preserve-dates
Set the access and modification dates of the output file to be the same as those of the input file.
-debugging
Convert debugging information, if possible. This is not the default because only certain debug­ging formats are supported, and the conversion process can be time consuming.
-gap-fill val
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 with the lower address, and filling in the extra space created with val.
-pad-to address
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-start val
Set the start address of the new file to val. Not all object file formats support setting the start address.
-change-start incr
-adjust-start incr
Change the start address by adding incr. Not all object file formats support setting the start address.
-change-addresses incr
-adjust-vma incr
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.
-change-section-address section{=,+,-}val
-adjust-section-vma section{=,+,-}val
Set or change both the VMA address and the LMA address of the named section. 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 section does not exist in the input file, a warning will be issued, unless -no-change-warnings is used.
-change-section-lma section{=,+,-}val
Set or change the LMA address of the named section. 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
Chapter 4. objcopy 17
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. 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 section does not exist in the input file, a warning will be issued, unless -no-change-warnings is used.
-change-section-vma section{=,+,-}val
Set or change the VMA address of the named section. 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 = 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 section does not exist in the input file, a warning will be issued, unless -no-change-warnings is used.
-change-warnings
-adjust-warnings
If -change-section-address or -change-section-lma or -change-section-vma is used, and the named section does not exist, issue a warning. This is the default.
-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 named section does not exist.
-set-section-flags section=flags
Set the flags for the named section. The flags argument is a comma separated string of flag names. The recognized names are alloc, contents, load, noload, readonly, code, data,
rom, share, and debug. You can set the contents flag for a section which does not have con-
tents, 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
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.
-rename-section oldname=newname[,flags]
Rename a section from oldname to newname, optionally changing the section’s flags to flags in the process. This has the advantage over usng a linker script to perform the rename in that the output stays as an object file and does not become a linked executable.
This option is particularly helpful when the input format is binary, since this will always cre­ate 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-Barchitecture\
--rename-section .data=.rodata,alloc,load,readonly,data,contents \
input_binary_file

output_object_file
-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
18 Chapter 4. objcopy
formats. If the object file formats use the same leading character, this option has no effect. Oth­erwise, it will add a 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. This is different from -change-leading-char because it always changes the symbol name when appropriate, regardless of the object file format of the output file.
-srec-len=ival
Meaningful only for srec output. Set 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. Avoid generation of S1/S2 records, creating S3-only record format.
-redefine-sym old=new
Change the name of a symbol old, to new. This can be useful when one is trying link two things together for which you have no source, and there are name collisions.
-weaken
Change 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
Apply -keep-symbol option to each symbol listed in the file 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
Apply -strip-symbol option to each symbol listed in the file filename. filename is sim­ply 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
Apply -keep-global-symbol option to each symbol listed in the file 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
Apply -localize-symbol option to each symbol listed in the file 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.
-weaken-symbols=filename
Apply -weaken-symbol option to each symbol listed in the file filename. filename is sim­ply 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.
Loading...
+ 50 hidden pages