Skip to content

Commit 2db6d35

Browse files
raramakrraramakr
andauthored
SWDEV-555589 - Edit zlib and zstd source code to create libraries with updated name (ROCm#1539)
The renamed and patchelf edited libraries in ROCk artifacts are not providing the symbol version tag. This was resulting in rpm package installation failure. Patch will create the library with the updated name. Patchelf editing is not required. librocm_sysdeps_z and librocm_sysdeps_zstd libraries will be created as part of zlib and zstd builds ## Motivation The patchelf edited libraries are not providing the symbol version tag ## Technical Details Rather than editing libraries to update soname , create libraries with the updated name by editing the target name in source code ## Test Plan Verified the elfdeps provides field of the libraries. ## Test Result Required symbol version tags are provided by the libraries ## Submission Checklist - [ ] Look over the contributing guidelines at https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests. --------- Co-authored-by: raramakr <raramakr@amd.com>
1 parent 8a228b2 commit 2db6d35

File tree

6 files changed

+40
-36
lines changed

6 files changed

+40
-36
lines changed

third-party/sysdeps/common/zlib/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT PATCHELF)
5454
message(FATAL_ERROR "Missing PATCHELF from super-project")
5555
endif()
5656

57+
# Apply patch source only on Linux
58+
set(patch_source_commands)
59+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
60+
list(APPEND patch_source_commands COMMAND
61+
bash "${CMAKE_CURRENT_SOURCE_DIR}/patch_source.sh" "${CMAKE_CURRENT_BINARY_DIR}/s")
62+
endif()
5763
# zlib provides a CMakeLists.txt, however, we have to do some post-processing
5864
# of the libraries in order to prepare them for our use, so we invoke it as
5965
# a sub-build. We do this uniformly across all platforms because it is easier
@@ -66,6 +72,8 @@ add_custom_target(
6672
"${CMAKE_COMMAND}" -E rm -rf -- "${CMAKE_INSTALL_PREFIX}" "${CMAKE_CURRENT_BINARY_DIR}/s"
6773
COMMAND
6874
"${CMAKE_COMMAND}" -E copy_directory "${SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/s"
75+
COMMAND
76+
${patch_source_commands}
6977
COMMAND
7078
# Provide our own version map with private symbol versions.
7179
"${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/version.lds" "${CMAKE_CURRENT_BINARY_DIR}/s/zlib.map"

third-party/sysdeps/common/zlib/patch_install.py

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,16 @@
1-
import os
21
from pathlib import Path
32
import platform
4-
import subprocess
3+
import shutil
54
import sys
65

76
PREFIX = sys.argv[1]
8-
PATCHELF = os.getenv("PATCHELF")
9-
THEROCK_SOURCE_DIR = os.getenv("THEROCK_SOURCE_DIR")
10-
11-
if not THEROCK_SOURCE_DIR:
12-
raise ValueError("Exepcted THEROCK_SOURCE_DIR env var")
137

148
if platform.system() == "Linux":
15-
if not PATCHELF:
16-
raise ValueError("Exepcted PATCHELF env var")
17-
# Patch libz.so
18-
subprocess.check_call(
19-
[
20-
sys.executable,
21-
str(Path(THEROCK_SOURCE_DIR) / "build_tools" / "patch_linux_so.py"),
22-
"--patchelf",
23-
PATCHELF,
24-
"--add-prefix",
25-
"rocm_sysdeps_",
26-
str(Path(PREFIX) / "lib" / "libz.so"),
27-
]
28-
)
9+
source = str(Path(PREFIX) / "lib" / "librocm_sysdeps_z.so")
10+
destination = str(Path(PREFIX) / "lib" / "libz.so")
11+
shutil.move(source, destination)
2912
# We don't want the static lib on Linux.
30-
(Path(PREFIX) / "lib" / "libz.a").unlink()
13+
(Path(PREFIX) / "lib" / "librocm_sysdeps_z.a").unlink()
3114
elif platform.system() == "Windows":
3215
# We don't want the libz.dll on Windows.
3316
(Path(PREFIX) / "bin" / "zlib.dll").unlink()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/bash
2+
set -e
3+
4+
SOURCE_DIR="${1:?Source directory must be given}"
5+
ZLIB_CMAKELIST="$SOURCE_DIR/CMakeLists.txt"
6+
echo "Patching sources..."
7+
8+
sed -i -E 's/(OUTPUT_NAME)[[:space:]]+z\)/\1 rocm_sysdeps_z)/' "$ZLIB_CMAKELIST"

third-party/sysdeps/common/zstd/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,20 @@ else()
8080
message(FATAL_ERROR "System not recognized")
8181
endif()
8282

83+
# Apply patch source only on Linux
84+
set(patch_source_commands)
85+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
86+
list(APPEND patch_source_commands COMMAND
87+
bash "${CMAKE_CURRENT_SOURCE_DIR}/patch_source.sh" "${SOURCE_DIR}")
88+
endif()
89+
8390
add_custom_target(
8491
build ALL
8592
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
8693
COMMAND
8794
"${CMAKE_COMMAND}" -E rm -rf -- "${CMAKE_INSTALL_PREFIX}"
95+
COMMAND
96+
${patch_source_commands}
8897
COMMAND
8998
"${CMAKE_COMMAND}"
9099
"-G${CMAKE_GENERATOR}"

third-party/sysdeps/common/zstd/patch_install.sh

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,8 @@
22
set -e
33

44
PREFIX="${1:?Expected install prefix argument}"
5-
PATCHELF="${PATCHELF:-patchelf}"
6-
THEROCK_SOURCE_DIR="${THEROCK_SOURCE_DIR:?THEROCK_SOURCE_DIR not defined}"
7-
Python3_EXECUTABLE="${Python3_EXECUTABLE:?Python3_EXECUTABLE not defined}"
8-
9-
"$Python3_EXECUTABLE" "$THEROCK_SOURCE_DIR/build_tools/patch_linux_so.py" \
10-
--patchelf "${PATCHELF}" --add-prefix rocm_sysdeps_ \
11-
$PREFIX/lib/libzstd.so
125

6+
# Rename librocm_sysdeps_zstd.so to libzstd.so
7+
mv $PREFIX/lib/librocm_sysdeps_zstd.so $PREFIX/lib/libzstd.so
138
# pc files are not output with a relative prefix. Sed it to relative.
149
sed -i -E 's|^prefix=.+|prefix=${pcfiledir}/../..|' $PREFIX/lib/pkgconfig/*.pc
15-
16-
# Rename -lzstd in the pc file.
17-
sed -i -E 's|-lzstd|-lrocm_sysdeps_zstd|' $PREFIX/lib/pkgconfig/*.pc
18-
19-
# Rename the IMPORTED_LOCATION and SONAME in the CMake target files.
20-
sed -i -E 's|lib/libzstd\.so\.[0-9\.]+|lib/librocm_sysdeps_zstd.so.1|' $PREFIX/lib/cmake/zstd/zstdTargets-*.cmake
21-
sed -i -E 's|libzstd\.so\.1|librocm_sysdeps_zstd\.so\.1|' $PREFIX/lib/cmake/zstd/zstdTargets-*.cmake
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/bash
2+
set -e
3+
4+
SOURCE_DIR="${1:?Source directory must be given}"
5+
ZSTD_CMAKELIST="$SOURCE_DIR/build/cmake/lib/CMakeLists.txt"
6+
echo "Patching sources..."
7+
8+
sed -i -E 's/(OUTPUT_NAME)[[:space:]]+zstd/\1 rocm_sysdeps_zstd/' "$ZSTD_CMAKELIST"

0 commit comments

Comments
 (0)