c_backend: Implement C backend - #3504
Open
ManuLinares wants to merge 8 commits into
Open
Conversation
Add the `--cflags` option to forward flags to the underlying C compiler
Cross-compiling for Windows using the C backend failed to produce valid C code and target object files. Win32 entry points were incorrectly named `main` with invalid parameter counts, untyped function pointer invocations produced illegal C syntax, and mismatched cross-module pointer types caused compiler rejections. Additionally, Clang emitted host-format binaries because target triples were not forwarded, and the runtime required non-freestanding headers.
Optimized builds targeting x86_64 encountered hardware alignment faults during execution under Windows/Wine. Local variables requiring 16-byte alignment, such as jmp_buf for setjmp and large aggregate buffers, lacked alignment specifiers in the generated C code. This caused unaligned stack placement and crashed SSE instructions like movdqa. Additionally, direct pointer dereferences of 128-bit integers led compilers to emit aligned vector instructions on unaligned memory. Ensure stack variables maintain required alignment and safely perform 128-bit integer pointer accesses. TODO: Needs cleaning
Check C3 type bit width on shifts to prevent false aborts. Unwrap replaced decls to fix local variable lookups. Emit weak attribute on functions to prevent link collisions. Add missing math builtins, bitwise intrinsics, and __dso_handle for TCC (although TCC doesn't support int128).
Consolidate repeated code patterns across C codegen to reduce size and improve maintainability. Guard against emitting types from inactive modules.
Member
Author
|
mmm, I don't know if I should "namespace" the externs, so they don't conflict with each other on same name but different args. |
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.
Add the
--cflagsoption to forward flags to the underlying C compiler.It's a biggie, it passed all the unit tests:
haven't tested on msvc yet so it most probably break there, but I'll put it in draft.