Skip to content

Commit 08e81cc

Browse files
committed
Fix unaligned pointer bug
Use sed to change the interpreter instead of patchelf to avoid a patchelf bug that causes SIGBUS due to unaligned pointers on MIPS
1 parent bcaf1e1 commit 08e81cc

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/build-dist.nix

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ let
6161
arch=''${util##*.}
6262
mkdir -p $out/dylibs/$arch
6363
old_interp=$(patchelf $util --print-interpreter)
64+
new_interp=/igloo/dylibs/$(basename $old_interp)
65+
66+
# Pad string so new interpreter path is the same length as the old one
67+
new_interp_padded=$new_interp
68+
while [ ''${#new_interp_padded} -lt ''${#old_interp} ]; do
69+
new_interp_padded="/$new_interp_padded"
70+
done
6471
6572
echo "Collecting interpreter from $util"
6673
ln -sf $old_interp $out/dylibs/$arch/$(basename $old_interp)
@@ -69,12 +76,13 @@ let
6976
copyDylibs $arch $util
7077
7178
echo "Switching $util to IGLOO paths"
72-
mkdir -p $out/utils
73-
mkdir -p $out/utils/$arch
79+
util_out_path=$out/utils/$arch/$(basename -s ".$arch" $util)
80+
mkdir -p $(dirname $util_out_path)
7481
patchelf $util \
7582
--set-rpath /igloo/dylibs \
76-
--set-interpreter /igloo/dylibs/$(basename $old_interp) \
77-
--output $out/utils/$arch/$(basename -s ".$arch" $util)
83+
--output $util_out_path
84+
# Hack to avoid unaligned pointer bug with patchelf and MIPS
85+
sed -i "s,$old_interp,$new_interp_padded,g" $util_out_path
7886
7987
done
8088

0 commit comments

Comments
 (0)