Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove C++ class names from binary dll file

I have a C++ project under Visual Studio 2010 which compiles into a dll. I have several private implementation-specific classes defined in my project, e.g. CMyClass. This class is not exported from the dll or by any interface function. However, when I check generated dll file, there is a string "CMyClass" stored in it. It is a release build, and I don't want this string to appear in the dll file. This dll is shipped to customers, and I want all names I used in my project to be stripped off the dll file, so nobody can get such a simple clue on what algorithms we use in our dll.

I use Release configuration. In project properties, the "Generate Debug Info" option under linker tab is turned off, the "Debug Information Format" under C/C++ tab is set to "Program Database (/Zi)". I tried to set empty string for "Debug Information Format" with no success.

The string found in the dll looks like .?AVCMyClass@@ and is located at the very end of the dll file. It is the only occurrence of the "CMyClass" string in the dll file. However, this string is presented for almost all my internal classes.

How to get rid of these mentions?

Update

Please note, I don't want to obfuscate the source code itself. The provided link is irrelevant. I just see no reason why class names are stored in the dll file. I can always rename my classes prior to build, but it is not very straight solution.

Update2

I don't agree with community on closing this qustion, since this is not a duplicate. And the answer is given in comments by Tyler Gill. Thanks to him and shame on others.

like image 743
Mikhail Avatar asked Feb 14 '13 07:02

Mikhail


1 Answers

As my guess from a comment appears correct, I'm reposting this as an answer.

The string of the class name is a result of having RTTI (Runtime Type Information) enabled for the compiled binaries. When RTTI is enabled, the compiler creates objects that store information about the types compiled into the binary, one of whose properties is the name of the type.

Note that some uses of dynamic_cast and typeid require RTTI, so disabling will cost you those features of C++.

In order to disable RTTI in Visual Studio, use the /GR- switch (see http://msdn.microsoft.com/en-us/library/we6hfdy0(v=vs.100).aspx, as Mikhail posted.)

To disable it in GCC, use the -fno-rtti switch.

like image 103
Tyler Gill Avatar answered Sep 18 '22 17:09

Tyler Gill