jni add strip

This commit is contained in:
yeyunpeng2020 2021-06-23 12:54:51 +08:00
parent 18eed2fb33
commit 1d08945704
2 changed files with 47 additions and 2 deletions

View File

@ -8,6 +8,39 @@ if(PLATFORM_ARM32 OR PLATFORM_ARM32)
add_compile_definitions(PLATFORM_ARM) add_compile_definitions(PLATFORM_ARM)
endif() endif()
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DDebug -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDebug -g")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=default")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=default")
else()
## enable for binscope for release
set(CMAKE_C_FLAGS "-fPIC -fPIE -D_FORTIFY_SOURCE=2 -O2 -Wall -Werror -fstack-protector-strong -Wno-attributes \
-Wno-deprecated-declarations -Wno-missing-braces ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-fPIC -fPIE -D_FORTIFY_SOURCE=2 -O2 -Wall -Werror -fstack-protector-strong -Wno-attributes \
-Wno-deprecated-declarations -Wno-missing-braces -Wno-overloaded-virtual ${CMAKE_CXX_FLAGS}")
if(TARGET_HIMIX200)
set(CMAKE_CXX_FLAGS "-Wno-error=maybe-uninitialized ${CMAKE_CXX_FLAGS}")
endif()
if(NOT WIN32)
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-z,relro,-z,now -Wl,-z,noexecstack ${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,-z,relro,-z,now -Wl,-z,noexecstack ${CMAKE_EXE_LINKER_FLAGS}")
endif()
endif()
if(PLATFORM_ARM32 OR PLATFORM_ARM64)
#for performance
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer -fstrict-aliasing -ffunction-sections \
-fdata-sections -ffast-math -fno-rtti -fno-exceptions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fomit-frame-pointer -fstrict-aliasing -ffunction-sections \
-fdata-sections -ffast-math -fno-rtti -fno-exceptions")
if(TARGET_HIMIX200)
string(REPLACE "-fno-rtti " "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
endif()
endif()
endif()
set(MS_VERSION_MAJOR ${MS_VERSION_MAJOR}) set(MS_VERSION_MAJOR ${MS_VERSION_MAJOR})
set(MS_VERSION_MINOR ${MS_VERSION_MINOR}) set(MS_VERSION_MINOR ${MS_VERSION_MINOR})
set(MS_VERSION_REVISION ${MS_VERSION_REVISION}) set(MS_VERSION_REVISION ${MS_VERSION_REVISION})
@ -80,3 +113,15 @@ if(SUPPORT_TRAIN)
endif() endif()
endif() endif()
set(NDK_STRIP
"${ANDROID_NDK}/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/aarch64-linux-android/bin/strip")
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
if(PLATFORM_ARM64 OR PLATFORM_ARM32)
add_custom_command(TARGET mindspore-lite-jni POST_BUILD COMMAND ${NDK_STRIP}
${CMAKE_BINARY_DIR}/libmindspore-lite*.so)
elseif(NOT WIN32)
add_custom_command(TARGET mindspore-lite-jni POST_BUILD COMMAND strip
${CMAKE_BINARY_DIR}/libmindspore-lite*.so)
endif()
endif()

View File

@ -158,7 +158,7 @@ extern "C" JNIEXPORT jboolean JNICALL Java_com_mindspore_lite_MSTensor_setData(J
return static_cast<jboolean>(false); return static_cast<jboolean>(false);
} }
auto *ms_tensor_ptr = static_cast<mindspore::tensor::MSTensor *>(pointer); auto *ms_tensor_ptr = static_cast<mindspore::tensor::MSTensor *>(pointer);
if (data_len != ms_tensor_ptr->Size()) { if (static_cast<size_t>(data_len) != ms_tensor_ptr->Size()) {
#ifdef ENABLE_ARM32 #ifdef ENABLE_ARM32
MS_LOGE("data_len(%lld) not equal to Size of ms_tensor(%zu)", data_len, ms_tensor_ptr->Size()); MS_LOGE("data_len(%lld) not equal to Size of ms_tensor(%zu)", data_len, ms_tensor_ptr->Size());
#else #else
@ -191,7 +191,7 @@ extern "C" JNIEXPORT jboolean JNICALL Java_com_mindspore_lite_MSTensor_setByteBu
} }
auto *ms_tensor_ptr = static_cast<mindspore::tensor::MSTensor *>(pointer); auto *ms_tensor_ptr = static_cast<mindspore::tensor::MSTensor *>(pointer);
if (data_len != ms_tensor_ptr->Size()) { if (static_cast<size_t>(data_len) != ms_tensor_ptr->Size()) {
#ifdef ENABLE_ARM32 #ifdef ENABLE_ARM32
MS_LOGE("data_len(%lld) not equal to Size of ms_tensor(%zu)", data_len, ms_tensor_ptr->Size()); MS_LOGE("data_len(%lld) not equal to Size of ms_tensor(%zu)", data_len, ms_tensor_ptr->Size());
#else #else