Skip to content

Fix fakeroot build by using od(1) to check 64-bit ELFs#943

Merged
McDutchie merged 4 commits intoksh93:devfrom
JohnoKing:fix-64bit-elf-detection
Apr 1, 2026
Merged

Fix fakeroot build by using od(1) to check 64-bit ELFs#943
McDutchie merged 4 commits intoksh93:devfrom
JohnoKing:fix-64bit-elf-detection

Conversation

@JohnoKing
Copy link
Copy Markdown

bin/package:

  • Use od to check the ELF header if file fails with an error. This allows ksh to build and install correctly in fakeroot environments without encountering bogus seccomp restrictions.

Fixes #919

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.

Fixes ksh93#919
- 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.
- Pass '-A n' to od(1) rather than '-An' for what should be better
  portability.
  - locale.sh: Also apply that change here since a quick grep showed
    this file was also passing -An to od.
@McDutchie
Copy link
Copy Markdown

McDutchie commented Apr 1, 2026

How is -A n more portable than -An? Is there a specific system on which it fails?

Option grouping is part of the POSIX Utility Syntax Guidelines (Guideline 5), which od is expected to follow, so this should work everywhere, just like -tx1 (which you didn't change to -t x1 in locale.sh).

@McDutchie
Copy link
Copy Markdown

Also, why use od instead of file --no-sandbox as the fallback? Hasn't the latter been shown to work already?

If so, the following should be enough, shouldn't it?

diff --git a/bin/package b/bin/package
index a40139161..149e31025 100755
--- a/bin/package
+++ b/bin/package
@@ -1523,7 +1523,9 @@ int b(void) { return 0; }
 					echo 'int main(void) { return 0; }' > $tmp.a.c
 					checkcc
 					$cc $CCFLAGS -o $tmp.a.exe $tmp.a.c </dev/null >/dev/null 2>&1
-					file $tmp.a.exe 2>/dev/null | sed "s/$tmp\.a\.exe//g"  )
+					{
+						file $tmp.a.exe || file --no-sandbox $tmp.a.exe
+					} 2>/dev/null | sed "s/$tmp\.a\.exe//g"  )
 				case $bits in
 				*\ 64-bit* | *\ 64\ bit* | *\ 64bit*)
 					bits=64 ;;

@JohnoKing
Copy link
Copy Markdown
Author

Also, why use od instead of file --no-sandbox as the fallback?

od is more portable than file --no-sandbox (the latter is Linux-specific), so the od version can be used as a fallback on any ELF-using system that provides a defective file command (though I'm not aware of any other defective file implementations beside Linux's).

The use of -A n is because I was concerned about the possibility of an older/obsolete OS lacking a properly POSIX-compliant version of od -A. That probably doesn't matter though, so I'll revert that change.

@McDutchie
Copy link
Copy Markdown

od is more portable than file --no-sandbox (the latter is Linux-specific),

I'm seeing it on macOS and FreeBSD as well.

In any case, since we're trying file without options first (in the patch above), and only falling back to file --no-sandbox if that fails, I don't really see how that's relevant.

@JohnoKing
Copy link
Copy Markdown
Author

JohnoKing commented Apr 1, 2026

I'm seeing it on macOS and FreeBSD as well.

You're apparently correct, the option is available (I should have checked). However, I don't think it does anything there; the --no-sandbox flag is meant to disable seccomp, which is available on neither FreeBSD nor macOS (the man page says it's a no-op if seccomp is unavailable). This makes a --no-sandbox fallback effectively Linux-only, even if it technically "works" on other operating systems lacking seccomp. The od fallback comparatively is more platform-neutral and could be worthwhile if file fails due to some reason other than seccomp (though I'll admit that's unlikely).

@McDutchie
Copy link
Copy Markdown

Alright then, in it goes, for more resilience against potential other forms of file(1) breakage.

@McDutchie McDutchie merged commit b27af45 into ksh93:dev Apr 1, 2026
McDutchie pushed a commit that referenced this pull request Apr 1, 2026
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
@JohnoKing JohnoKing deleted the fix-64bit-elf-detection branch April 1, 2026 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Arch Linux AUR (PKGBUILD) - gitignore

2 participants