Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some portability improvements and cleanups in zig.h #22130

Merged
merged 18 commits into from
Dec 7, 2024

Conversation

alexrp
Copy link
Member

@alexrp alexrp commented Dec 3, 2024

I recommend reviewing each commit individually.

Closes #22114. There's still more work to do in bootstrap.c for non-GCC/Clang compilers, but I'll do that in #22054.

@alexrp
Copy link
Member Author

alexrp commented Dec 3, 2024

cc @kcbanner @fuhsnn

@fuhsnn
Copy link

fuhsnn commented Dec 3, 2024

Perhaps #if guards for inline assembly can be summarized to something like use_gnu_style_inline_asm? That would make future modifications simpler.

alexrp added 18 commits December 3, 2024 11:57
… check.

The former is supported by most compilers while the latter is Clang-only.
tcc doesn't have __has_attribute and __has_builtin, so we need to manually check
for tcc in these preprocessor paths.
The old spellings from C11 are deprecated in C23.
There's only one spot in the header where we want to handle GCC but not Clang,
so just add an extra check there.
It seems like only Clang supports this in MinGW mode, and Clang will already
take the __builtin_debugtrap() path anyway.
Just use inline assembly instead, which is what that header does. Also make sure
we have a dummy implementation when inline assembly is unavailable.
We already do this for C99 only later in the file.
If present, these headers are usable even when compiling for older C language
versions.

Most notably, this enables zig.h atomics to work with slimcc and TinyCC in C99
mode (and earlier).
@alexrp alexrp force-pushed the zig-h-portability branch from fbb97d8 to c27488a Compare December 3, 2024 11:11
@fuhsnn
Copy link

fuhsnn commented Dec 3, 2024

Will the changes carry over to stage1/zig.h? As bootstrap.c use -Istage1 this one (lib/zig.h) probably won't get used in bootstrap.

@alexrp
Copy link
Member Author

alexrp commented Dec 3, 2024

Will the changes carry over to stage1/zig.h?

They will on the next zig1.wasm update; see the update-zig1 logic in build.zig.

@fuhsnn
Copy link

fuhsnn commented Dec 3, 2024

They will on the next zig1.wasm update; see the update-zig1 logic in build.zig.

So I couldn't wait and swapped -Istage1 with -Ilib, looks pretty smooth!

user@debian:~/zig_al$ ~/slimcc/slimcc -o zig2 zig2.c compiler_rt.c -std=c99 -O2 -fno-stack-protector -Ilib/ -Wl,-z,stack-size=0x10000000
user@debian:~/zig_al$ echo $?
0

@alexrp
Copy link
Member Author

alexrp commented Dec 6, 2024

Will merge this soon-ish if no one has any other review comments.

@alexrp alexrp merged commit 4894ac4 into ziglang:master Dec 7, 2024
10 checks passed
@alexrp alexrp deleted the zig-h-portability branch December 7, 2024 11:20
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.

Bootstrapping from bootstrap.c, issues compiling zig2.c with tcc and slimcc
2 participants