From 0a0551cf26ecdfd849d30270061b76a29c24f294 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 13 Mar 2024 12:11:19 +1100 Subject: [PATCH] CMake: suppress warnings building with mold on Linux Support manipulating symbols_unix.map using symbols_unix.map.cmake script. Currently this removes symbols that generate noisy warnings with the mold linker. --- .../cmake/platform/platform_unix.cmake | 7 +++++ source/creator/CMakeLists.txt | 24 +++++++++++++++ source/creator/symbols_unix.map.cmake | 30 +++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 source/creator/symbols_unix.map.cmake diff --git a/build_files/cmake/platform/platform_unix.cmake b/build_files/cmake/platform/platform_unix.cmake index b8c20e2106e..e01c1f8aa1f 100644 --- a/build_files/cmake/platform/platform_unix.cmake +++ b/build_files/cmake/platform/platform_unix.cmake @@ -1078,6 +1078,13 @@ unset(_IS_LINKER_DEFAULT) # Avoid conflicts with Mesa llvmpipe, Luxrender, and other plug-ins that may # use the same libraries as Blender with a different version or build options. set(PLATFORM_SYMBOLS_MAP ${CMAKE_SOURCE_DIR}/source/creator/symbols_unix.map) + +# Prevent noisy warnings for symbols that MOLD doesn't define. +if(WITH_LINKER_MOLD) + set(PLATFORM_SYMBOLS_MAP_SOURCE "${PLATFORM_SYMBOLS_MAP}") + set(PLATFORM_SYMBOLS_MAP ${CMAKE_BINARY_DIR}/source/creator/symbols_unix.map.gen) +endif() + set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -Wl,--version-script='${PLATFORM_SYMBOLS_MAP}'" ) diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt index a5dac69c46f..572ae34339a 100644 --- a/source/creator/CMakeLists.txt +++ b/source/creator/CMakeLists.txt @@ -148,6 +148,30 @@ set(SRC creator_intern.h ) +# When a source is defined, the map file is generated and may need to be re-generated. +if(DEFINED PLATFORM_SYMBOLS_MAP) + list(APPEND SRC "${PLATFORM_SYMBOLS_MAP}") + + if(DEFINED PLATFORM_SYMBOLS_MAP_SOURCE) + add_custom_command( + COMMAND + "${CMAKE_COMMAND}" + -D "PLATFORM_SYMBOLS_MAP_SOURCE=${PLATFORM_SYMBOLS_MAP_SOURCE}" + -D "PLATFORM_SYMBOLS_MAP=${PLATFORM_SYMBOLS_MAP}" + -D "WITH_LINKER_MOLD=${WITH_LINKER_MOLD}" + -D "WITH_LINKER_GOLD=${WITH_LINKER_GOLD}" + -D "WITH_LINKER_LLD=${WITH_LINKER_LLD}" + -P "${PLATFORM_SYMBOLS_MAP_SOURCE}.cmake" + DEPENDS + "${PLATFORM_SYMBOLS_MAP_SOURCE}" + "${PLATFORM_SYMBOLS_MAP_SOURCE}.cmake" + OUTPUT + "${PLATFORM_SYMBOLS_MAP}" + ) + set_source_files_properties("${PLATFORM_SYMBOLS_MAP}" PROPERTIES GENERATED TRUE) + endif() +endif() + if(CMAKE_GENERATOR MATCHES "^Visual Studio.+") # This helps visual studio find the debugger visualizers list(APPEND SRC ${CMAKE_SOURCE_DIR}/tools/utils_ide/natvis/Blender.natvis) diff --git a/source/creator/symbols_unix.map.cmake b/source/creator/symbols_unix.map.cmake new file mode 100644 index 00000000000..40d3395dc29 --- /dev/null +++ b/source/creator/symbols_unix.map.cmake @@ -0,0 +1,30 @@ +# SPDX-FileCopyrightText: 2024 Blender Authors +# +# SPDX-License-Identifier: GPL-2.0-or-later + +# This script generates a modified symbols map, +# use this for situations where dynamic modifications of symbols map is needed, +# or done to suppress noisy output. + +if(NOT DEFINED PLATFORM_SYMBOLS_MAP_SOURCE) + message(FATAL_ERROR "PLATFORM_SYMBOLS_MAP_SOURCE was not defined!") +endif() +if(NOT DEFINED PLATFORM_SYMBOLS_MAP) + message(FATAL_ERROR "PLATFORM_SYMBOLS_MAP was not defined!") +endif() + +file(READ "${PLATFORM_SYMBOLS_MAP_SOURCE}" file_data) + +if(WITH_LINKER_MOLD) + # These generate noisy warnings. + set(sym_list_remove + " _bss_start\;" + " __end\;" + " aligned_free\;" + ) + foreach(sym ${sym_list_remove}) + string(REPLACE "${sym}" "/* ${sym} */" file_data "${file_data}") + endforeach() +endif() + +file(WRITE "${PLATFORM_SYMBOLS_MAP}" "${file_data}")