From bf99cd2d3b655621f86b15e43f761ba2c169b936 Mon Sep 17 00:00:00 2001 From: Benson Ma Date: Mon, 23 Sep 2024 11:48:28 -0700 Subject: [PATCH] [fbgemm_gpu] Remove errant RPATHs from binaries - Remove errant RPATHs from binaries (https://github.com/pytorch/FBGEMM/issues/3098) --- .github/scripts/fbgemm_gpu_build.bash | 3 +++ .github/scripts/fbgemm_gpu_postbuild.bash | 21 +++++++++++++++++++ .github/scripts/utils_build.bash | 1 + fbgemm_gpu/CMakeLists.txt | 4 ++++ fbgemm_gpu/FbgemmGpu.cmake | 6 ++++++ .../experimental/example/CMakeLists.txt | 6 ++++++ fbgemm_gpu/experimental/gen_ai/CMakeLists.txt | 6 ++++++ 7 files changed, 47 insertions(+) create mode 100644 .github/scripts/fbgemm_gpu_postbuild.bash diff --git a/.github/scripts/fbgemm_gpu_build.bash b/.github/scripts/fbgemm_gpu_build.bash index fd76b5669d..1a7ca88264 100644 --- a/.github/scripts/fbgemm_gpu_build.bash +++ b/.github/scripts/fbgemm_gpu_build.bash @@ -416,6 +416,9 @@ __print_library_infos () { echo "[CHECK] Listing out external shared libraries linked:" print_exec ldd "${library}" + + echo "[CHECK] Displaying ELF information:" + print_exec readelf -d "${library}" echo "################################################################################" echo "" echo "" diff --git a/.github/scripts/fbgemm_gpu_postbuild.bash b/.github/scripts/fbgemm_gpu_postbuild.bash new file mode 100644 index 0000000000..95f4a7daf9 --- /dev/null +++ b/.github/scripts/fbgemm_gpu_postbuild.bash @@ -0,0 +1,21 @@ +#!/bin/sh +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + +echo "################################################################################" +echo "[CMAKE] Running post-build script ..." + +# Print directory +pwd + +# List all generated .SO files +find . -name *.so + +# Remove errant RPATHs from the .SO +find . -name *.so | xargs patchelf --remove-rpath + +echo "[CMAKE] Removed errant RPATHs" +echo "################################################################################" diff --git a/.github/scripts/utils_build.bash b/.github/scripts/utils_build.bash index 1191bf34d1..60127ed053 100644 --- a/.github/scripts/utils_build.bash +++ b/.github/scripts/utils_build.bash @@ -297,6 +297,7 @@ install_build_tools () { ncurses \ ninja \ openblas \ + patchelf \ scikit-build \ wheel) || return 1 diff --git a/fbgemm_gpu/CMakeLists.txt b/fbgemm_gpu/CMakeLists.txt index d56a9ca368..10a72bbe43 100644 --- a/fbgemm_gpu/CMakeLists.txt +++ b/fbgemm_gpu/CMakeLists.txt @@ -112,3 +112,7 @@ if(NOT FBGEMM_CPU_ONLY AND NOT USE_ROCM) # add_subdirectory(experimental/gen_ai) endif() + + +# install(CODE "execute_process(COMMAND ../.github/scripts/fbgemm_gpu_postbuild.sh)") +# ; patchelf --remove-rpath *.so) diff --git a/fbgemm_gpu/FbgemmGpu.cmake b/fbgemm_gpu/FbgemmGpu.cmake index f67a6b6b24..27b4ec8843 100644 --- a/fbgemm_gpu/FbgemmGpu.cmake +++ b/fbgemm_gpu/FbgemmGpu.cmake @@ -725,3 +725,9 @@ install(FILES ${gen_python_source_files} install(FILES ${gen_defused_optim_py_files} DESTINATION fbgemm_gpu/split_embedding_optimizer_codegen) + +add_custom_target(fbgemm_gpu_py_clean_rpath ALL + WORKING_DIRECTORY ${OUTPUT_DIR} + COMMAND bash ${FBGEMM}/.github/scripts/fbgemm_gpu_postbuild.bash) + +add_dependencies(fbgemm_gpu_py_clean_rpath fbgemm_gpu_py) diff --git a/fbgemm_gpu/experimental/example/CMakeLists.txt b/fbgemm_gpu/experimental/example/CMakeLists.txt index ecf72d6777..490a6a617a 100644 --- a/fbgemm_gpu/experimental/example/CMakeLists.txt +++ b/fbgemm_gpu/experimental/example/CMakeLists.txt @@ -70,3 +70,9 @@ install(TARGETS fbgemm_gpu_experimental_example_py install(FILES ${experimental_example_python_source_files} DESTINATION fbgemm_gpu/experimental/example) + +add_custom_target(fbgemm_gpu_experimental_example_py_clean_rpath ALL + WORKING_DIRECTORY ${OUTPUT_DIR} + COMMAND bash ${FBGEMM}/.github/scripts/fbgemm_gpu_postbuild.bash) + +add_dependencies(fbgemm_gpu_experimental_example_py_clean_rpath fbgemm_gpu_experimental_example_py) diff --git a/fbgemm_gpu/experimental/gen_ai/CMakeLists.txt b/fbgemm_gpu/experimental/gen_ai/CMakeLists.txt index 7716c39c17..bd4be8b00a 100644 --- a/fbgemm_gpu/experimental/gen_ai/CMakeLists.txt +++ b/fbgemm_gpu/experimental/gen_ai/CMakeLists.txt @@ -154,3 +154,9 @@ install(TARGETS fbgemm_gpu_experimental_gen_ai_py install(FILES ${experimental_gen_ai_python_source_files} DESTINATION fbgemm_gpu/experimental/gen_ai) + +add_custom_target(fbgemm_gpu_experimental_gen_ai_py_clean_rpath ALL + WORKING_DIRECTORY ${OUTPUT_DIR} + COMMAND bash ${FBGEMM}/.github/scripts/fbgemm_gpu_postbuild.bash) + +add_dependencies(fbgemm_gpu_experimental_gen_ai_py_clean_rpath fbgemm_gpu_experimental_gen_ai_py)