From 93f535dbc4af31a567853d926ab89f852f304944 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Wed, 6 Sep 2023 15:31:12 +0200 Subject: [PATCH] Added ARM errata mitigations Reworked #189 --- .github/workflows/c-cpp.yml | 10 +++++----- CMakeLists.txt | 7 +++++++ cmake/flags.cmake | 20 ++++++++++++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 94bf9596..fa7eeb87 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -19,7 +19,7 @@ jobs: matrix: config: - {arch: x86_64, flags: "-flto=2 -fuse-linker-plugin -ffunction-sections -Wno-error=inline"} - - {arch: aarch64, flags: "-flto=2 -fuse-linker-plugin -ffunction-sections -Wno-error=inline"} + - {arch: aarch64, flags: "-flto=2 -fuse-linker-plugin -ffunction-sections -Wno-error=inline -mfix-cortex-a53-835769 -mfix-cortex-a53-843419"} steps: - name: Setup Alpine Linux @@ -68,7 +68,7 @@ jobs: run: | mkdir build cd build - cmake .. -DCMAKE_C_FLAGS='${{ matrix.config.flags }} -Wl,-s -Wl,--gc-sections' -DCMAKE_CXX_FLAGS='${{ matrix.config.flags }} -Wl,-s -Wl,--gc-sections' -DSTATIC_BINARY=ON + cmake .. -DCMAKE_C_FLAGS='${{ matrix.config.flags }} -Wl,-s -Wl,--gc-sections' -DCMAKE_CXX_FLAGS='${{ matrix.config.flags }} -Wl,-s -Wl,--gc-sections' -DSTATIC_BINARY=ON -DARCH_ID=${{ matrix.config.arch }} make -j$(nproc) - name: Run RandomX tests @@ -83,7 +83,7 @@ jobs: cd tests mkdir build cd build - cmake .. -DCMAKE_C_FLAGS='${{ matrix.config.flags }} -Wl,-s -Wl,--gc-sections' -DCMAKE_CXX_FLAGS='${{ matrix.config.flags }} -Wl,-s -Wl,--gc-sections' -DSTATIC_LIBS=ON + cmake .. -DCMAKE_C_FLAGS='${{ matrix.config.flags }} -Wl,-s -Wl,--gc-sections' -DCMAKE_CXX_FLAGS='${{ matrix.config.flags }} -Wl,-s -Wl,--gc-sections' -DSTATIC_LIBS=ON -DARCH_ID=${{ matrix.config.arch }} make -j$(nproc) - name: Run tests @@ -246,8 +246,8 @@ jobs: strategy: matrix: config: - - {os: ubuntu-20.04, flags: "-flto=2 -fuse-linker-plugin -ffunction-sections"} - - {os: ubuntu-22.04, flags: "-flto=2 -fuse-linker-plugin -ffunction-sections"} + - {os: ubuntu-20.04, flags: "-flto=2 -fuse-linker-plugin -ffunction-sections -mfix-cortex-a53-835769 -mfix-cortex-a53-843419"} + - {os: ubuntu-22.04, flags: "-flto=2 -fuse-linker-plugin -ffunction-sections -mfix-cortex-a53-835769 -mfix-cortex-a53-843419"} steps: - name: Install dependencies diff --git a/CMakeLists.txt b/CMakeLists.txt index 61864c64..4b9e1db3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -359,3 +359,10 @@ if (STATIC_BINARY OR STATIC_LIBS) else() target_link_libraries(${CMAKE_PROJECT_NAME} debug ${ZMQ_LIBRARY_DEBUG} debug ${UV_LIBRARY_DEBUG} debug ${CURL_LIBRARY_DEBUG} optimized ${ZMQ_LIBRARY} optimized ${UV_LIBRARY} optimized ${CURL_LIBRARY} ${LIBS}) endif() + +message(STATUS "Summary of build options: + C compiler: ${CMAKE_C_COMPILER} (${CMAKE_C_COMPILER_ID}) + CXX compiler: ${CMAKE_CXX_COMPILER} (${CMAKE_CXX_COMPILER_ID}) + C_FLAGS: ${CMAKE_C_FLAGS} + CXX_FLAGS: ${CMAKE_CXX_FLAGS} +") diff --git a/cmake/flags.cmake b/cmake/flags.cmake index bd2c59e8..f7a8d66f 100644 --- a/cmake/flags.cmake +++ b/cmake/flags.cmake @@ -5,9 +5,24 @@ set(CMAKE_CXX_STANDARD 14) set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD_REQUIRED ON) +if(NOT ARCH_ID) + if(CMAKE_SYSTEM_PROCESSOR STREQUAL "") + set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR}) + endif() + string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" ARCH_ID) +endif() + +if (ARCH_ID MATCHES "^(aarch64|arm64|armv8-a)$") + set(ARMv8 1) +endif() + if (CMAKE_CXX_COMPILER_ID MATCHES GNU) set(GENERAL_FLAGS "-pthread") + if (ARMv8) + set(GENERAL_FLAGS "${GENERAL_FLAGS} -mfix-cortex-a53-835769 -mfix-cortex-a53-843419") + endif() + if (DEV_WITH_TSAN) set(GENERAL_FLAGS "${GENERAL_FLAGS} -fno-omit-frame-pointer -fsanitize=thread") endif() @@ -69,11 +84,16 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES MSVC) set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG") elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang) if (WIN32) + set(GENERAL_FLAGS "") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static") else() set(GENERAL_FLAGS "-pthread") endif() + if (ARMv8) + set(GENERAL_FLAGS "${GENERAL_FLAGS} -mfix-cortex-a53-835769 -mfix-cortex-a53-843419") + endif() + set(WARNING_FLAGS "-Wall -Wextra -Wno-undefined-internal -Wunreachable-code-aggressive -Wmissing-prototypes -Wmissing-variable-declarations -Werror") if (DEV_WITH_MSAN)