strip.html 16 KB

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