Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

beetrees
Copy link
Contributor

@beetrees beetrees commented Jun 18, 2025

Fixes the 64-bit SPARC part of #115609 by replacing the current implementation with a new implementation modelled on the RISC-V calling convention code (SPARC ABI reference).

Pinging sparcv9-sun-solaris target maintainers: @psumbera @kulikjak
Fixes #115336
Fixes #115399
Fixes #122620
r? @workingjubilee

@rustbot
Copy link
Collaborator

rustbot commented Jun 18, 2025

workingjubilee is currently at their maximum review capacity.
They may take a while to respond.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 18, 2025
@beetrees
Copy link
Contributor Author

r? @bjorn3

@rustbot rustbot assigned bjorn3 and unassigned workingjubilee Jun 18, 2025
@beetrees
Copy link
Contributor Author

beetrees commented Jun 18, 2025

Note that there are currently two places that Clang and GCC disagree AFAIK:

  • Clang fails to correctly align 16-byte structs when passing them as arguments, whereas GCC correctly aligns them. As the specification states that the structs must be aligned, I've filed an Clang bug at Clang: 64-bit SPARC doesn't align struct arguments as required by ABIΒ llvm/llvm-project#144709.
  • Clang passes floating point fields in packed structs in floating point register if the field is aligned within the argument as a whole, whereas GCC always passes packed structs in integer registers. The specification doesn't consider the existence of packed structs, however in my opinion Clang's interpretation seems more correct so that's what I've implemented in this PR. Issues for Rust, Clang and GCC.

@psumbera
Copy link
Contributor

Thank you for doing this! My knowledge in this area is rather limited.

I was able to build latest Rust sources with your fix on top on Solaris 11.4 SPARC. Then I used this version to build Firefox on Solaris. There was no problem. Firefox also worked as expected.

I also tested some problematic cases which I was handling few years ago (https://github.com/psumbera/rust-sparc64-abi-tests). All seemed to be ok.

@bjorn3
Copy link
Member

bjorn3 commented Jul 3, 2025

I don't have time to properly review this right now.

r? compiler

@rustbot rustbot assigned WaffleLapkin and unassigned bjorn3 Jul 3, 2025
@workingjubilee workingjubilee self-assigned this Jul 4, 2025
@bors
Copy link
Collaborator

bors commented Jul 6, 2025

β˜” The latest upstream changes (presumably #143521) made this pull request unmergeable. Please resolve the merge conflicts.

@beetrees beetrees force-pushed the sparc64-float-struct-abi branch from 4eb3ce5 to 9e4a7bc Compare July 6, 2025 14:45
@beetrees
Copy link
Contributor Author

beetrees commented Jul 6, 2025

Rebased

@WaffleLapkin WaffleLapkin removed their assignment Jul 8, 2025
@bors
Copy link
Collaborator

bors commented Jul 22, 2025

β˜” The latest upstream changes (presumably #144249) made this pull request unmergeable. Please resolve the merge conflicts.

@beetrees beetrees force-pushed the sparc64-float-struct-abi branch from 9e4a7bc to b7b3ed7 Compare July 27, 2025 08:50
@wesleywiser
Copy link
Member

Hi @workingjubilee, are you still interested in reviewing this? If not, we can reroll for a different reviewer. Thanks!

@tgross35
Copy link
Contributor

tgross35 commented Sep 5, 2025

Looks like there is a Clang fix in llvm/llvm-project#155829

@workingjubilee
Copy link
Member

Sorry about that, currently in catchup mode so I am going to delegate, yes.

r? @tgross35

@rustbot rustbot assigned tgross35 and unassigned workingjubilee Sep 10, 2025
@beetrees beetrees force-pushed the sparc64-float-struct-abi branch from b7b3ed7 to 7cba46f Compare September 10, 2025 19:41
@rustbot

This comment has been minimized.

@beetrees beetrees force-pushed the sparc64-float-struct-abi branch from 7cba46f to b2e4ee9 Compare September 10, 2025 19:51
@rustbot
Copy link
Collaborator

rustbot commented Sep 10, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is neededβ€”this note is just to help reviewers.

Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

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

This looks great, thanks for the updates. I requested a few more comments for things that weren't obvious, r=me after those.

View changes since this review

Comment on lines +174 to +182
if let [Some(reg), None, ..] = regs {
arg.cast_to_and_pad_i32(CastTarget::from(reg).with_attrs(attrs.into()), pad);
} else {
arg.cast_to_and_pad_i32(
CastTarget::prefixed(regs, Uniform::new(Reg::i8(), Size::ZERO))
.with_attrs(attrs.into()),
pad,
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a note about why the Some(reg), None case is special?

_ => {
if let BackendRepr::ScalarPair(scalar1, scalar2) = &layout.backend_repr {
data = arg_scalar_pair(cx, scalar1, scalar2, offset, data);
_ => {}
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens in the fallback case where offset isn't aligned?

Comment on lines +77 to +79
// Match Clang by ignoring whether a struct is packed and just considering
// whether individual fields are aligned. GCC currently uses only integer
// registers when passing packed structs.
Copy link
Contributor

Choose a reason for hiding this comment

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

This has come up a couple of times; it may be worth noting in a comment for the module that GCC and Clang have disagreements that the ABI doesn't resolve, and we match Clang's behavior in these cases.

},
Size::ZERO,
);
let mut double_words = [DoubleWord::Words([Word::Integer; 2]); 4];
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you note where the length 4 comes from? Assuming 8 word-sized registers for arg passing.

Comment on lines -216 to +191
classify_arg(cx, &mut fn_abi.ret, Size::from_bytes(32));
classify_arg(cx, &mut fn_abi.ret, Size::from_bytes(32), &mut 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you mention the significance of 32 bytes?

continue;
}
classify_arg(cx, arg, Size::from_bytes(16));
classify_arg(cx, arg, Size::from_bytes(16), &mut double_word_count);
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly for 16 here

@tgross35
Copy link
Contributor

@rustbot author
@bors delegate+

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 24, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 24, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@bors
Copy link
Collaborator

bors commented Sep 24, 2025

✌️ @beetrees, you can now approve this pull request!

If @tgross35 told you to "r=me" after making some further change, please make that change, then do @bors r=@tgross35

@tgross35
Copy link
Contributor

tgross35 commented Sep 24, 2025

@psumbera if you have access to a sparc machine, any chance you could run https://github.com/Gankra/abi-cafe with and without this PR as a sanity check? You should be able to clone the repo and run cargo run -- --toolchains 'rustc,cc,gcc,clang' and post the list of failures from stdout. To rerun with the PATH=

It picks the first rustc/gcc/cc/clang so I think it needs to be run with PATH=$(realpath build/target/stage1/bin/rustc):$PATH to use a built version.

Edit: looks like packed structs may not work yet Gankra/abi-cafe#33. Still a valuable test._

@brad0
Copy link

brad0 commented Sep 26, 2025

The LLVM fix llvm/llvm-project#155829 has gone into main and I am going to see about backporting to 21.

@psumbera
Copy link
Contributor

@psumbera if you have access to a sparc machine, any chance you could run https://github.com/Gankra/abi-cafe with and without this PR as a sanity check? You should be able to clone the repo and run cargo run -- --toolchains 'rustc,cc,gcc,clang' and post the list of failures from stdout. To rerun with the PATH=

Not sure how to analyze it. But grep failed! test.log | wc -l gives me 156 without the change and 228 with the change. So there seems to be some regression.

Generally I would suggest to use for tests: https://portal.cfarm.net/machines/list/ (cfarm216). This is latest Solaris (SPARC-M8).

I'm ready to help and provide full logs somewhere or anything.

Here are just few tests which are newly failing:

+  F32Array::conv_c::repr_c::cc_calls_rustc::struct_in_1              failed!
+  F32Array::conv_c::repr_c::cc_calls_rustc::val_in                   failed!
+  F32Array::conv_c::repr_c::cc_calls_rustc::val_in_10                failed!
..
+  F32Array::conv_c::repr_c::gcc_calls_rustc::struct_in_1              failed!
+  F32Array::conv_c::repr_c::gcc_calls_rustc::val_in                   failed!
+  F32Array::conv_c::repr_c::gcc_calls_rustc::val_in_10                failed!
..
+  Test F32Array::conv_c::repr_c::cc_calls_rustc::struct_in_1              failed!
+  Test F32Array::conv_c::repr_c::cc_calls_rustc::val_in                   failed!
+  Test F32Array::conv_c::repr_c::cc_calls_rustc::val_in_10    
..
+  Test F32Array::conv_c::repr_c::gcc_calls_rustc::struct_in_1              failed!
+  Test F32Array::conv_c::repr_c::gcc_calls_rustc::val_in                   failed!
+  Test F32Array::conv_c::repr_c::gcc_calls_rustc::val_in_10                failed!
..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
10 participants