-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
"Handle" calls to upstream monomorphizations in compiler_builtins #122580
Conversation
These commits modify the If this was unintentional then you should revert the changes before this PR is merged. |
This comment has been minimized.
This comment has been minimized.
67470be
to
34feef3
Compare
return MergingSucc::False; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cg_clif will need this change too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I apply this change to cranelift, how would I verify that it works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And the new code would likely be somewhere around https://github.com/rust-lang/rustc_codegen_cranelift/blob/4cf4ffc6ba514f171b3f52d1c731063e4fc45be3/src/abi/mod.rs#L374
34feef3
to
f3131d7
Compare
Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 |
f3131d7
to
5f4f252
Compare
I like this approach since it removes the need for existing hacks like disabling debug assertions and disabling overflow checks. |
That's also why I like it! For the record, @dpaoliello deserves some credit for saying this:
Which taken literally is not possible, but it's a very good line of thinking that led me to this. |
Hmm. Is there any way to test the behavior being introduced here as part of our CI test suite? It seems like testing it would require either:
... so after some reflection, I am guessing that Options 1 and 2 are impossible or non-desirable; option 3 might be doable but isn't really attractive from an overall development trajectory standpoint. And instead, we just say "we do not intend to regression test this PR as part of our test suite. One can test it in a local fashion by making local changes to compiler-builtins that expose the behavior in question." Does that all sound right? |
This looks fine to me as it stands, assuming that I'm correct about it not being reasonable to try to test it in CI. But I also am inferring that it should not land without the corresponding changes to cg_clif @rustbot author |
This has been added to the PR since I made that comment. |
Oh, whoops! Thanks! |
@bors r+ |
I agree that we should have some tests for this. I'll open an issue with some ideas. |
@bors rollup=never |
Finished benchmarking commit (b3df0d7): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 669.525s -> 669.004s (-0.08%) |
These symbols may be undefined in a debug build of compiler_builtins:\n\ | ||
{:?}", | ||
undefined_relocations | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this extra check needed, given the check during codegen? How can it even fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are compiler changes in the commit that I only discovered are necessary by adding this test. Normally we always build compielr_builtins with optimizations enabled. So those changes would probably have been build failures in the -nopt
jobs, but that's such a late failure. Here's that commit: 2f6fb23 And those changes are:
Not only is -Copt-level=0
not optimized, it enables -Zshare-generics
by default. So compiler_builtins needs to opt out of this, because sharing the generics of core also makes it inherit panics.
The check in codegen is awfully fiddly to get right. I forgot to apply the "abort on panic" logic inside terminate_block
; compiler_builtins uses some rustc_nounwind
functions, and that attribute makes us insert UnwindTerminate blocks just in case there is an unwind. Those blocks tend to be optimized out, but if optimizations are off, they become calls into core.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay so this kind of sanity-checks the codegen-time checks? Makes sense, thanks. (That may be worth a comment in the code though so it's also clear to a future reader.)
While trying to solve the CI issues in compiler_builtins, I noticed that That's not what's causing the currently issues in CI (x86_64-apple-darwin seems to still be generating references to panic), but it might be worth fixing. |
I just noticed this as well. I'm starting to look into it. |
Ah no what I was looking at is another case of #118770, at least this time it's just me causing trouble for me. You probably don't care to support I'll extract a reproducer of the embed-bitcode issue from the compiler-builtins CI. |
…, r=pnkfelix "Handle" calls to upstream monomorphizations in compiler_builtins This is pretty cooked, but I think it works. compiler-builtins has a long-standing problem that at link time, its rlib cannot contain any calls to `core`. And yet, in codegen we _love_ inserting calls to symbols in `core`, generally from various panic entrypoints. I intend this PR to attack that problem as completely as possible. When we generate a function call, we now check if we are generating a function call from `compiler_builtins` and whether the callee is a function which was not lowered in the current crate, meaning we will have to link to it. If those conditions are met, actually generating the call is asking for a linker error. So we don't. If the callee diverges, we lower to an abort with the same behavior as `core::intrinsics::abort`. If the callee does not diverge, we produce an error. This means that compiler-builtins can contain panics, but they'll SIGILL instead of panicking. I made non-diverging calls a compile error because I'm guessing that they'd mostly get into compiler-builtins by someone making a mistake while working on the crate, and compile errors are better than linker errors. We could turn such calls into aborts as well if that's preferred.
@saethlin
Looks like the test suite uses a wrong temporary directory on Windows in some cases. |
@petrochenkov Judging from the error message, it's emitted from codegen: rust/compiler/rustc_codegen_ssa/src/back/link.rs Lines 99 to 102 in 22f5bdc
Where somehow |
Oh it's using In this case either |
I think the helper lib could have a |
I'll work on a patch for this |
@ChrisDenton I opened #125426, for now I only preserve |
Isn't that a terrible fallback? If that's happening in our implementation, it seems better to error out than provide an unwriteable directory. |
It's not our fallback. See https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppath2w |
Ah, unfortunate. I wonder if that's worth working around on our side. But |
We could still describe this in the docs, because it is very surprising... EDIT: filed #125439 to not forget. |
…<try> Update `compiler-builtins` test to not clear essential env vars Noticed in rust-lang#122580 (comment), the `compiler-builtins` test failed on Windows for a `cargo` invocation because necessary env vars `TMP` and `TEMP` were cleared by `Command::env_clear`, causing temp dir eventually used by codegen to fallback to the Windows directory, which will trigger permission errors. This PR adds a `clear_non_essential_env_vars` helper, which is a more conservative `Command::env_clear` that does not clear `TMP` or `TEMP` on Windows, and does not clear `TMPDIR` on non-Windows platforms. cc `@ChrisDenton` do you happen to know if there are any more "essential" env vars that we should not clear (on Windows or other platforms)? r? `@saethlin` (feel free to reroll, since you authored the test) try-job: x86_64-msvc try-job: test-various
…<try> Update `compiler-builtins` test to not clear essential env vars Noticed in rust-lang#122580 (comment), the `compiler-builtins` test failed on Windows for a `cargo` invocation because necessary env vars `TMP` and `TEMP` were cleared by `Command::env_clear`, causing temp dir eventually used by codegen to fallback to the Windows directory, which will trigger permission errors. This PR adds a `clear_non_essential_env_vars` helper, which is a more conservative `Command::env_clear` that does not clear `TMP` or `TEMP` on Windows, and does not clear `TMPDIR` on non-Windows platforms. cc `@ChrisDenton` do you happen to know if there are any more "essential" env vars that we should not clear (on Windows or other platforms)? r? `@saethlin` (feel free to reroll, since you authored the test) try-job: x86_64-msvc try-job: test-various
…saethlin Update `compiler-builtins` test to not clear essential env vars Noticed in rust-lang#122580 (comment), the `compiler-builtins` test failed on Windows for a `cargo` invocation because necessary env vars `TMP` and `TEMP` were cleared by `Command::env_clear`, causing temp dir eventually used by codegen to fallback to the Windows directory, which will trigger permission errors. This PR removes the `env_clear` on the cargo invocation. r? `@saethlin` (feel free to reroll, since you authored the test) try-job: x86_64-msvc try-job: test-various
Update `compiler-builtins` test to not clear essential env vars Noticed in rust-lang/rust#122580 (comment), the `compiler-builtins` test failed on Windows for a `cargo` invocation because necessary env vars `TMP` and `TEMP` were cleared by `Command::env_clear`, causing temp dir eventually used by codegen to fallback to the Windows directory, which will trigger permission errors. This PR removes the `env_clear` on the cargo invocation. r? `@saethlin` (feel free to reroll, since you authored the test) try-job: x86_64-msvc try-job: test-various
This is pretty cooked, but I think it works.
compiler-builtins has a long-standing problem that at link time, its rlib cannot contain any calls to
core
. And yet, in codegen we love inserting calls to symbols incore
, generally from various panic entrypoints.I intend this PR to attack that problem as completely as possible. When we generate a function call, we now check if we are generating a function call from
compiler_builtins
and whether the callee is a function which was not lowered in the current crate, meaning we will have to link to it.If those conditions are met, actually generating the call is asking for a linker error. So we don't. If the callee diverges, we lower to an abort with the same behavior as
core::intrinsics::abort
. If the callee does not diverge, we produce an error. This means that compiler-builtins can contain panics, but they'll SIGILL instead of panicking. I made non-diverging calls a compile error because I'm guessing that they'd mostly get into compiler-builtins by someone making a mistake while working on the crate, and compile errors are better than linker errors. We could turn such calls into aborts as well if that's preferred.