Boost C++ Libraries: Ticket #12554: boost/core/typeinfo.hpp creates unwanted strings in release binary https://svn.boost.org/trac10/ticket/12554 <p> If a program is compiled for a production build then strings are created in program binary. Location where the strings are created: boost/core/typeinfo.hpp -&gt; boost::core::detail::core_typeid_::name -&gt; BOOST_CURRENT_FUNCTION. </p> <p> Current behavior has two drawbacks for a production version of a program: </p> <ol><li>binary program file size become larger </li><li>code symbols are present in production version of a program </li></ol><p> Five minutes proposed solution from me is replace function "name" by </p> <div class="wikipage" style="font-size: 80%"><p> Code highlighting: </p> <div class="wiki-code"><div class="code"><pre> <span class="k">static</span> <span class="kt">char</span> <span class="k">const</span> <span class="o">*</span> <span class="nf">name</span><span class="p">()</span> <span class="p">{</span> <span class="cp">#ifdef NDEBUG</span> <span class="k">return</span> <span class="s">&quot;&quot;</span><span class="p">;</span> <span class="cp">#else</span> <span class="k">return</span> <span class="n">BOOST_CURRENT_FUNCTION</span><span class="p">;</span> <span class="cp">#endif</span> <span class="p">}</span> </pre></div></div></div><p> </p> <p> Sorry for English... </p> <p> Thank you for attention. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12554 Trac 1.4.3 Lev Sch <Zorechfan@…> Wed, 26 Oct 2016 21:13:14 GMT component changed; owner set https://svn.boost.org/trac10/ticket/12554#comment:1 https://svn.boost.org/trac10/ticket/12554#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">Peter Dimov</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">core</span> </li> </ul> Ticket Lev Sch <Zorechfan@…> Thu, 27 Oct 2016 09:37:35 GMT <link>https://svn.boost.org/trac10/ticket/12554#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12554#comment:2</guid> <description> <p> At this morning, I have created minimal steps to reproduce. </p> <ol><li>Create "Win32 Console Application" in Microsoft Visual Studio with default settings </li><li>select "Release" configuration to build </li><li>add preprocessor include path to boost </li><li>add preprocessor definition BOOST_NO_TYPEID </li><li>disable RTTI by compiler flag </li><li>replace content of file that contains "main" function by: <div class="wikipage" style="font-size: 80%"><p> Code highlighting: </p> <div class="wiki-code"><div class="code"><pre> <span class="c1">// ConsoleApplication2.cpp : Defines the entry point for the console application.</span> <span class="c1">//</span> <span class="cp">#include</span> <span class="cpf">&quot;stdafx.h&quot;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/shared_ptr.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/make_shared.hpp&gt;</span><span class="cp"></span> <span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span> <span class="k">class</span> <span class="nc">MyFavoriteClass</span> <span class="p">{</span> <span class="k">public</span><span class="o">:</span> <span class="kt">void</span> <span class="n">print</span><span class="p">()</span> <span class="p">{</span> <span class="n">printf</span><span class="p">(</span><span class="s">&quot;HelloWorldABC</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span> <span class="p">}</span> <span class="p">};</span> <span class="c1">//boost::shared_ptr&lt;MyFavoriteClass&gt; ptr(new MyFavoriteClass());</span> <span class="n">boost</span><span class="o">::</span><span class="n">shared_ptr</span><span class="o">&lt;</span><span class="n">MyFavoriteClass</span><span class="o">&gt;</span> <span class="n">ptr</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">make_shared</span><span class="o">&lt;</span><span class="n">MyFavoriteClass</span><span class="o">&gt;</span><span class="p">();</span> <span class="n">ptr</span><span class="o">-&gt;</span><span class="n">print</span><span class="p">();</span> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> <span class="p">}</span> </pre></div></div></div></li><li>build application </li><li>(!) ConsoleApplication2.exe will contain "MyFavoriteClass" </li><li>In file boost\core\typeinfo.hpp replace BOOST_CURRENT_FUNCTION by "" (empty string) </li><li>build application </li><li>(!) ConsoleApplication2.exe will NOT contain "MyFavoriteClass" </li></ol> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Thu, 27 Oct 2016 14:33:32 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12554#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12554#comment:3</guid> <description> <p> We could add a dedicated macro to make <code>name()</code> return an empty string or something like <code>"(unknown)"</code>. <code>NDEBUG</code> doesn't seem right here because programs could rely on <code>name()</code> in release builds (for logging, exceptions, and so on.) </p> </description> <category>Ticket</category> </item> <item> <author>Lev Sch <Zorechfan@…></author> <pubDate>Thu, 27 Oct 2016 15:33:27 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12554#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12554#comment:4</guid> <description> <p> Dedicated macro is suitable for me. </p> </description> <category>Ticket</category> </item> <item> <author>Lev Sch <Zorechfan@…></author> <pubDate>Mon, 31 Oct 2016 10:19:00 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12554#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12554#comment:5</guid> <description> <p> In last days I was thinking in background about this ticket. </p> <p> The example program (from second comment) does not use string, but string is present in binary file. </p> <p> Is there rule violation: <a class="ext-link" href="http://www.stroustrup.com/crc.pdf"><span class="icon">​</span>http://www.stroustrup.com/crc.pdf</a> -&gt; "Low-level programming support rules" -&gt; "What you don’t use, you don’t pay for (zero-overhead rule)." ? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Mon, 31 Oct 2016 13:12:56 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12554#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12554#comment:6</guid> <description> <p> The reason is that <code>BOOST_TYPEID</code> emulates the built-in <code>typeid</code> operator, which returns a reference to <code>typeinfo</code>, which is a non-template class. So <code>typeinfo::name()</code> has to be present. If <code>BOOST_TYPEID</code> could return <code>typeinfo&lt;T&gt;</code> instead, <code>name()</code> would not be instantiated unless used. But it can't. </p> <p> Why are you defining <code>BOOST_NO_TYPEID</code> by hand under MSVC though? It's not required. </p> </description> <category>Ticket</category> </item> <item> <author>Lev Sch <Zorechfan@…></author> <pubDate>Mon, 31 Oct 2016 17:52:06 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12554#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12554#comment:7</guid> <description> <p> If only this line is used </p> <blockquote> <p> printf("%s\n",typeid(MyFavoriteClass)==typeid(MyFavoriteClass) ? "true" : "false"); </p> </blockquote> <p> and RTTI is disabled then binary file will contain this string: </p> <blockquote> <p> .?AVMyFavoriteClass@?1??main@@YAHXZ@ </p> </blockquote> <p> I do not want these lines and I have no influence to compiler. I disabled RTTI for my project and does not use "typeid" operator. Another libraries should not use typeid also, to prevent these strings. So, I disabled usage of typeid by Boost by defining BOOST_NO_TYPEID. </p> <p> I use own implementation of typeid that does not generate these strings. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Mon, 31 Oct 2016 22:33:13 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12554#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12554#comment:8</guid> <description> <p> I wonder whether the right fix for this isn't to add a macro that disables <code>BOOST_CURRENT_FUNCTION</code> altogether instead of just this use of it. It seems to me that if you want this use to not put a string into the executable, you probably don't want any other uses to emit strings either. </p> </description> <category>Ticket</category> </item> <item> <author>Lev Sch <Zorechfan@…></author> <pubDate>Tue, 01 Nov 2016 07:31:39 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12554#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12554#comment:9</guid> <description> <p> Summary: </p> <ol><li>my code must not put code strings into an executable </li><li>third party code must not put my code strings into an executable </li><li>third party code can put third party code strings into an executable, but it is not desired </li></ol><p> I'm developing under Android also. Every string is doubled (x86 and Arm platforms). </p> <p> Currently, after patch was applied from Description, following strings are put into executable also (Android x86): </p> <pre class="wiki"> boost::filesystem::canonical boost::filesystem::copy boost::filesystem::copy_directory boost::filesystem::copy_file boost::filesystem::create_directories boost::filesystem::create_directory boost::filesystem::create_directory_symlink boost::filesystem::create_hard_link boost::filesystem::create_symlink boost::filesystem::current_path boost::filesystem::equivalent boost::filesystem::file_size boost::filesystem::hard_link_count boost::filesystem::is_empty boost::filesystem::last_write_time boost::filesystem::permissions boost::filesystem::read_symlink boost::filesystem::relative boost::filesystem::remove boost::filesystem::remove_all boost::filesystem::rename boost::filesystem::resize_file boost::filesystem::space boost::filesystem::status boost::filesystem::temp_directory_path boost::filesystem::weakly_canonical boost::filesystem::directory_iterator::construct boost::filesystem::directory_iterator::operator++ boost::condition_variable::wait failed in pthread_cond_wait boost unique_lock has no mutex boost unique_lock doesn't own the mutex boost unique_lock owns already the mutex boost: mutex lock failed in pthread_mutex_lock boost::condition_variable::do_wait_until failed in pthread_cond_timedwait boost::exception_ptr boost::exception_detail::get_static_exception_object() [Exception = boost::exception_detail::bad_alloc_] C:\lib\boost_1_62_0\boost/exception/detail/exception_ptr.hpp boost::exception_ptr boost::exception_detail::get_static_exception_object() [Exception = boost::exception_detail::bad_exception_] boost:: mutex constructor failed in pthread_mutex_init boost::condition_variable::condition_variable() constructor failed in pthread_mutex_init boost::condition_variable::condition_variable() constructor failed in detail::monotonic_pthread_cond_init static const char *boost::detail::ctti&lt;boost::algorithm::detail::token_finderF&lt;boost::algorithm::detail::is_any_ofF&lt;char&gt; &gt; &gt;::n() [T = boost::algorithm::detail::token_finderF&lt;boost::algorithm::detail::is_any_ofF&lt;char&gt; &gt;] call to empty boost::function bad lexical cast: source type value could not be interpreted as target N5boost18thread_interruptedE N5boost9exceptionE N5boost16exception_detail10clone_baseE N5boost16exception_detail10clone_implINS0_10bad_alloc_EEE N5boost16exception_detail10bad_alloc_E N5boost16exception_detail10clone_implINS0_14bad_exception_EEE N5boost16exception_detail14bad_exception_E </pre><p> Following compiler flags were used: </p> <pre class="wiki"> "-DANDROID", "-DANDROID_NDK", "-DBOOST_NO_TYPEID", "-DBOOST_FILESYSTEM_NO_DEPRECATED", "-DLOKI_OBJECT_LEVEL_THREADING", "-DBOOST_ENABLE_ASSERT_DEBUG_HANDLER", "-DBOOST_EXECUTION_CONTEXT=1", "-fPIC", "-fvisibility=hidden", "-fvisibility-inlines-hidden", "-ffunction-sections", "-fdata-sections", "-fno-rtti", "-g", "-Os", "-DNDEBUG", "-U_DEBUG", </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Tue, 01 Nov 2016 16:47:21 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12554#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12554#comment:10</guid> <description> <p> OK, I added a macro <code>BOOST_DISABLE_CURRENT_FUNCTION</code> in </p> <p> <a class="ext-link" href="https://github.com/boostorg/assert/commit/c67fe0a9249a304dc4ccdf5059999efc1e5ad267"><span class="icon">​</span>https://github.com/boostorg/assert/commit/c67fe0a9249a304dc4ccdf5059999efc1e5ad267</a> </p> <p> This should take care of some of the strings. </p> </description> <category>Ticket</category> </item> <item> <author>Lev Sch <Zorechfan@…></author> <pubDate>Tue, 01 Nov 2016 21:19:39 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12554#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12554#comment:11</guid> <description> <p> Thank you! </p> </description> <category>Ticket</category> </item> <item> <author>Lev Sch <zorechfan@…></author> <pubDate>Fri, 10 Feb 2017 20:19:43 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12554#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12554#comment:12</guid> <description> <p> I've checked on 1.63. The fix works fine. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Sat, 18 Nov 2017 09:49:18 GMT</pubDate> <title>owner, component, severity, milestone changed https://svn.boost.org/trac10/ticket/12554#comment:13 https://svn.boost.org/trac10/ticket/12554#comment:13 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Peter Dimov</span> to <span class="trac-author">jsiek</span> </li> <li><strong>component</strong> <span class="trac-field-old">core</span> → <span class="trac-field-new">tokenizer</span> </li> <li><strong>severity</strong> <span class="trac-field-old">Problem</span> → <span class="trac-field-new">Optimization</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Website 1.X</span> </li> </ul> Ticket