From fa0fa971551269323bc0eade9ca5ab01a29c1c4b Mon Sep 17 00:00:00 2001 From: Daniel Jurek Date: Mon, 3 Jan 2022 13:56:41 -0800 Subject: [PATCH] Generate map files (#3181) * Generate map files in build * Add .map file artifact publishing * Add Xlinker to spelling exceptions * Remove PublishMapFiles from clang builds * Generate the map file artifact name * CXX_COMPILER_ID and some logging for Clang which might be linking using the GNU linker by default * More logging * Move logging out of conditional * Logging up high, use OS to determine which link flags to set * Use linker options specific to AppleClang's context, publish map files for all platforms --- .vscode/cspell.json | 3 ++- CMakeLists.txt | 3 +++ cmake-modules/CreateMapFile.cmake | 21 ++++++++++++++++ eng/pipelines/templates/jobs/ci.tests.yml | 25 +++++++++++++++++++ .../templates/stages/platform-matrix.json | 24 ++++++++++++------ sdk/core/azure-core-test/CMakeLists.txt | 1 + .../test/fault-injector/CMakeLists.txt | 2 ++ sdk/core/azure-core/test/ut/CMakeLists.txt | 7 ++++++ sdk/core/perf/CMakeLists.txt | 1 + sdk/core/perf/test/CMakeLists.txt | 2 ++ .../azure-identity/test/e2e/CMakeLists.txt | 2 +- .../azure-identity/test/perf/CMakeLists.txt | 2 ++ .../azure-identity/test/ut/CMakeLists.txt | 2 ++ .../test/ut/CMakeLists.txt | 2 ++ .../test/perf/CMakeLists.txt | 2 ++ .../test/ut/CMakeLists.txt | 2 ++ .../test/test-app/CMakeLists.txt | 2 ++ .../test/ut/CMakeLists.txt | 2 ++ sdk/storage/CMakeLists.txt | 1 + .../azure-template/test/CMakeLists.txt | 2 ++ 20 files changed, 98 insertions(+), 10 deletions(-) create mode 100644 cmake-modules/CreateMapFile.cmake diff --git a/.vscode/cspell.json b/.vscode/cspell.json index 1a2fc8328..8e418c4fc 100644 --- a/.vscode/cspell.json +++ b/.vscode/cspell.json @@ -170,7 +170,8 @@ "fprofile", "ftest", "mathjax", - "mdfile" + "mdfile", + "Xlinker" ] } ], diff --git a/CMakeLists.txt b/CMakeLists.txt index 114802c37..75a40cfc7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,6 +84,9 @@ endif() # compiler warning flags globally include(AzureGlobalCompileOptions) +# Add create_map_file function +include(CreateMapFile) + # Documentation automation function include(AzureDoxygen) diff --git a/cmake-modules/CreateMapFile.cmake b/cmake-modules/CreateMapFile.cmake new file mode 100644 index 000000000..a1bd9460f --- /dev/null +++ b/cmake-modules/CreateMapFile.cmake @@ -0,0 +1,21 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# SPDX-License-Identifier: MIT +# +# Instructs linker to generate map files and optimize build for minimal size +# Requires CMake version >= 3.13 to use add_link_options + +function(create_map_file TARGET_NAME MAP_FILE_NAME) + if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.13") + if(MSVC) + target_link_options(${TARGET_NAME} PRIVATE /MAP) + elseif(CMAKE_CXX_COMPILER_ID MATCHES "AppleClang") + target_link_options(${TARGET_NAME} PRIVATE LINKER:SHELL:-Wl,-map,${MAP_FILE_NAME}) + target_link_options(${TARGET_NAME} PRIVATE -Os) + else() + target_link_options(${TARGET_NAME} PRIVATE -Xlinker -Map=${MAP_FILE_NAME}) + target_link_options(${TARGET_NAME} PRIVATE -Os) + endif() + else() + message("Skipping map file generation because CMake version does not support target_link_options") + endif() +endfunction() diff --git a/eng/pipelines/templates/jobs/ci.tests.yml b/eng/pipelines/templates/jobs/ci.tests.yml index 9e6b3bd9c..291083e0c 100644 --- a/eng/pipelines/templates/jobs/ci.tests.yml +++ b/eng/pipelines/templates/jobs/ci.tests.yml @@ -200,3 +200,28 @@ jobs: # Minimum baseline for branch coverage coverageThreshold: ${{ parameters.BranchCoverageTarget }} condition: and(succeededOrFailed(), eq(variables['CODE_COVERAGE'], 'enabled'), eq(variables['Skip.BranchCoverageEnforcement'], '')) + + # Use the job name to create the artifact name for MAP file publishing. + # "Validate Windows2019_UWP_debug_x86" -> "Windows2019_UWP_debug_x86" + - pwsh: | + $artifactName = '$(Agent.JobName)' + $parts = $artifactName -split ' ' + if ($parts[1]) { + $artifactName = $parts[1] + } + Write-Host "##vso[task.setvariable variable=MapFileArtifactName;]$artifactName" + displayName: Set map file artifact name + condition: eq(variables['PublishMapFiles'], 'true') + + - task: CopyFiles@2 + inputs: + contents: "**/*.map" + targetFolder: $(Build.ArtifactStagingDirectory) + flattenFolders: true + condition: eq(variables['PublishMapFiles'], 'true') + + - task: PublishPipelineArtifact@1 + inputs: + artifactName: map-files-$(MapFileArtifactName) + path: $(Build.ArtifactStagingDirectory) + condition: eq(variables['PublishMapFiles'], 'true') \ No newline at end of file diff --git a/eng/pipelines/templates/stages/platform-matrix.json b/eng/pipelines/templates/stages/platform-matrix.json index d0f669cd0..748ef1986 100644 --- a/eng/pipelines/templates/stages/platform-matrix.json +++ b/eng/pipelines/templates/stages/platform-matrix.json @@ -19,7 +19,8 @@ "VcpkgInstall": "curl[ssl] libxml2 openssl", "BuildArgs": "-j 10", "VCPKG_DEFAULT_TRIPLET": "x64-osx", - "CmakeArgs": " -DBUILD_TESTING=ON -DBUILD_PERFORMANCE_TESTS=ON -DRUN_LONG_UNIT_TESTS=ON -DBUILD_TRANSPORT_CURL=ON" + "CmakeArgs": " -DBUILD_TESTING=ON -DBUILD_PERFORMANCE_TESTS=ON -DRUN_LONG_UNIT_TESTS=ON -DBUILD_TRANSPORT_CURL=ON", + "PublishMapFiles": "true" } }, "BuildConfig": { @@ -48,11 +49,13 @@ "Win32Api_release_curl": { "VcpkgInstall": "curl[winssl]", "CmakeArgs": " -DBUILD_TESTING=ON -DBUILD_PERFORMANCE_TESTS=ON -DRUN_LONG_UNIT_TESTS=ON -DBUILD_TRANSPORT_CURL=ON", - "CMAKE_BUILD_TYPE": "Release" + "CMAKE_BUILD_TYPE": "Release", + "PublishMapFiles": "true" }, "Win32Api_debug_tests": { "VcpkgInstall": "curl[winssl]", - "CmakeArgs": " -DBUILD_TESTING=ON -DBUILD_PERFORMANCE_TESTS=ON -DRUN_LONG_UNIT_TESTS=ON -DBUILD_TRANSPORT_CURL=ON -DBUILD_TRANSPORT_WINHTTP=ON" + "CmakeArgs": " -DBUILD_TESTING=ON -DBUILD_PERFORMANCE_TESTS=ON -DRUN_LONG_UNIT_TESTS=ON -DBUILD_TRANSPORT_CURL=ON -DBUILD_TRANSPORT_WINHTTP=ON", + "PublishMapFiles": "true" } }, "TargetArchitecture": { @@ -73,7 +76,8 @@ "Pool": "azsdk-pool-mms-win-2019-general", "BuildArgs": "--parallel 8", "CMAKE_GENERATOR": "Visual Studio 16 2019", - "CmakeArgs": " -DBUILD_TRANSPORT_WINHTTP=ON -DBUILD_TESTING=ON -DBUILD_PERFORMANCE_TESTS=ON -DRUN_LONG_UNIT_TESTS=ON" + "CmakeArgs": " -DBUILD_TRANSPORT_WINHTTP=ON -DBUILD_TESTING=ON -DBUILD_PERFORMANCE_TESTS=ON -DRUN_LONG_UNIT_TESTS=ON", + "PublishMapFiles": "true" } }, "TargetPlatform": { @@ -126,15 +130,18 @@ "AptDependencies": "gcovr lcov", "CmakeArgs": " -DBUILD_TESTING=ON -DBUILD_PERFORMANCE_TESTS=ON -DRUN_LONG_UNIT_TESTS=ON -DCMAKE_BUILD_TYPE=Debug -DBUILD_CODE_COVERAGE=ON -DCMAKE_VERBOSE_MAKEFILE=ON", "CODE_COVERAGE_COLLECT_ONLY": "1", - "CODE_COVERAGE": "enabled" + "CODE_COVERAGE": "enabled", + "PublishMapFiles": "true" }, "included": {}, "included_release": { "CMAKE_BUILD_TYPE": "Release", - "CmakeArgs": " -DBUILD_TESTING=ON -DBUILD_PERFORMANCE_TESTS=ON -DRUN_LONG_UNIT_TESTS=ON" + "CmakeArgs": " -DBUILD_TESTING=ON -DBUILD_PERFORMANCE_TESTS=ON -DRUN_LONG_UNIT_TESTS=ON", + "PublishMapFiles": "true" }, "included_samples": { - "CmakeArgs": " -DBUILD_TESTING=ON -DBUILD_SAMPLES=ON -DBUILD_STORAGE_SAMPLES=ON" + "CmakeArgs": " -DBUILD_TESTING=ON -DBUILD_SAMPLES=ON -DBUILD_STORAGE_SAMPLES=ON", + "PublishMapFiles": "true" } } }, @@ -148,7 +155,8 @@ "BuildArgs": "-j 10", "CC": "/usr/bin/clang-11", "CXX": "/usr/bin/clang++-11", - "CmakeArgs": " -DBUILD_TESTING=ON -DBUILD_PERFORMANCE_TESTS=ON -DRUN_LONG_UNIT_TESTS=ON" + "CmakeArgs": " -DBUILD_TESTING=ON -DBUILD_PERFORMANCE_TESTS=ON -DRUN_LONG_UNIT_TESTS=ON", + "PublishMapFiles": "true" } }, "BuildSettings": { diff --git a/sdk/core/azure-core-test/CMakeLists.txt b/sdk/core/azure-core-test/CMakeLists.txt index df6f8425b..225091a2c 100644 --- a/sdk/core/azure-core-test/CMakeLists.txt +++ b/sdk/core/azure-core-test/CMakeLists.txt @@ -48,3 +48,4 @@ target_include_directories (azure-core-test-fw # make sure that users can consume the project as a library. add_library (Azure::Core::Test ALIAS azure-core-test-fw) target_link_libraries(azure-core-test-fw PRIVATE azure-core gtest) +create_map_file(azure-core-test-fw azure-core-test-fw.map) \ No newline at end of file diff --git a/sdk/core/azure-core/test/fault-injector/CMakeLists.txt b/sdk/core/azure-core/test/fault-injector/CMakeLists.txt index 13c3f9df7..abec21b63 100644 --- a/sdk/core/azure-core/test/fault-injector/CMakeLists.txt +++ b/sdk/core/azure-core/test/fault-injector/CMakeLists.txt @@ -15,3 +15,5 @@ add_executable ( ) target_link_libraries(azure-core-test-fault-injector PRIVATE azure-core) + +create_map_file(azure-core-test-fault-injector azure-core-test-fault-injector.map) diff --git a/sdk/core/azure-core/test/ut/CMakeLists.txt b/sdk/core/azure-core/test/ut/CMakeLists.txt index 92cbc7320..95a5ef8ed 100644 --- a/sdk/core/azure-core/test/ut/CMakeLists.txt +++ b/sdk/core/azure-core/test/ut/CMakeLists.txt @@ -100,11 +100,16 @@ target_include_directories (azure-core-test PRIVATE $