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

compiler_rt: aarch64 outline atomics #11828

Merged
merged 4 commits into from
Nov 22, 2022
Merged

Conversation

devins2518
Copy link
Contributor

@devins2518 devins2518 commented Jun 9, 2022

Ported from llvm's port of libgcc's outline atomics.

Includes #11667 though, I can remove if this pr is merged before hazes. Removed

Fixes #10086 and zig c++ as noted here.

Issues

  1. The code is admittedly pretty ugly. There's a lot of inline assembly created through a mixture of multiline strings and regular string concatenation which is not ideal. Not sure if the level of comptime variable parsing is possible through just using inputs for inline assembly.
  2. Most of this is not tested. __aarch64_ldadd4_acq_rel is tested as it was the test case, but I'm not too sure about all of the other functions.
  3. __aarch64_have_lse_atomics is constructed through a function in the .ctors section which is definitely hidden control flow. Would be interesting to see any more ziggy solutions to fixing this. __init_aarch64_have_lse_atomics needs to be linked into either __DATA,__mod_init_func or .init_array depending on platform, but @export section handling isn't implemented. Right now, it is just called at the beginning of each outlined function.
  4. initHaveLseAtomics also calls std.os.linux.getauxval even on macOS, which doesn't seem right. This seems beyond the scope of this PR though.

@devins2518 devins2518 force-pushed the arm-atomics branch 12 times, most recently from ae4d00f to 4a4cd4d Compare June 15, 2022 12:46
@devins2518 devins2518 marked this pull request as ready for review June 15, 2022 16:03
@devins2518
Copy link
Contributor Author

@PiotrSikora could you try this to see if it fixes #10777 ?

@devins2518 devins2518 force-pushed the arm-atomics branch 4 times, most recently from 31fc53d to 4fee891 Compare June 22, 2022 22:18
@devins2518 devins2518 force-pushed the arm-atomics branch 2 times, most recently from 0a660f1 to d111ab7 Compare June 24, 2022 01:18
@andrewrk andrewrk force-pushed the arm-atomics branch 2 times, most recently from 2300bba to d6823f9 Compare November 22, 2022 00:04
devins2518 and others added 4 commits November 21, 2022 17:17
 * Rely on libSystem when targeting macOS.
 * Make tools/gen_outline_atomics.zig more idiomatic.
 * Remove the CPU detection / auxval checking from compiler_rt. This
   functionality belongs in a different component. Zig's compiler_rt
   must not rely on constructors. Instead it will export a symbol for
   setting the value, and start code can detect and activate it.
 * Remove the separate logic for inline assembly when the target does or
   does not have lse support. `.inst` works in both cases.
After this, the machine code generated by zig matches identically to
gcc's after the differences in loading the have_lse flag.
@andrewrk andrewrk merged commit 271cc52 into ziglang:master Nov 22, 2022
@andrewrk
Copy link
Member

@devins2518 thank you for implementing this. It took me a long time to get around to merging it but it finally landed in 271cc52. I made some edits to what you have here:

  • no more branching logic for has_lse. the same .inst assembler instruction can work with or without that feature. It's strange that the corresponding gcc code bothered to have that in there.
  • no more branching logic for darwin. libSystem already has these symbols, so no need to duplicate them in compiler_rt.a for darwin.
  • removed the auxval integration. zig's compiler_rt has a requirement of not using constructors. instead, we will export a function that can be called from third party start code to tell compiler_rt what CPU features are enabled. That will be a follow-up enhancement.
  • cleaned up the tools script to be more idiomatic and take advantage of arena allocation.

@devins2518
Copy link
Contributor Author

Thanks so much! It's so awesome to have my first meaningful contribution to zig merged 🎉! I've been planning to rewrite this a bit since #12756 was merged which would remove the need for the generation script and simplify aarch64_outline_atomics.zig a decent amount.

@andrewrk
Copy link
Member

andrewrk commented Nov 22, 2022

Follow-up: #13622

@devins2518 let's chat with @MasterQ32 about inline assembly - right now zig is at a fork in the road about whether to proceed with string concatenation or a more sophisticated inline assembly syntax built into the language.

@andrewrk andrewrk added this to the 0.10.1 milestone Jan 9, 2023
andrewrk added a commit that referenced this pull request Jan 9, 2023
compiler_rt: aarch64 outline atomics
messense added a commit to rust-cross/cargo-zigbuild that referenced this pull request Jan 18, 2023
zig aarch64 outline atomics was resolved in ziglang/zig#11828

[ci skip]
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.

compiler-rt does not define aarch64 outline atomics
2 participants