I'm writing a native module for Node but would like to remove the debugging information. I'm using node-gyp to build the module.
It's doing a release build, but still, the symbol table is included in the output file.
So I need to remove it with the strip Unix command after the build. Is there a way to remove it in the build itself - ie. specify something in the .gyp file?
Furthermore, even after stripping the debug symbols, I can still use
strings [node-module]
And it lists the names of my functions. Is it possible to remove these also?
This is the command I use to build the native module:
node-gyp rebuild --target=v8.9.4
And this is my binding.gyp:
{
"targets": [
{
"libraries": [
"/usr/lib/x86_64-linux-gnu/libudev.so",
"/usr/lib/x86_64-linux-gnu/libboost_regex.so.1.58.0"
],
"target_name": "utils",
"sources": [ "src/native/utils.cpp" ]
}
]
}
Thanks!
As you probably know, a node native module is a dynamic library. You
cannot strip the dynamic symbol table from a dynamic library because the
dynamic symbol table is necessary at runtime for dynamically linking the library.
Even strip --strip-all will not remove the dynamic symbol table. strip --strip-all or strip --strip-unneeded
strips everything that can be stripped from a dynamic library. Adding -g0 to the compilation flags
eliminates all debugging information, but symbol tables contain more than
debugging information.
You can instruct the linker to do the same thing as strip --strip-all at
linktime by passing it the option -s|--strip-all. To do this, your binding.gyp
would be:
{
"targets": [
{
"libraries": [
"/usr/lib/x86_64-linux-gnu/libudev.so",
"/usr/lib/x86_64-linux-gnu/libboost_regex.so.1.58.0"
],
"target_name": "utils",
"ldflags" : [ "-Wl,-s" ],
"sources": [ "src/native/utils.cpp" ],
}
]
}
The resulting node module is then as stripped as a shared library can be:
$ file ./build/Release/utils.node
./build/Release/utils.node: ELF 64-bit LSB shared object, x86-64, \
version 1 (SYSV), dynamically linked, \
BuildID[sha1]=eb53cee5839c71b41176bc7a852802035009e8ae, stripped
^^^^^^^^
I have searched a bit and there may be a brute force solution of specifying the compiler flag -g0 manually. Take a look here:https://github.com/nodejs/node-gyp/issues/26 . So following Your example and advices given in the github issue the input file should be like this:
{
"targets": [
{
"libraries": [
"/usr/lib/x86_64-linux-gnu/libudev.so",
"/usr/lib/x86_64-linux-gnu/libboost_regex.so.1.58.0"
],
"target_name": "utils",
"cflags_cc": [ "-g0" ]
"sources": [ "src/native/utils.cpp" ]
}
]
}
Sadly, there is no way for me to test it and it is not platform independant.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With