1OBJCOPY(1) GNU Development Tools OBJCOPY(1)
2
3
4
6 objcopy - copy and translate object files
7
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 [-L symbolname|--localize-symbol=symbolname]
20 [--globalize-symbol=symbolname]
21 [-W symbolname|--weaken-symbol=symbolname]
22 [-w|--wildcard]
23 [-x|--discard-all]
24 [-X|--discard-locals]
25 [-b byte|--byte=byte]
26 [-i interleave|--interleave=interleave]
27 [-j sectionname|--only-section=sectionname]
28 [-R sectionname|--remove-section=sectionname]
29 [-p|--preserve-dates]
30 [--debugging]
31 [--gap-fill=val]
32 [--pad-to=address]
33 [--set-start=val]
34 [--adjust-start=incr]
35 [--change-addresses=incr]
36 [--change-section-address section{=,+,-}val]
37 [--change-section-lma section{=,+,-}val]
38 [--change-section-vma section{=,+,-}val]
39 [--change-warnings] [--no-change-warnings]
40 [--set-section-flags section=flags]
41 [--add-section sectionname=filename]
42 [--rename-section oldname=newname[,flags]]
43 [--change-leading-char] [--remove-leading-char]
44 [--srec-len=ival] [--srec-forceS3]
45 [--redefine-sym old=new]
46 [--redefine-syms=filename]
47 [--weaken]
48 [--keep-symbols=filename]
49 [--strip-symbols=filename]
50 [--strip-unneeded-symbols=filename]
51 [--keep-global-symbols=filename]
52 [--localize-symbols=filename]
53 [--globalize-symbols=filename]
54 [--weaken-symbols=filename]
55 [--alt-machine-code=index]
56 [--prefix-symbols=string]
57 [--prefix-sections=string]
58 [--prefix-alloc-sections=string]
59 [--add-gnu-debuglink=path-to-file]
60 [--keep-file-symbols]
61 [--only-keep-debug]
62 [--writable-text]
63 [--readonly-text]
64 [--pure]
65 [--impure]
66 [-v|--verbose]
67 [-V|--version]
68 [--help] [--info]
69 infile [outfile]
70
72 The GNU objcopy utility copies the contents of an object file to
73 another. objcopy uses the GNU BFD Library to read and write the object
74 files. It can write the destination object file in a format different
75 from that of the source object file. The exact behavior of objcopy is
76 controlled by command-line options. Note that objcopy should be able
77 to copy a fully linked file between any two formats. However, copying a
78 relocatable object file between any two formats may not work as
79 expected.
80
81 objcopy creates temporary files to do its translations and deletes them
82 afterward. objcopy uses BFD to do all its translation work; it has
83 access to all the formats described in BFD and thus is able to recog‐
84 nize most formats without being told explicitly.
85
86 objcopy can be used to generate S-records by using an output target of
87 srec (e.g., use -O srec).
88
89 objcopy can be used to generate a raw binary file by using an output
90 target of binary (e.g., use -O binary). When objcopy generates a raw
91 binary file, it will essentially produce a memory dump of the contents
92 of the input object file. All symbols and relocation information will
93 be discarded. The memory dump will start at the load address of the
94 lowest section copied into the output file.
95
96 When generating an S-record or a raw binary file, it may be helpful to
97 use -S to remove sections containing debugging information. In some
98 cases -R will be useful to remove sections which contain information
99 that is not needed by the binary file.
100
101 Note---objcopy is not able to change the endianness of its input files.
102 If the input format has an endianness (some formats do not), objcopy
103 can only copy the inputs into file formats that have the same endian‐
104 ness or which have no endianness (e.g., srec).
105
107 infile
108 outfile
109 The input and output files, respectively. If you do not specify
110 outfile, objcopy creates a temporary file and destructively renames
111 the result with the name of infile.
112
113 -I bfdname
114 --input-target=bfdname
115 Consider the source file's object format to be bfdname, rather than
116 attempting to deduce it.
117
118 -O bfdname
119 --output-target=bfdname
120 Write the output file using the object format bfdname.
121
122 -F bfdname
123 --target=bfdname
124 Use bfdname as the object format for both the input and the output
125 file; i.e., simply transfer data from source to destination with no
126 translation.
127
128 -B bfdarch
129 --binary-architecture=bfdarch
130 Useful when transforming a raw binary input file into an object
131 file. In this case the output architecture can be set to bfdarch.
132 This option will be ignored if the input file has a known bfdarch.
133 You can access this binary data inside a program by referencing the
134 special symbols that are created by the conversion process. These
135 symbols are called _binary_objfile_start, _binary_objfile_end and
136 _binary_objfile_size. e.g. you can transform a picture file into
137 an object file and then access it in your code using these symbols.
138
139 -j sectionname
140 --only-section=sectionname
141 Copy only the named section from the input file to the output file.
142 This option may be given more than once. Note that using this
143 option inappropriately may make the output file unusable.
144
145 -R sectionname
146 --remove-section=sectionname
147 Remove any section named sectionname from the output file. This
148 option may be given more than once. Note that using this option
149 inappropriately may make the output file unusable.
150
151 -S
152 --strip-all
153 Do not copy relocation and symbol information from the source file.
154
155 -g
156 --strip-debug
157 Do not copy debugging symbols or sections from the source file.
158
159 --strip-unneeded
160 Strip all symbols that are not needed for relocation processing.
161
162 -K symbolname
163 --keep-symbol=symbolname
164 When stripping symbols, keep symbol symbolname even if it would
165 normally be stripped. This option may be given more than once.
166
167 -N symbolname
168 --strip-symbol=symbolname
169 Do not copy symbol symbolname from the source file. This option
170 may be given more than once.
171
172 --strip-unneeded-symbol=symbolname
173 Do not copy symbol symbolname from the source file unless it is
174 needed by a relocation. This option may be given more than once.
175
176 -G symbolname
177 --keep-global-symbol=symbolname
178 Keep only symbol symbolname global. Make all other symbols local
179 to the file, so that they are not visible externally. This option
180 may be given more than once.
181
182 -L symbolname
183 --localize-symbol=symbolname
184 Make symbol symbolname local to the file, so that it is not visible
185 externally. This option may be given more than once.
186
187 -W symbolname
188 --weaken-symbol=symbolname
189 Make symbol symbolname weak. This option may be given more than
190 once.
191
192 --globalize-symbol=symbolname
193 Give symbol symbolname global scoping so that it is visible outside
194 of the file in which it is defined. This option may be given more
195 than once.
196
197 -w
198 --wildcard
199 Permit regular expressions in symbolnames used in other command
200 line options. The question mark (?), asterisk (*), backslash (\)
201 and square brackets ([]) operators can be used anywhere in the sym‐
202 bol name. If the first character of the symbol name is the excla‐
203 mation point (!) then the sense of the switch is reversed for that
204 symbol. For example:
205
206 -w -W !foo -W fo*
207
208 would cause objcopy to weaken all symbols that start with "fo"
209 except for the symbol "foo".
210
211 -x
212 --discard-all
213 Do not copy non-global symbols from the source file.
214
215 -X
216 --discard-locals
217 Do not copy compiler-generated local symbols. (These usually start
218 with L or ..)
219
220 -b byte
221 --byte=byte
222 Keep only every byteth byte of the input file (header data is not
223 affected). byte can be in the range from 0 to interleave-1, where
224 interleave is given by the -i or --interleave option, or the
225 default of 4. This option is useful for creating files to program
226 ROM. It is typically used with an "srec" output target.
227
228 -i interleave
229 --interleave=interleave
230 Only copy one out of every interleave bytes. Select which byte to
231 copy with the -b or --byte option. The default is 4. objcopy
232 ignores this option if you do not specify either -b or --byte.
233
234 -p
235 --preserve-dates
236 Set the access and modification dates of the output file to be the
237 same as those of the input file.
238
239 --debugging
240 Convert debugging information, if possible. This is not the
241 default because only certain debugging formats are supported, and
242 the conversion process can be time consuming.
243
244 --gap-fill val
245 Fill gaps between sections with val. This operation applies to the
246 load address (LMA) of the sections. It is done by increasing the
247 size of the section with the lower address, and filling in the
248 extra space created with val.
249
250 --pad-to address
251 Pad the output file up to the load address address. This is done
252 by increasing the size of the last section. The extra space is
253 filled in with the value specified by --gap-fill (default zero).
254
255 --set-start val
256 Set the start address of the new file to val. Not all object file
257 formats support setting the start address.
258
259 --change-start incr
260 --adjust-start incr
261 Change the start address by adding incr. Not all object file for‐
262 mats support setting the start address.
263
264 --change-addresses incr
265 --adjust-vma incr
266 Change the VMA and LMA addresses of all sections, as well as the
267 start address, by adding incr. Some object file formats do not
268 permit section addresses to be changed arbitrarily. Note that this
269 does not relocate the sections; if the program expects sections to
270 be loaded at a certain address, and this option is used to change
271 the sections such that they are loaded at a different address, the
272 program may fail.
273
274 --change-section-address section{=,+,-}val
275 --adjust-section-vma section{=,+,-}val
276 Set or change both the VMA address and the LMA address of the named
277 section. If = is used, the section address is set to val. Other‐
278 wise, val is added to or subtracted from the section address. See
279 the comments under --change-addresses, above. If section does not
280 exist in the input file, a warning will be issued, unless
281 --no-change-warnings is used.
282
283 --change-section-lma section{=,+,-}val
284 Set or change the LMA address of the named section. The LMA
285 address is the address where the section will be loaded into memory
286 at program load time. Normally this is the same as the VMA
287 address, which is the address of the section at program run time,
288 but on some systems, especially those where a program is held in
289 ROM, the two can be different. If = is used, the section address
290 is set to val. Otherwise, val is added to or subtracted from the
291 section address. See the comments under --change-addresses, above.
292 If section does not exist in the input file, a warning will be
293 issued, unless --no-change-warnings is used.
294
295 --change-section-vma section{=,+,-}val
296 Set or change the VMA address of the named section. The VMA
297 address is the address where the section will be located once the
298 program has started executing. Normally this is the same as the
299 LMA address, which is the address where the section will be loaded
300 into memory, but on some systems, especially those where a program
301 is held in ROM, the two can be different. If = is used, the sec‐
302 tion address is set to val. Otherwise, val is added to or sub‐
303 tracted from the section address. See the comments under
304 --change-addresses, above. If section does not exist in the input
305 file, a warning will be issued, unless --no-change-warnings is
306 used.
307
308 --change-warnings
309 --adjust-warnings
310 If --change-section-address or --change-section-lma or
311 --change-section-vma is used, and the named section does not exist,
312 issue a warning. This is the default.
313
314 --no-change-warnings
315 --no-adjust-warnings
316 Do not issue a warning if --change-section-address or --adjust-sec‐
317 tion-lma or --adjust-section-vma is used, even if the named section
318 does not exist.
319
320 --set-section-flags section=flags
321 Set the flags for the named section. The flags argument is a comma
322 separated string of flag names. The recognized names are alloc,
323 contents, load, noload, readonly, code, data, rom, share, and
324 debug. You can set the contents flag for a section which does not
325 have contents, but it is not meaningful to clear the contents flag
326 of a section which does have contents--just remove the section
327 instead. Not all flags are meaningful for all object file formats.
328
329 --add-section sectionname=filename
330 Add a new section named sectionname while copying the file. The
331 contents of the new section are taken from the file filename. The
332 size of the section will be the size of the file. This option only
333 works on file formats which can support sections with arbitrary
334 names.
335
336 --rename-section oldname=newname[,flags]
337 Rename a section from oldname to newname, optionally changing the
338 section's flags to flags in the process. This has the advantage
339 over usng a linker script to perform the rename in that the output
340 stays as an object file and does not become a linked executable.
341
342 This option is particularly helpful when the input format is
343 binary, since this will always create a section called .data. If
344 for example, you wanted instead to create a section called .rodata
345 containing binary data you could use the following command line to
346 achieve it:
347
348 objcopy -I binary -O <output_format> -B <architecture> \
349 --rename-section .data=.rodata,alloc,load,readonly,data,contents \
350 <input_binary_file> <output_object_file>
351
352 --change-leading-char
353 Some object file formats use special characters at the start of
354 symbols. The most common such character is underscore, which com‐
355 pilers often add before every symbol. This option tells objcopy to
356 change the leading character of every symbol when it converts
357 between object file formats. If the object file formats use the
358 same leading character, this option has no effect. Otherwise, it
359 will add a character, or remove a character, or change a character,
360 as appropriate.
361
362 --remove-leading-char
363 If the first character of a global symbol is a special symbol lead‐
364 ing character used by the object file format, remove the character.
365 The most common symbol leading character is underscore. This
366 option will remove a leading underscore from all global symbols.
367 This can be useful if you want to link together objects of differ‐
368 ent file formats with different conventions for symbol names. This
369 is different from --change-leading-char because it always changes
370 the symbol name when appropriate, regardless of the object file
371 format of the output file.
372
373 --srec-len=ival
374 Meaningful only for srec output. Set the maximum length of the
375 Srecords being produced to ival. This length covers both address,
376 data and crc fields.
377
378 --srec-forceS3
379 Meaningful only for srec output. Avoid generation of S1/S2
380 records, creating S3-only record format.
381
382 --redefine-sym old=new
383 Change the name of a symbol old, to new. This can be useful when
384 one is trying link two things together for which you have no
385 source, and there are name collisions.
386
387 --redefine-syms=filename
388 Apply --redefine-sym to each symbol pair "old new" listed in the
389 file filename. filename is simply a flat file, with one symbol
390 pair per line. Line comments may be introduced by the hash charac‐
391 ter. This option may be given more than once.
392
393 --weaken
394 Change all global symbols in the file to be weak. This can be use‐
395 ful when building an object which will be linked against other
396 objects using the -R option to the linker. This option is only
397 effective when using an object file format which supports weak sym‐
398 bols.
399
400 --keep-symbols=filename
401 Apply --keep-symbol option to each symbol listed in the file file‐
402 name. filename is simply a flat file, with one symbol name per
403 line. Line comments may be introduced by the hash character. This
404 option may be given more than once.
405
406 --strip-symbols=filename
407 Apply --strip-symbol option to each symbol listed in the file file‐
408 name. filename is simply a flat file, with one symbol name per
409 line. Line comments may be introduced by the hash character. This
410 option may be given more than once.
411
412 --strip-unneeded-symbols=filename
413 Apply --strip-unneeded-symbol option to each symbol listed in the
414 file filename. filename is simply a flat file, with one symbol
415 name per line. Line comments may be introduced by the hash charac‐
416 ter. This option may be given more than once.
417
418 --keep-global-symbols=filename
419 Apply --keep-global-symbol option to each symbol listed in the file
420 filename. filename is simply a flat file, with one symbol name per
421 line. Line comments may be introduced by the hash character. This
422 option may be given more than once.
423
424 --localize-symbols=filename
425 Apply --localize-symbol option to each symbol listed in the file
426 filename. filename is simply a flat file, with one symbol name per
427 line. Line comments may be introduced by the hash character. This
428 option may be given more than once.
429
430 --globalize-symbols=filename
431 Apply --globalize-symbol option to each symbol listed in the file
432 filename. filename is simply a flat file, with one symbol name per
433 line. Line comments may be introduced by the hash character. This
434 option may be given more than once.
435
436 --weaken-symbols=filename
437 Apply --weaken-symbol option to each symbol listed in the file
438 filename. filename is simply a flat file, with one symbol name per
439 line. Line comments may be introduced by the hash character. This
440 option may be given more than once.
441
442 --alt-machine-code=index
443 If the output architecture has alternate machine codes, use the
444 indexth code instead of the default one. This is useful in case a
445 machine is assigned an official code and the tool-chain adopts the
446 new code, but other applications still depend on the original code
447 being used. For ELF based architectures if the index alternative
448 does not exist then the value is treated as an absolute number to
449 be stored in the e_machine field of the ELF header.
450
451 --writable-text
452 Mark the output text as writable. This option isn't meaningful for
453 all object file formats.
454
455 --readonly-text
456 Make the output text write protected. This option isn't meaningful
457 for all object file formats.
458
459 --pure
460 Mark the output file as demand paged. This option isn't meaningful
461 for all object file formats.
462
463 --impure
464 Mark the output file as impure. This option isn't meaningful for
465 all object file formats.
466
467 --prefix-symbols=string
468 Prefix all symbols in the output file with string.
469
470 --prefix-sections=string
471 Prefix all section names in the output file with string.
472
473 --prefix-alloc-sections=string
474 Prefix all the names of all allocated sections in the output file
475 with string.
476
477 --add-gnu-debuglink=path-to-file
478 Creates a .gnu_debuglink section which contains a reference to
479 path-to-file and adds it to the output file.
480
481 --keep-file-symbols
482 When stripping a file, perhaps with --strip-debug or
483 --strip-unneeded, retain any symbols specifying source file names,
484 which would otherwise get stripped.
485
486 --only-keep-debug
487 Strip a file, removing contents of any sections that would not be
488 stripped by --strip-debug and leaving the debugging sections
489 intact.
490
491 The intention is that this option will be used in conjunction with
492 --add-gnu-debuglink to create a two part executable. One a
493 stripped binary which will occupy less space in RAM and in a dis‐
494 tribution and the second a debugging information file which is only
495 needed if debugging abilities are required. The suggested proce‐
496 dure to create these files is as follows:
497
498 1.<Link the executable as normal. Assuming that is is called>
499 "foo" then...
500
501 1.<Run "objcopy --only-keep-debug foo foo.dbg" to>
502 create a file containing the debugging info.
503
504 1.<Run "objcopy --strip-debug foo" to create a>
505 stripped executable.
506
507 1.<Run "objcopy --add-gnu-debuglink=foo.dbg foo">
508 to add a link to the debugging info into the stripped exe‐
509 cutable.
510
511 Note - the choice of ".dbg" as an extension for the debug info file
512 is arbitrary. Also the "--only-keep-debug" step is optional. You
513 could instead do this:
514
515 1.<Link the executable as normal.>
516 1.<Copy "foo" to "foo.full">
517 1.<Run "objcopy --strip-debug foo">
518 1.<Run "objcopy --add-gnu-debuglink=foo.full foo">
519
520 i.e. the file pointed to by the --add-gnu-debuglink can be the full
521 executable. It does not have to be a file created by the
522 --only-keep-debug switch.
523
524 -V
525 --version
526 Show the version number of objcopy.
527
528 -v
529 --verbose
530 Verbose output: list all object files modified. In the case of ar‐
531 chives, objcopy -V lists all members of the archive.
532
533 --help
534 Show a summary of the options to objcopy.
535
536 --info
537 Display a list showing all architectures and object formats avail‐
538 able.
539
540 @file
541 Read command-line options from file. The options read are inserted
542 in place of the original @file option. If file does not exist, or
543 cannot be read, then the option will be treated literally, and not
544 removed.
545
546 Options in file are separated by whitespace. A whitespace charac‐
547 ter may be included in an option by surrounding the entire option
548 in either single or double quotes. Any character (including a
549 backslash) may be included by prefixing the character to be
550 included with a backslash. The file may itself contain additional
551 @file options; any such options will be processed recursively.
552
554 ld(1), objdump(1), and the Info entries for binutils.
555
557 Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
558 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
559
560 Permission is granted to copy, distribute and/or modify this document
561 under the terms of the GNU Free Documentation License, Version 1.1 or
562 any later version published by the Free Software Foundation; with no
563 Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
564 Texts. A copy of the license is included in the section entitled "GNU
565 Free Documentation License".
566
567
568
569binutils-2.17 2006-06-23 OBJCOPY(1)