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