Ship inline/macros.h and stubs.h, with a fix for gcc 13+ miscompilation - #16
Open
codewiz wants to merge 2 commits into
Open
Ship inline/macros.h and stubs.h, with a fix for gcc 13+ miscompilation#16codewiz wants to merge 2 commits into
codewiz wants to merge 2 commits into
Conversation
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
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.
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.