From c1fdcb9dd73a48a8846ee593beffe9763126c9ee Mon Sep 17 00:00:00 2001 From: zhoufeng Date: Fri, 24 Feb 2023 16:33:24 +0800 Subject: [PATCH] dump debuginfo files when compile with -f option Signed-off-by: zhoufeng --- cmake/package_plugin.cmake | 9 +++++ cmake/plugin_debuginfo_script.cmake | 34 +++++++++++++++++++ .../kernel/aicpu/aicpu_ops/CMakeLists.txt | 5 +++ .../aicpu/aicpu_ops/cpu_kernel/CMakeLists.txt | 1 - 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 cmake/plugin_debuginfo_script.cmake diff --git a/cmake/package_plugin.cmake b/cmake/package_plugin.cmake index c71a7ccff08..65c8c5d68e7 100644 --- a/cmake/package_plugin.cmake +++ b/cmake/package_plugin.cmake @@ -113,4 +113,13 @@ if(ENABLE_AKG AND CMAKE_SYSTEM_NAME MATCHES "Linux") endif() endif() +if(ENABLE_SYM_FILE) + set(CPACK_CUSTOM_INSTALL_VARIABLES) + list(APPEND CPACK_CUSTOM_INSTALL_VARIABLES MS_PACK_ROOT_DIR=${CPACK_PACKAGE_DIRECTORY}) + list(APPEND CPACK_CUSTOM_INSTALL_VARIABLES + MS_INSTALL_DIR=${CPACK_PACKAGE_DIRECTORY}/_CPack_Packages/${CMAKE_HOST_SYSTEM_NAME}/${CPACK_GENERATOR}) + list(APPEND CPACK_CUSTOM_INSTALL_VARIABLES MS_PACKAGE_FILE_NAME=${CPACK_PACKAGE_FILE_NAME}) + install(SCRIPT ${CMAKE_SOURCE_DIR}/cmake/plugin_debuginfo_script.cmake) +endif() + include(CPack) diff --git a/cmake/plugin_debuginfo_script.cmake b/cmake/plugin_debuginfo_script.cmake new file mode 100644 index 00000000000..cb9c43cd549 --- /dev/null +++ b/cmake/plugin_debuginfo_script.cmake @@ -0,0 +1,34 @@ +set(CMAKE_OBJCOPY $ENV{CROSS_COMPILE}objcopy) +set(CMAKE_STRIP $ENV{CROSS_COMPILE}strip) + +file(GLOB ALL_BINARIES + ${MS_INSTALL_DIR}/${MS_PACKAGE_FILE_NAME}/*.so + ${MS_INSTALL_DIR}/${MS_PACKAGE_FILE_NAME}/lib/*.so + ${MS_INSTALL_DIR}/${MS_PACKAGE_FILE_NAME}/lib/plugin/*.so* + ${MS_INSTALL_DIR}/${MS_PACKAGE_FILE_NAME}/lib/plugin/*/*.so + ) + +foreach(item ${ALL_BINARIES}) + execute_process( + COMMAND ${CMAKE_OBJCOPY} --only-keep-debug ${item} ${item}.sym + WORKING_DIRECTORY ${MS_PACK_ROOT_DIR} + ) + execute_process( + COMMAND ${CMAKE_STRIP} ${item} + WORKING_DIRECTORY ${MS_PACK_ROOT_DIR} + ) +endforeach() + +file(GLOB DEBUG_SYM_FILE + ${MS_INSTALL_DIR}/${MS_PACKAGE_FILE_NAME}/*.sym + ${MS_INSTALL_DIR}/${MS_PACKAGE_FILE_NAME}/lib/*.sym + ${MS_INSTALL_DIR}/${MS_PACKAGE_FILE_NAME}/lib/plugin/*.sym + ${MS_INSTALL_DIR}/${MS_PACKAGE_FILE_NAME}/lib/plugin/*/*.sym + ) + +file(MAKE_DIRECTORY ${MS_PACK_ROOT_DIR}/debug_info) +file(COPY ${DEBUG_SYM_FILE} DESTINATION ${MS_PACK_ROOT_DIR}/debug_info/) +file(REMOVE_RECURSE ${DEBUG_SYM_FILE}) +execute_process(COMMAND ${CMAKE_COMMAND} -E tar cfv ${MS_PACKAGE_FILE_NAME}.debuginfo.zip debug_info/ + --format=zip WORKING_DIRECTORY ${MS_PACK_ROOT_DIR}) +file(REMOVE_RECURSE ${MS_PACK_ROOT_DIR}/debug_info) diff --git a/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/CMakeLists.txt b/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/CMakeLists.txt index 79d1c574a5a..7f869ec6f67 100644 --- a/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/CMakeLists.txt +++ b/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/CMakeLists.txt @@ -11,6 +11,11 @@ set(CMAKE_C_COMPILER ${TOOLCHAIN_PATH}/hcc/bin/aarch64-target-linux-gnu-gcc) set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PATH}/hcc/bin/aarch64-target-linux-gnu-g++) if(EXISTS ${CMAKE_C_COMPILER} AND EXISTS ${CMAKE_CXX_COMPILER}) + if(ENABLE_SYM_FILE) + string(REPLACE "-ggdb" " " CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") + string(REPLACE "-g" " " CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") + endif() + include(${CMAKE_SOURCE_DIR}/cmake/dependency_securec_arm.cmake) include(${CMAKE_SOURCE_DIR}/cmake/external_libs/protobuf_arm.cmake) diff --git a/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/cpu_kernel/CMakeLists.txt b/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/cpu_kernel/CMakeLists.txt index d1a3c943cb5..b58d1a2a2c7 100644 --- a/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/cpu_kernel/CMakeLists.txt +++ b/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/cpu_kernel/CMakeLists.txt @@ -57,4 +57,3 @@ install(TARGETS mindspore_cpu_kernels OPTIONAL EXPORT mindspore_cpu_kernels-targets LIBRARY DESTINATION ${INSTALL_LIBRARY_DIR}/ascend ) -