⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 objcopy.html

📁 gcc手册
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<html lang="en">

<head>

<title>GNU Binary Utilities</title>

<meta http-equiv="Content-Type" content="text/html">

<meta name="description" content="GNU Binary Utilities">

<meta name="generator" content="makeinfo 4.3">

<link href="http://www.gnu.org/software/texinfo/" rel="generator-home">

</head>

<body>

<div class="node">

<p>

Node:<a name="objcopy">objcopy</a>,

Next:<a rel="next" accesskey="n" href="objdump.html#objdump">objdump</a>,

Previous:<a rel="previous" accesskey="p" href="nm.html#nm">nm</a>,

Up:<a rel="up" accesskey="u" href="index.html#Top">Top</a>

<hr><br>

</div>



<h2 class="chapter">objcopy</h2>



<pre class="smallexample">     objcopy [<code>-F</code> <var>bfdname</var>|<code>--target=</code><var>bfdname</var>]

             [<code>-I</code> <var>bfdname</var>|<code>--input-target=</code><var>bfdname</var>]

             [<code>-O</code> <var>bfdname</var>|<code>--output-target=</code><var>bfdname</var>]

             [<code>-B</code> <var>bfdarch</var>|<code>--binary-architecture=</code><var>bfdarch</var>]

             [<code>-S</code>|<code>--strip-all</code>] [<code>-g</code>|<code>--strip-debug</code>]

             [<code>-K</code> <var>symbolname</var>|<code>--keep-symbol=</code><var>symbolname</var>]

             [<code>-N</code> <var>symbolname</var>|<code>--strip-symbol=</code><var>symbolname</var>]

             [<code>-G</code> <var>symbolname</var>|<code>--keep-global-symbol=</code><var>symbolname</var>]

             [<code>-L</code> <var>symbolname</var>|<code>--localize-symbol=</code><var>symbolname</var>]

             [<code>-W</code> <var>symbolname</var>|<code>--weaken-symbol=</code><var>symbolname</var>]

             [<code>-x</code>|<code>--discard-all</code>] [<code>-X</code>|<code>--discard-locals</code>]

             [<code>-b</code> <var>byte</var>|<code>--byte=</code><var>byte</var>]

             [<code>-i</code> <var>interleave</var>|<code>--interleave=</code><var>interleave</var>]

             [<code>-j</code> <var>sectionname</var>|<code>--only-section=</code><var>sectionname</var>]

             [<code>-R</code> <var>sectionname</var>|<code>--remove-section=</code><var>sectionname</var>]

             [<code>-p</code>|<code>--preserve-dates</code>]

             [<code>--debugging</code>]

             [<code>--gap-fill=</code><var>val</var>] [<code>--pad-to=</code><var>address</var>]

             [<code>--set-start=</code><var>val</var>] [<code>--adjust-start=</code><var>incr</var>]

             [<code>--change-addresses=</code><var>incr</var>]

             [<code>--change-section-address</code> <var>section</var>{=,+,-}<var>val</var>]

             [<code>--change-section-lma</code> <var>section</var>{=,+,-}<var>val</var>]

             [<code>--change-section-vma</code> <var>section</var>{=,+,-}<var>val</var>]

             [<code>--change-warnings</code>] [<code>--no-change-warnings</code>]

             [<code>--set-section-flags</code> <var>section</var>=<var>flags</var>]

             [<code>--add-section</code> <var>sectionname</var>=<var>filename</var>]

             [<code>--rename-section</code> <var>oldname</var>=<var>newname</var>[,<var>flags</var>]]

             [<code>--change-leading-char</code> ] [<code>--remove-leading-char</code>]

             [<code>--srec-len=</code><var>ival</var> ] [<code>--srec-forceS3</code>]

             [<code>--redefine-sym</code> <var>old</var>=<var>new</var> ]

             [<code>--weaken</code>]

             [<code>--keep-symbols=</code><var>filename</var>]

             [<code>--strip-symbols=</code><var>filename</var>]

             [<code>--keep-global-symbols=</code><var>filename</var>]

             [<code>--localize-symbols=</code><var>filename</var>]

             [<code>--weaken-symbols=</code><var>filename</var>]

             [<code>--alt-machine-code=</code><var>index</var><code></code>]

             [<code>-v</code>|<code>--verbose</code>]

             [<code>-V</code>|<code>--version</code>]

             [<code>--help</code>]

             <var>infile</var> [<var>outfile</var>]

     </pre>



   <p>The <small>GNU</small> <code>objcopy</code> utility copies the contents of an object

file to another.  <code>objcopy</code> uses the <small>GNU</small> <small>BFD</small> Library to

read and write the object files.  It can write the destination object

file in a format different from that of the source object file.  The

exact behavior of <code>objcopy</code> is controlled by command-line options. 

Note that <code>objcopy</code> should be able to copy a fully linked file

between any two formats. However, copying a relocatable object file

between any two formats may not work as expected.



   <p><code>objcopy</code> creates temporary files to do its translations and

deletes them afterward.  <code>objcopy</code> uses <small>BFD</small> to do all its

translation work; it has access to all the formats described in <small>BFD</small>

and thus is able to recognize most formats without being told

explicitly.  See <a href="../ld.info/BFD.html#BFD">BFD</a>.



   <p><code>objcopy</code> can be used to generate S-records by using an output

target of <code>srec</code> (e.g., use <code>-O srec</code>).



   <p><code>objcopy</code> can be used to generate a raw binary file by using an

output target of <code>binary</code> (e.g., use <code>-O binary</code>).  When

<code>objcopy</code> generates a raw binary file, it will essentially produce

a memory dump of the contents of the input object file.  All symbols and

relocation information will be discarded.  The memory dump will start at

the load address of the lowest section copied into the output file.



   <p>When generating an S-record or a raw binary file, it may be helpful to

use <code>-S</code> to remove sections containing debugging information.  In

some cases <code>-R</code> will be useful to remove sections which contain

information that is not needed by the binary file.



   <p>Note - <code>objcopy</code> is not able to change the endianness of its input

files.  If the input format has an endianness, (some formats do not),

<code>objcopy</code> can only copy the inputs into file formats that have the

same endianness or which have no endianness (eg <code>srec</code>).



     <dl>

<dt><code></code><var>infile</var><code></code>

     <dd><dt><code></code><var>outfile</var><code></code>

     <dd>The input and output files, respectively. 

If you do not specify <var>outfile</var>, <code>objcopy</code> creates a

temporary file and destructively renames the result with

the name of <var>infile</var>.



     <br><dt><code>-I </code><var>bfdname</var><code></code>

     <dd><dt><code>--input-target=</code><var>bfdname</var><code></code>

     <dd>Consider the source file's object format to be <var>bfdname</var>, rather than

attempting to deduce it.  See <a href="Target-Selection.html#Target%20Selection">Target Selection</a>, for more information.



     <br><dt><code>-O </code><var>bfdname</var><code></code>

     <dd><dt><code>--output-target=</code><var>bfdname</var><code></code>

     <dd>Write the output file using the object format <var>bfdname</var>. 

See <a href="Target-Selection.html#Target%20Selection">Target Selection</a>, for more information.



     <br><dt><code>-F </code><var>bfdname</var><code></code>

     <dd><dt><code>--target=</code><var>bfdname</var><code></code>

     <dd>Use <var>bfdname</var> as the object format for both the input and the output

file; i.e., simply transfer data from source to destination with no

translation.  See <a href="Target-Selection.html#Target%20Selection">Target Selection</a>, for more information.



     <br><dt><code>-B </code><var>bfdarch</var><code></code>

     <dd><dt><code>--binary-architecture=</code><var>bfdarch</var><code></code>

     <dd>Useful when transforming a raw binary input file into an object file. 

In this case the output architecture can be set to <var>bfdarch</var>. This

option will be ignored if the input file has a known <var>bfdarch</var>. You

can access this binary data inside a program by referencing the special

symbols that are created by the conversion process.  These symbols are

called _binary_<var>objfile</var>_start, _binary_<var>objfile</var>_end and

_binary_<var>objfile</var>_size.  e.g. you can transform a picture file into

an object file and then access it in your code using these symbols.



     <br><dt><code>-j </code><var>sectionname</var><code></code>

     <dd><dt><code>--only-section=</code><var>sectionname</var><code></code>

     <dd>Copy only the named section from the input file to the output file. 

This option may be given more than once.  Note that using this option

inappropriately may make the output file unusable.



     <br><dt><code>-R </code><var>sectionname</var><code></code>

     <dd><dt><code>--remove-section=</code><var>sectionname</var><code></code>

     <dd>Remove any section named <var>sectionname</var> from the output file.  This

option may be given more than once.  Note that using this option

inappropriately may make the output file unusable.



     <br><dt><code>-S</code>

     <dd><dt><code>--strip-all</code>

     <dd>Do not copy relocation and symbol information from the source file.



     <br><dt><code>-g</code>

     <dd><dt><code>--strip-debug</code>

     <dd>Do not copy debugging symbols from the source file.



     <br><dt><code>--strip-unneeded</code>

     <dd>Strip all symbols that are not needed for relocation processing.



     <br><dt><code>-K </code><var>symbolname</var><code></code>

     <dd><dt><code>--keep-symbol=</code><var>symbolname</var><code></code>

     <dd>Copy only symbol <var>symbolname</var> from the source file.  This option may

be given more than once.



     <br><dt><code>-N </code><var>symbolname</var><code></code>

     <dd><dt><code>--strip-symbol=</code><var>symbolname</var><code></code>

     <dd>Do not copy symbol <var>symbolname</var> from the source file.  This option

may be given more than once.



     <br><dt><code>-G </code><var>symbolname</var><code></code>

     <dd><dt><code>--keep-global-symbol=</code><var>symbolname</var><code></code>

     <dd>Keep only symbol <var>symbolname</var> global.  Make all other symbols local

to the file, so that they are not visible externally.  This option may

be given more than once.



     <br><dt><code>-L </code><var>symbolname</var><code></code>

     <dd><dt><code>--localize-symbol=</code><var>symbolname</var><code></code>

     <dd>Make symbol <var>symbolname</var> local to the file, so that it is not

visible externally.  This option may be given more than once.



     <br><dt><code>-W </code><var>symbolname</var><code></code>

     <dd><dt><code>--weaken-symbol=</code><var>symbolname</var><code></code>

     <dd>Make symbol <var>symbolname</var> weak. This option may be given more than once.



     <br><dt><code>-x</code>

     <dd><dt><code>--discard-all</code>

     <dd>Do not copy non-global symbols from the source file.



     <br><dt><code>-X</code>

     <dd><dt><code>--discard-locals</code>

     <dd>Do not copy compiler-generated local symbols. 

(These usually start with <code>L</code> or <code>.</code>.)



     <br><dt><code>-b </code><var>byte</var><code></code>

     <dd><dt><code>--byte=</code><var>byte</var><code></code>

     <dd>Keep only every <var>byte</var>th byte of the input file (header data is not

affected).  <var>byte</var> can be in the range from 0 to <var>interleave</var>-1,

where <var>interleave</var> is given by the <code>-i</code> or <code>--interleave</code>

option, or the default of 4.  This option is useful for creating files

to program <small>ROM</small>.  It is typically used with an <code>srec</code> output

target.



     <br><dt><code>-i </code><var>interleave</var><code></code>

     <dd><dt><code>--interleave=</code><var>interleave</var><code></code>

     <dd>Only copy one out of every <var>interleave</var> bytes.  Select which byte to

copy with the <code>-b</code> or <code>--byte</code> option.  The default is 4. 

<code>objcopy</code> ignores this option if you do not specify either <code>-b</code> or

<code>--byte</code>.



     <br><dt><code>-p</code>

     <dd><dt><code>--preserve-dates</code>

     <dd>Set the access and modification dates of the output file to be the same

as those of the input file.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -