Skip to content

Commit a17b70c

Browse files
Limit global symbols on shared lib (#920)
1 parent ad246e5 commit a17b70c

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

Build/libHttpClient.Android/CMakeLists.txt

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,17 @@ if (NOT DEFINED HC_NOZLIB)
8989
"${PATH_TO_ROOT}/External/zlib/contrib/minizip"
9090
)
9191

92+
set(ZLIB_COMPILE_DEFINITIONS "HAVE_UNISTD_H")
93+
94+
# ftello and fseeko become available on minSdkVersion >= 24
95+
if (ANDROID_PLATFORM_LEVEL LESS 24)
96+
list(APPEND ZLIB_COMPILE_DEFINITIONS "USE_FILE32API")
97+
endif()
98+
99+
92100
set_source_files_properties(
93-
"${PATH_TO_ROOT}/External/zlib/contrib/minizip/ioapi.c"
94-
PROPERTIES COMPILE_DEFINITIONS "MINIZIP_FOPEN_NO_64=1"
101+
${ZLIB_SOURCE_FILES}
102+
PROPERTIES COMPILE_DEFINITIONS "${ZLIB_COMPILE_DEFINITIONS}"
95103
)
96104
endif()
97105

@@ -109,12 +117,7 @@ endif()
109117
)
110118

111119
set(ANDROID_INCLUDE_DIRS
112-
"${PATH_TO_ROOT}/External/opensslGeneratedHeaders/android"
113-
)
114-
115-
add_compile_options(
116-
$<$<COMPILE_LANGUAGE:CXX>:-Wno-error=implicit-function-declaration>
117-
$<$<COMPILE_LANGUAGE:C>:-Wno-error=implicit-function-declaration>
120+
"${PATH_TO_ROOT}/External/opensslGeneratedHeaders/android"
118121
)
119122

120123
#########################
@@ -136,6 +139,25 @@ target_include_directories(
136139
"${ZLIB_INCLUDE_DIRS}"
137140
)
138141

142+
if (BUILD_SHARED_LIBS)
143+
target_link_libraries(
144+
"${PROJECT_NAME}"
145+
PRIVATE
146+
log
147+
# Following should be moved to target_link_options when available with cmake 3.13
148+
-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/libHttpClient.Android.map.txt
149+
# This causes the linker to emit an error when a version script names a
150+
# symbol that is not found, rather than silently ignoring that line.
151+
-Wl,--no-undefined-version
152+
)
153+
154+
set_target_properties(
155+
"${PROJECT_NAME}"
156+
PROPERTIES
157+
LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/libHttpClient.Android.map.txt
158+
)
159+
endif()
160+
139161
include("../libHttpClient.CMake/GetLibHCFlags.cmake")
140162
get_libhc_flags(FLAGS FLAGS_DEBUG FLAGS_RELEASE)
141163

Build/libHttpClient.Android/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ android {
1515
}
1616
if (project.hasProperty("BUILD_SHARED_LIBS")) {
1717
arguments << "-DBUILD_SHARED_LIBS=1"
18+
arguments << "-DANDROID_STL=c++_shared"
1819
}
1920

2021
// Support 16KB page sizes on 64-bit devices
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# The name used here doesn't matter. This is the name of the "version"
2+
# which matters when the version script is actually used to create multiple
3+
# versions of the same symbol, but that's not what we're doing.
4+
# For more info: https://developer.android.com/ndk/guides/symbol-visibility
5+
LIBHTTPCLIENT {
6+
global:
7+
# Every symbol named in this section will have "default" (that is, public)
8+
# visibility.
9+
HC*;
10+
XAsync*;
11+
XTaskQueue*;
12+
Java_com_xbox_httpclient*;
13+
local:
14+
# Every symbol in this section will have "local" (that is, hidden)
15+
# visibility. The wildcard * is used to indicate that all symbols not listed
16+
# in the global section should be hidden.
17+
*;
18+
};

0 commit comments

Comments
 (0)