From 2acbecc1b9e3e669627573c707d2137a5e3b02ad Mon Sep 17 00:00:00 2001 From: Ranjith Ramakrishnan Date: Fri, 3 Mar 2023 00:24:25 -0800 Subject: [PATCH 01/11] SWDEV-351540 - ASAN packaging for rocm-core Package only ASAN libraries Component based install Suffix "asan" added to package name Change-Id: Ic758eefef27742df3a4a4301fd3661714de4bb36 --- CMakeLists.txt | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b769fe360..0b6c24edd7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,7 +69,7 @@ set( SRCS rocm_version.cpp ) add_library( ${CORE_TARGET} ${SRCS} ) set( CXX_FLAGS ${CXX_FLAGS} -g -fPIC -fvisibility=hidden -W -Wall -Wextra -Wno-unused-parameter -Wformat-security -Wundef -Wshadow -Wpointer-arith -Wcast-qual -Wmissing-declarations -Wredundant-decls -Wunreachable-code -std=c++11 ) -set( CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} "-Wl,-z,nodelete -Wl,-no-undefined" ) +set( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,nodelete -Wl,-no-undefined" ) target_include_directories( ${CORE_TARGET} PRIVATE ${BUILD_DIR} ) ## Set the VERSION and SOVERSION values @@ -77,17 +77,25 @@ set( SO_VERSION_STRING "${SO_MAJOR}.${SO_MINOR}.${ROCM_LIBPATCH_VERSION}" ) set_property( TARGET ${CORE_TARGET} PROPERTY VERSION "${SO_VERSION_STRING}" ) set_property( TARGET ${CORE_TARGET} PROPERTY SOVERSION "${SO_MAJOR}" ) +if(ENABLE_ASAN_PACKAGING) + # Only libraries required for ASAN Package + set( CPACK_COMPONENTS_ALL asan ) + set(COMP_TYPE "asan") +else() + set( CPACK_COMPONENTS_ALL runtime ) + set(COMP_TYPE "runtime") +endif() #intallation directive file ( WRITE "${CMAKE_CURRENT_BINARY_DIR}/version" "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-${BUILD_ID}\n" ) -install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/version DESTINATION .info ) -install ( TARGETS ${CORE_TARGET} DESTINATION ${CMAKE_INSTALL_LIBDIR} PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) -install ( FILES ${BUILD_DIR}/rocm_version.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) -install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/rocmmod DESTINATION ${CMAKE_INSTALL_LIBDIR} ) - +install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/version DESTINATION .info COMPONENT runtime ) +install ( TARGETS ${CORE_TARGET} DESTINATION ${CMAKE_INSTALL_LIBDIR} + PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE + COMPONENT ${COMP_TYPE} ) +install ( FILES ${BUILD_DIR}/rocm_version.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT runtime ) +install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/rocmmod DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT runtime ) ## Packaging directives -set ( CPACK_PACKAGE_NAME ${CORE_TARGET} ) set ( CPACK_PACKAGE_VENDOR "Advanced Micro Devices, Inc." ) set ( CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR} ) set ( CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR} ) @@ -96,7 +104,6 @@ set ( CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERS set ( CPACK_PACKAGE_CONTACT "ROCm Dev Support " ) set ( CPACK_PACKAGE_DESCRIPTION_SUMMARY "Radeon Open Compute (ROCm) Runtime software stack" ) set ( CPACK_RESOURCE_FILE_LICENSE "${COPYRIGHT_FILE}" ) - ## packaging variables if ( DEFINED ROCM_LIBPATCH_VERSION ) set ( CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}.${ROCM_LIBPATCH_VERSION}" ) @@ -104,10 +111,18 @@ if ( DEFINED ROCM_LIBPATCH_VERSION ) endif() ## Debian package specific variables +set ( CPACK_DEB_COMPONENT_INSTALL ON ) +set ( CPACK_DEBIAN_RUNTIME_PACKAGE_NAME "${CORE_TARGET}" ) +# ASAN package name +set ( CPACK_DEBIAN_ASAN_PACKAGE_NAME ${CORE_TARGET}-asan ) message ( STATUS "Using CPACK_DEBIAN_PACKAGE_RELEASE ${CPACK_DEBIAN_PACKAGE_RELEASE}" ) set ( CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT" ) ## RPM package specific variables +set ( CPACK_RPM_COMPONENT_INSTALL ON ) +set ( CPACK_RPM_RUNTIME_PACKAGE_NAME "${CORE_TARGET}" ) +# ASAN package name +set ( CPACK_RPM_ASAN_PACKAGE_NAME ${CORE_TARGET}-asan ) ## 'dist' breaks manual builds on debian systems due to empty Provides execute_process( COMMAND rpm --eval %{?dist} @@ -124,13 +139,17 @@ set ( CPACK_RPM_FILE_NAME "RPM-DEFAULT" ) # Debian package specific variables set ( CPACK_DEBIAN_PACKAGE_DEPENDS ${DEB_DEPENDS_STRING} ) set ( CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/RadeonOpenCompute/ROCm" ) -set ( CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${BUILD_DIR}/postinst;${BUILD_DIR}/prerm" ) +if(NOT ENABLE_ASAN_PACKAGING) + set ( CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${BUILD_DIR}/postinst;${BUILD_DIR}/prerm" ) +endif() ## RPM package specific variables set ( CPACK_RPM_PACKAGE_REQUIRES ${RPM_DEPENDS_STRING} ) set ( CPACK_RPM_PACKAGE_LICENSE "MIT" ) -set ( CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/postinst" ) -set ( CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/prerm" ) +if(NOT ENABLE_ASAN_PACKAGING) + set ( CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/postinst" ) + set ( CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/prerm" ) +endif() if ( DEFINED CPACK_PACKAGING_INSTALL_PREFIX ) set ( CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "${CPACK_PACKAGING_INSTALL_PREFIX} ${CPACK_PACKAGING_INSTALL_PREFIX}/.info" ) From 572f1cc601003beee7f93baaed7a4bb2241f17a3 Mon Sep 17 00:00:00 2001 From: Ranjith Ramakrishnan Date: Tue, 14 Mar 2023 10:43:32 -0700 Subject: [PATCH 02/11] SWDEV-351540 - Improvements for ASAN changes in rocm-core License file added to rocm-core asan and normal package Package description updated for ASAN package Added rocm-core-asan dependency to rocm-core, so that removing rocm-core will cleanup all asan pacakges as well Added component name to cpack post install variables Change-Id: Id8b69b4469ff3c66a6bd32503defd6411ce3b6c7 --- CMakeLists.txt | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b6c24edd7..6a8743d24c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,10 +80,12 @@ set_property( TARGET ${CORE_TARGET} PROPERTY SOVERSION "${SO_MAJOR}" ) if(ENABLE_ASAN_PACKAGING) # Only libraries required for ASAN Package set( CPACK_COMPONENTS_ALL asan ) - set(COMP_TYPE "asan") + set( COMP_TYPE "asan" ) + set( PKG_DESCRIPTION "Radeon Open Compute (ROCm) AddressSanitizer Instrumented Runtime software stack" ) else() set( CPACK_COMPONENTS_ALL runtime ) - set(COMP_TYPE "runtime") + set( COMP_TYPE "runtime" ) + set( PKG_DESCRIPTION "Radeon Open Compute (ROCm) Runtime software stack" ) endif() #intallation directive @@ -95,6 +97,10 @@ install ( TARGETS ${CORE_TARGET} DESTINATION ${CMAKE_INSTALL_LIBDIR} install ( FILES ${BUILD_DIR}/rocm_version.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT runtime ) install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/rocmmod DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT runtime ) +# License file +install(FILES ${COPYRIGHT_FILE} DESTINATION ${CMAKE_INSTALL_DOCDIR} RENAME LICENSE.txt COMPONENT runtime) +install(FILES ${COPYRIGHT_FILE} DESTINATION ${CMAKE_INSTALL_DOCDIR}-asan RENAME LICENSE.txt COMPONENT asan) + ## Packaging directives set ( CPACK_PACKAGE_VENDOR "Advanced Micro Devices, Inc." ) set ( CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR} ) @@ -102,7 +108,7 @@ set ( CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR} ) set ( CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH} ) set ( CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}" ) set ( CPACK_PACKAGE_CONTACT "ROCm Dev Support " ) -set ( CPACK_PACKAGE_DESCRIPTION_SUMMARY "Radeon Open Compute (ROCm) Runtime software stack" ) +set ( CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PKG_DESCRIPTION}" ) set ( CPACK_RESOURCE_FILE_LICENSE "${COPYRIGHT_FILE}" ) ## packaging variables if ( DEFINED ROCM_LIBPATCH_VERSION ) @@ -138,18 +144,16 @@ set ( CPACK_RPM_FILE_NAME "RPM-DEFAULT" ) # Debian package specific variables set ( CPACK_DEBIAN_PACKAGE_DEPENDS ${DEB_DEPENDS_STRING} ) +set ( CPACK_DEBIAN_ASAN_PACKAGE_DEPENDS ${CORE_TARGET} ) set ( CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/RadeonOpenCompute/ROCm" ) -if(NOT ENABLE_ASAN_PACKAGING) - set ( CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${BUILD_DIR}/postinst;${BUILD_DIR}/prerm" ) -endif() +set ( CPACK_DEBIAN_RUNTIME_PACKAGE_CONTROL_EXTRA "${BUILD_DIR}/postinst;${BUILD_DIR}/prerm" ) ## RPM package specific variables set ( CPACK_RPM_PACKAGE_REQUIRES ${RPM_DEPENDS_STRING} ) +set ( CPACK_RPM_ASAN_PACKAGE_REQUIRES ${CORE_TARGET} ) set ( CPACK_RPM_PACKAGE_LICENSE "MIT" ) -if(NOT ENABLE_ASAN_PACKAGING) - set ( CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/postinst" ) - set ( CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/prerm" ) -endif() +set ( CPACK_RPM_RUNTIME_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/postinst" ) +set ( CPACK_RPM_RUNTIME_POST_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/prerm" ) if ( DEFINED CPACK_PACKAGING_INSTALL_PREFIX ) set ( CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "${CPACK_PACKAGING_INSTALL_PREFIX} ${CPACK_PACKAGING_INSTALL_PREFIX}/.info" ) From f347955757a893f9a9c12110f530ee4a87c48748 Mon Sep 17 00:00:00 2001 From: Icarus Sparry Date: Wed, 5 Apr 2023 07:16:56 +0000 Subject: [PATCH 03/11] Update rocm module for MANPATH Allow access to the manuals for llvm Change-Id: Iea4c83412ff2defb0a2a013aab1a555eb3e24e8c Signed-off-by: Icarus Sparry --- rocmmod.in | 1 + 1 file changed, 1 insertion(+) diff --git a/rocmmod.in b/rocmmod.in index 6acde293f8..ba5c23780d 100644 --- a/rocmmod.in +++ b/rocmmod.in @@ -11,6 +11,7 @@ proc ModulesHelp { } { prepend-path PATH "@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_BINDIR@:@CPACK_PACKAGING_INSTALL_PREFIX@/llvm/bin" +prepend-path MANPATH "@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_MANDIR@:@CPACK_PACKAGING_INSTALL_PREFIX@/llvm/share/man1" prepend-path CMAKE_PREFIX_PATH "@CPACK_PACKAGING_INSTALL_PREFIX@" setenv ROCM_PATH "@CPACK_PACKAGING_INSTALL_PREFIX@" setenv HIP_PATH "@CPACK_PACKAGING_INSTALL_PREFIX@" From 8ce1529027a789e51758f00c400acf148c4f3765 Mon Sep 17 00:00:00 2001 From: Ranjith Ramakrishnan Date: Thu, 18 May 2023 05:22:02 -0700 Subject: [PATCH 04/11] For testing purpose removing the dependency of rocm-core-asan with rocm-core The change is made temporarily for testing the ASAN jenkins build. Need to revert this change after testing Change-Id: Icbfcfec423170114becdc82696afcf54b6d79d48 --- CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a8743d24c..6f68bb9a8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -144,13 +144,15 @@ set ( CPACK_RPM_FILE_NAME "RPM-DEFAULT" ) # Debian package specific variables set ( CPACK_DEBIAN_PACKAGE_DEPENDS ${DEB_DEPENDS_STRING} ) -set ( CPACK_DEBIAN_ASAN_PACKAGE_DEPENDS ${CORE_TARGET} ) +# TODO: Need to enable this later :Commenting for testing purpose +#set ( CPACK_DEBIAN_ASAN_PACKAGE_DEPENDS ${CORE_TARGET} ) set ( CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/RadeonOpenCompute/ROCm" ) set ( CPACK_DEBIAN_RUNTIME_PACKAGE_CONTROL_EXTRA "${BUILD_DIR}/postinst;${BUILD_DIR}/prerm" ) ## RPM package specific variables set ( CPACK_RPM_PACKAGE_REQUIRES ${RPM_DEPENDS_STRING} ) -set ( CPACK_RPM_ASAN_PACKAGE_REQUIRES ${CORE_TARGET} ) +# TODO: Need to enable this later :Commenting for testing purpose +#set ( CPACK_RPM_ASAN_PACKAGE_REQUIRES ${CORE_TARGET} ) set ( CPACK_RPM_PACKAGE_LICENSE "MIT" ) set ( CPACK_RPM_RUNTIME_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/postinst" ) set ( CPACK_RPM_RUNTIME_POST_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/prerm" ) From 3d625f35e8eb263fa8292e0ebe224024260155a6 Mon Sep 17 00:00:00 2001 From: Ranjith Ramakrishnan Date: Tue, 25 Jul 2023 17:36:28 -0700 Subject: [PATCH 05/11] SWDEV-366827 - Header file installation path changed as per file reorganization Change-Id: Idb94bd3c4cb32fa11ee6821b62ccd04d77a830e8 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f68bb9a8e..271c6647e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,7 +94,7 @@ install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/version DESTINATION .info COMPONENT install ( TARGETS ${CORE_TARGET} DESTINATION ${CMAKE_INSTALL_LIBDIR} PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE COMPONENT ${COMP_TYPE} ) -install ( FILES ${BUILD_DIR}/rocm_version.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT runtime ) +install ( FILES ${BUILD_DIR}/rocm_version.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/rocm-core COMPONENT runtime ) install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/rocmmod DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT runtime ) # License file From 86b7e2ff4f54f945076b704232a32b47893d5e44 Mon Sep 17 00:00:00 2001 From: Ranjith Ramakrishnan Date: Wed, 2 Aug 2023 13:34:37 -0400 Subject: [PATCH 06/11] Revert "For testing purpose removing the dependency of rocm-core-asan with rocm-core" This reverts commit 8ce1529027a789e51758f00c400acf148c4f3765. Reason for revert: Change-Id: Ie7618c7aa2b3d71efba950e296b48e728c651ff7 --- CMakeLists.txt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 271c6647e9..61e65d4ba8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -144,15 +144,13 @@ set ( CPACK_RPM_FILE_NAME "RPM-DEFAULT" ) # Debian package specific variables set ( CPACK_DEBIAN_PACKAGE_DEPENDS ${DEB_DEPENDS_STRING} ) -# TODO: Need to enable this later :Commenting for testing purpose -#set ( CPACK_DEBIAN_ASAN_PACKAGE_DEPENDS ${CORE_TARGET} ) +set ( CPACK_DEBIAN_ASAN_PACKAGE_DEPENDS ${CORE_TARGET} ) set ( CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/RadeonOpenCompute/ROCm" ) set ( CPACK_DEBIAN_RUNTIME_PACKAGE_CONTROL_EXTRA "${BUILD_DIR}/postinst;${BUILD_DIR}/prerm" ) ## RPM package specific variables set ( CPACK_RPM_PACKAGE_REQUIRES ${RPM_DEPENDS_STRING} ) -# TODO: Need to enable this later :Commenting for testing purpose -#set ( CPACK_RPM_ASAN_PACKAGE_REQUIRES ${CORE_TARGET} ) +set ( CPACK_RPM_ASAN_PACKAGE_REQUIRES ${CORE_TARGET} ) set ( CPACK_RPM_PACKAGE_LICENSE "MIT" ) set ( CPACK_RPM_RUNTIME_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/postinst" ) set ( CPACK_RPM_RUNTIME_POST_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/prerm" ) From f77cd2cca186da2e46f86df73be0450a2a020825 Mon Sep 17 00:00:00 2001 From: Ranjith Ramakrishnan Date: Thu, 3 Aug 2023 14:26:45 -0700 Subject: [PATCH 07/11] SWDEV-415345 - Correct the installation path of rocm_version.h header file Added file reorg backward compatibility support by creating wrapper header file. Change-Id: Iee4644c8ae51ba508c21abb765a1e1d974dc6e97 --- CMakeLists.txt | 27 ++++++++++++++ header_template.hpp.in | 48 +++++++++++++++++++++++++ rocm-core-backward-compat.cmake | 63 +++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 header_template.hpp.in create mode 100644 rocm-core-backward-compat.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 61e65d4ba8..7a2763a10b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,10 @@ set( CPACK_GENERATOR "TGZ;DEB;RPM" CACHE STRING "package types to be produced " set( COPYRIGHT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/copyright" ) set( BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR} ) +if(NOT ENABLE_ASAN_PACKAGING) + option(FILE_REORG_BACKWARD_COMPATIBILITY "Enable File Reorg with backward compatibility" OFF) +endif() + ## Set variables set_variables() @@ -64,6 +68,29 @@ configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/rocm-core.prerm ${BUILD_DIR}/prerm @ #Generate BUILD_INFO configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/rocm_version.h.in ${BUILD_DIR}/rocm_version.h @ONLY ) +#File reorg Backward compatibility function +if(NOT WIN32) + if(FILE_REORG_BACKWARD_COMPATIBILITY) + # To enabe/disable #error in wrapper header files + if(NOT DEFINED ROCM_HEADER_WRAPPER_WERROR) + if(DEFINED ENV{ROCM_HEADER_WRAPPER_WERROR}) + set(ROCM_HEADER_WRAPPER_WERROR "$ENV{ROCM_HEADER_WRAPPER_WERROR}" + CACHE STRING "Header wrapper warnings as errors.") + else() + set(ROCM_HEADER_WRAPPER_WERROR "OFF" CACHE STRING "Header wrapper warnings as errors.") + endif() + endif() + + if(ROCM_HEADER_WRAPPER_WERROR) + set(deprecated_error 1) + else() + set(deprecated_error 0) + endif() + + include(rocm-core-backward-compat.cmake) + endif() #FILE_REORG_BACKWARD_COMPATIBILITY +endif() + #Make the rocmlib set( SRCS rocm_version.cpp ) add_library( ${CORE_TARGET} ${SRCS} ) diff --git a/header_template.hpp.in b/header_template.hpp.in new file mode 100644 index 0000000000..0d8c481e90 --- /dev/null +++ b/header_template.hpp.in @@ -0,0 +1,48 @@ +/* + MIT License + + Copyright (c) 2017 - 2023 Advanced Micro Devices, Inc. All rights Reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ +#ifndef @include_guard@ +#define @include_guard@ + +#ifndef ROCM_HEADER_WRAPPER_WERROR +#define ROCM_HEADER_WRAPPER_WERROR @deprecated_error@ +#endif +#if ROCM_HEADER_WRAPPER_WERROR /* ROCM_HEADER_WRAPPER_WERROR 1 */ +#error "@file_name@ has moved to @CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@/@headerfile_dir@ " +#else /* ROCM_HEADER_WRAPPER_WERROR 0 */ +#if defined(__GNUC__) +#warning "@file_name@ has moved to @CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@/@headerfile_dir@ " +#else +#pragma message ("@file_name@ has moved to @CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@/@headerfile_dir@ ") +#endif +#endif /* ROCM_HEADER_WRAPPER_WERROR */ + +@include_statements@ + +@hashzero_check@ + +@file_contents@ + +@hash_endif@ + +#endif diff --git a/rocm-core-backward-compat.cmake b/rocm-core-backward-compat.cmake new file mode 100644 index 0000000000..e96572e669 --- /dev/null +++ b/rocm-core-backward-compat.cmake @@ -0,0 +1,63 @@ +# Copyright (c) 2023 Advanced Micro Devices, Inc. All Rights Reserved. +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +cmake_minimum_required(VERSION 3.16.8) + +set(ROCM_CORE_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}) +set(ROCM_CORE_WRAPPER_DIR ${ROCM_CORE_BUILD_DIR}/wrapper_dir) +set(ROCM_CORE_WRAPPER_INC_DIR ${ROCM_CORE_WRAPPER_DIR}/include) +set(headerfile_dir "rocm-core") + +#Function to set actual file contents in wrapper files +#Some components grep for the contents in the file +function(set_file_contents input_file) + set(hashzero_check "#if 0 +/* The following is a copy of the original file for the benefit of build systems which grep for values + * in this file rather than preprocess it. This is just for backward compatibility */") + + file(READ ${input_file} file_contents) + set(hash_endif "#endif") + get_filename_component(file_name ${input_file} NAME) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/header_template.hpp.in ${ROCM_CORE_WRAPPER_INC_DIR}/${file_name}) +endfunction() + +#use header template file and generate wrapper header files +function(generate_wrapper_header) + file(MAKE_DIRECTORY ${ROCM_CORE_WRAPPER_INC_DIR}) + + #find all header files + file(GLOB include_files ${ROCM_CORE_BUILD_DIR}/*.h) + #Create wrapper files + foreach(header_file ${include_files}) + # set include guard + get_filename_component(INC_GAURD_NAME ${header_file} NAME_WE) + string(TOUPPER ${INC_GAURD_NAME} INC_GAURD_NAME) + set(include_guard "ROCM_CORE_WRAPPER_INCLUDE_${INC_GAURD_NAME}_H") + #set #include statement + get_filename_component(file_name ${header_file} NAME) + set(include_statements "#include \"${headerfile_dir}/${file_name}\"\n") + set_file_contents(${header_file}) + endforeach() + +endfunction() + +#Use template header file and generater wrapper header files +generate_wrapper_header() +install(DIRECTORY ${ROCM_CORE_WRAPPER_INC_DIR} DESTINATION . COMPONENT runtime) + From 478270cb11849a94a61e6f6b2d00486b08311b42 Mon Sep 17 00:00:00 2001 From: Nirmal Unnikrishnan Date: Thu, 31 Aug 2023 14:28:49 -0500 Subject: [PATCH 08/11] SWDEV-310152 : Adding script to convert RUNPATH to RPATH in libs/bins Change-Id: Ic6c49544cb7450384592b4f5609fb394f1f12f02 --- CHANGELOG.md | 11 +++- CMakeLists.txt | 3 ++ runpath_to_rpath.py | 127 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 runpath_to_rpath.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 294b597e90..7be9b06418 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ Change Logs for rocm-core -Unreleased for ROCm5.5.0 + +Unreleased ROCm6.0.0 release + - Added script to convert RUNPATH in libraries and binaries to RPATH. + - Disabled ROCm file reorg backward compatibility + +ROCm5.6.0 release + - Added initial support for Adress Sanitizer(ASAN) enabled builds. + - Full support of ASAN will be coming in later release + +ROCm5.5.0 release - Added module file support for ROCm. - From ROCm5.5.0 release ROCm module files can be loaded as rocm/5.5.0 diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a2763a10b..3597012ca9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -122,6 +122,7 @@ install ( TARGETS ${CORE_TARGET} DESTINATION ${CMAKE_INSTALL_LIBDIR} PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE COMPONENT ${COMP_TYPE} ) install ( FILES ${BUILD_DIR}/rocm_version.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/rocm-core COMPONENT runtime ) +install ( FILES ${CMAKE_CURRENT_SOURCE_DIR}/runpath_to_rpath.py DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/rocm-core COMPONENT runtime ) install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/rocmmod DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT runtime ) # License file @@ -173,12 +174,14 @@ set ( CPACK_RPM_FILE_NAME "RPM-DEFAULT" ) set ( CPACK_DEBIAN_PACKAGE_DEPENDS ${DEB_DEPENDS_STRING} ) set ( CPACK_DEBIAN_ASAN_PACKAGE_DEPENDS ${CORE_TARGET} ) set ( CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/RadeonOpenCompute/ROCm" ) +set ( CPACK_DEBIAN_PACKAGE_DEPENDS "patchelf" ) set ( CPACK_DEBIAN_RUNTIME_PACKAGE_CONTROL_EXTRA "${BUILD_DIR}/postinst;${BUILD_DIR}/prerm" ) ## RPM package specific variables set ( CPACK_RPM_PACKAGE_REQUIRES ${RPM_DEPENDS_STRING} ) set ( CPACK_RPM_ASAN_PACKAGE_REQUIRES ${CORE_TARGET} ) set ( CPACK_RPM_PACKAGE_LICENSE "MIT" ) +set ( CPACK_RPM_PACKAGE_REQUIRES "patchelf" ) set ( CPACK_RPM_RUNTIME_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/postinst" ) set ( CPACK_RPM_RUNTIME_POST_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/prerm" ) diff --git a/runpath_to_rpath.py b/runpath_to_rpath.py new file mode 100644 index 0000000000..0b93b51694 --- /dev/null +++ b/runpath_to_rpath.py @@ -0,0 +1,127 @@ +#!/usr/bin/env python3 +################################################################################ +## +## MIT License +## +## Copyright (c) 2017 - 2023 Advanced Micro Devices, Inc. All rights Reserved. +## +## Permission is hereby granted, free of charge, to any person obtaining a copy +## of this software and associated documentation files (the "Software"), to deal +## in the Software without restriction, including without limitation the rights +## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +## copies of the Software, and to permit persons to whom the Software is +## furnished to do so, subject to the following conditions: +## +## The above copyright notice and this permission notice shall be included in all +## copies or substantial portions of the Software. +## +## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +## SOFTWARE. +## +################################################################################ + +import os +import sys +import subprocess +import argparse +import pathlib + +try: + from elftools.elf.elffile import ELFFile + from elftools.elf.dynamic import DynamicSection + from elftools.common.exceptions import ELFError +except ImportError: + print("Error : pyelftools failed to import.\n" + "Run \'pip3 install pyelftools\' to install the prerequisite\n") + +# Function remove the runpath from the binary +def remove_runpath(filename) : + ''' Remove the DT_RUNPATH tag from filename''' + REMOVE_RPATH_COMMAND = ['patchelf', '--remove-rpath', filename] + print("Executing the command : ", REMOVE_RPATH_COMMAND) + subprocess.run(REMOVE_RPATH_COMMAND, check=True) + +def add_rpath(filename, runpath) : + ''' Use runpath and add it as DT_PATH tag in filename''' + ADD_RPATH_COMMAND = ['patchelf', '--force-rpath', '--set-rpath', runpath, filename] + print("Executing the command : ", ADD_RPATH_COMMAND) + subprocess.run(ADD_RPATH_COMMAND, check=True) + +def update_rpath(search_path, excludes) : + ''' Function helps to change DT_RUNPATH in libraries and binaries in search_path to DT_RPATH. + Its done with the following steps : + 1. Check all if the file is an ELF except in excludes folder + 2. Read and store the DT_RUNPATH from the binaries/libraries. + 3. Delete DT_RUNPATH and readd it as DT_RPATH ''' + for path, dirs, files in os.walk(search_path, topdown=True, followlinks=True): + dirs[:] = [d for d in dirs if d not in excludes] + print( dirs ) + for filename in files: + filename = os.path.join(path, filename) + print("Opening file ", filename) + # Open the file and check if its ELF file + try : + with open(filename, 'rb') as file: + elffile = ELFFile(file) + for section in elffile.iter_sections(): + if not isinstance(section, DynamicSection): + continue + for tag in section.iter_tags(): + if tag.entry.d_tag == 'DT_RUNPATH': + runpath = tag.runpath + print(runpath) + remove_runpath(filename) + add_rpath(filename, runpath) + break + break + except ELFError: + print("Discarding file as its not an ELF file", filename) + continue + except FileNotFoundError: + print("Discarding file with bad links", filename) + continue + except OSError: + print("Discarding file with OS error", filename) + continue + except Exception as ex: + print("Discarding file ", filename, ex) + continue + +def main(): + # The script expect a search folder as parameter. It finds all ELF files and updates RPATH + argparser = argparse.ArgumentParser( + usage='usage: %(prog)s ', + description='Find the ELF files in the specified folder and convert the RUNPATH to RPATH. \n', + add_help=False, + prog='runpath_to_rpath.py') + + argparser.add_argument('searchdir', + nargs='?', type=pathlib.Path, default=None, + help='Folder to search for ELF file. \nPlease note: Any folder with name llvm in that path will be discarded') + argparser.add_argument('-h', '--help', + action='store_true', dest='help', + help='Display this information') + + args = argparser.parse_args() + if args.help or not args.searchdir: + argparser.print_help() + sys.exit(0) + + # pyelftools is a mandatory requirement for this script. Exit if requirement is not met + if 'ELFFile' not in globals(): + print('Please install pyelftools using \'pip3 install pyelftools\' ' + + 'before using the script : runpath_to_rpath.py') + sys.exit(0) + + # Find the elf files in the serach path and update RPATH + excludes = ['llvm', 'rocm-llvm', 'llvm-alt'] + update_rpath(args.searchdir, excludes) + print("Done with rpath update") + +if __name__ == "__main__": + main() From d448048fa7e72fd78eac827f4b69f9c3a0254154 Mon Sep 17 00:00:00 2001 From: Nirmal Unnikrishnan Date: Mon, 16 Oct 2023 15:23:53 -0500 Subject: [PATCH 09/11] SWDEV-427268 SWDEV-427256 : Changing the patchelf package from requirement to recommends Change-Id: I2c909f2a7a7fc601be1890bfbcef50177695931b --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3597012ca9..69b6e07288 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -174,14 +174,14 @@ set ( CPACK_RPM_FILE_NAME "RPM-DEFAULT" ) set ( CPACK_DEBIAN_PACKAGE_DEPENDS ${DEB_DEPENDS_STRING} ) set ( CPACK_DEBIAN_ASAN_PACKAGE_DEPENDS ${CORE_TARGET} ) set ( CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/RadeonOpenCompute/ROCm" ) -set ( CPACK_DEBIAN_PACKAGE_DEPENDS "patchelf" ) +set ( CPACK_DEBIAN_PACKAGE_RECOMMENDS "patchelf" ) set ( CPACK_DEBIAN_RUNTIME_PACKAGE_CONTROL_EXTRA "${BUILD_DIR}/postinst;${BUILD_DIR}/prerm" ) ## RPM package specific variables set ( CPACK_RPM_PACKAGE_REQUIRES ${RPM_DEPENDS_STRING} ) set ( CPACK_RPM_ASAN_PACKAGE_REQUIRES ${CORE_TARGET} ) set ( CPACK_RPM_PACKAGE_LICENSE "MIT" ) -set ( CPACK_RPM_PACKAGE_REQUIRES "patchelf" ) +set ( CPACK_RPM_PACKAGE_SUGGESTS "patchelf" ) set ( CPACK_RPM_RUNTIME_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/postinst" ) set ( CPACK_RPM_RUNTIME_POST_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/prerm" ) From 1544e398c601f757eece7faa0ac726b691e40d5a Mon Sep 17 00:00:00 2001 From: Nirmal Unnikrishnan Date: Wed, 18 Oct 2023 17:23:42 -0500 Subject: [PATCH 10/11] SWDEV-427268 SWDEV-427256 : Removing dependency with patchelf completely Change-Id: I71ccebdbbd9b3c79ea8412acd54a71a96af3e26f --- CMakeLists.txt | 2 -- runpath_to_rpath.py | 45 ++++++++++++++++++--------------------------- 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 69b6e07288..3400824a47 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -174,14 +174,12 @@ set ( CPACK_RPM_FILE_NAME "RPM-DEFAULT" ) set ( CPACK_DEBIAN_PACKAGE_DEPENDS ${DEB_DEPENDS_STRING} ) set ( CPACK_DEBIAN_ASAN_PACKAGE_DEPENDS ${CORE_TARGET} ) set ( CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/RadeonOpenCompute/ROCm" ) -set ( CPACK_DEBIAN_PACKAGE_RECOMMENDS "patchelf" ) set ( CPACK_DEBIAN_RUNTIME_PACKAGE_CONTROL_EXTRA "${BUILD_DIR}/postinst;${BUILD_DIR}/prerm" ) ## RPM package specific variables set ( CPACK_RPM_PACKAGE_REQUIRES ${RPM_DEPENDS_STRING} ) set ( CPACK_RPM_ASAN_PACKAGE_REQUIRES ${CORE_TARGET} ) set ( CPACK_RPM_PACKAGE_LICENSE "MIT" ) -set ( CPACK_RPM_PACKAGE_SUGGESTS "patchelf" ) set ( CPACK_RPM_RUNTIME_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/postinst" ) set ( CPACK_RPM_RUNTIME_POST_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/prerm" ) diff --git a/runpath_to_rpath.py b/runpath_to_rpath.py index 0b93b51694..99875981ac 100644 --- a/runpath_to_rpath.py +++ b/runpath_to_rpath.py @@ -35,29 +35,17 @@ try: from elftools.elf.elffile import ELFFile from elftools.elf.dynamic import DynamicSection from elftools.common.exceptions import ELFError + from elftools.elf.dynamic import ENUM_D_TAG except ImportError: print("Error : pyelftools failed to import.\n" "Run \'pip3 install pyelftools\' to install the prerequisite\n") -# Function remove the runpath from the binary -def remove_runpath(filename) : - ''' Remove the DT_RUNPATH tag from filename''' - REMOVE_RPATH_COMMAND = ['patchelf', '--remove-rpath', filename] - print("Executing the command : ", REMOVE_RPATH_COMMAND) - subprocess.run(REMOVE_RPATH_COMMAND, check=True) - -def add_rpath(filename, runpath) : - ''' Use runpath and add it as DT_PATH tag in filename''' - ADD_RPATH_COMMAND = ['patchelf', '--force-rpath', '--set-rpath', runpath, filename] - print("Executing the command : ", ADD_RPATH_COMMAND) - subprocess.run(ADD_RPATH_COMMAND, check=True) - def update_rpath(search_path, excludes) : ''' Function helps to change DT_RUNPATH in libraries and binaries in search_path to DT_RPATH. Its done with the following steps : 1. Check all if the file is an ELF except in excludes folder - 2. Read and store the DT_RUNPATH from the binaries/libraries. - 3. Delete DT_RUNPATH and readd it as DT_RPATH ''' + 2. Find the DT_RUNPATH tag and its offset from file. + 3. Toggle the DT_RUNPATH(0x1d) tag byte to DT_RPATH(0xf) and write back to file ''' for path, dirs, files in os.walk(search_path, topdown=True, followlinks=True): dirs[:] = [d for d in dirs if d not in excludes] print( dirs ) @@ -66,19 +54,22 @@ def update_rpath(search_path, excludes) : print("Opening file ", filename) # Open the file and check if its ELF file try : - with open(filename, 'rb') as file: + with open(filename, 'rb+') as file: elffile = ELFFile(file) - for section in elffile.iter_sections(): - if not isinstance(section, DynamicSection): - continue - for tag in section.iter_tags(): - if tag.entry.d_tag == 'DT_RUNPATH': - runpath = tag.runpath - print(runpath) - remove_runpath(filename) - add_rpath(filename, runpath) - break - break + # Find the dynamic section and look for DT_RUNPATH tag + section = elffile.get_section_by_name('.dynamic') + if not section: break + n = 0 + for tag in section.iter_tags(): + # DT_RUNPATH tag found. Toggle the byte to DT_RPATH + if tag.entry.d_tag == 'DT_RUNPATH': + offset = section.header.sh_offset + n* section._tagsize + section.stream.seek(offset) + section.stream.write(bytes([ENUM_D_TAG['DT_RPATH']])) # DT_PATH + print("DT_RUNPATH changed to DT_RPATH ") + break + # DT_RUNPATH tag not found. Loop to the next tag + n = n + 1 except ELFError: print("Discarding file as its not an ELF file", filename) continue From 8723cc52a2f2ae7a1f3d95e6901e77d6a5c31df4 Mon Sep 17 00:00:00 2001 From: Nirmal Unnikrishnan Date: Fri, 10 Nov 2023 17:56:16 -0600 Subject: [PATCH 11/11] SWDEV-310152 : Updating llvm config file to default to RPATH after running this script Change-Id: I67d1a4b1d19032cfe187fadc5f7b6ee540d08672 --- runpath_to_rpath.py | 65 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/runpath_to_rpath.py b/runpath_to_rpath.py index 99875981ac..c4415124f7 100644 --- a/runpath_to_rpath.py +++ b/runpath_to_rpath.py @@ -30,6 +30,7 @@ import sys import subprocess import argparse import pathlib +import re try: from elftools.elf.elffile import ELFFile @@ -83,6 +84,64 @@ def update_rpath(search_path, excludes) : print("Discarding file ", filename, ex) continue +def update_config_file(cfg_path): + ''' Function helps to update rocm llvm config file to default to DT_RPATH. ''' + print("Updating cfg file in", cfg_path) + config_file_exist = os.path.exists(cfg_path) + if config_file_exist: + print("cfg file exist in path, going ahead with update ") + search_str = "enable-new-dtags" + replace_str = "disable-new-dtags" + try: + # Read contents from file as a single string + file_string = '' + with open(cfg_path, 'r') as f: + file_string = f.read() + + # Use RE package for string replacement + file_string = (re.sub(search_str, replace_str, file_string)) + + # Write contents back to file. Using mode 'w' truncates the file. + with open(cfg_path, 'w') as f: + f.write(file_string) + except Exception as ex: + print("Couldnt update rocm.cfg file. ", ex) + else: + print("Config path doesnt exist", cfg_path) + +def update_compiler_config(search_path): + ''' Function search for rocm llvm config(rocm.cfg) file in the search_path folder. + If the config file is not foung search in ROCM_PATH. Once the config file is found, + update llvm config to default to DT_RPATH ''' + cfg_file_name = "rocm.cfg" + found_cfg = False + print("Searching for ", cfg_file_name) + for path, dirs, files in os.walk(search_path): + # Search for rocm.cfg in the search path and default to DT_RPATH + if cfg_file_name in files: + cfg_path = os.path.join(path, cfg_file_name) + print(" Found cfg file cfg_path") + found_cfg = True + update_config_file(cfg_path) + # Continue with the search as there could be cfg files in llvm and llvm/alt + continue; + if found_cfg: + return + # rocm.cfg config file not found in search path. Search in the ROCM_PATH. + print(cfg_file_name, " not found in search_path. Trying to search in ROCM_PATH") + try : + rocm_path = os.environ["ROCM_PATH"] + print(" Found ROCM_PATH trying for rocm.cfg") + # There are multiple possible paths for cfg file. + # ROCM_PATH/llvm/bin and ROCM_PATH/lib/llvm/bin. Also alt location + update_config_file(rocm_path + "/llvm/bin/" + cfg_file_name) + update_config_file(rocm_path + "/llvm/alt/bin/" + cfg_file_name) + update_config_file(rocm_path + "/lib/llvm/bin/" + cfg_file_name) + update_config_file(rocm_path + "/lib/llvm/alt/bin/" + cfg_file_name) + # Found config file. Change default DT_RUNPATH setting to DT_RPATH + except Exception as ex: + print("ROCM_PATH not found ", ex) + def main(): # The script expect a search folder as parameter. It finds all ELF files and updates RPATH argparser = argparse.ArgumentParser( @@ -109,9 +168,11 @@ def main(): 'before using the script : runpath_to_rpath.py') sys.exit(0) - # Find the elf files in the serach path and update RPATH - excludes = ['llvm', 'rocm-llvm', 'llvm-alt'] + # Find the elf files in the serach path and update DT_RUNPATH to DT_RPATH + excludes = ['llvm', 'rocm-llvm', 'rocm-llvm-alt'] update_rpath(args.searchdir, excludes) + # Update rocm clang configs to default to DT_RPATH + update_compiler_config(args.searchdir) print("Done with rpath update") if __name__ == "__main__":