Skip to content

Commit 00fbdcd

Browse files
committed
Merged PR 8050244: Fix Pluton OS Build
Handful of CMake and header changes to support building SymCrypt in the Pluton OS build environment. See individual commit messages for additional details.
1 parent 93a8271 commit 00fbdcd

File tree

4 files changed

+33
-18
lines changed

4 files changed

+33
-18
lines changed

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ if(SYMCRYPT_FIPS_BUILD)
4545
add_compile_options(-DSYMCRYPT_DO_FIPS_SELFTESTS=1)
4646
endif()
4747

48+
option(
49+
SYMCRYPT_STACK_PROTECTION
50+
"When enabled, SymCrypt will enable various stack protection mechanisms to protect against buffer overruns and the like. Only
51+
applicable to non-Windows systems. Defaults to ON, but may need to be disabled for specialized targets such as embedded systems."
52+
ON)
53+
54+
option(
55+
SYMCRYPT_PIC
56+
"When enabled, SymCrypt will be compiled as position-independent code (PIC). Only applicable to non-Windows systems. Defaults to
57+
ON, but may need to be disabled for specialized targets such as embedded systems."
58+
ON)
59+
4860
include(${CMAKE_SOURCE_DIR}/cmake-configs/SymCrypt-Platforms.cmake)
4961

5062
if(NOT DEFINED CMAKE_BUILD_TYPE)

cmake-configs/SymCrypt-Platforms.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ endif()
1414
if(NOT DEFINED SYMCRYPT_TARGET_ARCH)
1515
if(CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|x86_64")
1616
set(SYMCRYPT_TARGET_ARCH "AMD64")
17-
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "[Xx]86")
17+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "[Xx]86|i[3456]86")
1818
set(SYMCRYPT_TARGET_ARCH "X86")
1919
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "ARM64|aarch64")
2020
set(SYMCRYPT_TARGET_ARCH "ARM64")
@@ -55,7 +55,9 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux")
5555
add_compile_options(-Wno-deprecated-declarations -Wno-deprecated)
5656
add_compile_options(-g)
5757
add_compile_options(-Wno-multichar)
58-
add_compile_options(-fPIC)
58+
if(SYMCRYPT_PIC)
59+
add_compile_options(-fPIC)
60+
endif()
5961
add_compile_options(-fno-plt)
6062
add_compile_options(-fno-builtin-bcmp)
6163

inc/symcrypt_internal.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,13 @@ typedef int BOOL;
223223
typedef unsigned int UINT;
224224
typedef unsigned long ULONG;
225225

226-
typedef signed char INT8, *PINT8;
227-
typedef signed short INT16, *PINT16;
228-
typedef signed int INT32, *PINT32;
226+
typedef int8_t INT8, *PINT8;
227+
typedef int16_t INT16, *PINT16;
228+
typedef int32_t INT32, *PINT32;
229229
typedef int64_t INT64, *PINT64;
230-
typedef unsigned char UINT8, *PUINT8;
231-
typedef unsigned short UINT16, *PUINT16;
232-
typedef unsigned int UINT32, *PUINT32;
230+
typedef uint8_t UINT8, *PUINT8;
231+
typedef uint16_t UINT16, *PUINT16;
232+
typedef uint32_t UINT32, *PUINT32;
233233
typedef uint64_t UINT64, *PUINT64;
234234

235235
typedef uint32_t ULONG32, *PULONG32;
@@ -526,10 +526,9 @@ SymCryptCpuFeaturesNeverPresent();
526526
#define SYMCRYPT_BSWAP32( x ) _byteswap_ulong(x)
527527
#define SYMCRYPT_BSWAP64( x ) _byteswap_uint64(x)
528528
#elif SYMCRYPT_GNUC
529-
#include <byteswap.h>
530-
#define SYMCRYPT_BSWAP16( x ) bswap_16(x)
531-
#define SYMCRYPT_BSWAP32( x ) bswap_32(x)
532-
#define SYMCRYPT_BSWAP64( x ) bswap_64(x)
529+
#define SYMCRYPT_BSWAP16( x ) __builtin_bswap16(x)
530+
#define SYMCRYPT_BSWAP32( x ) __builtin_bswap32(x)
531+
#define SYMCRYPT_BSWAP64( x ) __builtin_bswap64(x)
533532
#elif SYMCRYPT_APPLE_CC
534533
#include <libkern/OSByteOrder.h>
535534
#define SYMCRYPT_BSWAP16( x ) OSSwapInt16(x)

lib/CMakeLists.txt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,15 @@ endif()
352352
if(NOT WIN32)
353353
add_compile_options(-Wno-trigraphs)
354354

355-
# Mitigate stack buffer overruns, and stack clash attacks
356-
add_compile_options(-fstack-protector-strong)
357-
add_compile_options(-Wstack-protector)
358-
add_compile_options(--param ssp-buffer-size=4)
355+
if (SYMCRYPT_STACK_PROTECTION)
356+
# Mitigate stack buffer overruns, and stack clash attacks
357+
add_compile_options(-fstack-protector-strong)
358+
add_compile_options(-Wstack-protector)
359+
add_compile_options(--param ssp-buffer-size=4)
359360

360-
if(CMAKE_C_COMPILER_ID MATCHES "GNU")
361-
add_compile_options(-fstack-clash-protection)
361+
if(CMAKE_C_COMPILER_ID MATCHES "GNU")
362+
add_compile_options(-fstack-clash-protection)
363+
endif()
362364
endif()
363365

364366
if(SYMCRYPT_TARGET_ARCH MATCHES "AMD64|X86")

0 commit comments

Comments
 (0)