質問

I am using VS-android framework to compile Android shared object directly from Microsoft Visual Studio 2012 + Android NDK. I disassembled my own .so file using IDA and was horrified to see that all my code is completely visible (names of the functions, names of the data buffers, names of classes, etc).

I want to remove all that debug and unneeded symbols so it would be hard to understand my code by disassembling it.

The compilation process is as following:

  1. I have 10 C++ files. Each is compiled to an .o file
  2. main_service.c is than compiled to main.o and linked against all the other *.o files to yield main_service.so library.

I have tried the following solutions and they didn't work:

  1. Giving argument -strip-all to the compiler and to the linker. It does not seem to work.
  2. After linking, call objcopy.exe with -strip-all on main_service.o. This reduces a bit the size of main_serivce.so but the symbols remain
  3. In my C++ code I never use "attribute ((visibility()))" so maybe the problem is that linker cannot remove symbols because it does not know what is private and can be hidden and what is public. I tried to add "attribute ((visibility("default")))" to the functions in main_service.c which I want to use in JNI and added -fvisibility=hidden flags to the compiler and the linker. But I got a warning : 'visibility' attribute ignored [-Wattributes], and the symbols are not removed

What am I missing here?

P.s. - I am completely new to "stripping symbols" so sorry if my question is a bit silly.

-

役に立ちましたか?

解決

I found a way to do this.

  1. I compiled and linked the code with g++.exe (For example arm-linux-androideabi-g++.exe).
  2. For each compiled file I gave the following 2 switches -fvisibility=hidden -s both to compiler and to the linker. You need both switches.
  3. No need to use __attribute visibility at all.
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top