pret / agbcc

C compiler
104 stars 75 forks source link

Refactor all uses of GEN_FCN to use locals #52

Closed holmesmr closed 1 year ago

holmesmr commented 2 years ago

An intermediate local value (cast to the appropriate signature) for lookups in the instruction generation jump table works around a code generation bug in macOS ARM64 clang that would cause their parameters to be pushed on the stack instead of passed in registers.

holmesmr commented 2 years ago

(addresses #43)

holmesmr commented 2 years ago

I've had feedback on the pret Discord server that this works and people are able to build projects such as pokefirered on M1 Macs.

Further research indicates that both vanilla Clang and gcc are also affected, so this might be a more general ABI problem. Either way, the issue is fixed by these changes; it's a matter of if they're acceptable to merge given the extent of them.

holmesmr commented 2 years ago

I've recently found some documentation indicating these may be consequences of deliberate changes made to the ARM64 ABI on Apple platforms: https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms#Update-Code-that-Passes-Arguments-to-Variadic-Functions

rawr51919 commented 2 years ago

@holmesmr If you use Fixes #43 or similar on the first comment of a PR, it'll make that PR so it'll close the issue once it's merged. Also works with Resolves #43 and Closes #43 This may also fix #46 and #38 (even though #38 already has a fix in #39)