Remove embedded source file names from shared libraries

When I create the shared library "mylib.so" from the source file "secret.cc", the resulting shared object contains the original file name:

... do_global_ctors_aux_@secret.cc ^ @__ DTOR_END ...

But I do not want to disclose the name of this file ("secret.cc") to users of my library. Is there a way to remove file name information from a shared object or prevent it from being included in the first place?

+1
source share
1 answer

This is pretty simple: don't let the compiler know the original file name from the beginning. Instead

g++ -std=c++11 -O3 -Wall -c my_source.cc -o my_source.o 

do the following:

 cat my_source.cc | g++ -std=c++11 -O3 -Wall -c -x c++ - -o my_source.o 

Note that you need to explicitly specify -x c++ , error messages will obviously no longer contain the file name, and there is one more caveat: when your sources contain relative inclusions, i.e. include in quotation marks ( #include "foo.hpp" ) instead of angle brackets ( #include <foo.hpp> ), they will no longer work, since the compiler cannot reference the file directory, it just sees the byte stream from the channel.

+3
source

All Articles