cross/crossdirect: fix "unsupported relocation"

Crossdirect redirects archivers (gz, bzip2, ...) to their native
versions when cross compiling. This works e.g. when extracting sources or
packing the .apks at the end of the build. But it currently fails when
such an archiver gets called during package().

For example with bootchart2:

  >>> bootchart2: Entering fakeroot...
  ...
  gzip -c bootchart2.1 > /home/pmos/build/pkg/bootchart2/usr/share/man/man1/bootchart2.1.gz
  Error relocating /native/usr/lib/libfakeroot.so: unsupported relocation type 6
  Error relocating /native/usr/lib/libfakeroot.so: unsupported relocation type 6
  Error relocating /native/usr/lib/libfakeroot.so: unsupported relocation type 1
  Error relocating /native/usr/lib/libfakeroot.so: unsupported relocation type 6

Fix this by running the foreign arch version when it gets called in a
fakeroot.

Fixes: 8a7c9ce7 ("cross/crossdirect: run archivers natively too")
Part-of: <https://gitlab.postmarketos.org/postmarketOS/pmaports/-/merge_requests/7120>
This commit is contained in:
Oliver Smith 2025-10-01 19:51:03 +02:00 committed by The Friendly Merge Bot
parent e59bbc4d6e
commit fca3e7d7ee
No known key found for this signature in database
2 changed files with 13 additions and 5 deletions

View file

@ -20,8 +20,8 @@
# as simple shell wrappers.
pkgname=crossdirect
pkgver=5.3.0
pkgrel=1
pkgver=5.3.1
pkgrel=0
pkgdesc="Wrappers to launch native programs (e.g. cross compilers) in foreign chroots"
url="https://postmarketOS.org"
arch="all"
@ -128,7 +128,7 @@ package() {
sha512sums="
0f4b48f250425dc57f63955fc8b38477d23db793bee367c3fbe03c3d2a559ba576434d07518310db4cae9d90d501af4051b80038b10fae94b980e537fc9374ad cargo.sh
b2e602b7fc95ed403d29f0d754879d5f773c39ee33e726bb10cff17b3c088406dac84f2ca6d8ad563c64370007d98af805d6ee9cd4a06fe3d4c61c0cb90c5c0c crossdirect.c
a87d91b6e3286ce29fb1f487954e7154f282194691a1bf19b4cd80cca07a9c36aa96306883b1a6671ffbc2b503575a8c9484dccde8c55431845056c6f377bec5 exec_native.sh
73e2b5d2d8ef7c6002b3a787d14945586991493b8d81f59e5c0beda0d3b290543e1fdc6f288da726c5dd121c0861d2a894410b7b749a537df0df5b409e102330 exec_native.sh
ea9bf8db3810d03d0a7395057f3d6e57f7127d87c55deaedc171c255288f5f3cc6fbcc680a5a1b92786cf573875d5dc22521173799fe2639acc97d0715ff905b rust-qemu-linker.sh
de2aa6929bbff5db9132673e667f4525b333d062cb1f7a0597dd924de9e5c7215a9f8e2e6263b6fb5ace06f2c4b64f4ebfd0ede9b78add07c2cd08ec8613e98f rustc.sh
"

View file

@ -1,12 +1,20 @@
#!/bin/sh -e
# Execute the binary from the native chroot if it is installed there. This is
# done for archiver tools such as unxz, so they don't need to go through QEMU.
BASENAME="$(basename "$0")"
if [ -n "$LD_PRELOAD" ]; then
# The archiver tool gets called during package(), which abuild runs
# with libfakeroot.so. Some packages do this, like bootchart2, which
# compresses man pages in its "make install". We can't run the native
# binary here due to the LD_PRELOAD, so run the foreign arch one.
export PATH="/usr/bin:/usr/sbin:/sbin:/bin"
exec "$BASENAME" "$@"
fi
# Try /native first, then the foreign arch paths. Never try
# /native/usr/lib/crossdirect as this would result in a loop.
UNWRAPPED_PATH="/native/usr/bin:/native/usr/sbin:/native/sbin:/native/bin:/usr/bin:/usr/sbin:/sbin:/bin"
BASENAME="$(basename "$0")"
UNWRAPPED_BIN="$(PATH="$UNWRAPPED_PATH" command -v "$BASENAME")"
case "$UNWRAPPED_BIN" in