From 377da0ed0c346ca5c9e2381baf61215d5fb3db6a Mon Sep 17 00:00:00 2001 From: Chris Burel Date: Mon, 14 Feb 2022 16:13:37 -0800 Subject: [PATCH 1/3] Ignore unused benchmark state variables Signed-off-by: Chris Burel --- Code/Framework/AzCore/Tests/DOM/DomPatchBenchmarks.cpp | 4 ++-- Code/Framework/AzCore/Tests/DOM/DomPathBenchmarks.cpp | 2 +- Gems/SurfaceData/Code/Tests/SurfaceDataBenchmarks.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Code/Framework/AzCore/Tests/DOM/DomPatchBenchmarks.cpp b/Code/Framework/AzCore/Tests/DOM/DomPatchBenchmarks.cpp index e44ba3ce67..d67597255f 100644 --- a/Code/Framework/AzCore/Tests/DOM/DomPatchBenchmarks.cpp +++ b/Code/Framework/AzCore/Tests/DOM/DomPatchBenchmarks.cpp @@ -78,7 +78,7 @@ namespace AZ::Dom::Benchmark if (apply) { auto patchInfo = GenerateHierarchicalDeltaPatch(m_before, m_after); - for (auto _ : state) + for ([[maybe_unused]] auto _ : state) { auto patchResult = patchInfo.m_forwardPatches.Apply(m_before); benchmark::DoNotOptimize(patchResult); @@ -86,7 +86,7 @@ namespace AZ::Dom::Benchmark } else { - for (auto _ : state) + for ([[maybe_unused]] auto _ : state) { auto patchInfo = GenerateHierarchicalDeltaPatch(m_before, m_after); benchmark::DoNotOptimize(patchInfo); diff --git a/Code/Framework/AzCore/Tests/DOM/DomPathBenchmarks.cpp b/Code/Framework/AzCore/Tests/DOM/DomPathBenchmarks.cpp index 10c5fa1394..56d1e1f6ab 100644 --- a/Code/Framework/AzCore/Tests/DOM/DomPathBenchmarks.cpp +++ b/Code/Framework/AzCore/Tests/DOM/DomPathBenchmarks.cpp @@ -104,7 +104,7 @@ namespace AZ::Dom::Benchmark PathEntry endOfArray; endOfArray.SetEndOfArray(); - for (auto _ : state) + for ([[maybe_unused]] auto _ : state) { benchmark::DoNotOptimize(name == name); benchmark::DoNotOptimize(name == index); diff --git a/Gems/SurfaceData/Code/Tests/SurfaceDataBenchmarks.cpp b/Gems/SurfaceData/Code/Tests/SurfaceDataBenchmarks.cpp index 187ace1cdb..549e8b8bea 100644 --- a/Gems/SurfaceData/Code/Tests/SurfaceDataBenchmarks.cpp +++ b/Gems/SurfaceData/Code/Tests/SurfaceDataBenchmarks.cpp @@ -289,7 +289,7 @@ namespace UnitTest tag = randomGenerator.GetRandom(); } - for (auto _ : state) + for ([[maybe_unused]] auto _ : state) { // We'll benchmark this two ways: // 1. We clear each time, which means each AddSurfaceWeightIfGreater call will search the whole list then add. @@ -340,7 +340,7 @@ namespace UnitTest comparisonTags.emplace_back(tag ^ 0x01); } - for (auto _ : state) + for ([[maybe_unused]] auto _ : state) { // Test to see if any of our tags match. // All of comparison tags should get compared against all of the added tags. From 8acda7d04de1515debf6a638aad6cead3fc20d4e Mon Sep 17 00:00:00 2001 From: Chris Burel Date: Mon, 14 Feb 2022 16:23:27 -0800 Subject: [PATCH 2/3] Prefer CMake's built-in `-fPIC` and `-fpie` support CMake has a built-in property, `POSITION_INDEPENDENT_CODE`, that determines if code will be built with `-fPIC`. This property is `True` by default for `SHARED` and `MODULE` library targets and `False` otherwise. Previously, we were always passing the `-fPIC` flag manually. With this change, we set the appropriate CMake variable that will enable the property for all compile jobs. Furthermore, with CMake policy CMP0083 set to "new" (which happens by default when the `cmake_minimum_required` version is >=3.14), CMake has built-in support for passing the `-fpie` flag when building executables. It uses the same property, `POSITION_INDEPENDENT_CODE`, so setting this property (and enabling it with the CMake `CheckPIESupported` module) allows us to use CMake's built-in support for these flags. Signed-off-by: Chris Burel --- cmake/Platform/Common/Clang/Configurations_clang.cmake | 2 -- cmake/Platform/Common/Configurations_common.cmake | 5 +++++ cmake/Platform/Linux/Configurations_linux.cmake | 2 -- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cmake/Platform/Common/Clang/Configurations_clang.cmake b/cmake/Platform/Common/Clang/Configurations_clang.cmake index fee81f7132..88789ad0d2 100644 --- a/cmake/Platform/Common/Clang/Configurations_clang.cmake +++ b/cmake/Platform/Common/Clang/Configurations_clang.cmake @@ -20,8 +20,6 @@ ly_append_configurations_options( -Wall -Werror - -fpie # Position-Independent Executables - ################### # Disabled warnings (please do not disable any others without first consulting sig-build) ################### diff --git a/cmake/Platform/Common/Configurations_common.cmake b/cmake/Platform/Common/Configurations_common.cmake index d16dfa3eea..c2ba5477e7 100644 --- a/cmake/Platform/Common/Configurations_common.cmake +++ b/cmake/Platform/Common/Configurations_common.cmake @@ -62,3 +62,8 @@ if(CMAKE_GENERATOR MATCHES "Ninja") ly_set(CMAKE_JOB_POOL_LINK link_job_pool) endif() endif() + +set(CMAKE_POSITION_INDEPENDENT_CODE True) + +include(CheckPIESupported) +check_pie_supported() diff --git a/cmake/Platform/Linux/Configurations_linux.cmake b/cmake/Platform/Linux/Configurations_linux.cmake index 3c3ea5bf62..37ef2f8fc3 100644 --- a/cmake/Platform/Linux/Configurations_linux.cmake +++ b/cmake/Platform/Linux/Configurations_linux.cmake @@ -16,7 +16,6 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") __linux__ LINUX64 COMPILATION - -fPIC -msse4.1 LINK_NON_STATIC -Wl,-undefined,error @@ -47,7 +46,6 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") __linux__ LINUX64 COMPILATION - -fPIC -msse4.1 LINK_NON_STATIC ${LY_GCC_GCOV_LFLAGS} From c89376e9c3b501bd02fff2485f6450c4a3873c3e Mon Sep 17 00:00:00 2001 From: Chris Burel Date: Mon, 14 Feb 2022 16:24:49 -0800 Subject: [PATCH 3/3] The flag is `--no-undefined`, not `-Wl,-undefined,error` Signed-off-by: Chris Burel --- cmake/Platform/Linux/Configurations_linux.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Platform/Linux/Configurations_linux.cmake b/cmake/Platform/Linux/Configurations_linux.cmake index 37ef2f8fc3..09a6feaf15 100644 --- a/cmake/Platform/Linux/Configurations_linux.cmake +++ b/cmake/Platform/Linux/Configurations_linux.cmake @@ -18,7 +18,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") COMPILATION -msse4.1 LINK_NON_STATIC - -Wl,-undefined,error + -Wl,--no-undefined -fpie -Wl,-z,relro,-z,now -Wl,-z,noexecstack