1OBJCOPY(1)                   GNU Development Tools                  OBJCOPY(1)
2
3
4

NAME

6       objcopy - copy and translate object files
7

SYNOPSIS

9       objcopy [-F bfdname|--target=bfdname]
10               [-I bfdname|--input-target=bfdname]
11               [-O bfdname|--output-target=bfdname]
12               [-B bfdarch|--binary-architecture=bfdarch]
13               [-S|--strip-all]
14               [-g|--strip-debug]
15               [-K symbolname|--keep-symbol=symbolname]
16               [-N symbolname|--strip-symbol=symbolname]
17               [--strip-unneeded-symbol=symbolname]
18               [-G symbolname|--keep-global-symbol=symbolname]
19               [--localize-hidden]
20               [-L symbolname|--localize-symbol=symbolname]
21               [--globalize-symbol=symbolname]
22               [-W symbolname|--weaken-symbol=symbolname]
23               [-w|--wildcard]
24               [-x|--discard-all]
25               [-X|--discard-locals]
26               [-b byte|--byte=byte]
27               [-i interleave|--interleave=interleave]
28               [-j sectionname|--only-section=sectionname]
29               [-R sectionname|--remove-section=sectionname]
30               [-p|--preserve-dates]
31               [--debugging]
32               [--gap-fill=val]
33               [--pad-to=address]
34               [--set-start=val]
35               [--adjust-start=incr]
36               [--change-addresses=incr]
37               [--change-section-address section{=,+,-}val]
38               [--change-section-lma section{=,+,-}val]
39               [--change-section-vma section{=,+,-}val]
40               [--change-warnings] [--no-change-warnings]
41               [--set-section-flags section=flags]
42               [--add-section sectionname=filename]
43               [--rename-section oldname=newname[,flags]]
44               [--long-section-names {enable,disable,keep}]
45               [--change-leading-char] [--remove-leading-char]
46               [--reverse-bytes=num]
47               [--srec-len=ival] [--srec-forceS3]
48               [--redefine-sym old=new]
49               [--redefine-syms=filename]
50               [--weaken]
51               [--keep-symbols=filename]
52               [--strip-symbols=filename]
53               [--strip-unneeded-symbols=filename]
54               [--keep-global-symbols=filename]
55               [--localize-symbols=filename]
56               [--globalize-symbols=filename]
57               [--weaken-symbols=filename]
58               [--alt-machine-code=index]
59               [--prefix-symbols=string]
60               [--prefix-sections=string]
61               [--prefix-alloc-sections=string]
62               [--add-gnu-debuglink=path-to-file]
63               [--keep-file-symbols]
64               [--only-keep-debug]
65               [--extract-symbol]
66               [--writable-text]
67               [--readonly-text]
68               [--pure]
69               [--impure]
70               [--file-alignment=num]
71               [--heap=size]
72               [--image-base=address]
73               [--section-alignment=num]
74               [--stack=size]
75               [--subsystem=which:major.minor]
76               [-v|--verbose]
77               [-V|--version]
78               [--help] [--info]
79               infile [outfile]
80

DESCRIPTION

82       The GNU objcopy utility copies the contents of an object file to
83       another.  objcopy uses the GNU BFD Library to read and write the object
84       files.  It can write the destination object file in a format different
85       from that of the source object file.  The exact behavior of objcopy is
86       controlled by command-line options.  Note that objcopy should be able
87       to copy a fully linked file between any two formats. However, copying a
88       relocatable object file between any two formats may not work as
89       expected.
90
91       objcopy creates temporary files to do its translations and deletes them
92       afterward.  objcopy uses BFD to do all its translation work; it has
93       access to all the formats described in BFD and thus is able to
94       recognize most formats without being told explicitly.
95
96       objcopy can be used to generate S-records by using an output target of
97       srec (e.g., use -O srec).
98
99       objcopy can be used to generate a raw binary file by using an output
100       target of binary (e.g., use -O binary).  When objcopy generates a raw
101       binary file, it will essentially produce a memory dump of the contents
102       of the input object file.  All symbols and relocation information will
103       be discarded.  The memory dump will start at the load address of the
104       lowest section copied into the output file.
105
106       When generating an S-record or a raw binary file, it may be helpful to
107       use -S to remove sections containing debugging information.  In some
108       cases -R will be useful to remove sections which contain information
109       that is not needed by the binary file.
110
111       Note---objcopy is not able to change the endianness of its input files.
112       If the input format has an endianness (some formats do not), objcopy
113       can only copy the inputs into file formats that have the same
114       endianness or which have no endianness (e.g., srec).  (However, see the
115       --reverse-bytes option.)
116

OPTIONS

118       infile
119       outfile
120           The input and output files, respectively.  If you do not specify
121           outfile, objcopy creates a temporary file and destructively renames
122           the result with the name of infile.
123
124       -I bfdname
125       --input-target=bfdname
126           Consider the source file's object format to be bfdname, rather than
127           attempting to deduce it.
128
129       -O bfdname
130       --output-target=bfdname
131           Write the output file using the object format bfdname.
132
133       -F bfdname
134       --target=bfdname
135           Use bfdname as the object format for both the input and the output
136           file; i.e., simply transfer data from source to destination with no
137           translation.
138
139       -B bfdarch
140       --binary-architecture=bfdarch
141           Useful when transforming a raw binary input file into an object
142           file.  In this case the output architecture can be set to bfdarch.
143           This option will be ignored if the input file has a known bfdarch.
144           You can access this binary data inside a program by referencing the
145           special symbols that are created by the conversion process.  These
146           symbols are called _binary_objfile_start, _binary_objfile_end and
147           _binary_objfile_size.  e.g. you can transform a picture file into
148           an object file and then access it in your code using these symbols.
149
150       -j sectionname
151       --only-section=sectionname
152           Copy only the named section from the input file to the output file.
153           This option may be given more than once.  Note that using this
154           option inappropriately may make the output file unusable.
155
156       -R sectionname
157       --remove-section=sectionname
158           Remove any section named sectionname from the output file.  This
159           option may be given more than once.  Note that using this option
160           inappropriately may make the output file unusable.
161
162       -S
163       --strip-all
164           Do not copy relocation and symbol information from the source file.
165
166       -g
167       --strip-debug
168           Do not copy debugging symbols or sections from the source file.
169
170       --strip-unneeded
171           Strip all symbols that are not needed for relocation processing.
172
173       -K symbolname
174       --keep-symbol=symbolname
175           When stripping symbols, keep symbol symbolname even if it would
176           normally be stripped.  This option may be given more than once.
177
178       -N symbolname
179       --strip-symbol=symbolname
180           Do not copy symbol symbolname from the source file.  This option
181           may be given more than once.
182
183       --strip-unneeded-symbol=symbolname
184           Do not copy symbol symbolname from the source file unless it is
185           needed by a relocation.  This option may be given more than once.
186
187       -G symbolname
188       --keep-global-symbol=symbolname
189           Keep only symbol symbolname global.  Make all other symbols local
190           to the file, so that they are not visible externally.  This option
191           may be given more than once.
192
193       --localize-hidden
194           In an ELF object, mark all symbols that have hidden or internal
195           visibility as local.  This option applies on top of symbol-specific
196           localization options such as -L.
197
198       -L symbolname
199       --localize-symbol=symbolname
200           Make symbol symbolname local to the file, so that it is not visible
201           externally.  This option may be given more than once.
202
203       -W symbolname
204       --weaken-symbol=symbolname
205           Make symbol symbolname weak. This option may be given more than
206           once.
207
208       --globalize-symbol=symbolname
209           Give symbol symbolname global scoping so that it is visible outside
210           of the file in which it is defined.  This option may be given more
211           than once.
212
213       -w
214       --wildcard
215           Permit regular expressions in symbolnames used in other command
216           line options.  The question mark (?), asterisk (*), backslash (\)
217           and square brackets ([]) operators can be used anywhere in the
218           symbol name.  If the first character of the symbol name is the
219           exclamation point (!) then the sense of the switch is reversed for
220           that symbol.  For example:
221
222                     -w -W !foo -W fo*
223
224           would cause objcopy to weaken all symbols that start with "fo"
225           except for the symbol "foo".
226
227       -x
228       --discard-all
229           Do not copy non-global symbols from the source file.
230
231       -X
232       --discard-locals
233           Do not copy compiler-generated local symbols.  (These usually start
234           with L or ..)
235
236       -b byte
237       --byte=byte
238           Keep only every byteth byte of the input file (header data is not
239           affected).  byte can be in the range from 0 to interleave-1, where
240           interleave is given by the -i or --interleave option, or the
241           default of 4.  This option is useful for creating files to program
242           ROM.  It is typically used with an "srec" output target.
243
244       -i interleave
245       --interleave=interleave
246           Only copy one out of every interleave bytes.  Select which byte to
247           copy with the -b or --byte option.  The default is 4.  objcopy
248           ignores this option if you do not specify either -b or --byte.
249
250       -p
251       --preserve-dates
252           Set the access and modification dates of the output file to be the
253           same as those of the input file.
254
255       --debugging
256           Convert debugging information, if possible.  This is not the
257           default because only certain debugging formats are supported, and
258           the conversion process can be time consuming.
259
260       --gap-fill val
261           Fill gaps between sections with val.  This operation applies to the
262           load address (LMA) of the sections.  It is done by increasing the
263           size of the section with the lower address, and filling in the
264           extra space created with val.
265
266       --pad-to address
267           Pad the output file up to the load address address.  This is done
268           by increasing the size of the last section.  The extra space is
269           filled in with the value specified by --gap-fill (default zero).
270
271       --set-start val
272           Set the start address of the new file to val.  Not all object file
273           formats support setting the start address.
274
275       --change-start incr
276       --adjust-start incr
277           Change the start address by adding incr.  Not all object file
278           formats support setting the start address.
279
280       --change-addresses incr
281       --adjust-vma incr
282           Change the VMA and LMA addresses of all sections, as well as the
283           start address, by adding incr.  Some object file formats do not
284           permit section addresses to be changed arbitrarily.  Note that this
285           does not relocate the sections; if the program expects sections to
286           be loaded at a certain address, and this option is used to change
287           the sections such that they are loaded at a different address, the
288           program may fail.
289
290       --change-section-address section{=,+,-}val
291       --adjust-section-vma section{=,+,-}val
292           Set or change both the VMA address and the LMA address of the named
293           section.  If = is used, the section address is set to val.
294           Otherwise, val is added to or subtracted from the section address.
295           See the comments under --change-addresses, above. If section does
296           not exist in the input file, a warning will be issued, unless
297           --no-change-warnings is used.
298
299       --change-section-lma section{=,+,-}val
300           Set or change the LMA address of the named section.  The LMA
301           address is the address where the section will be loaded into memory
302           at program load time.  Normally this is the same as the VMA
303           address, which is the address of the section at program run time,
304           but on some systems, especially those where a program is held in
305           ROM, the two can be different.  If = is used, the section address
306           is set to val.  Otherwise, val is added to or subtracted from the
307           section address.  See the comments under --change-addresses, above.
308           If section does not exist in the input file, a warning will be
309           issued, unless --no-change-warnings is used.
310
311       --change-section-vma section{=,+,-}val
312           Set or change the VMA address of the named section.  The VMA
313           address is the address where the section will be located once the
314           program has started executing.  Normally this is the same as the
315           LMA address, which is the address where the section will be loaded
316           into memory, but on some systems, especially those where a program
317           is held in ROM, the two can be different.  If = is used, the
318           section address is set to val.  Otherwise, val is added to or
319           subtracted from the section address.  See the comments under
320           --change-addresses, above.  If section does not exist in the input
321           file, a warning will be issued, unless --no-change-warnings is
322           used.
323
324       --change-warnings
325       --adjust-warnings
326           If --change-section-address or --change-section-lma or
327           --change-section-vma is used, and the named section does not exist,
328           issue a warning.  This is the default.
329
330       --no-change-warnings
331       --no-adjust-warnings
332           Do not issue a warning if --change-section-address or
333           --adjust-section-lma or --adjust-section-vma is used, even if the
334           named section does not exist.
335
336       --set-section-flags section=flags
337           Set the flags for the named section.  The flags argument is a comma
338           separated string of flag names.  The recognized names are alloc,
339           contents, load, noload, readonly, code, data, rom, share, and
340           debug.  You can set the contents flag for a section which does not
341           have contents, but it is not meaningful to clear the contents flag
342           of a section which does have contents--just remove the section
343           instead.  Not all flags are meaningful for all object file formats.
344
345       --add-section sectionname=filename
346           Add a new section named sectionname while copying the file.  The
347           contents of the new section are taken from the file filename.  The
348           size of the section will be the size of the file.  This option only
349           works on file formats which can support sections with arbitrary
350           names.
351
352       --rename-section oldname=newname[,flags]
353           Rename a section from oldname to newname, optionally changing the
354           section's flags to flags in the process.  This has the advantage
355           over usng a linker script to perform the rename in that the output
356           stays as an object file and does not become a linked executable.
357
358           This option is particularly helpful when the input format is
359           binary, since this will always create a section called .data.  If
360           for example, you wanted instead to create a section called .rodata
361           containing binary data you could use the following command line to
362           achieve it:
363
364                     objcopy -I binary -O <output_format> -B <architecture> \
365                      --rename-section .data=.rodata,alloc,load,readonly,data,contents \
366                      <input_binary_file> <output_object_file>
367
368       --long-section-names {enable,disable,keep}
369           Controls the handling of long section names when processing "COFF"
370           and "PE-COFF" object formats.  The default behaviour, keep, is to
371           preserve long section names if any are present in the input file.
372           The enable and disable options forcibly enable or disable the use
373           of long section names in the output object; when disable is in
374           effect, any long section names in the input object will be
375           truncated.  The enable option will only emit long section names if
376           any are present in the inputs; this is mostly the same as keep, but
377           it is left undefined whether the enable option might force the
378           creation of an empty string table in the output file.
379
380       --change-leading-char
381           Some object file formats use special characters at the start of
382           symbols.  The most common such character is underscore, which
383           compilers often add before every symbol.  This option tells objcopy
384           to change the leading character of every symbol when it converts
385           between object file formats.  If the object file formats use the
386           same leading character, this option has no effect.  Otherwise, it
387           will add a character, or remove a character, or change a character,
388           as appropriate.
389
390       --remove-leading-char
391           If the first character of a global symbol is a special symbol
392           leading character used by the object file format, remove the
393           character.  The most common symbol leading character is underscore.
394           This option will remove a leading underscore from all global
395           symbols.  This can be useful if you want to link together objects
396           of different file formats with different conventions for symbol
397           names.  This is different from --change-leading-char because it
398           always changes the symbol name when appropriate, regardless of the
399           object file format of the output file.
400
401       --reverse-bytes=num
402           Reverse the bytes in a section with output contents.  A section
403           length must be evenly divisible by the value given in order for the
404           swap to be able to take place. Reversing takes place before the
405           interleaving is performed.
406
407           This option is used typically in generating ROM images for
408           problematic target systems.  For example, on some target boards,
409           the 32-bit words fetched from 8-bit ROMs are re-assembled in
410           little-endian byte order regardless of the CPU byte order.
411           Depending on the programming model, the endianness of the ROM may
412           need to be modified.
413
414           Consider a simple file with a section containing the following
415           eight bytes:  12345678.
416
417           Using --reverse-bytes=2 for the above example, the bytes in the
418           output file would be ordered 21436587.
419
420           Using --reverse-bytes=4 for the above example, the bytes in the
421           output file would be ordered 43218765.
422
423           By using --reverse-bytes=2 for the above example, followed by
424           --reverse-bytes=4 on the output file, the bytes in the second
425           output file would be ordered 34127856.
426
427       --srec-len=ival
428           Meaningful only for srec output.  Set the maximum length of the
429           Srecords being produced to ival.  This length covers both address,
430           data and crc fields.
431
432       --srec-forceS3
433           Meaningful only for srec output.  Avoid generation of S1/S2
434           records, creating S3-only record format.
435
436       --redefine-sym old=new
437           Change the name of a symbol old, to new.  This can be useful when
438           one is trying link two things together for which you have no
439           source, and there are name collisions.
440
441       --redefine-syms=filename
442           Apply --redefine-sym to each symbol pair "old new" listed in the
443           file filename.  filename is simply a flat file, with one symbol
444           pair per line.  Line comments may be introduced by the hash
445           character.  This option may be given more than once.
446
447       --weaken
448           Change all global symbols in the file to be weak.  This can be
449           useful when building an object which will be linked against other
450           objects using the -R option to the linker.  This option is only
451           effective when using an object file format which supports weak
452           symbols.
453
454       --keep-symbols=filename
455           Apply --keep-symbol option to each symbol listed in the file
456           filename.  filename is simply a flat file, with one symbol name per
457           line.  Line comments may be introduced by the hash character.  This
458           option may be given more than once.
459
460       --strip-symbols=filename
461           Apply --strip-symbol option to each symbol listed in the file
462           filename.  filename is simply a flat file, with one symbol name per
463           line.  Line comments may be introduced by the hash character.  This
464           option may be given more than once.
465
466       --strip-unneeded-symbols=filename
467           Apply --strip-unneeded-symbol option to each symbol listed in the
468           file filename.  filename is simply a flat file, with one symbol
469           name per line.  Line comments may be introduced by the hash
470           character.  This option may be given more than once.
471
472       --keep-global-symbols=filename
473           Apply --keep-global-symbol option to each symbol listed in the file
474           filename.  filename is simply a flat file, with one symbol name per
475           line.  Line comments may be introduced by the hash character.  This
476           option may be given more than once.
477
478       --localize-symbols=filename
479           Apply --localize-symbol option to each symbol listed in the file
480           filename.  filename is simply a flat file, with one symbol name per
481           line.  Line comments may be introduced by the hash character.  This
482           option may be given more than once.
483
484       --globalize-symbols=filename
485           Apply --globalize-symbol option to each symbol listed in the file
486           filename.  filename is simply a flat file, with one symbol name per
487           line.  Line comments may be introduced by the hash character.  This
488           option may be given more than once.
489
490       --weaken-symbols=filename
491           Apply --weaken-symbol option to each symbol listed in the file
492           filename.  filename is simply a flat file, with one symbol name per
493           line.  Line comments may be introduced by the hash character.  This
494           option may be given more than once.
495
496       --alt-machine-code=index
497           If the output architecture has alternate machine codes, use the
498           indexth code instead of the default one.  This is useful in case a
499           machine is assigned an official code and the tool-chain adopts the
500           new code, but other applications still depend on the original code
501           being used.  For ELF based architectures if the index alternative
502           does not exist then the value is treated as an absolute number to
503           be stored in the e_machine field of the ELF header.
504
505       --writable-text
506           Mark the output text as writable.  This option isn't meaningful for
507           all object file formats.
508
509       --readonly-text
510           Make the output text write protected.  This option isn't meaningful
511           for all object file formats.
512
513       --pure
514           Mark the output file as demand paged.  This option isn't meaningful
515           for all object file formats.
516
517       --impure
518           Mark the output file as impure.  This option isn't meaningful for
519           all object file formats.
520
521       --prefix-symbols=string
522           Prefix all symbols in the output file with string.
523
524       --prefix-sections=string
525           Prefix all section names in the output file with string.
526
527       --prefix-alloc-sections=string
528           Prefix all the names of all allocated sections in the output file
529           with string.
530
531       --add-gnu-debuglink=path-to-file
532           Creates a .gnu_debuglink section which contains a reference to
533           path-to-file and adds it to the output file.
534
535       --keep-file-symbols
536           When stripping a file, perhaps with --strip-debug or
537           --strip-unneeded, retain any symbols specifying source file names,
538           which would otherwise get stripped.
539
540       --only-keep-debug
541           Strip a file, removing contents of any sections that would not be
542           stripped by --strip-debug and leaving the debugging sections
543           intact.  In ELF files, this preserves all note sections in the
544           output.
545
546           The intention is that this option will be used in conjunction with
547           --add-gnu-debuglink to create a two part executable.  One a
548           stripped binary which will occupy less space in RAM and in a
549           distribution and the second a debugging information file which is
550           only needed if debugging abilities are required.  The suggested
551           procedure to create these files is as follows:
552
553           1.<Link the executable as normal.  Assuming that is is called>
554               "foo" then...
555
556           1.<Run "objcopy --only-keep-debug foo foo.dbg" to>
557               create a file containing the debugging info.
558
559           1.<Run "objcopy --strip-debug foo" to create a>
560               stripped executable.
561
562           1.<Run "objcopy --add-gnu-debuglink=foo.dbg foo">
563               to add a link to the debugging info into the stripped
564               executable.
565
566           Note---the choice of ".dbg" as an extension for the debug info file
567           is arbitrary.  Also the "--only-keep-debug" step is optional.  You
568           could instead do this:
569
570           1.<Link the executable as normal.>
571           1.<Copy "foo" to  "foo.full">
572           1.<Run "objcopy --strip-debug foo">
573           1.<Run "objcopy --add-gnu-debuglink=foo.full foo">
574
575           i.e., the file pointed to by the --add-gnu-debuglink can be the
576           full executable.  It does not have to be a file created by the
577           --only-keep-debug switch.
578
579           Note---this switch is only intended for use on fully linked files.
580           It does not make sense to use it on object files where the
581           debugging information may be incomplete.  Besides the gnu_debuglink
582           feature currently only supports the presence of one filename
583           containing debugging information, not multiple filenames on a one-
584           per-object-file basis.
585
586       --file-alignment num
587           Specify the file alignment.  Sections in the file will always begin
588           at file offsets which are multiples of this number.  This defaults
589           to 512.  [This option is specific to PE targets.]
590
591       --heap reserve
592       --heap reserve,commit
593           Specify the number of bytes of memory to reserve (and optionally
594           commit) to be used as heap for this program.  [This option is
595           specific to PE targets.]
596
597       --image-base value
598           Use value as the base address of your program or dll.  This is the
599           lowest memory location that will be used when your program or dll
600           is loaded.  To reduce the need to relocate and improve performance
601           of your dlls, each should have a unique base address and not
602           overlap any other dlls.  The default is 0x400000 for executables,
603           and 0x10000000 for dlls.  [This option is specific to PE targets.]
604
605       --section-alignment num
606           Sets the section alignment.  Sections in memory will always begin
607           at addresses which are a multiple of this number.  Defaults to
608           0x1000.  [This option is specific to PE targets.]
609
610       --stack reserve
611       --stack reserve,commit
612           Specify the number of bytes of memory to reserve (and optionally
613           commit) to be used as stack for this program.  [This option is
614           specific to PE targets.]
615
616       --subsystem which
617       --subsystem which:major
618       --subsystem which:major.minor
619           Specifies the subsystem under which your program will execute.  The
620           legal values for which are "native", "windows", "console", "posix",
621           "efi-app", "efi-bsd", "efi-rtd", "sal-rtd", and "xbox".  You may
622           optionally set the subsystem version also.  Numeric values are also
623           accepted for which.  [This option is specific to PE targets.]
624
625       --extract-symbol
626           Keep the file's section flags and symbols but remove all section
627           data.  Specifically, the option:
628
629           *<removes the contents of all sections;>
630           *<sets the size of every section to zero; and>
631           *<sets the file's start address to zero.>
632
633           This option is used to build a .sym file for a VxWorks kernel.  It
634           can also be a useful way of reducing the size of a --just-symbols
635           linker input file.
636
637       -V
638       --version
639           Show the version number of objcopy.
640
641       -v
642       --verbose
643           Verbose output: list all object files modified.  In the case of
644           archives, objcopy -V lists all members of the archive.
645
646       --help
647           Show a summary of the options to objcopy.
648
649       --info
650           Display a list showing all architectures and object formats
651           available.
652
653       @file
654           Read command-line options from file.  The options read are inserted
655           in place of the original @file option.  If file does not exist, or
656           cannot be read, then the option will be treated literally, and not
657           removed.
658
659           Options in file are separated by whitespace.  A whitespace
660           character may be included in an option by surrounding the entire
661           option in either single or double quotes.  Any character (including
662           a backslash) may be included by prefixing the character to be
663           included with a backslash.  The file may itself contain additional
664           @file options; any such options will be processed recursively.
665

SEE ALSO

667       ld(1), objdump(1), and the Info entries for binutils.
668
670       Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
671       2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free
672       Software Foundation, Inc.
673
674       Permission is granted to copy, distribute and/or modify this document
675       under the terms of the GNU Free Documentation License, Version 1.3 or
676       any later version published by the Free Software Foundation; with no
677       Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
678       Texts.  A copy of the license is included in the section entitled "GNU
679       Free Documentation License".
680
681
682
683binutils-2.20                     2009-10-16                        OBJCOPY(1)
Impressum