Repository navigation
led: keep the structs in a module aligned for the host - #385
Merged
Merged
Conversation
maarten-boot
commented
Oct 31, 2026
Contributor
With USEMALLOC every piece is its own malloc block, but offsets inside ALLOMODL were only 4-aligned: the archive magic took sizeof(int), int_align() rounded to sizeof(int), and the name table followed the 20-byte header and section entries. struct outname, struct ar_hdr and ind_t (8-byte aligned on a 64-bit host) were then used at 4 (mod 8) addresses, which is undefined behaviour (UBSan -fsanitize=alignment reports it on every link with an archive) and would fault on a strict-alignment host. int_align() now rounds to _Alignof(max_align_t), the magic takes int_align(sizeof(int)), the section, name and offset tables start aligned (IND_SECT, IND_NAME, IND_EMIT), and modulsize() is computed from that layout so the parts direct_alloc() and read_modul() allocate add up to it. Linked programs are byte-identical. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
|
Nice, thanks; we can probably dispense with the !USEMALLOC case entirely and remove the #ifdef. It would simplify the code. |
USEMALLOC was always defined, so the !USEMALLOC memory manager (sbreak(), the brk() halves of init_core(), move_up() and compact(), copy_down() and copy_up()) was never compiled. Removed with the #ifdefs, the #define and <unistd.h>; the comments now describe the malloc() pieces. Every linked program is byte-identical to before (cpm, linux68k, linuxppc, pc86; hilo_bas differs between any two builds anyway), all tests pass, and -fsanitize=alignment reports nothing for led. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
maarten-boot
added a commit
to maarten-boot/ack
that referenced
this pull request
Nov 1, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
maarten-boot
added a commit
to maarten-boot/ack
that referenced
this pull request
Nov 1, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Done: USEMALLOC was always defined, so the brk() allocator was never compiled. 38656bd removes it with the #ifdefs (memory.c goes from 810 to 469 lines). On cpm, linux68k, linuxppc and pc86 every linked program is byte-identical to before and all tests pass; with |
Owner
|
Excellent, thanks. Merging. |
maarten-boot
added a commit
to maarten-boot/ack
that referenced
this pull request
Nov 1, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
maarten-boot
added a commit
to maarten-boot/ack
that referenced
this pull request
Nov 1, 2026
…checks Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.