Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

387 lines
16KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1991-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3
  6. or any later version published by the Free Software Foundation;
  7. with no Invariant Sections, with no Front-Cover Texts, and with no
  8. Back-Cover Texts. A copy of the license is included in the
  9. section entitled "GNU Free Documentation License".
  10. -->
  11. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  12. <head>
  13. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  14. <title>strip (GNU Binary Utilities)</title>
  15. <meta name="description" content="strip (GNU Binary Utilities)">
  16. <meta name="keywords" content="strip (GNU Binary Utilities)">
  17. <meta name="resource-type" content="document">
  18. <meta name="distribution" content="global">
  19. <meta name="Generator" content="makeinfo">
  20. <link href="index.html#Top" rel="start" title="Top">
  21. <link href="Binutils-Index.html#Binutils-Index" rel="index" title="Binutils Index">
  22. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  23. <link href="index.html#Top" rel="up" title="Top">
  24. <link href="c_002b_002bfilt.html#c_002b_002bfilt" rel="next" title="c++filt">
  25. <link href="strings.html#strings" rel="prev" title="strings">
  26. <style type="text/css">
  27. <!--
  28. a.summary-letter {text-decoration: none}
  29. blockquote.indentedblock {margin-right: 0em}
  30. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  31. blockquote.smallquotation {font-size: smaller}
  32. div.display {margin-left: 3.2em}
  33. div.example {margin-left: 3.2em}
  34. div.lisp {margin-left: 3.2em}
  35. div.smalldisplay {margin-left: 3.2em}
  36. div.smallexample {margin-left: 3.2em}
  37. div.smalllisp {margin-left: 3.2em}
  38. kbd {font-style: oblique}
  39. pre.display {font-family: inherit}
  40. pre.format {font-family: inherit}
  41. pre.menu-comment {font-family: serif}
  42. pre.menu-preformatted {font-family: serif}
  43. pre.smalldisplay {font-family: inherit; font-size: smaller}
  44. pre.smallexample {font-size: smaller}
  45. pre.smallformat {font-family: inherit; font-size: smaller}
  46. pre.smalllisp {font-size: smaller}
  47. span.nolinebreak {white-space: nowrap}
  48. span.roman {font-family: initial; font-weight: normal}
  49. span.sansserif {font-family: sans-serif; font-weight: normal}
  50. ul.no-bullet {list-style: none}
  51. -->
  52. </style>
  53. </head>
  54. <body lang="en">
  55. <a name="strip"></a>
  56. <div class="header">
  57. <p>
  58. Next: <a href="c_002b_002bfilt.html#c_002b_002bfilt" accesskey="n" rel="next">c++filt</a>, Previous: <a href="strings.html#strings" accesskey="p" rel="prev">strings</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Binutils-Index.html#Binutils-Index" title="Index" rel="index">Index</a>]</p>
  59. </div>
  60. <hr>
  61. <a name="strip-1"></a>
  62. <h2 class="chapter">8 strip</h2>
  63. <a name="index-strip"></a>
  64. <a name="index-removing-symbols"></a>
  65. <a name="index-discarding-symbols"></a>
  66. <a name="index-symbols_002c-discarding"></a>
  67. <div class="smallexample">
  68. <pre class="smallexample">strip [<samp>-F</samp> <var>bfdname</var> |<samp>--target=</samp><var>bfdname</var>]
  69. [<samp>-I</samp> <var>bfdname</var> |<samp>--input-target=</samp><var>bfdname</var>]
  70. [<samp>-O</samp> <var>bfdname</var> |<samp>--output-target=</samp><var>bfdname</var>]
  71. [<samp>-s</samp>|<samp>--strip-all</samp>]
  72. [<samp>-S</samp>|<samp>-g</samp>|<samp>-d</samp>|<samp>--strip-debug</samp>]
  73. [<samp>--strip-dwo</samp>]
  74. [<samp>-K</samp> <var>symbolname</var>|<samp>--keep-symbol=</samp><var>symbolname</var>]
  75. [<samp>-M</samp>|<samp>--merge-notes</samp>][<samp>--no-merge-notes</samp>]
  76. [<samp>-N</samp> <var>symbolname</var> |<samp>--strip-symbol=</samp><var>symbolname</var>]
  77. [<samp>-w</samp>|<samp>--wildcard</samp>]
  78. [<samp>-x</samp>|<samp>--discard-all</samp>] [<samp>-X</samp> |<samp>--discard-locals</samp>]
  79. [<samp>-R</samp> <var>sectionname</var> |<samp>--remove-section=</samp><var>sectionname</var>]
  80. [<samp>--keep-section=</samp><var>sectionpattern</var>]
  81. [<samp>--remove-relocations=</samp><var>sectionpattern</var>]
  82. [<samp>-o</samp> <var>file</var>] [<samp>-p</samp>|<samp>--preserve-dates</samp>]
  83. [<samp>-D</samp>|<samp>--enable-deterministic-archives</samp>]
  84. [<samp>-U</samp>|<samp>--disable-deterministic-archives</samp>]
  85. [<samp>--keep-file-symbols</samp>]
  86. [<samp>--only-keep-debug</samp>]
  87. [<samp>-v</samp> |<samp>--verbose</samp>] [<samp>-V</samp>|<samp>--version</samp>]
  88. [<samp>--help</samp>] [<samp>--info</samp>]
  89. <var>objfile</var>&hellip;
  90. </pre></div>
  91. <p><small>GNU</small> <code>strip</code> discards all symbols from object files
  92. <var>objfile</var>. The list of object files may include archives.
  93. At least one object file must be given.
  94. </p>
  95. <p><code>strip</code> modifies the files named in its argument,
  96. rather than writing modified copies under different names.
  97. </p>
  98. <dl compact="compact">
  99. <dt><code>-F <var>bfdname</var></code></dt>
  100. <dt><code>--target=<var>bfdname</var></code></dt>
  101. <dd><p>Treat the original <var>objfile</var> as a file with the object
  102. code format <var>bfdname</var>, and rewrite it in the same format.
  103. See <a href="Target-Selection.html#Target-Selection">Target Selection</a>, for more information.
  104. </p>
  105. </dd>
  106. <dt><code>--help</code></dt>
  107. <dd><p>Show a summary of the options to <code>strip</code> and exit.
  108. </p>
  109. </dd>
  110. <dt><code>--info</code></dt>
  111. <dd><p>Display a list showing all architectures and object formats available.
  112. </p>
  113. </dd>
  114. <dt><code>-I <var>bfdname</var></code></dt>
  115. <dt><code>--input-target=<var>bfdname</var></code></dt>
  116. <dd><p>Treat the original <var>objfile</var> as a file with the object
  117. code format <var>bfdname</var>.
  118. See <a href="Target-Selection.html#Target-Selection">Target Selection</a>, for more information.
  119. </p>
  120. </dd>
  121. <dt><code>-O <var>bfdname</var></code></dt>
  122. <dt><code>--output-target=<var>bfdname</var></code></dt>
  123. <dd><p>Replace <var>objfile</var> with a file in the output format <var>bfdname</var>.
  124. See <a href="Target-Selection.html#Target-Selection">Target Selection</a>, for more information.
  125. </p>
  126. </dd>
  127. <dt><code>-R <var>sectionname</var></code></dt>
  128. <dt><code>--remove-section=<var>sectionname</var></code></dt>
  129. <dd><p>Remove any section named <var>sectionname</var> from the output file, in
  130. addition to whatever sections would otherwise be removed. This
  131. option may be given more than once. Note that using this option
  132. inappropriately may make the output file unusable. The wildcard
  133. character &lsquo;<samp>*</samp>&rsquo; may be given at the end of <var>sectionname</var>. If
  134. so, then any section starting with <var>sectionname</var> will be removed.
  135. </p>
  136. <p>If the first character of <var>sectionpattern</var> is the exclamation
  137. point (!) then matching sections will not be removed even if an
  138. earlier use of <samp>--remove-section</samp> on the same command line
  139. would otherwise remove it. For example:
  140. </p>
  141. <div class="smallexample">
  142. <pre class="smallexample"> --remove-section=.text.* --remove-section=!.text.foo
  143. </pre></div>
  144. <p>will remove all sections matching the pattern &rsquo;.text.*&rsquo;, but will not
  145. remove the section &rsquo;.text.foo&rsquo;.
  146. </p>
  147. </dd>
  148. <dt><code>--keep-section=<var>sectionpattern</var></code></dt>
  149. <dd><p>When removing sections from the output file, keep sections that match
  150. <var>sectionpattern</var>.
  151. </p>
  152. </dd>
  153. <dt><code>--remove-relocations=<var>sectionpattern</var></code></dt>
  154. <dd><p>Remove relocations from the output file for any section matching
  155. <var>sectionpattern</var>. This option may be given more than once. Note
  156. that using this option inappropriately may make the output file
  157. unusable. Wildcard characters are accepted in <var>sectionpattern</var>.
  158. For example:
  159. </p>
  160. <div class="smallexample">
  161. <pre class="smallexample"> --remove-relocations=.text.*
  162. </pre></div>
  163. <p>will remove the relocations for all sections matching the patter
  164. &rsquo;.text.*&rsquo;.
  165. </p>
  166. <p>If the first character of <var>sectionpattern</var> is the exclamation
  167. point (!) then matching sections will not have their relocation
  168. removed even if an earlier use of <samp>--remove-relocations</samp> on the
  169. same command line would otherwise cause the relocations to be removed.
  170. For example:
  171. </p>
  172. <div class="smallexample">
  173. <pre class="smallexample"> --remove-relocations=.text.* --remove-relocations=!.text.foo
  174. </pre></div>
  175. <p>will remove all relocations for sections matching the pattern
  176. &rsquo;.text.*&rsquo;, but will not remove relocations for the section
  177. &rsquo;.text.foo&rsquo;.
  178. </p>
  179. </dd>
  180. <dt><code>-s</code></dt>
  181. <dt><code>--strip-all</code></dt>
  182. <dd><p>Remove all symbols.
  183. </p>
  184. </dd>
  185. <dt><code>-g</code></dt>
  186. <dt><code>-S</code></dt>
  187. <dt><code>-d</code></dt>
  188. <dt><code>--strip-debug</code></dt>
  189. <dd><p>Remove debugging symbols only.
  190. </p>
  191. </dd>
  192. <dt><code>--strip-dwo</code></dt>
  193. <dd><p>Remove the contents of all DWARF .dwo sections, leaving the
  194. remaining debugging sections and all symbols intact.
  195. See the description of this option in the <code>objcopy</code> section
  196. for more information.
  197. </p>
  198. </dd>
  199. <dt><code>--strip-unneeded</code></dt>
  200. <dd><p>Remove all symbols that are not needed for relocation processing.
  201. </p>
  202. </dd>
  203. <dt><code>-K <var>symbolname</var></code></dt>
  204. <dt><code>--keep-symbol=<var>symbolname</var></code></dt>
  205. <dd><p>When stripping symbols, keep symbol <var>symbolname</var> even if it would
  206. normally be stripped. This option may be given more than once.
  207. </p>
  208. </dd>
  209. <dt><code>-M</code></dt>
  210. <dt><code>--merge-notes</code></dt>
  211. <dt><code>--no-merge-notes</code></dt>
  212. <dd><p>For ELF files, attempt (or do not attempt) to reduce the size of any
  213. SHT_NOTE type sections by removing duplicate notes. The default is to
  214. attempt this reduction unless stripping debug or DWO information.
  215. </p>
  216. </dd>
  217. <dt><code>-N <var>symbolname</var></code></dt>
  218. <dt><code>--strip-symbol=<var>symbolname</var></code></dt>
  219. <dd><p>Remove symbol <var>symbolname</var> from the source file. This option may be
  220. given more than once, and may be combined with strip options other than
  221. <samp>-K</samp>.
  222. </p>
  223. </dd>
  224. <dt><code>-o <var>file</var></code></dt>
  225. <dd><p>Put the stripped output in <var>file</var>, rather than replacing the
  226. existing file. When this argument is used, only one <var>objfile</var>
  227. argument may be specified.
  228. </p>
  229. </dd>
  230. <dt><code>-p</code></dt>
  231. <dt><code>--preserve-dates</code></dt>
  232. <dd><p>Preserve the access and modification dates of the file.
  233. </p>
  234. </dd>
  235. <dt><code>-D</code></dt>
  236. <dt><code>--enable-deterministic-archives</code></dt>
  237. <dd><a name="index-deterministic-archives-6"></a>
  238. <a name="index-_002d_002denable_002ddeterministic_002darchives-6"></a>
  239. <p>Operate in <em>deterministic</em> mode. When copying archive members
  240. and writing the archive index, use zero for UIDs, GIDs, timestamps,
  241. and use consistent file modes for all files.
  242. </p>
  243. <p>If <samp>binutils</samp> was configured with
  244. <samp>--enable-deterministic-archives</samp>, then this mode is on by default.
  245. It can be disabled with the &lsquo;<samp>-U</samp>&rsquo; option, below.
  246. </p>
  247. </dd>
  248. <dt><code>-U</code></dt>
  249. <dt><code>--disable-deterministic-archives</code></dt>
  250. <dd><a name="index-deterministic-archives-7"></a>
  251. <a name="index-_002d_002denable_002ddeterministic_002darchives-7"></a>
  252. <p>Do <em>not</em> operate in <em>deterministic</em> mode. This is the
  253. inverse of the <samp>-D</samp> option, above: when copying archive members
  254. and writing the archive index, use their actual UID, GID, timestamp,
  255. and file mode values.
  256. </p>
  257. <p>This is the default unless <samp>binutils</samp> was configured with
  258. <samp>--enable-deterministic-archives</samp>.
  259. </p>
  260. </dd>
  261. <dt><code>-w</code></dt>
  262. <dt><code>--wildcard</code></dt>
  263. <dd><p>Permit regular expressions in <var>symbolname</var>s used in other command
  264. line options. The question mark (?), asterisk (*), backslash (\) and
  265. square brackets ([]) operators can be used anywhere in the symbol
  266. name. If the first character of the symbol name is the exclamation
  267. point (!) then the sense of the switch is reversed for that symbol.
  268. For example:
  269. </p>
  270. <div class="smallexample">
  271. <pre class="smallexample"> -w -K !foo -K fo*
  272. </pre></div>
  273. <p>would cause strip to only keep symbols that start with the letters
  274. &ldquo;fo&rdquo;, but to discard the symbol &ldquo;foo&rdquo;.
  275. </p>
  276. </dd>
  277. <dt><code>-x</code></dt>
  278. <dt><code>--discard-all</code></dt>
  279. <dd><p>Remove non-global symbols.
  280. </p>
  281. </dd>
  282. <dt><code>-X</code></dt>
  283. <dt><code>--discard-locals</code></dt>
  284. <dd><p>Remove compiler-generated local symbols.
  285. (These usually start with &lsquo;<samp>L</samp>&rsquo; or &lsquo;<samp>.</samp>&rsquo;.)
  286. </p>
  287. </dd>
  288. <dt><code>--keep-file-symbols</code></dt>
  289. <dd><p>When stripping a file, perhaps with <samp>--strip-debug</samp> or
  290. <samp>--strip-unneeded</samp>, retain any symbols specifying source file names,
  291. which would otherwise get stripped.
  292. </p>
  293. </dd>
  294. <dt><code>--only-keep-debug</code></dt>
  295. <dd><p>Strip a file, emptying the contents of any sections that would not be
  296. stripped by <samp>--strip-debug</samp> and leaving the debugging sections
  297. intact. In ELF files, this preserves all the note sections in the
  298. output as well.
  299. </p>
  300. <p>Note - the section headers of the stripped sections are preserved,
  301. including their sizes, but the contents of the section are discarded.
  302. The section headers are preserved so that other tools can match up the
  303. debuginfo file with the real executable, even if that executable has
  304. been relocated to a different address space.
  305. </p>
  306. <p>The intention is that this option will be used in conjunction with
  307. <samp>--add-gnu-debuglink</samp> to create a two part executable. One a
  308. stripped binary which will occupy less space in RAM and in a
  309. distribution and the second a debugging information file which is only
  310. needed if debugging abilities are required. The suggested procedure
  311. to create these files is as follows:
  312. </p>
  313. <ol>
  314. <li> Link the executable as normal. Assuming that it is called
  315. <code>foo</code> then...
  316. </li><li> Run <code>objcopy --only-keep-debug foo foo.dbg</code> to
  317. create a file containing the debugging info.
  318. </li><li> Run <code>objcopy --strip-debug foo</code> to create a
  319. stripped executable.
  320. </li><li> Run <code>objcopy --add-gnu-debuglink=foo.dbg foo</code>
  321. to add a link to the debugging info into the stripped executable.
  322. </li></ol>
  323. <p>Note&mdash;the choice of <code>.dbg</code> as an extension for the debug info
  324. file is arbitrary. Also the <code>--only-keep-debug</code> step is
  325. optional. You could instead do this:
  326. </p>
  327. <ol>
  328. <li> Link the executable as normal.
  329. </li><li> Copy <code>foo</code> to <code>foo.full</code>
  330. </li><li> Run <code>strip --strip-debug foo</code>
  331. </li><li> Run <code>objcopy --add-gnu-debuglink=foo.full foo</code>
  332. </li></ol>
  333. <p>i.e., the file pointed to by the <samp>--add-gnu-debuglink</samp> can be the
  334. full executable. It does not have to be a file created by the
  335. <samp>--only-keep-debug</samp> switch.
  336. </p>
  337. <p>Note&mdash;this switch is only intended for use on fully linked files. It
  338. does not make sense to use it on object files where the debugging
  339. information may be incomplete. Besides the gnu_debuglink feature
  340. currently only supports the presence of one filename containing
  341. debugging information, not multiple filenames on a one-per-object-file
  342. basis.
  343. </p>
  344. </dd>
  345. <dt><code>-V</code></dt>
  346. <dt><code>--version</code></dt>
  347. <dd><p>Show the version number for <code>strip</code>.
  348. </p>
  349. </dd>
  350. <dt><code>-v</code></dt>
  351. <dt><code>--verbose</code></dt>
  352. <dd><p>Verbose output: list all object files modified. In the case of
  353. archives, &lsquo;<samp>strip -v</samp>&rsquo; lists all members of the archive.
  354. </p></dd>
  355. </dl>
  356. <hr>
  357. <div class="header">
  358. <p>
  359. Next: <a href="c_002b_002bfilt.html#c_002b_002bfilt" accesskey="n" rel="next">c++filt</a>, Previous: <a href="strings.html#strings" accesskey="p" rel="prev">strings</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Binutils-Index.html#Binutils-Index" title="Index" rel="index">Index</a>]</p>
  360. </div>
  361. </body>
  362. </html>