Skip to content

Commit b27af45

Browse files
authored
Fix fakeroot build by using od(1) to check 64-bit ELFs (#943)
bin/package: - Use od(1) to check the ELF header if the file command fails. This allows ksh to build and install correctly in fakeroot environments without encountering bogus seccomp restrictions. - Check the first five bytes to guarantee it's actually an ELF binary. - Return 'Unknown bits' if it's neither a 64-bit ELF nor 32-bit ELF (i.e. it could be anything). This isn't functionally different but is better for clarity. Resolves: #919
1 parent fb8d814 commit b27af45

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

bin/package

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,18 @@ int b(void) { return 0; }
15231523
echo 'int main(void) { return 0; }' > $tmp.a.c
15241524
checkcc
15251525
$cc $CCFLAGS -o $tmp.a.exe $tmp.a.c </dev/null >/dev/null 2>&1
1526-
file $tmp.a.exe 2>/dev/null | sed "s/$tmp\.a\.exe//g" )
1526+
file_result=$(file $tmp.a.exe 2>/dev/null | sed "s/$tmp\.a\.exe//g") || true
1527+
# Use od(1) to check the ELF header directly if file(1) failed
1528+
if test -z "$file_result" && test "$(uname -s | sed 's/-.*//')" != CYGWIN
1529+
then elfbytes=$(od -An -tx1 -N 5 $tmp.a.exe | tr -d ' \n')
1530+
if test "$elfbytes" = "7f454c4602"
1531+
then echo "ELF 64-bit"
1532+
elif test "$elfbytes" = "7f454c4601"
1533+
then echo "ELF 32-bit"
1534+
else echo "Unknown bits"
1535+
fi
1536+
else echo "$file_result"
1537+
fi )
15271538
case $bits in
15281539
*\ 64-bit* | *\ 64\ bit* | *\ 64bit*)
15291540
bits=64 ;;

0 commit comments

Comments
 (0)