Skip to content

Commit

Permalink
Fix Android FIPS build on armv8 (#299)
Browse files Browse the repository at this point in the history
### Issues:
Resolves #192

### Description of changes: 
* Clang with the Android NDK doesn't compile with `-Werror` on clang due to implicit addition of `-Wa,noexecstack`. Since `--Wa,--noexecstack` is not used during the preprocessor step (because assembler is not invoked), Clang reports that argument as unused. Added a removal the flag during FIPS builds for Android. 
Context: android/ndk#171

* CMAKE inserts a `\` before whitespaces in arguments, which Android line does not recognize when using
  `add_custom_command`. This caused `${CMAKE_ASM_COMPILER}` to fail during the preprocessing step. Replacing whitespaces with `;` fixes this. 
  Context: https://stackoverflow.com/questions/8925396/why-does-cmake-prefixes-spaces-with-backslashes-when-executing-a-command

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
  • Loading branch information
samuel40791765 committed Nov 11, 2021
1 parent 59eccdf commit e1bdb6e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion crypto/fipsmodule/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ if(FIPS_SHARED AND FIPS_VENDOR_AFFIRM_BCM_O_PATH)
return()
endif()

if(ANDROID)
# Since "--Wa,--noexecstack" is not used during the preprocessor step of Android (because assembler is not invoked),
# Clang reports that argument as unused. We remove the flag only for the FIPS build of Android.
string(FIND ${CMAKE_CXX_FLAGS} "noexecstack" CXX_EXTRA_WA)
string(FIND ${CMAKE_C_FLAGS} "noexecstack" C_EXTRA_WA)
if(NOT ${CXX_EXTRA_WA} EQUAL '-1')
string( REPLACE "-Wa,--noexecstack" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" )
endif()
if(NOT ${C_EXTRA_WA} EQUAL '-1')
string( REPLACE "-Wa,--noexecstack" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" )
endif()
endif()

if(ARCH STREQUAL "x86_64")
set(
BCM_ASM_SOURCES
Expand Down Expand Up @@ -152,9 +165,10 @@ function(cpreprocess dest src)
set(TARGET "--target=${CMAKE_ASM_COMPILER_TARGET}")
endif()

string(REGEX REPLACE "[ ]+" ";" CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS}")
add_custom_command(
OUTPUT ${dest}
COMMAND ${CMAKE_ASM_COMPILER} ${TARGET} $CMAKE_ASM_FLAGS -E ${src} -I${PROJECT_SOURCE_DIR}/include > ${dest}
COMMAND ${CMAKE_ASM_COMPILER} ${TARGET} ${CMAKE_ASM_FLAGS} -E ${src} -I${PROJECT_SOURCE_DIR}/include > ${dest}
DEPENDS
${src}
${PROJECT_SOURCE_DIR}/include/openssl/arm_arch.h
Expand Down

0 comments on commit e1bdb6e

Please sign in to comment.