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               [--change-leading-char] [--remove-leading-char]
45               [--reverse-bytes=num]
46               [--srec-len=ival] [--srec-forceS3]
47               [--redefine-sym old=new]
48               [--redefine-syms=filename]
49               [--weaken]
50               [--keep-symbols=filename]
51               [--strip-symbols=filename]
52               [--strip-unneeded-symbols=filename]
53               [--keep-global-symbols=filename]
54               [--localize-symbols=filename]
55               [--globalize-symbols=filename]
56               [--weaken-symbols=filename]
57               [--alt-machine-code=index]
58               [--prefix-symbols=string]
59               [--prefix-sections=string]
60               [--prefix-alloc-sections=string]
61               [--add-gnu-debuglink=path-to-file]
62               [--keep-file-symbols]
63               [--only-keep-debug]
64               [--extract-symbol]
65               [--writable-text]
66               [--readonly-text]
67               [--pure]
68               [--impure]
69               [-v|--verbose]
70               [-V|--version]
71               [--help] [--info]
72               infile [outfile]
73

DESCRIPTION

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

OPTIONS

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

SEE ALSO

609       ld(1), objdump(1), and the Info entries for binutils.
610
612       Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
613       2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software
614       Foundation, Inc.
615
616       Permission is granted to copy, distribute and/or modify this document
617       under the terms of the GNU Free Documentation License, Version 1.2 or
618       any later version published by the Free Software Foundation; with no
619       Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
620       Texts.  A copy of the license is included in the section entitled "GNU
621       Free Documentation License".
622
623
624
625binutils-2.19.50.0.1              2009-07-28                        OBJCOPY(1)
Impressum