Search code examples
c++clangdebug-symbolsclang++

clang: stripping class names from the output


I build a C++ project of mine using clang++, using the following command line command (split into lines):

clang++
  -std=c++11
  -W -Wall -Wextra -pedantic -Wno-newline-eof -Werror
  -O4
  -I<dirs>
  -L<dirs>
  -l<libs>
  -framework <frameworks>
  -D <defs>
  -o <filename>
  <files>

However, when I run strings <filename>, several class names show up, despite the -O4 in the command line. I've tried -Wl,-s which should tell llvm to strip all symbols, but that doesn't remove these.

The class names that show up seem to all have one thing in common: they have a vtable. One of these classes is :

class MyClass {
public:
    virtual void myFunc() = 0;  
};

It shows up as the symbol :

N9namespace7MyClassE

I don't like it that my namespace and class names show up in the final file. How do I strip these? My binary is a command line utility, so only the main function should be exported.


Even after supplying -fno-rtti (as suggested by @n.m.), some names still remain, such as :

__ZN15MyClassInstance6myFuncEv

(MyClassInstance being a subclass of the MyClass above)

Additionally, even the names of global variables are in the binary.


Solution

  • I solved this by supplying the clang argument -fno-rtti, which disables RTTI, a C++ feature I don't use anyway.

    [edit]
    It looks like -O4 does not imply strip, and the last few references to my class names can be removed by executing strip.