<p>Linux/Gcc/LD - Toolchain.</p>

<p>I would like to remove STL/Boost debug symbols from libraries and executable, for two reasons:</p>

<ol>
<li>Linking gets very slow for big programs</li>
<li>Debugging jumps into stl/boost code, which is annoying</li>
</ol>

<p>For 1. incremental linking would be a big improvement, but AFAIK ld does not support incremental linking. There is a workaround "pseudo incremental linking" in an 1999 dr.dobb's journal (not in the web any more, but at <a href="http://web.archive.org/web/20000131063231/www.ddj.com/articles/1999/9910/9910d/9910d.htm" rel="nofollow noreferrer">archive.org</a> (the idea is to put everything in a dynamic library and all updated object files in an second one that is loaded first) but this is not really a general solution.</p>

<p>For 2. there is a script <a href="http://ubuntuforums.org/showthread.php?p=4368377" rel="nofollow noreferrer">here</a>, but a) it did not work for me (it did not remove symbols), b) it is very slow as it works at the end of the pipe, while it would be more efficient to remove the symbols earlier.</p>

<p>Obviously, the other debug symbols should stay in place.</p>

[{'answer_id': 73570, 'author': 'hatcat', 'author_id': 11483, 'author_profile': 'https://Stackoverflow.com/users/11483', 'pm_score': -1, 'selected': False, 'text': '<p>Which compiler are you using?  For example, if I understand your question correctly, this is a trivial matter in MS Visual Studio.</p>\n'}, {'answer_id': 74075, 'author': 'Kris Kumler', 'author_id': 4281, 'author_profile': 'https://Stackoverflow.com/users/4281', 'pm_score': 1, 'selected': False, 'text': '<p>You probably don\'t want to strip the debug symbols from the shared libraries, as you may need that at some point.</p>\n\n<p>If you are using GDB or DDD to debug, you may be able to get away with removing the Boost source files from the Source Path so it can\'t trace into the functions. (Or just don\'t trace into them, trace over!)</p>\n\n<p>You can remove the option to compile the program with debug symbols, which will speed the link time.</p>\n\n<p>Like the script you link to, you can consult the strip program ("man strip") to remove all or certain symbols.</p>\n'}, {'answer_id': 74103, 'author': 'Leon Timmermans', 'author_id': 4727, 'author_profile': 'https://Stackoverflow.com/users/4727', 'pm_score': 1, 'selected': False, 'text': "<p>You may want to use strip.\nstrip --strip-unneeded --strip-debug libfoo.so</p>\n\n<p>Why don't you just build without debugging in the first place though?</p>\n"}, {'answer_id': 75676, 'author': 'Pieter', 'author_id': 5822, 'author_profile': 'https://Stackoverflow.com/users/5822', 'pm_score': 2, 'selected': False, 'text': "<p>As far as I know there's no real option to do what you want in gcc. The main problem being that all the code you want to strip debug symbols for is defined in headers.</p>\n\n<p>Otherwhise it would be possible to build a library separatly, strip that, and link with the stripped version.</p>\n\n<p>But only getting debug symbols from certain parts of a compilation unit, while building and linking (for your desired link time speedup) is not possible in gcc as far as I know.</p>\n"}, {'answer_id': 81654, 'author': 'MSalters', 'author_id': 15416, 'author_profile': 'https://Stackoverflow.com/users/15416', 'pm_score': 2, 'selected': False, 'text': "<p>GNU strip accepts regex arguments to --strip-symbols=\nThe STL and boost symbols are name-mangled because of the namespaces they're in. I don't have GCC binutils handy at this moment, but just peek at the name mangling used for namespaces and construct the regex for 'symbols from namespace X' and pass this to --strip-symbols=</p>\n"}, {'answer_id': 42669612, 'author': 'gospes', 'author_id': 2250406, 'author_profile': 'https://Stackoverflow.com/users/2250406', 'pm_score': 1, 'selected': False, 'text': '<p>This answer provides some specifics that I needed to make MSalters\' answer work for removing STL symbols. </p>\n\n<p>The STL symbol names are mangled. The trick is to find a regular expression that covers these names. I looked these symbols up with GNU\'s Binutils:</p>\n\n<pre><code>&gt; nm --debug-syms &lt;objectfile&gt;\n</code></pre>\n\n<p>I basically searched on STL functions, like <code>resize</code>. If this is difficult, the output becomes readable when using the following command:</p>\n\n<pre><code>&gt; nm --debug-syms --demangle &lt;objectfile&gt;\n</code></pre>\n\n<p>Look up a line number containing an STL function call, then look up it\'s mangled name on that same line number using the first provided command. This allowed me to see that all STL symbol names began with <strong>_ZNSt[0-9]+</strong> or <strong>_ZSt[0-9]+</strong>, etc.</p>\n\n<p>To allow GNU Strip to remove these symbols I used:</p>\n\n<pre><code>&gt; strip --wildcard              \\\n    --strip-symbol=\'_ZNKSt*\'    \\\n    --strip-symbol=\'_ZNSt*\'     \\\n    --strip-symbol=\'_ZSt*\'      \\\n    --strip-symbol=\'_ZNSa*\'     \\\n    &lt;objectfile&gt;\n</code></pre>\n\n<p>I used these commands directly on the compiled/linked binary. I verified the removal of these symbols by comparing the output of <code>nm</code> before and after the removal (I wrote the output to files and used <code>vimdiff</code>). The <code>--wildcard</code> option allows the use of regular expressions. Although I would expect <strong>[0-9]*</strong> to mean 0 to an infinite amount of numbers, here it actually means 1 number followed by an infinite amount of anything (until the end of the line).</p>\n\n<p>If you are looking to <strong>not step into STL code</strong> this can be achieved by gdb\'s <code>skip file</code> command, as done <a href="https://stackoverflow.com/a/42721326/2250406">here</a>.</p>\n\n<p>Hope it helps</p>\n'}]
['https://Stackoverflow.com/questions/73519', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11344/']