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