无法在 armeabi-v7a 中隐藏导出

Cannot hide exports in armeabi-v7a

这是我的 CMakeLists.txt:

cmake_minimum_required(VERSION 3.4.1)

set(CMAKE_SYSTEM_PROCESSOR arm)

set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -s")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s")

set(sources ...)
set(includes ...)
add_library(mylib SHARED ${sources})
include_directories(${includes})
find_library(log-lib log )
target_link_libraries(test ${log-lib} )

当我编译时,我的库已成功构建,而当我 运行 file 时,它说库已被删除。我为全局变量使用了以下属性:

__attribute__((visibility("hidden"))

但这似乎并不影响armeabi-v7a。我仍然在 armeabi-v7a 的库导出符号 table 中看到它们。我能做些什么来隐藏它吗?

已解决:

@rprichard commented on 19 Feb 2019
This looks like the same issue as https://bugs.llvm.org/show_bug.cgi?id=39413 / #829. -Oz turns on the GlobalMerge optimization, which isn't preserving the visibility attributes on variables.

Adding -mno-global-merge to the cflags is a workaround

来源 - https://github.com/android/ndk/issues/913#issuecomment-465357660