简体   繁体   English

如何防止某些功能被剥夺?

[英]How do I prevent certain functions from getting stripped?

I have a static library that contains some JNICALL functions, ie they are expected to be called from the JVM and are never referenced by the shared library that links the static library. 我有一个包含一些JNICALL函数的静态库,即应该从JVM调用它们,而链接静态库的共享库永远不会引用它们。

However, it seems like function stripping is exterminating the JNICALL function (it's not visible in arm-eabi-objdump -t). 但是,似乎函数剥离正在消除JNICALL函数(在arm-eabi-objdump -t中不可见)。 I'm working around it by adding a dummy function with an impossible condition that calls the JNICALL function, but that's dirty. 我正在通过添加具有不可能条件的伪函数来调用JNICALL函数来解决此问题,但这很脏。 I know that there is a link option to prevent certain modules from getting their unused data stripped, but what is it? 我知道有一个链接选项可以防止某些模块剥夺其未使用的数据,但这是什么呢? And how do I specify that option in the .mk file? 以及如何在.mk文件中指定该选项? I didn't see anything immediately obvious in arm-eabi-ld. 我没有立即在arm-eabi-ld中看到任何明显的东西。

Incidentally, the function stripping doesn't strip out JNICALL functions in the shared library itself, but it will remove those from the static library that the shared library is linking. 顺便说一句,功能剥离不会在共享库本身中剥离JNICALL函数,但是会从共享库链接的静态库中删除那些功能。 What's the reason for that? 是什么原因呢?

It actually looks like the NDK team started supporting that (or stopped?), and there are traces of it in the build system, but some vital parts are missing. 实际上,NDK团队似乎开始支持(或停止了?),并且在构建系统中有痕迹,但是缺少一些重要的部分。 The good news is that it can be easily implemented. 好消息是它可以轻松实现。

Go to the "build" directory in the NDK installation and search for all instances of LOCAL_STATIC_LIBRARIES. 转到NDK安装中的“ build”目录,并搜索LOCAL_STATIC_LIBRARIES的所有实例。 Copy and paste all of them and add a version that version that does the same thing with LOCAL_STATIC_WHOLE_LIBRARIES. 复制并粘贴所有这些内容,并添加一个与LOCAL_STATIC_WHOLE_LIBRARIES具有相同功能的版本。

To be precise: In build/core/build-binary.mk, you'll need: 准确地说:在build / core / build-binary.mk中,您需要:

LOCAL_STATIC_LIBRARIES := $(call strip-lib-prefix,$(LOCAL_STATIC_LIBRARIES))
LOCAL_STATIC_WHOLE_LIBRARIES := $(call strip-lib-prefix,$(LOCAL_STATIC_WHOLE_LIBRARIES))

[...] [...]

static_libraries := $(call map,static-library-path,$(LOCAL_STATIC_LIBRARIES))
static_whole_libraries := $(call map,static-library-path,$(LOCAL_STATIC_WHOLE_LIBRARIES))

[...] [...]

$(call module-add-static-depends,$(LOCAL_MODULE),$(LOCAL_STATIC_LIBRARIES))
$(call module-add-static-depends,$(LOCAL_MODULE),$(LOCAL_STATIC_WHOLE_LIBRARIES))

[...] [...]

$(LOCAL_BUILT_MODULE): $(static_libraries) $(static_whole_libraries) $(shared_libraries)

[...] [...]

$(LOCAL_BUILT_MODULE): PRIVATE_STATIC_LIBRARIES := $(static_libraries)
$(LOCAL_BUILT_MODULE): PRIVATE_WHOLE_STATIC_LIBRARIES := $(static_whole_libraries)

Note the discrepancy between STATIC_WHOLE and WHOLE_STATIC - that's how it is in the NDK, I chose to keep it that way even though it's inconsistent. 注意STATIC_WHOLE和WHOLE_STATIC之间的差异-这就是NDK中的方式,即使不一致,我还是选择保持这种方式。

Now, finally, in build/toolchains/arm-eabi-4.4.0/setup.mk: There's already the PRIVATE_WHOLE_STATIC_LIBRARIES block for shared libraries. 现在,最后,在build / toolchains / arm-eabi-4.4.0 / setup.mk中:共享库已经有了PRIVATE_WHOLE_STATIC_LIBRARIES块。 You can choose to add that for executables as well, although that's most likely not necessary. 您也可以选择为可执行文件添加它,尽管这很有可能不是必需的。

看到另一个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM