Skip to content

Commit

Permalink
Patch libelf sources more robustly.
Browse files Browse the repository at this point in the history
  • Loading branch information
stellaraccident committed Feb 24, 2025
1 parent d4fdaf1 commit 6a0e4ef
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 19 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ message(STATUS "ROCM_GIT_DIR is set to: ${ROCM_GIT_DIR}")
set(THEROCK_ARTIFACT_ARCHIVE_SUFFIX "" CACHE STRING "Suffix to add to artifact archive file stem names")
set(THEROCK_ARTIFACT_ARCHIVE_TYPES "tar.xz" CACHE STRING "List of artifact archive types to generate")

option(THEROCK_BUNDLE_SYSDEPS "Builds bundled system deps for portable builds into lib/rocm_sysdeps" OFF)
cmake_dependent_option(
THEROCK_BUNDLE_SYSDEPS "Builds bundled system deps for portable builds into lib/rocm_sysdeps"
ON "CMAKE_SYSTEM_NAME STREQUAL \"Linux\"" OFF)

# Overall build settings.
option(THEROCK_VERBOSE "Enables verbose CMake statuses" OFF)
Expand Down Expand Up @@ -218,6 +220,7 @@ endif()

set(THEROCK_OPTIONAL_SYSDEP_SUBPROJECTS)
if(THEROCK_BUNDLE_SYSDEPS)
message(STATUS "Building with bundled system dependencies enabled")
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
find_program(PATCHELF patchelf)
if(NOT PATCHELF)
Expand Down
20 changes: 20 additions & 0 deletions packaging/linux-portable/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,23 @@
Build scripts for producing ready to run manylinux based bundles that feed into a variety of distribution packages.

These are all based on our `build_manylinux` docker containers (see `/dockerfiles/build_manylinux_x86_64.Dockerfile` and the corresponding packages in the registry). Such builds are generally compatible with any glibc based Linux distribution that is greater than or equal to that which was used to build. See the [manylinux](https://github.com/pypa/manylinux) project for more information.

## Invocation

Build with defaults:

```shell
python build_portable.py -- -DTHEROCK_AMDGPU_FAMILIES=gfx110X-dgpu
```

Build using podman instead of docker (preserves host permissions and does not
run as root):

```shell
python build_portable.py --docker=podman -- -DTHEROCK_AMDGPU_FAMILIES=gfx110X-dgpu
```

Drop into an interactive shell with podman:
```shell
python build_portable.py --docker=podman --interactive
```
4 changes: 3 additions & 1 deletion packaging/linux-portable/detail/build_in_container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ export CMAKE_C_COMPILER_LAUNCHER=ccache
export CMAKE_CXX_COMPILER_LAUNCHER=ccache

set -o xtrace
time cmake -GNinja -S /therock/src -B "$OUTPUT_DIR/build" "$@"
time cmake -GNinja -S /therock/src -B "$OUTPUT_DIR/build" \
-DTHEROCK_BUNDLE_SYSDEPS=ON \
"$@"
time cmake --build "$OUTPUT_DIR/build"
18 changes: 10 additions & 8 deletions third-party/sysdeps/linux/elfutils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,22 @@ add_custom_target(
build ALL
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
COMMAND
"${CMAKE_COMMAND}" -E rm -rf -- "${CMAKE_INSTALL_PREFIX}"
"${CMAKE_COMMAND}" -E rm -rf -- "${CMAKE_INSTALL_PREFIX}" "${CMAKE_CURRENT_BINARY_DIR}/s"
COMMAND
# Note that --disable-symbol-versioning below merely disables the emission
# of old compatibility symbols. Libraries are still linked against the
# map files in the source tree. We patch those with custom versions that
# hardcode all symbols to our version.
"${CMAKE_COMMAND}" -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/overlay" "${SOURCE_DIR}"
# We have to patch the sources so make a fresh copy.
"${CMAKE_COMMAND}" -E copy_directory "${SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/s"
COMMAND
"${CMAKE_CURRENT_SOURCE_DIR}/patch_source.sh" "${CMAKE_CURRENT_BINARY_DIR}/s"
COMMAND
"${CMAKE_COMMAND}" -E env
"PKG_CONFIG_PATH=$ENV{PKG_CONFIG_PATH}"
# Escaping: Double $ to satisfy CMake, then double $ to satisfy configure,
# then escaped single quotes to make it to the linker command line.
"LDFLAGS=${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath=\\'\\$$\\$$ORIGIN\\'"
--
"${SOURCE_DIR}/configure"
"${CMAKE_CURRENT_BINARY_DIR}/s/configure"
--prefix "${CMAKE_INSTALL_PREFIX}"
--disable-debuginfod
--disable-symbol-versioning
--enable-install-elfh
--with-bzlib --with-zlib --with-zstd
# We don't have an lzma sysdep yet and may not need it.
Expand All @@ -90,6 +88,10 @@ add_custom_target(
"THEROCK_SOURCE_DIR=${THEROCK_SOURCE_DIR}"
"Python3_EXECUTABLE=${Python3_EXECUTABLE}" --
"${CMAKE_CURRENT_SOURCE_DIR}/patch_install.sh" ${CMAKE_INSTALL_PREFIX}

DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/patch_source.sh"
"${CMAKE_CURRENT_SOURCE_DIR}/patch_install.sh"
)

# This matches the conventions of the FindLibElf.cmake module in ROCR-Runtime.
Expand Down

This file was deleted.

3 changes: 0 additions & 3 deletions third-party/sysdeps/linux/elfutils/overlay/libdw/libdw.map

This file was deleted.

3 changes: 0 additions & 3 deletions third-party/sysdeps/linux/elfutils/overlay/libelf/libelf.map

This file was deleted.

18 changes: 18 additions & 0 deletions third-party/sysdeps/linux/elfutils/patch_source.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

set -e

SOURCE_DIR="${1:?Source directory must be given}"
MAP_FILES="$(find $SOURCE_DIR -name '*.map')"
C_FILES="$(find $SOURCE_DIR -name '*.c')"
CONFIGURE_FILE="$SOURCE_DIR/configure"

# Prefix symbol version file symbols.
echo "Patching map files: $MAP_FILES"
sed -i -E 's|\b(ELFUTILS_[0-9\.]+)|AMDROCM_SYSDEPS_1.0_\1|' $MAP_FILES

# Prefix symbol version definitions in source files (configure contains a test
# too).
echo "Patching source files: $C_FILES"
sed -i -E 's@^((OLD_VERSION|NEW_VERSION|COMPAT_VERSION_NEWPROTO|COMPAT_VERSION).+)(ELFUTILS_[0-9\.]+.*)$@\1AMDROCM_SYSDEPS_1.0_\3@' \
$C_FILES $CONFIGURE_FILE

0 comments on commit 6a0e4ef

Please sign in to comment.