Android: Link position-independent executables with proper flags

Add `-fPIE -pie` to the default executable link flags when
`CMAKE_POSITION_INDEPENDENT_CODE` is enabled.  This is required by
Android 16 and above for executables to run on the device.

Closes: #16382
This commit is contained in:
Brad King 2016-10-24 11:45:18 -04:00
parent 6205f1797e
commit 4c272adbe1
1 changed files with 4 additions and 0 deletions

View File

@ -8,6 +8,10 @@ if(NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE
set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif() endif()
if(CMAKE_POSITION_INDEPENDENT_CODE)
string(APPEND _ANDROID_ABI_INIT_EXE_LDFLAGS " -fPIE -pie")
endif()
string(APPEND _ANDROID_ABI_INIT_EXE_LDFLAGS " -Wl,--gc-sections") string(APPEND _ANDROID_ABI_INIT_EXE_LDFLAGS " -Wl,--gc-sections")
if(NOT _ANDROID_ABI_INIT_EXE_LDFLAGS_NO_nocopyreloc) if(NOT _ANDROID_ABI_INIT_EXE_LDFLAGS_NO_nocopyreloc)