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

watchOS: fixes for ilp32 ABI #21765

Merged
merged 4 commits into from
Oct 29, 2024
Merged

Conversation

marionauta
Copy link
Contributor

Xcode requires target amd64_32 (aarch64-watchos-ilp32) in order to build code for Apple Watches. This commit fixes compilation errors that appear when compiling with that target.


This PR is a followup to #21752

Xcode requires target amd64_32 (aarch64-watchos-ilp32) in order to
build code for Apple Watches. This commit fixes compilation errors
that appear when compiling with that target.
lib/std/debug.zig Outdated Show resolved Hide resolved
lib/std/macho.zig Outdated Show resolved Hide resolved
Leave `std.macho` as it was and use `@intCast` to that some `u64`
values fit in a `usize`. The `ilp32` ABI uses 32bit pointers, so
usize is also smaller.
@marionauta marionauta requested a review from alexrp October 22, 2024 18:58
Copy link
Member

@alexrp alexrp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable to me given the API shape of std.macho, but I'd like @kubkon to take a look at the std.debug.SelfInfo changes.

@alexrp alexrp requested a review from kubkon October 25, 2024 09:06
@kubkon
Copy link
Member

kubkon commented Oct 25, 2024

I haven't looked closely yet, but do we really need all those intcasts sprinkled everywhere? Do we currently handle any 32bit arch for linux perhaps? If so how do we deal with the issue there?

@alexrp
Copy link
Member

alexrp commented Oct 25, 2024

No, I've only just started the basics of x32/n32 support over in #21717. Standard library support is still on the to-do list. I believe that with these changes, aarch64-watchos-ilp32 will be the first ILP32-on-64 target that's actually usable with the standard library.

As I understand it, the int casts are necessary because of the API shape of std.c and std.macho:

  • std.c.thread_state is defined in terms of u64s on aarch64, so when we want to put those register values into usize (u32) fields, we of course run into trouble. I checked the C headers and couldn't find any indication that this struct is different between aarch64-*-none and aarch64-*-ilp32. So I don't think we can do anything about this.
  • For std.macho.section_64 the issue is similar. It's my understanding that aarch64-*-ilp32 on Darwin uses the 64-bit Mach-O format just like aarch64-*-none, so it doesn't seem like there's much to be done here either.

lib/std/debug.zig Outdated Show resolved Hide resolved
@marionauta
Copy link
Contributor Author

As I understand it, the int casts are necessary because of the API shape of std.c and std.macho

Yeah, exactly that. I wasn't sure what was better, @intCast or @truncate, but I will apply the changes you suggested.

@marionauta
Copy link
Contributor Author

with these changes, aarch64-watchos-ilp32 will be the first ILP32-on-64 target that's actually usable with the standard library.

Exciting! Just FYI, I've been using my branch to build static libraries (.a) for my watch game with not problems. And I've been using the standard library quite a lot.

@alexrp alexrp merged commit 4661705 into ziglang:master Oct 29, 2024
10 checks passed
@marionauta marionauta deleted the aarch64-watchos-ilp32 branch October 30, 2024 09:36
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.

3 participants