I've noticed that, even after stripping symbols from my executable, class names and their methods are still included at the end of the executable file.

For instance:

#include <iostream>

using namespace std;

class Clingons
    void clingForever()
        cout << "Qapla" << endl;

int main(int argc, char *argv[])
    Clingons cling;


    return 0;

Then compile and link with:

g++ cling.cpp -o cling

Now, when I look at the bottom of the resulting "cling" file with a hex editor, I can see the "Clingons" class name along with it's methods. I can also see this information while debugging..

even after I strip them:

strip -x cling

I can still see the same information.

So why wasn't this information stripped away when I used the command above? Is there a way to strip (or mangle) this information other than by hand?

The used version of GCC is i686-apple-darwin10-llvm-g++-4.2 (GCC) 4.2.1

This is just an example case. My real project involves the Qt framework.


It is possible that you are using RTTI. Try compiling your code with option -fno-rtti.

Update: It is really RTTI.

I don't know how exactly it works, but I succeeded to remove those strings as follows:

$ g++ -Xlinker -unexported_symbol -Xlinker "*" -o executable file.cpp
$ strip executable

(This was found at https://stackoverflow.com/questions/1931626/how-to-really-strip-a-binary-in-macos )

  • 1
    Keep in mind that there are edge cases where RTTI may indeed be required at runtime, though. – 0xC0000022L Jun 23 '14 at 6:25
  • I know about this one (I commented on the accepted answer) but it doesn't seem to remove everything from my current Qt project. – user2005 Jun 24 '14 at 2:36
  • @Access Denied: RTTI is disabled by default on Qt libraries so I don't think disabling it would cause an issue. I tried disabling it via -fno-rtti and it didn't do anything. – user2005 Jun 24 '14 at 2:38
  • Upon further inspection, I realize that this solution does work. It does keep references to classes and functions in external libraries but nothing from my own code. – user2005 Jun 24 '14 at 2:53

Try compiling your program as a static assembly, and strip it using the compiler. You won't find any 'cling' references in the resultant executable.

$ g++ -static -s cling.cpp -o cling

$ ls -l cling*
-rwxr-x--- 1 lornix lornix 1,313,792 Jun 22 19:19 cling*
-rw-r----- 1 lornix lornix       222 Jun 22 19:16 cling.cpp

$ strings -a cling | grep -ic cling
  • I tried your suggestion but it wouldn't build: can't locate file for: -lcrt0.o ... Also, my real project is using the Qt framework so I can't build static unless I purchase a commercial license. – user2005 Jun 24 '14 at 2:44

The toolbox ELFKicker has an utility called sstrip that strip an ELF executable down to the bones.

But, it seems that you are using Mach-O executable format. So, I would recommend to look at the source code of sstrip and build your own stripper.

You can also take a look at the source code of the strip command for Mach-O and get inspiration. And, also, this Python script strip_save_dsym might also give some hints.

Finally, here are a few comparisons between ELF and Mach-O formats:

  • 1
    Although your answer doesn't provide an instant solution, it's bold and I like it a lot. Studying sstrip looks like fun and maybe I'll end up creating my own special tool for the job. – user2005 Jun 24 '14 at 3:04
  • 1
    Thanks, but I also totally agree with your choice of marking WS answer as the answer ! Mine is, at most, some complementary information about the topic. – perror Jun 24 '14 at 6:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy