Skip to content

The C backend builds and runs on a 32-bit host (ARMv7) - #2350

Open
np wants to merge 3 commits into
bendlang:mainfrom
np:host-32bit
Open

np wants to merge 3 commits into
bendlang:mainfrom
np:host-32bit

Conversation

@np

@np np commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

TLDR: I well know that this change has little chance being included, yet it might serve others in need of an off the shelf 32 bit version.

The rest has been made by Claude Fable 5.2.

A binary built by bend main.bend -o main for a 32-bit Linux target stops at
bend: reservation failed: the runtime reserves an 8 GiB corpus and 2 GiB per
worker stack. These three commits make it run there. A 64-bit host takes the
same paths as before.

What changes

  • Runtime (comp.ts): on a 32-bit host the corpus is 1 GiB and a stack
    64 MiB.
  • Effects (effs/): read_at and write_at zero-extend their U32
    offset, which an intptr_t sign-extended past 2^31. File.read grows its
    buffer from 64 KiB instead of allocating max bytes up front, and
    TCP.recv fills 16 MiB at most.
  • CLI (main.ts): -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64, and
    -Wno-ignored-attributes for preserve_none on a target without it.
    35 lines added, 12 removed. No new file, no change to bend.ts.

Why

A Raspberry Pi 2 experiment with a Bend program. Through the JS target it takes
11.05 ms of processor per frame and 68 MiB; through the C target, with this change,
5.34 ms and 2 MiB.

Tested

On a Raspberry Pi 2 Model B (ARMv7, 902 MiB, glibc 2.44), cross-compiled with
clang 22, the commits applied on 0e2f38f:

  • The tree of 2^20 leaves of the BendRT paper: right sum on 1 and 4 threads.
  • The C lane of every directory of tests/ (compile to C, build, run, compare
    with the #| lines): 1 866 files, 897 pass, 953 not run by the C lane,
    12 need X11 or ALSA, 4 fail. The four are below.
  • The experiment program: outputs are byte for byte the same as the JS
    target's, for three sets of options (one does FFTs in F32).
    On x86-64 (clang 18), the commits rebased on 6180be5, same script: 904 pass,
    1 fails (io_tcp_text_residue).

Not tested, and limits

  • Four tests of tests/io fail on the Pi and were not investigated:
    io_process_run (it also runs /usr/bin/perl, absent there),
    io_tcp_text_residue (fails on x86-64 too), io_tcp_send_slow_peer
    (out of time) and io_file_write_at_control (it interposes pwrite; with
    64-bit file offsets the runtime calls pwrite64, which is probably why).
  • Rebased on 6180be5, the commits build for ARMv7 but were not run there: the
    runs on the Pi are on 0e2f38f.
  • One 32-bit target only: ARMv7 with glibc and clang. Not musl, not gcc.
    32-bit x86 does not build: clang 22 crashes on it.
  • The gates were not run. gates/repo.ts needs ttok, which I could not run:
    the change adds a few lines to comp.ts and main.ts, and I do not know
    how close they are to their caps.
  • On a 32-bit host a program has 1 GiB of corpus at most, and a deep
    recursion faults at 64 MiB of stack instead of 2 GiB.

np and others added 3 commits November 24, 2026 23:35
A 32-bit host cannot reserve the 8 GiB corpus or 2 GiB per worker stack:
the binary stops at "reservation failed". There the corpus is 1 GiB and
a stack 64 MiB; a 64-bit host is unchanged. The corpus hints above 4 GiB
truncate to NULL and are refused, so corpus_map needs no change.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NeFHfjcD91QfgepK9AbuXt
read_at and write_at keep their U32 offset in an intptr_t, which a 32-bit
host sign-extends past 2^31: zero-extend it. File.read and TCP.recv
allocate max bytes up front, which only a 64-bit address space affords:
on a 32-bit host a read grows its buffer from 64 KiB and a recv fills at
most 16 MiB. A 64-bit host takes the same paths as before.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NeFHfjcD91QfgepK9AbuXt
64-bit file offsets and clocks, where the C library has both sizes, and
no warning for preserve_none on a target without it (the segments then
use the default convention, still under musttail).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NeFHfjcD91QfgepK9AbuXt
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.

1 participant