Reduce usage of AddressSpace::ZERO#12
Merged
xdoardo merged 1 commit intoCHERIoT-Platform:betafrom Sep 2, 2025
Merged
Conversation
16a783f to
acf8d4b
Compare
seharris
approved these changes
Sep 1, 2025
Collaborator
seharris
left a comment
There was a problem hiding this comment.
Looks good to me! Just make sure you're okay with my comment on the CI config. If you think messing with that later will make too much mess then we might want to reconsider that change.
| pull_master_script: git fetch origin master | ||
| tidy_script: CC="clang" CXX="clang++" ./x test tidy | ||
| check_script: CC="clang" CXX="clang++" ./x check | ||
| ui_test_script: CC="clang" CXX="clang++" ./x test ui |
Collaborator
There was a problem hiding this comment.
This should be fine at this stage, but may need fiddling with once we start adding new targets (the ui suite includes tests that run code, and I think it will default to running for all targets enabled in config.toml).
Collaborator
Author
There was a problem hiding this comment.
Yep, could be especially pesky for CHERIoT. I think it's okay for now, and we can adapt it to our needs later.
xdoardo
pushed a commit
that referenced
this pull request
Sep 29, 2025
match clang's `va_arg` assembly on arm targets tracking issue: rust-lang/rust#44930 For this example ```rust #![feature(c_variadic)] #[unsafe(no_mangle)] unsafe extern "C" fn variadic(a: f64, mut args: ...) -> f64 { let b = args.arg::<f64>(); let c = args.arg::<f64>(); a + b + c } ``` We currently generate (via llvm): ```asm variadic: sub sp, sp, #12 stmib sp, {r2, r3} vmov d0, r0, r1 add r0, sp, #4 vldr d1, [sp, #4] add r0, r0, #15 bic r0, r0, #7 vadd.f64 d0, d0, d1 add r1, r0, #8 str r1, [sp] vldr d1, [r0] vadd.f64 d0, d0, d1 vmov r0, r1, d0 add sp, sp, #12 bx lr ``` LLVM is not doing a good job. In fact, it's well-known that LLVM's implementation of `va_arg` is kind of bad, and we implement it ourselves (based on clang) for many targets already. For arm, our own `emit_ptr_va_arg` saves 3 instructions. Next, it turns out it's important for LLVM to explicitly start and end the lifetime of the `va_list`. In rust-lang/rust#146059 I already end the lifetime, but when looking at this again, I noticed that it is important to also start it, see https://godbolt.org/z/EGqvKTTsK: failing to explicitly start the lifetime uses an extra register. So, the combination of `emit_ptr_va_arg` with starting/ending the lifetime makes rustc emit exactly the instructions that clang generates:: ```asm variadic: sub sp, sp, #12 stmib sp, {r2, r3} vmov d16, r0, r1 vldr d17, [sp, #4] vadd.f64 d16, d16, d17 vldr d17, [sp, #12] vadd.f64 d16, d16, d17 vmov r0, r1, d16 add sp, sp, #12 bx lr ``` The arguments to `emit_ptr_va_arg` are based on [the clang implementation](https://github.com/llvm/llvm-project/blob/03dc2a41f3d9a500e47b513de5c5008c06860d65/clang/lib/CodeGen/Targets/ARM.cpp#L798-L844). r? ``@workingjubilee`` (I can re-roll if your queue is too full, but you do seem like the right person here) try-job: armhf-gnu
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.
PR rust-lang/rust#143182 added the ability to set the default address space for targets. This is of course useful for CHERI; however, some pieces of code still use the hard-coded
AddressSpace::ZERO. This PR tries to reduce the usage of that constant in relevant places and when possible (that is, there is a way to get a reference to theTargetDataLayoutfor the target).Most notably, this PR moves
fn type_ptrfrom theBaseTypeCodegenMethodstrait, which has no access to theTargetDataLayoutfor the current target, to theLayoutTypeCodegenMethodstrait.About CI
Piggy-backing on this change there's a change to CI to run `./x test ui`.