Skip to content

ass: keep the areas of its allocator aligned for the host - #391

Merged
davidgiven merged 1 commit into
davidgiven:defaultfrom
maarten-boot:upstream/ass-align
Nov 3, 2026
Merged

davidgiven merged 1 commit into
davidgiven:defaultfrom
maarten-boot:upstream/ass-align

Conversation

@maarten-boot

Copy link
Copy Markdown
Contributor

em22's assembler (util/ass) has its own allocator in asscm.c.
getarea() rounds sizes to sizeof(int) and splits free blocks from
the end, so after a name (strlen + 1 bytes) the next area lands at 4
(mod 8). The structs kept there (line_t, relc_t, locl_t,
stat_t, and the allocator's own freeblock) hold pointers, so they
are misaligned on a 64-bit host. Built with -fsanitize=alignment,
em_ass reports 919 misaligned accesses while linking the seven em22
examples.

This rounds all sizes to _Alignof(max_align_t) (and to at least the
size of a free block's header), as led does since #385, and aligns the
workspace in main() that is given to the allocator at start.

Tested: all platforms, 226 tests pass. With -fsanitize=alignment:
919 reports before, 0 after (and 919 again with the change reverted).
The seven em22 programs are byte-for-byte identical with and without
the change.

🤖 Generated with Claude Code

getarea() rounds sizes to sizeof(int) and splits free blocks from the
end, so after a name (strlen + 1 bytes) the next area is at 4 (mod 8),
and the structs kept there (line_t, relc_t, locl_t, stat_t and the
allocator's own freeblock, all with pointers) are misaligned on a 64-bit
host: -fsanitize=alignment reports 919 accesses in em_ass when the em22
examples are linked.

Round all sizes to _Alignof(max_align_t), and to at least the size of a
free block's header, as led does since its alignment fix; align the
workspace in main()'s frame that is given to the allocator at start.
em_ass's output is unchanged (the seven em22 examples are identical).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@davidgiven

Copy link
Copy Markdown
Owner

Merging, thanks (although I think I'll just rip out the custom allocator here; they're usually a terrible idea).

@davidgiven
davidgiven merged commit c2d5f8a into davidgiven:default Nov 3, 2026
3 checks passed
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.

2 participants