Skip to content

Commit 212940d

Browse files
authored
Support FIPS build for Windows/ARM64 (#2688)
### Issues: Addresses: P265970495 ### Description of changes: Support FIPS build for Windows/ARM64 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.
1 parent a66b1de commit 212940d

File tree

4 files changed

+42
-25
lines changed

4 files changed

+42
-25
lines changed

CMakeLists.txt

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ if(MSVC)
2525
set(CMAKE_GENERATOR_CC cl)
2626
endif()
2727

28-
if(ARCH STREQUAL "aarch64" AND CMAKE_GENERATOR MATCHES "Visual Studio" AND NOT "${CMAKE_VS_PLATFORM_TOOLSET}" MATCHES "ClangCL")
29-
message(FATAL_ERROR "AWS-LC Windows/ARM64 assembly code requires ClangCL. Current toolset: ${CMAKE_VS_PLATFORM_TOOLSET}")
30-
endif()
31-
3228
include(sources.cmake)
3329
include(TestBigEndian)
3430
include(CheckCCompilerFlag)
@@ -658,18 +654,19 @@ elseif(MSVC)
658654
set(CMAKE_C_FLAGS "-utf-8 -Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}")
659655
set(CMAKE_CXX_FLAGS "-utf-8 -Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}")
660656

661-
# If we're using MSVC on Windows in FIPS mode with RelWithDebInfo then we want to override some of the default RelWithDebInfo flags.
662-
# This fixes the problem we run into with RelWithDebInfo and FIPS mode on Windows where the FIPS module wouldn't span the expected symbol.
663-
if(CMAKE_BUILD_TYPE_LOWER MATCHES "relwithdebinfo" AND FIPS)
664-
# /Zi requires the /debug flag for executables/libraries that we want .pdb files for.
665-
# We want to replace the default /debug flag with /DEBUG:FULL, to explicitly make sure that the .pdb files can be used on machines other than one on which it's built.
666-
string(REPLACE "/debug" "/DEBUG:FULL" CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO}")
667-
string(REPLACE "/debug" "/DEBUG:FULL" CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}")
668-
669-
# The /debug flag also turns off the /OPT linker flag so we want to turn them back on across the board.
670-
set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} /OPT:REF,ICF,LBR")
671-
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /OPT:REF,ICF,LBR")
672-
endif()
657+
endif()
658+
659+
# If we're using MSVC on Windows in FIPS mode with RelWithDebInfo then we want to override some of the default RelWithDebInfo flags.
660+
# This fixes the problem we run into with RelWithDebInfo and FIPS mode on Windows where the FIPS module wouldn't span the expected symbol.
661+
if(MSVC AND CMAKE_BUILD_TYPE_LOWER MATCHES "relwithdebinfo" AND FIPS)
662+
# /Zi requires the /debug flag for executables/libraries that we want .pdb files for.
663+
# We want to replace the default /debug flag with /DEBUG:FULL, to explicitly make sure that the .pdb files can be used on machines other than one on which it's built.
664+
string(REPLACE "/debug" "/DEBUG:FULL" CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO}")
665+
string(REPLACE "/debug" "/DEBUG:FULL" CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}")
666+
667+
# The /debug flag also turns off the /OPT linker flag so we want to turn them back on across the board.
668+
set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} /OPT:REF,ICF,LBR")
669+
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /OPT:REF,ICF,LBR")
673670
endif()
674671

675672
if(WIN32)
@@ -810,9 +807,7 @@ if(FIPS)
810807
message(FATAL_ERROR "Static FIPS build of AWS-LC is supported only on Linux")
811808
endif()
812809

813-
if(WIN32 AND CMAKE_BUILD_TYPE_LOWER STREQUAL "debug")
814-
message(FATAL_ERROR "Windows Debug build is not supported with FIPS, use Release or RelWithDebInfo")
815-
endif()
810+
816811

817812
string(REGEX MATCH "(^| )-DAWSLC_FIPS_FAILURE_CALLBACK($| )" FIPS_CALLBACK_ENABLED "${CMAKE_C_FLAGS}")
818813
if(FIPS_CALLBACK_ENABLED AND BUILD_SHARED_LIBS)
@@ -924,6 +919,14 @@ else()
924919
set(ARCH "generic")
925920
endif()
926921

922+
if(ARCH STREQUAL "aarch64" AND CMAKE_GENERATOR MATCHES "Visual Studio" AND NOT "${CMAKE_VS_PLATFORM_TOOLSET}" MATCHES "ClangCL")
923+
message(FATAL_ERROR "AWS-LC Windows/ARM64 assembly code requires ClangCL. Current toolset: ${CMAKE_VS_PLATFORM_TOOLSET}")
924+
endif()
925+
926+
if(WIN32 AND FIPS AND (CMAKE_BUILD_TYPE_LOWER STREQUAL "debug" OR (CMAKE_BUILD_TYPE_LOWER STREQUAL "relwithdebinfo" AND ARCH STREQUAL "aarch64")))
927+
message(FATAL_ERROR "Windows Debug and RelWithDebInfo builds are not supported with FIPS, use Release")
928+
endif()
929+
927930
# If target ARCH is 32-bit x86, ensure SSE2 is enabled since it's used by the optimized assembly.
928931
# To build for targets that do not support SSE2, use the `OPENSSL_NO_ASM` flag.
929932
if(ARCH STREQUAL "x86" AND NOT OPENSSL_NO_SSE2_FOR_TESTING)

crypto/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ if(NOT OPENSSL_NO_ASM)
103103
else()
104104
if(ARCH STREQUAL "aarch64")
105105
set(PERLASM_STYLE win64)
106+
if("${CMAKE_BUILD_TYPE_LOWER}" STREQUAL "relwithdebinfo" OR
107+
"${CMAKE_BUILD_TYPE_LOWER}" STREQUAL "debug")
108+
# Provide debug in the default format
109+
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -g")
110+
endif()
111+
106112
set(ASM_EXT S)
107113
enable_language(ASM)
108114
else()

crypto/fipsmodule/CMakeLists.txt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,10 @@ elseif(FIPS_SHARED)
523523
message(FATAL_ERROR "FIPS_SHARED set but not BUILD_SHARED_LIBS")
524524
endif()
525525

526+
if (ARCH STREQUAL "aarch64" AND CMAKE_GENERATOR MATCHES "Visual Studio")
527+
msbuild_aarch64_asm(TARGET fipsmodule ASM_FILES ${BCM_ASM_SOURCES} OUTPUT_OBJECTS BCM_ASM_OBJECTS)
528+
endif()
529+
526530
add_library(
527531
fipsmodule
528532

@@ -602,14 +606,18 @@ elseif(FIPS_SHARED)
602606
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/fips_shared_library_marker.c
603607
)
604608

605-
get_filename_component(MSVC_BIN ${CMAKE_LINKER} DIRECTORY)
606-
set(MSVC_LIB "${MSVC_BIN}/lib.exe")
609+
if(CMAKE_AR)
610+
set(MSVC_LIB "${CMAKE_AR}")
611+
else()
612+
get_filename_component(MSVC_BIN ${CMAKE_LINKER} DIRECTORY)
613+
set(MSVC_LIB "${MSVC_BIN}/lib.exe")
614+
endif()
607615

608616
add_custom_command(
609617
OUTPUT ${BCM_NAME}
610618
# This takes bcm_library which is static library and possibly a collection of assembly files in a CMake list.
611-
# lib.exe does not handle the CMake list which uses semicolons between items, this generator expression converts
612-
# it to a list of quoted strings, it also needs to be itself string escaped
619+
# The archiver does not handle the CMake list which uses semicolons between items, this generator expression
620+
# converts it to a list of quoted strings, it also needs to be itself string escaped
613621
COMMAND ${MSVC_LIB} /nologo fips_msvc_start.obj "\"$<JOIN:$<TARGET_OBJECTS:bcm_library>,\" \">\"" fips_msvc_end.obj /OUT:${BCM_NAME}
614622
DEPENDS fips_msvc_start.obj fips_msvc_end.obj bcm_library
615623
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}

tests/ci/run_windows_tests.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ call :build_and_test Release "-DOPENSSL_NO_ASM=1" || goto error
4040
@rem tests or copy them around so Windows can find it in the same directory. Instead just put the dll's location onto the path
4141
set PATH=%BUILD_DIR%;%BUILD_DIR%\crypto;%BUILD_DIR%\ssl;%PATH%
4242
call :build_and_test Release "-DBUILD_SHARED_LIBS=1" || goto error
43+
call :build_and_test Release "-DBUILD_SHARED_LIBS=1 -DFIPS=1" || goto error
4344
if /i not "%ARCH_OPTION%" == "arm64" (
44-
call :build_and_test Release "-DBUILD_SHARED_LIBS=1 -DFIPS=1" || goto error
45-
@rem For FIPS on Windows we also have a RelWithDebInfo build to generate debug symbols.
45+
@rem For FIPS on Windows/x86-64 we also have a RelWithDebInfo build to generate debug symbols.
4646
call :build_and_test RelWithDebInfo "-DBUILD_SHARED_LIBS=1 -DFIPS=1" || goto error
4747
)
4848

0 commit comments

Comments
 (0)