Skip to content

Ship inline/macros.h and stubs.h, with a fix for gcc 13+ miscompilation - #16

Open
codewiz wants to merge 2 commits into
adtools:masterfrom
codewiz:inline-macros
Open

Ship inline/macros.h and stubs.h, with a fix for gcc 13+ miscompilation#16
codewiz wants to merge 2 commits into
adtools:masterfrom
codewiz:inline-macros

Conversation

@codewiz

@codewiz codewiz commented Aug 2, 2026

Copy link
Copy Markdown

sfdc-generated headers include <inline/macros.h>, but the file itself has
always been shipped by fd2pragma, which has seen no changes in years. Since
sfdc is the tool that actually generates the code depending on these macros,
it seems a better home for them nowadays: m68k-amigaos toolchains (e.g.
amiga-gcc, which currently copies them out of a fd2pragma checkout) could
ship them from here instead.

The first commit imports inline/macros.h and inline/stubs.h verbatim from
AmigaPorts/fd2pragma e98f0901, the copy current toolchains install.

The second commit fixes a silent miscompilation on gcc 13 and later: the
macros bind arguments to local register variables, and the GCC manual warns
that a const-qualified register variable may be substituted with its
initializer inside the asm. gcc 13+ actually does this at -O1 and above, so
a compile-time constant passed to a CONST-typed parameter (e.g. BltPattern's
CONST PLANEPTR mask) lands in a compiler-chosen register instead of the one
named in __asm, and the library call receives garbage:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126552

On gcc 16+ the macros now use hard register constraints (which require
-mlra), the documented replacement with no such hazard. Older compilers keep
the existing definitions, byte-identical, in the #else branch.

Tested with gcc 16.1 (stefanreinauer/amiga-gcc:gcc-v16.1) by building the
p96cts conformance suite against the new macros.h: the NULL mask is now
correctly zeroed into a0 at every BltPattern call site, and the full suite
passes on AmigaOS 3.x on native PAL planar, Picasso96 uaegfx and the P96
software rasterizer, in 8 and 24 bit.

sfdc-generated headers include <inline/macros.h>, but the file itself was
only shipped by fd2pragma, which has not been maintained for years. Import
both headers verbatim from AmigaPorts/fd2pragma e98f0901 (the copy current
m68k-amigaos toolchains install) so sfdc provides the macros its output
depends on.
The GCC manual warns that a local register variable with a const-qualified
type may be substituted with its initializer inside the asm, and gcc 13 and
later actually do it at -O1 and above: a compile-time constant passed to a
CONST-typed parameter (e.g. BltPattern's CONST PLANEPTR mask) is materialized
in a compiler-chosen register instead of the one named in __asm, and the
library call silently receives garbage in that register.

Hard register constraints (gcc 16+, requires -mlra) are the documented
replacement and have no such hazard, so define every LPxx macro with them on
gcc 16 and keep the local-register-variable definitions for older compilers.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126552
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