gpt4 book ai didi

c++ - NodeJS native 模块 - 如何删除调试符号

转载 作者:太空狗 更新时间:2023-10-29 21:11:55 25 4
gpt4 key购买 nike

我正在为 Node 编写 native 模块,但想删除调试信息。我正在使用 node-gyp 构建模块。

它正在进行发布构建,但符号表仍包含在输出文件中。

因此我需要在构建后使用 strip Unix 命令将其删除。有没有办法在构建本身中删除它 - 即。在 .gyp 文件中指定一些内容?

此外,即使去掉调试符号,我仍然可以使用

strings [node-module]

它列出了我的函数名称。是否也可以删除这些?

这是我用来构建原生模块的命令:

node-gyp rebuild --target=v8.9.4

这是我的 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" ]
}
]
}

谢谢!

最佳答案

您可能知道, Node native 模块是一个动态库。你不能从动态库中删除动态符号表,因为动态符号表在运行时是动态链接库所必需的。即使 strip --strip-all 也不会删除动态符号表。 strip --strip-allstrip --strip-unneeded剥离所有可以从动态库中剥离的东西。将 -g0 添加到编译标志消除所有调试信息,但符号表包含超过调试信息。

您可以指示链接器执行与 strip --strip-all 相同的操作通过将选项 -s|--strip-all 传递给链接时间。为此,您的 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",
"ldflags" : [ "-Wl,-s" ],
"sources": [ "src/native/utils.cpp" ],
}
]
}

然后生成的 Node 模块将像共享库一样被剥离:

$ 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
^^^^^^^^

关于c++ - NodeJS native 模块 - 如何删除调试符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48948559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com