Stripping symbols from Shared Objects

79 Views Asked by At

I'm attempting to strip away all symbols from a shared object. I know that this kinda goes against the norm when it comes to so's, but I'm making a self contained addon to another program. I made myself a little toy program to test which looks like this;

#include <fstream>
#include <iostream>

void PrintMessage(std::string msg)
{
    std::cout << msg << std::endl;
}

void HelloWorld()
{
    std::string s = "HelloWorld!";
    std::cout << s << std::endl;
}

extern "C" void __attribute__((constructor)) SoMain() {
    std::ofstream file("HelloWorld");
    file.close();
    HelloWorld();
}

And I compiled it like so g++ -shared -fPIC -o test.so test.cpp

I'm fine with SoMain() being a known symbol, but everything from there should be "hidden". I.e., one should not be able to open a disassembler such as IDA and see the function names such as "HelloWorld" or "PrintMessage".

Is there a way to achieve this behavior for shared objects?

0

There are 0 best solutions below