1<html lang="en"> 2<head> 3<title>objcopy - GNU Binary Utilities</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="GNU Binary Utilities"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="prev" href="nm.html#nm" title="nm"> 9<link rel="next" href="objdump.html#objdump" title="objdump"> 10<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 11<!-- 12Copyright (C) 1991-2013 Free Software Foundation, Inc. 13 14Permission is granted to copy, distribute and/or modify this document 15under the terms of the GNU Free Documentation License, Version 1.3 16or any later version published by the Free Software Foundation; 17with no Invariant Sections, with no Front-Cover Texts, and with no 18Back-Cover Texts. A copy of the license is included in the 19section entitled ``GNU Free Documentation License''. 20 21--> 22<meta http-equiv="Content-Style-Type" content="text/css"> 23<style type="text/css"><!-- 24 pre.display { font-family:inherit } 25 pre.format { font-family:inherit } 26 pre.smalldisplay { font-family:inherit; font-size:smaller } 27 pre.smallformat { font-family:inherit; font-size:smaller } 28 pre.smallexample { font-size:smaller } 29 pre.smalllisp { font-size:smaller } 30 span.sc { font-variant:small-caps } 31 span.roman { font-family:serif; font-weight:normal; } 32 span.sansserif { font-family:sans-serif; font-weight:normal; } 33--></style> 34<link rel="stylesheet" type="text/css" href="../cs.css"> 35</head> 36<body> 37<div class="node"> 38<a name="objcopy"></a> 39<p> 40Next: <a rel="next" accesskey="n" href="objdump.html#objdump">objdump</a>, 41Previous: <a rel="previous" accesskey="p" href="nm.html#nm">nm</a>, 42Up: <a rel="up" accesskey="u" href="index.html#Top">Top</a> 43<hr> 44</div> 45 46<h2 class="chapter">3 objcopy</h2> 47 48<!-- man title objcopy copy and translate object files --> 49<pre class="smallexample"> <!-- man begin SYNOPSIS objcopy --> 50 objcopy [<samp><span class="option">-F</span></samp> <var>bfdname</var>|<samp><span class="option">--target=</span></samp><var>bfdname</var>] 51 [<samp><span class="option">-I</span></samp> <var>bfdname</var>|<samp><span class="option">--input-target=</span></samp><var>bfdname</var>] 52 [<samp><span class="option">-O</span></samp> <var>bfdname</var>|<samp><span class="option">--output-target=</span></samp><var>bfdname</var>] 53 [<samp><span class="option">-B</span></samp> <var>bfdarch</var>|<samp><span class="option">--binary-architecture=</span></samp><var>bfdarch</var>] 54 [<samp><span class="option">-S</span></samp>|<samp><span class="option">--strip-all</span></samp>] 55 [<samp><span class="option">-g</span></samp>|<samp><span class="option">--strip-debug</span></samp>] 56 [<samp><span class="option">-K</span></samp> <var>symbolname</var>|<samp><span class="option">--keep-symbol=</span></samp><var>symbolname</var>] 57 [<samp><span class="option">-N</span></samp> <var>symbolname</var>|<samp><span class="option">--strip-symbol=</span></samp><var>symbolname</var>] 58 [<samp><span class="option">--strip-unneeded-symbol=</span></samp><var>symbolname</var>] 59 [<samp><span class="option">-G</span></samp> <var>symbolname</var>|<samp><span class="option">--keep-global-symbol=</span></samp><var>symbolname</var>] 60 [<samp><span class="option">--localize-hidden</span></samp>] 61 [<samp><span class="option">-L</span></samp> <var>symbolname</var>|<samp><span class="option">--localize-symbol=</span></samp><var>symbolname</var>] 62 [<samp><span class="option">--globalize-symbol=</span></samp><var>symbolname</var>] 63 [<samp><span class="option">-W</span></samp> <var>symbolname</var>|<samp><span class="option">--weaken-symbol=</span></samp><var>symbolname</var>] 64 [<samp><span class="option">-w</span></samp>|<samp><span class="option">--wildcard</span></samp>] 65 [<samp><span class="option">-x</span></samp>|<samp><span class="option">--discard-all</span></samp>] 66 [<samp><span class="option">-X</span></samp>|<samp><span class="option">--discard-locals</span></samp>] 67 [<samp><span class="option">-b</span></samp> <var>byte</var>|<samp><span class="option">--byte=</span></samp><var>byte</var>] 68 [<samp><span class="option">-i</span></samp> [<var>breadth</var>]|<samp><span class="option">--interleave</span></samp>[=<var>breadth</var>]] 69 [<samp><span class="option">--interleave-width=</span></samp><var>width</var>] 70 [<samp><span class="option">-j</span></samp> <var>sectionpattern</var>|<samp><span class="option">--only-section=</span></samp><var>sectionpattern</var>] 71 [<samp><span class="option">-R</span></samp> <var>sectionpattern</var>|<samp><span class="option">--remove-section=</span></samp><var>sectionpattern</var>] 72 [<samp><span class="option">-p</span></samp>|<samp><span class="option">--preserve-dates</span></samp>] 73 [<samp><span class="option">-D</span></samp>|<samp><span class="option">--enable-deterministic-archives</span></samp>] 74 [<samp><span class="option">-U</span></samp>|<samp><span class="option">--disable-deterministic-archives</span></samp>] 75 [<samp><span class="option">--debugging</span></samp>] 76 [<samp><span class="option">--gap-fill=</span></samp><var>val</var>] 77 [<samp><span class="option">--pad-to=</span></samp><var>address</var>] 78 [<samp><span class="option">--set-start=</span></samp><var>val</var>] 79 [<samp><span class="option">--adjust-start=</span></samp><var>incr</var>] 80 [<samp><span class="option">--change-addresses=</span></samp><var>incr</var>] 81 [<samp><span class="option">--change-section-address</span></samp> <var>sectionpattern</var>{=,+,-}<var>val</var>] 82 [<samp><span class="option">--change-section-lma</span></samp> <var>sectionpattern</var>{=,+,-}<var>val</var>] 83 [<samp><span class="option">--change-section-vma</span></samp> <var>sectionpattern</var>{=,+,-}<var>val</var>] 84 [<samp><span class="option">--change-warnings</span></samp>] [<samp><span class="option">--no-change-warnings</span></samp>] 85 [<samp><span class="option">--set-section-flags</span></samp> <var>sectionpattern</var>=<var>flags</var>] 86 [<samp><span class="option">--add-section</span></samp> <var>sectionname</var>=<var>filename</var>] 87 [<samp><span class="option">--rename-section</span></samp> <var>oldname</var>=<var>newname</var>[,<var>flags</var>]] 88 [<samp><span class="option">--long-section-names</span></samp> {enable,disable,keep}] 89 [<samp><span class="option">--change-leading-char</span></samp>] [<samp><span class="option">--remove-leading-char</span></samp>] 90 [<samp><span class="option">--reverse-bytes=</span></samp><var>num</var>] 91 [<samp><span class="option">--srec-len=</span></samp><var>ival</var>] [<samp><span class="option">--srec-forceS3</span></samp>] 92 [<samp><span class="option">--redefine-sym</span></samp> <var>old</var>=<var>new</var>] 93 [<samp><span class="option">--redefine-syms=</span></samp><var>filename</var>] 94 [<samp><span class="option">--weaken</span></samp>] 95 [<samp><span class="option">--keep-symbols=</span></samp><var>filename</var>] 96 [<samp><span class="option">--strip-symbols=</span></samp><var>filename</var>] 97 [<samp><span class="option">--strip-unneeded-symbols=</span></samp><var>filename</var>] 98 [<samp><span class="option">--keep-global-symbols=</span></samp><var>filename</var>] 99 [<samp><span class="option">--localize-symbols=</span></samp><var>filename</var>] 100 [<samp><span class="option">--globalize-symbols=</span></samp><var>filename</var>] 101 [<samp><span class="option">--weaken-symbols=</span></samp><var>filename</var>] 102 [<samp><span class="option">--alt-machine-code=</span></samp><var>index</var>] 103 [<samp><span class="option">--prefix-symbols=</span></samp><var>string</var>] 104 [<samp><span class="option">--prefix-sections=</span></samp><var>string</var>] 105 [<samp><span class="option">--prefix-alloc-sections=</span></samp><var>string</var>] 106 [<samp><span class="option">--add-gnu-debuglink=</span></samp><var>path-to-file</var>] 107 [<samp><span class="option">--keep-file-symbols</span></samp>] 108 [<samp><span class="option">--only-keep-debug</span></samp>] 109 [<samp><span class="option">--strip-dwo</span></samp>] 110 [<samp><span class="option">--extract-dwo</span></samp>] 111 [<samp><span class="option">--extract-symbol</span></samp>] 112 [<samp><span class="option">--writable-text</span></samp>] 113 [<samp><span class="option">--readonly-text</span></samp>] 114 [<samp><span class="option">--pure</span></samp>] 115 [<samp><span class="option">--impure</span></samp>] 116 [<samp><span class="option">--file-alignment=</span></samp><var>num</var>] 117 [<samp><span class="option">--heap=</span></samp><var>size</var>] 118 [<samp><span class="option">--image-base=</span></samp><var>address</var>] 119 [<samp><span class="option">--section-alignment=</span></samp><var>num</var>] 120 [<samp><span class="option">--stack=</span></samp><var>size</var>] 121 [<samp><span class="option">--subsystem=</span></samp><var>which</var>:<var>major</var>.<var>minor</var>] 122 [<samp><span class="option">--compress-debug-sections</span></samp>] 123 [<samp><span class="option">--decompress-debug-sections</span></samp>] 124 [<samp><span class="option">--dwarf-depth=</span><var>n</var></samp>] 125 [<samp><span class="option">--dwarf-start=</span><var>n</var></samp>] 126 [<samp><span class="option">-v</span></samp>|<samp><span class="option">--verbose</span></samp>] 127 [<samp><span class="option">-V</span></samp>|<samp><span class="option">--version</span></samp>] 128 [<samp><span class="option">--help</span></samp>] [<samp><span class="option">--info</span></samp>] 129 <var>infile</var> [<var>outfile</var>] 130 <!-- man end --> 131</pre> 132<!-- man begin DESCRIPTION objcopy --> 133 <p>The <span class="sc">gnu</span> <samp><span class="command">objcopy</span></samp> utility copies the contents of an object 134file to another. <samp><span class="command">objcopy</span></samp> uses the <span class="sc">gnu</span> <span class="sc">bfd</span> Library to 135read and write the object files. It can write the destination object 136file in a format different from that of the source object file. The 137exact behavior of <samp><span class="command">objcopy</span></samp> is controlled by command-line options. 138Note that <samp><span class="command">objcopy</span></samp> should be able to copy a fully linked file 139between any two formats. However, copying a relocatable object file 140between any two formats may not work as expected. 141 142 <p><samp><span class="command">objcopy</span></samp> creates temporary files to do its translations and 143deletes them afterward. <samp><span class="command">objcopy</span></samp> uses <span class="sc">bfd</span> to do all its 144translation work; it has access to all the formats described in <span class="sc">bfd</span> 145and thus is able to recognize most formats without being told 146explicitly. See <a href="../ld/BFD.html#BFD">BFD</a>. 147 148 <p><samp><span class="command">objcopy</span></samp> can be used to generate S-records by using an output 149target of ‘<samp><span class="samp">srec</span></samp>’ (e.g., use ‘<samp><span class="samp">-O srec</span></samp>’). 150 151 <p><samp><span class="command">objcopy</span></samp> can be used to generate a raw binary file by using an 152output target of ‘<samp><span class="samp">binary</span></samp>’ (e.g., use <samp><span class="option">-O binary</span></samp>). When 153<samp><span class="command">objcopy</span></samp> generates a raw binary file, it will essentially produce 154a memory dump of the contents of the input object file. All symbols and 155relocation information will be discarded. The memory dump will start at 156the load address of the lowest section copied into the output file. 157 158 <p>When generating an S-record or a raw binary file, it may be helpful to 159use <samp><span class="option">-S</span></samp> to remove sections containing debugging information. In 160some cases <samp><span class="option">-R</span></samp> will be useful to remove sections which contain 161information that is not needed by the binary file. 162 163 <p>Note—<samp><span class="command">objcopy</span></samp> is not able to change the endianness of its input 164files. If the input format has an endianness (some formats do not), 165<samp><span class="command">objcopy</span></samp> can only copy the inputs into file formats that have the 166same endianness or which have no endianness (e.g., ‘<samp><span class="samp">srec</span></samp>’). 167(However, see the <samp><span class="option">--reverse-bytes</span></samp> option.) 168 169<!-- man end --> 170<!-- man begin OPTIONS objcopy --> 171 <dl> 172<dt><samp><var>infile</var></samp><dt><samp><var>outfile</var></samp><dd>The input and output files, respectively. 173If you do not specify <var>outfile</var>, <samp><span class="command">objcopy</span></samp> creates a 174temporary file and destructively renames the result with 175the name of <var>infile</var>. 176 177 <br><dt><samp><span class="env">-I </span><var>bfdname</var></samp><dt><samp><span class="env">--input-target=</span><var>bfdname</var></samp><dd>Consider the source file's object format to be <var>bfdname</var>, rather than 178attempting to deduce it. See <a href="Target-Selection.html#Target-Selection">Target Selection</a>, for more information. 179 180 <br><dt><samp><span class="env">-O </span><var>bfdname</var></samp><dt><samp><span class="env">--output-target=</span><var>bfdname</var></samp><dd>Write the output file using the object format <var>bfdname</var>. 181See <a href="Target-Selection.html#Target-Selection">Target Selection</a>, for more information. 182 183 <br><dt><samp><span class="env">-F </span><var>bfdname</var></samp><dt><samp><span class="env">--target=</span><var>bfdname</var></samp><dd>Use <var>bfdname</var> as the object format for both the input and the output 184file; i.e., simply transfer data from source to destination with no 185translation. See <a href="Target-Selection.html#Target-Selection">Target Selection</a>, for more information. 186 187 <br><dt><samp><span class="env">-B </span><var>bfdarch</var></samp><dt><samp><span class="env">--binary-architecture=</span><var>bfdarch</var></samp><dd>Useful when transforming a architecture-less input file into an object file. 188In this case the output architecture can be set to <var>bfdarch</var>. This 189option will be ignored if the input file has a known <var>bfdarch</var>. You 190can access this binary data inside a program by referencing the special 191symbols that are created by the conversion process. These symbols are 192called _binary_<var>objfile</var>_start, _binary_<var>objfile</var>_end and 193_binary_<var>objfile</var>_size. e.g. you can transform a picture file into 194an object file and then access it in your code using these symbols. 195 196 <br><dt><samp><span class="env">-j </span><var>sectionpattern</var></samp><dt><samp><span class="env">--only-section=</span><var>sectionpattern</var></samp><dd>Copy only the indicated sections from the input file to the output file. 197This option may be given more than once. Note that using this option 198inappropriately may make the output file unusable. Wildcard 199characters are accepted in <var>sectionpattern</var>. 200 201 <br><dt><samp><span class="env">-R </span><var>sectionpattern</var></samp><dt><samp><span class="env">--remove-section=</span><var>sectionpattern</var></samp><dd>Remove any section matching <var>sectionpattern</var> from the output file. 202This option may be given more than once. Note that using this option 203inappropriately may make the output file unusable. Wildcard 204characters are accepted in <var>sectionpattern</var>. Using both the 205<samp><span class="option">-j</span></samp> and <samp><span class="option">-R</span></samp> options together results in undefined 206behaviour. 207 208 <br><dt><samp><span class="env">-S</span></samp><dt><samp><span class="env">--strip-all</span></samp><dd>Do not copy relocation and symbol information from the source file. 209 210 <br><dt><samp><span class="env">-g</span></samp><dt><samp><span class="env">--strip-debug</span></samp><dd>Do not copy debugging symbols or sections from the source file. 211 212 <br><dt><samp><span class="env">--strip-unneeded</span></samp><dd>Strip all symbols that are not needed for relocation processing. 213 214 <br><dt><samp><span class="env">-K </span><var>symbolname</var></samp><dt><samp><span class="env">--keep-symbol=</span><var>symbolname</var></samp><dd>When stripping symbols, keep symbol <var>symbolname</var> even if it would 215normally be stripped. This option may be given more than once. 216 217 <br><dt><samp><span class="env">-N </span><var>symbolname</var></samp><dt><samp><span class="env">--strip-symbol=</span><var>symbolname</var></samp><dd>Do not copy symbol <var>symbolname</var> from the source file. This option 218may be given more than once. 219 220 <br><dt><samp><span class="env">--strip-unneeded-symbol=</span><var>symbolname</var></samp><dd>Do not copy symbol <var>symbolname</var> from the source file unless it is needed 221by a relocation. This option may be given more than once. 222 223 <br><dt><samp><span class="env">-G </span><var>symbolname</var></samp><dt><samp><span class="env">--keep-global-symbol=</span><var>symbolname</var></samp><dd>Keep only symbol <var>symbolname</var> global. Make all other symbols local 224to the file, so that they are not visible externally. This option may 225be given more than once. 226 227 <br><dt><samp><span class="env">--localize-hidden</span></samp><dd>In an ELF object, mark all symbols that have hidden or internal visibility 228as local. This option applies on top of symbol-specific localization options 229such as <samp><span class="option">-L</span></samp>. 230 231 <br><dt><samp><span class="env">-L </span><var>symbolname</var></samp><dt><samp><span class="env">--localize-symbol=</span><var>symbolname</var></samp><dd>Make symbol <var>symbolname</var> local to the file, so that it is not 232visible externally. This option may be given more than once. 233 234 <br><dt><samp><span class="env">-W </span><var>symbolname</var></samp><dt><samp><span class="env">--weaken-symbol=</span><var>symbolname</var></samp><dd>Make symbol <var>symbolname</var> weak. This option may be given more than once. 235 236 <br><dt><samp><span class="env">--globalize-symbol=</span><var>symbolname</var></samp><dd>Give symbol <var>symbolname</var> global scoping so that it is visible 237outside of the file in which it is defined. This option may be given 238more than once. 239 240 <br><dt><samp><span class="env">-w</span></samp><dt><samp><span class="env">--wildcard</span></samp><dd>Permit regular expressions in <var>symbolname</var>s used in other command 241line options. The question mark (?), asterisk (*), backslash (\) and 242square brackets ([]) operators can be used anywhere in the symbol 243name. If the first character of the symbol name is the exclamation 244point (!) then the sense of the switch is reversed for that symbol. 245For example: 246 247 <pre class="smallexample"> -w -W !foo -W fo* 248</pre> 249 <p>would cause objcopy to weaken all symbols that start with “fo” 250except for the symbol “foo”. 251 252 <br><dt><samp><span class="env">-x</span></samp><dt><samp><span class="env">--discard-all</span></samp><dd>Do not copy non-global symbols from the source file. 253<!-- FIXME any reason to prefer "non-global" to "local" here? --> 254 255 <br><dt><samp><span class="env">-X</span></samp><dt><samp><span class="env">--discard-locals</span></samp><dd>Do not copy compiler-generated local symbols. 256(These usually start with ‘<samp><span class="samp">L</span></samp>’ or ‘<samp><span class="samp">.</span></samp>’.) 257 258 <br><dt><samp><span class="env">-b </span><var>byte</var></samp><dt><samp><span class="env">--byte=</span><var>byte</var></samp><dd>If interleaving has been enabled via the <samp><span class="option">--interleave</span></samp> option 259then start the range of bytes to keep at the <var>byte</var>th byte. 260<var>byte</var> can be in the range from 0 to <var>breadth</var>-1, where 261<var>breadth</var> is the value given by the <samp><span class="option">--interleave</span></samp> option. 262 263 <br><dt><samp><span class="env">-i [</span><var>breadth</var><span class="env">]</span></samp><dt><samp><span class="env">--interleave[=</span><var>breadth</var><span class="env">]</span></samp><dd>Only copy a range out of every <var>breadth</var> bytes. (Header data is 264not affected). Select which byte in the range begins the copy with 265the <samp><span class="option">--byte</span></samp> option. Select the width of the range with the 266<samp><span class="option">--interleave-width</span></samp> option. 267 268 <p>This option is useful for creating files to program <span class="sc">rom</span>. It is 269typically used with an <code>srec</code> output target. Note that 270<samp><span class="command">objcopy</span></samp> will complain if you do not specify the 271<samp><span class="option">--byte</span></samp> option as well. 272 273 <p>The default interleave breadth is 4, so with <samp><span class="option">--byte</span></samp> set to 0, 274<samp><span class="command">objcopy</span></samp> would copy the first byte out of every four bytes 275from the input to the output. 276 277 <br><dt><samp><span class="env">--interleave-width=</span><var>width</var></samp><dd>When used with the <samp><span class="option">--interleave</span></samp> option, copy <var>width</var> 278bytes at a time. The start of the range of bytes to be copied is set 279by the <samp><span class="option">--byte</span></samp> option, and the extent of the range is set with 280the <samp><span class="option">--interleave</span></samp> option. 281 282 <p>The default value for this option is 1. The value of <var>width</var> plus 283the <var>byte</var> value set by the <samp><span class="option">--byte</span></samp> option must not exceed 284the interleave breadth set by the <samp><span class="option">--interleave</span></samp> option. 285 286 <p>This option can be used to create images for two 16-bit flashes interleaved 287in a 32-bit bus by passing <samp><span class="option">-b 0 -i 4 --interleave-width=2</span></samp> 288and <samp><span class="option">-b 2 -i 4 --interleave-width=2</span></samp> to two <samp><span class="command">objcopy</span></samp> 289commands. If the input was '12345678' then the outputs would be 290'1256' and '3478' respectively. 291 292 <br><dt><samp><span class="env">-p</span></samp><dt><samp><span class="env">--preserve-dates</span></samp><dd>Set the access and modification dates of the output file to be the same 293as those of the input file. 294 295 <br><dt><samp><span class="env">-D</span></samp><dt><samp><span class="env">--enable-deterministic-archives</span></samp><dd><a name="index-deterministic-archives-58"></a><a name="index-g_t_002d_002denable_002ddeterministic_002darchives-59"></a>Operate in <em>deterministic</em> mode. When copying archive members 296and writing the archive index, use zero for UIDs, GIDs, timestamps, 297and use consistent file modes for all files. 298 299 <p>If <samp><span class="file">binutils</span></samp> was configured with 300<samp><span class="option">--enable-deterministic-archives</span></samp>, then this mode is on by default. 301It can be disabled with the ‘<samp><span class="samp">-U</span></samp>’ option, below. 302 303 <br><dt><samp><span class="env">-U</span></samp><dt><samp><span class="env">--disable-deterministic-archives</span></samp><dd><a name="index-deterministic-archives-60"></a><a name="index-g_t_002d_002denable_002ddeterministic_002darchives-61"></a>Do <em>not</em> operate in <em>deterministic</em> mode. This is the 304inverse of the <samp><span class="option">-D</span></samp> option, above: when copying archive members 305and writing the archive index, use their actual UID, GID, timestamp, 306and file mode values. 307 308 <p>This is the default unless <samp><span class="file">binutils</span></samp> was configured with 309<samp><span class="option">--enable-deterministic-archives</span></samp>. 310 311 <br><dt><samp><span class="env">--debugging</span></samp><dd>Convert debugging information, if possible. This is not the default 312because only certain debugging formats are supported, and the 313conversion process can be time consuming. 314 315 <br><dt><samp><span class="env">--gap-fill </span><var>val</var></samp><dd>Fill gaps between sections with <var>val</var>. This operation applies to 316the <em>load address</em> (LMA) of the sections. It is done by increasing 317the size of the section with the lower address, and filling in the extra 318space created with <var>val</var>. 319 320 <br><dt><samp><span class="env">--pad-to </span><var>address</var></samp><dd>Pad the output file up to the load address <var>address</var>. This is 321done by increasing the size of the last section. The extra space is 322filled in with the value specified by <samp><span class="option">--gap-fill</span></samp> (default zero). 323 324 <br><dt><samp><span class="env">--set-start </span><var>val</var></samp><dd>Set the start address of the new file to <var>val</var>. Not all object file 325formats support setting the start address. 326 327 <br><dt><samp><span class="env">--change-start </span><var>incr</var></samp><dt><samp><span class="env">--adjust-start </span><var>incr</var></samp><dd><a name="index-changing-start-address-62"></a>Change the start address by adding <var>incr</var>. Not all object file 328formats support setting the start address. 329 330 <br><dt><samp><span class="env">--change-addresses </span><var>incr</var></samp><dt><samp><span class="env">--adjust-vma </span><var>incr</var></samp><dd><a name="index-changing-object-addresses-63"></a>Change the VMA and LMA addresses of all sections, as well as the start 331address, by adding <var>incr</var>. Some object file formats do not permit 332section addresses to be changed arbitrarily. Note that this does not 333relocate the sections; if the program expects sections to be loaded at a 334certain address, and this option is used to change the sections such 335that they are loaded at a different address, the program may fail. 336 337 <br><dt><samp><span class="env">--change-section-address </span><var>sectionpattern</var><span class="env">{=,+,-}</span><var>val</var></samp><dt><samp><span class="env">--adjust-section-vma </span><var>sectionpattern</var><span class="env">{=,+,-}</span><var>val</var></samp><dd><a name="index-changing-section-address-64"></a>Set or change both the VMA address and the LMA address of any section 338matching <var>sectionpattern</var>. If ‘<samp><span class="samp">=</span></samp>’ is used, the section 339address is set to <var>val</var>. Otherwise, <var>val</var> is added to or 340subtracted from the section address. See the comments under 341<samp><span class="option">--change-addresses</span></samp>, above. If <var>sectionpattern</var> does not 342match any sections in the input file, a warning will be issued, unless 343<samp><span class="option">--no-change-warnings</span></samp> is used. 344 345 <br><dt><samp><span class="env">--change-section-lma </span><var>sectionpattern</var><span class="env">{=,+,-}</span><var>val</var></samp><dd><a name="index-changing-section-LMA-65"></a>Set or change the LMA address of any sections matching 346<var>sectionpattern</var>. The LMA address is the address where the 347section will be loaded into memory at program load time. Normally 348this is the same as the VMA address, which is the address of the 349section at program run time, but on some systems, especially those 350where a program is held in ROM, the two can be different. If ‘<samp><span class="samp">=</span></samp>’ 351is used, the section address is set to <var>val</var>. Otherwise, 352<var>val</var> is added to or subtracted from the section address. See the 353comments under <samp><span class="option">--change-addresses</span></samp>, above. If 354<var>sectionpattern</var> does not match any sections in the input file, a 355warning will be issued, unless <samp><span class="option">--no-change-warnings</span></samp> is used. 356 357 <br><dt><samp><span class="env">--change-section-vma </span><var>sectionpattern</var><span class="env">{=,+,-}</span><var>val</var></samp><dd><a name="index-changing-section-VMA-66"></a>Set or change the VMA address of any section matching 358<var>sectionpattern</var>. The VMA address is the address where the 359section will be located once the program has started executing. 360Normally this is the same as the LMA address, which is the address 361where the section will be loaded into memory, but on some systems, 362especially those where a program is held in ROM, the two can be 363different. If ‘<samp><span class="samp">=</span></samp>’ is used, the section address is set to 364<var>val</var>. Otherwise, <var>val</var> is added to or subtracted from the 365section address. See the comments under <samp><span class="option">--change-addresses</span></samp>, 366above. If <var>sectionpattern</var> does not match any sections in the 367input file, a warning will be issued, unless 368<samp><span class="option">--no-change-warnings</span></samp> is used. 369 370 <br><dt><samp><span class="env">--change-warnings</span></samp><dt><samp><span class="env">--adjust-warnings</span></samp><dd>If <samp><span class="option">--change-section-address</span></samp> or <samp><span class="option">--change-section-lma</span></samp> or 371<samp><span class="option">--change-section-vma</span></samp> is used, and the section pattern does not 372match any sections, issue a warning. This is the default. 373 374 <br><dt><samp><span class="env">--no-change-warnings</span></samp><dt><samp><span class="env">--no-adjust-warnings</span></samp><dd>Do not issue a warning if <samp><span class="option">--change-section-address</span></samp> or 375<samp><span class="option">--adjust-section-lma</span></samp> or <samp><span class="option">--adjust-section-vma</span></samp> is used, even 376if the section pattern does not match any sections. 377 378 <br><dt><samp><span class="env">--set-section-flags </span><var>sectionpattern</var><span class="env">=</span><var>flags</var></samp><dd>Set the flags for any sections matching <var>sectionpattern</var>. The 379<var>flags</var> argument is a comma separated string of flag names. The 380recognized names are ‘<samp><span class="samp">alloc</span></samp>’, ‘<samp><span class="samp">contents</span></samp>’, ‘<samp><span class="samp">load</span></samp>’, 381‘<samp><span class="samp">noload</span></samp>’, ‘<samp><span class="samp">readonly</span></samp>’, ‘<samp><span class="samp">code</span></samp>’, ‘<samp><span class="samp">data</span></samp>’, ‘<samp><span class="samp">rom</span></samp>’, 382‘<samp><span class="samp">share</span></samp>’, and ‘<samp><span class="samp">debug</span></samp>’. You can set the ‘<samp><span class="samp">contents</span></samp>’ flag 383for a section which does not have contents, but it is not meaningful 384to clear the ‘<samp><span class="samp">contents</span></samp>’ flag of a section which does have 385contents–just remove the section instead. Not all flags are 386meaningful for all object file formats. 387 388 <br><dt><samp><span class="env">--add-section </span><var>sectionname</var><span class="env">=</span><var>filename</var></samp><dd>Add a new section named <var>sectionname</var> while copying the file. The 389contents of the new section are taken from the file <var>filename</var>. The 390size of the section will be the size of the file. This option only 391works on file formats which can support sections with arbitrary names. 392 393 <br><dt><samp><span class="env">--rename-section </span><var>oldname</var><span class="env">=</span><var>newname</var><span class="env">[,</span><var>flags</var><span class="env">]</span></samp><dd>Rename a section from <var>oldname</var> to <var>newname</var>, optionally 394changing the section's flags to <var>flags</var> in the process. This has 395the advantage over usng a linker script to perform the rename in that 396the output stays as an object file and does not become a linked 397executable. 398 399 <p>This option is particularly helpful when the input format is binary, 400since this will always create a section called .data. If for example, 401you wanted instead to create a section called .rodata containing binary 402data you could use the following command line to achieve it: 403 404 <pre class="smallexample"> objcopy -I binary -O <output_format> -B <architecture> \ 405 --rename-section .data=.rodata,alloc,load,readonly,data,contents \ 406 <input_binary_file> <output_object_file> 407</pre> 408 <br><dt><samp><span class="env">--long-section-names {enable,disable,keep}</span></samp><dd>Controls the handling of long section names when processing <code>COFF</code> 409and <code>PE-COFF</code> object formats. The default behaviour, ‘<samp><span class="samp">keep</span></samp>’, 410is to preserve long section names if any are present in the input file. 411The ‘<samp><span class="samp">enable</span></samp>’ and ‘<samp><span class="samp">disable</span></samp>’ options forcibly enable or disable 412the use of long section names in the output object; when ‘<samp><span class="samp">disable</span></samp>’ 413is in effect, any long section names in the input object will be truncated. 414The ‘<samp><span class="samp">enable</span></samp>’ option will only emit long section names if any are 415present in the inputs; this is mostly the same as ‘<samp><span class="samp">keep</span></samp>’, but it 416is left undefined whether the ‘<samp><span class="samp">enable</span></samp>’ option might force the 417creation of an empty string table in the output file. 418 419 <br><dt><samp><span class="env">--change-leading-char</span></samp><dd>Some object file formats use special characters at the start of 420symbols. The most common such character is underscore, which compilers 421often add before every symbol. This option tells <samp><span class="command">objcopy</span></samp> to 422change the leading character of every symbol when it converts between 423object file formats. If the object file formats use the same leading 424character, this option has no effect. Otherwise, it will add a 425character, or remove a character, or change a character, as 426appropriate. 427 428 <br><dt><samp><span class="env">--remove-leading-char</span></samp><dd>If the first character of a global symbol is a special symbol leading 429character used by the object file format, remove the character. The 430most common symbol leading character is underscore. This option will 431remove a leading underscore from all global symbols. This can be useful 432if you want to link together objects of different file formats with 433different conventions for symbol names. This is different from 434<samp><span class="option">--change-leading-char</span></samp> because it always changes the symbol name 435when appropriate, regardless of the object file format of the output 436file. 437 438 <br><dt><samp><span class="env">--reverse-bytes=</span><var>num</var></samp><dd>Reverse the bytes in a section with output contents. A section length must 439be evenly divisible by the value given in order for the swap to be able to 440take place. Reversing takes place before the interleaving is performed. 441 442 <p>This option is used typically in generating ROM images for problematic 443target systems. For example, on some target boards, the 32-bit words 444fetched from 8-bit ROMs are re-assembled in little-endian byte order 445regardless of the CPU byte order. Depending on the programming model, the 446endianness of the ROM may need to be modified. 447 448 <p>Consider a simple file with a section containing the following eight 449bytes: <code>12345678</code>. 450 451 <p>Using ‘<samp><span class="samp">--reverse-bytes=2</span></samp>’ for the above example, the bytes in the 452output file would be ordered <code>21436587</code>. 453 454 <p>Using ‘<samp><span class="samp">--reverse-bytes=4</span></samp>’ for the above example, the bytes in the 455output file would be ordered <code>43218765</code>. 456 457 <p>By using ‘<samp><span class="samp">--reverse-bytes=2</span></samp>’ for the above example, followed by 458‘<samp><span class="samp">--reverse-bytes=4</span></samp>’ on the output file, the bytes in the second 459output file would be ordered <code>34127856</code>. 460 461 <br><dt><samp><span class="env">--srec-len=</span><var>ival</var></samp><dd>Meaningful only for srec output. Set the maximum length of the Srecords 462being produced to <var>ival</var>. This length covers both address, data and 463crc fields. 464 465 <br><dt><samp><span class="env">--srec-forceS3</span></samp><dd>Meaningful only for srec output. Avoid generation of S1/S2 records, 466creating S3-only record format. 467 468 <br><dt><samp><span class="env">--redefine-sym </span><var>old</var><span class="env">=</span><var>new</var></samp><dd>Change the name of a symbol <var>old</var>, to <var>new</var>. This can be useful 469when one is trying link two things together for which you have no 470source, and there are name collisions. 471 472 <br><dt><samp><span class="env">--redefine-syms=</span><var>filename</var></samp><dd>Apply <samp><span class="option">--redefine-sym</span></samp> to each symbol pair "<var>old</var> <var>new</var>" 473listed in the file <var>filename</var>. <var>filename</var> is simply a flat file, 474with one symbol pair per line. Line comments may be introduced by the hash 475character. This option may be given more than once. 476 477 <br><dt><samp><span class="env">--weaken</span></samp><dd>Change all global symbols in the file to be weak. This can be useful 478when building an object which will be linked against other objects using 479the <samp><span class="option">-R</span></samp> option to the linker. This option is only effective when 480using an object file format which supports weak symbols. 481 482 <br><dt><samp><span class="env">--keep-symbols=</span><var>filename</var></samp><dd>Apply <samp><span class="option">--keep-symbol</span></samp> option to each symbol listed in the file 483<var>filename</var>. <var>filename</var> is simply a flat file, with one symbol 484name per line. Line comments may be introduced by the hash character. 485This option may be given more than once. 486 487 <br><dt><samp><span class="env">--strip-symbols=</span><var>filename</var></samp><dd>Apply <samp><span class="option">--strip-symbol</span></samp> option to each symbol listed in the file 488<var>filename</var>. <var>filename</var> is simply a flat file, with one symbol 489name per line. Line comments may be introduced by the hash character. 490This option may be given more than once. 491 492 <br><dt><samp><span class="env">--strip-unneeded-symbols=</span><var>filename</var></samp><dd>Apply <samp><span class="option">--strip-unneeded-symbol</span></samp> option to each symbol listed in 493the file <var>filename</var>. <var>filename</var> is simply a flat file, with one 494symbol name per line. Line comments may be introduced by the hash 495character. This option may be given more than once. 496 497 <br><dt><samp><span class="env">--keep-global-symbols=</span><var>filename</var></samp><dd>Apply <samp><span class="option">--keep-global-symbol</span></samp> option to each symbol listed in the 498file <var>filename</var>. <var>filename</var> is simply a flat file, with one 499symbol name per line. Line comments may be introduced by the hash 500character. This option may be given more than once. 501 502 <br><dt><samp><span class="env">--localize-symbols=</span><var>filename</var></samp><dd>Apply <samp><span class="option">--localize-symbol</span></samp> option to each symbol listed in the file 503<var>filename</var>. <var>filename</var> is simply a flat file, with one symbol 504name per line. Line comments may be introduced by the hash character. 505This option may be given more than once. 506 507 <br><dt><samp><span class="env">--globalize-symbols=</span><var>filename</var></samp><dd>Apply <samp><span class="option">--globalize-symbol</span></samp> option to each symbol listed in the file 508<var>filename</var>. <var>filename</var> is simply a flat file, with one symbol 509name per line. Line comments may be introduced by the hash character. 510This option may be given more than once. 511 512 <br><dt><samp><span class="env">--weaken-symbols=</span><var>filename</var></samp><dd>Apply <samp><span class="option">--weaken-symbol</span></samp> option to each symbol listed in the file 513<var>filename</var>. <var>filename</var> is simply a flat file, with one symbol 514name per line. Line comments may be introduced by the hash character. 515This option may be given more than once. 516 517 <br><dt><samp><span class="env">--alt-machine-code=</span><var>index</var></samp><dd>If the output architecture has alternate machine codes, use the 518<var>index</var>th code instead of the default one. This is useful in case 519a machine is assigned an official code and the tool-chain adopts the 520new code, but other applications still depend on the original code 521being used. For ELF based architectures if the <var>index</var> 522alternative does not exist then the value is treated as an absolute 523number to be stored in the e_machine field of the ELF header. 524 525 <br><dt><samp><span class="env">--writable-text</span></samp><dd>Mark the output text as writable. This option isn't meaningful for all 526object file formats. 527 528 <br><dt><samp><span class="env">--readonly-text</span></samp><dd>Make the output text write protected. This option isn't meaningful for all 529object file formats. 530 531 <br><dt><samp><span class="env">--pure</span></samp><dd>Mark the output file as demand paged. This option isn't meaningful for all 532object file formats. 533 534 <br><dt><samp><span class="env">--impure</span></samp><dd>Mark the output file as impure. This option isn't meaningful for all 535object file formats. 536 537 <br><dt><samp><span class="env">--prefix-symbols=</span><var>string</var></samp><dd>Prefix all symbols in the output file with <var>string</var>. 538 539 <br><dt><samp><span class="env">--prefix-sections=</span><var>string</var></samp><dd>Prefix all section names in the output file with <var>string</var>. 540 541 <br><dt><samp><span class="env">--prefix-alloc-sections=</span><var>string</var></samp><dd>Prefix all the names of all allocated sections in the output file with 542<var>string</var>. 543 544 <br><dt><samp><span class="env">--add-gnu-debuglink=</span><var>path-to-file</var></samp><dd>Creates a .gnu_debuglink section which contains a reference to <var>path-to-file</var> 545and adds it to the output file. 546 547 <br><dt><samp><span class="env">--keep-file-symbols</span></samp><dd>When stripping a file, perhaps with <samp><span class="option">--strip-debug</span></samp> or 548<samp><span class="option">--strip-unneeded</span></samp>, retain any symbols specifying source file names, 549which would otherwise get stripped. 550 551 <br><dt><samp><span class="env">--only-keep-debug</span></samp><dd>Strip a file, removing contents of any sections that would not be 552stripped by <samp><span class="option">--strip-debug</span></samp> and leaving the debugging sections 553intact. In ELF files, this preserves all note sections in the output. 554 555 <p>The intention is that this option will be used in conjunction with 556<samp><span class="option">--add-gnu-debuglink</span></samp> to create a two part executable. One a 557stripped binary which will occupy less space in RAM and in a 558distribution and the second a debugging information file which is only 559needed if debugging abilities are required. The suggested procedure 560to create these files is as follows: 561 562 <ol type=1 start=1> 563<li>Link the executable as normal. Assuming that is is called 564<code>foo</code> then... 565<li>Run <code>objcopy --only-keep-debug foo foo.dbg</code> to 566create a file containing the debugging info. 567<li>Run <code>objcopy --strip-debug foo</code> to create a 568stripped executable. 569<li>Run <code>objcopy --add-gnu-debuglink=foo.dbg foo</code> 570to add a link to the debugging info into the stripped executable. 571 </ol> 572 573 <p>Note—the choice of <code>.dbg</code> as an extension for the debug info 574file is arbitrary. Also the <code>--only-keep-debug</code> step is 575optional. You could instead do this: 576 577 <ol type=1 start=1> 578<li>Link the executable as normal. 579<li>Copy <code>foo</code> to <code>foo.full</code> 580<li>Run <code>objcopy --strip-debug foo</code> 581<li>Run <code>objcopy --add-gnu-debuglink=foo.full foo</code> 582 </ol> 583 584 <p>i.e., the file pointed to by the <samp><span class="option">--add-gnu-debuglink</span></samp> can be the 585full executable. It does not have to be a file created by the 586<samp><span class="option">--only-keep-debug</span></samp> switch. 587 588 <p>Note—this switch is only intended for use on fully linked files. It 589does not make sense to use it on object files where the debugging 590information may be incomplete. Besides the gnu_debuglink feature 591currently only supports the presence of one filename containing 592debugging information, not multiple filenames on a one-per-object-file 593basis. 594 595 <br><dt><samp><span class="env">--strip-dwo</span></samp><dd>Remove the contents of all DWARF .dwo sections, leaving the 596remaining debugging sections and all symbols intact. 597This option is intended for use by the compiler as part of 598the <samp><span class="option">-gsplit-dwarf</span></samp> option, which splits debug information 599between the .o file and a separate .dwo file. The compiler 600generates all debug information in the same file, then uses 601the <samp><span class="option">--extract-dwo</span></samp> option to copy the .dwo sections to 602the .dwo file, then the <samp><span class="option">--strip-dwo</span></samp> option to remove 603those sections from the original .o file. 604 605 <br><dt><samp><span class="env">--extract-dwo</span></samp><dd>Extract the contents of all DWARF .dwo sections. See the 606<samp><span class="option">--strip-dwo</span></samp> option for more information. 607 608 <br><dt><samp><span class="env">--file-alignment </span><var>num</var></samp><dd>Specify the file alignment. Sections in the file will always begin at 609file offsets which are multiples of this number. This defaults to 610512. 611[This option is specific to PE targets.] 612 613 <br><dt><samp><span class="env">--heap </span><var>reserve</var></samp><dt><samp><span class="env">--heap </span><var>reserve</var><span class="env">,</span><var>commit</var></samp><dd>Specify the number of bytes of memory to reserve (and optionally commit) 614to be used as heap for this program. 615[This option is specific to PE targets.] 616 617 <br><dt><samp><span class="env">--image-base </span><var>value</var></samp><dd>Use <var>value</var> as the base address of your program or dll. This is 618the lowest memory location that will be used when your program or dll 619is loaded. To reduce the need to relocate and improve performance of 620your dlls, each should have a unique base address and not overlap any 621other dlls. The default is 0x400000 for executables, and 0x10000000 622for dlls. 623[This option is specific to PE targets.] 624 625 <br><dt><samp><span class="env">--section-alignment </span><var>num</var></samp><dd>Sets the section alignment. Sections in memory will always begin at 626addresses which are a multiple of this number. Defaults to 0x1000. 627[This option is specific to PE targets.] 628 629 <br><dt><samp><span class="env">--stack </span><var>reserve</var></samp><dt><samp><span class="env">--stack </span><var>reserve</var><span class="env">,</span><var>commit</var></samp><dd>Specify the number of bytes of memory to reserve (and optionally commit) 630to be used as stack for this program. 631[This option is specific to PE targets.] 632 633 <br><dt><samp><span class="env">--subsystem </span><var>which</var></samp><dt><samp><span class="env">--subsystem </span><var>which</var><span class="env">:</span><var>major</var></samp><dt><samp><span class="env">--subsystem </span><var>which</var><span class="env">:</span><var>major</var><span class="env">.</span><var>minor</var></samp><dd>Specifies the subsystem under which your program will execute. The 634legal values for <var>which</var> are <code>native</code>, <code>windows</code>, 635<code>console</code>, <code>posix</code>, <code>efi-app</code>, <code>efi-bsd</code>, 636<code>efi-rtd</code>, <code>sal-rtd</code>, and <code>xbox</code>. You may optionally set 637the subsystem version also. Numeric values are also accepted for 638<var>which</var>. 639[This option is specific to PE targets.] 640 641 <br><dt><samp><span class="env">--extract-symbol</span></samp><dd>Keep the file's section flags and symbols but remove all section data. 642Specifically, the option: 643 644 <ul> 645<li>removes the contents of all sections; 646<li>sets the size of every section to zero; and 647<li>sets the file's start address to zero. 648</ul> 649 650 <p>This option is used to build a <samp><span class="file">.sym</span></samp> file for a VxWorks kernel. 651It can also be a useful way of reducing the size of a <samp><span class="option">--just-symbols</span></samp> 652linker input file. 653 654 <br><dt><samp><span class="env">--compress-debug-sections</span></samp><dd>Compress DWARF debug sections using zlib. 655 656 <br><dt><samp><span class="env">--decompress-debug-sections</span></samp><dd>Decompress DWARF debug sections using zlib. 657 658 <br><dt><samp><span class="env">-V</span></samp><dt><samp><span class="env">--version</span></samp><dd>Show the version number of <samp><span class="command">objcopy</span></samp>. 659 660 <br><dt><samp><span class="env">-v</span></samp><dt><samp><span class="env">--verbose</span></samp><dd>Verbose output: list all object files modified. In the case of 661archives, ‘<samp><span class="samp">objcopy -V</span></samp>’ lists all members of the archive. 662 663 <br><dt><samp><span class="env">--help</span></samp><dd>Show a summary of the options to <samp><span class="command">objcopy</span></samp>. 664 665 <br><dt><samp><span class="env">--info</span></samp><dd>Display a list showing all architectures and object formats available. 666</dl> 667 668<!-- man end --> 669 </body></html> 670 671