Skip to content

Update rustc to nightly-2022-08-08#595

Merged
kkysen merged 21 commits into
masterfrom
kkysen/update-rustc
Aug 16, 2022
Merged

Update rustc to nightly-2022-08-08#595
kkysen merged 21 commits into
masterfrom
kkysen/update-rustc

Conversation

@kkysen

@kkysen kkysen commented Aug 10, 2022

Copy link
Copy Markdown
Contributor

Supercedes #513.

I kept behavior identical (at least I meant to) during this update, even if it may make more sense to relax a match or avoid an .unwrap() now. We can fix those later if we determine it is correct to do so. These places I marked with TODOs.

I fixed almost all of the errors that came up with upgrading rustc; many were similar/the same to #513, but there are a few left in c2rust-analyze that I was unsure how to handle. Some enums got more variants, and I'm not sure how we should handle those in matches, as that's new behavior. @spernsteiner, if you can help with those, that'd be great!

@spernsteiner spernsteiner left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

c2rust-analyze changes look good to me.

Comment thread c2rust-analyze/src/borrowck/type_check.rs
@spernsteiner

Copy link
Copy Markdown
Collaborator

I pushed fixes for the remaining c2rust-analyze build errors on the update-rustc-analyze-fixes branch.

@kkysen

kkysen commented Aug 10, 2022

Copy link
Copy Markdown
Contributor Author

Thanks! You could've just pushed directly here, though.

@kkysen kkysen requested a review from oinoom August 10, 2022 19:23
@kkysen

kkysen commented Aug 10, 2022

Copy link
Copy Markdown
Contributor Author

It seems atomic intrinsics were changed, so we need to update them: c2rust-testsuite CI failure.

Why are we using unstable intrinsics anyways?

@thedataking

Copy link
Copy Markdown
Contributor

Why are we using unstable intrinsics anyways?

As far as I remember, these correspond to atomic operations on values in the input C code. We'd introduce some pretty horrible bugs in the generated Rust if we didn't.

@fw-immunant

Copy link
Copy Markdown
Contributor

Looks like it was rust-lang/rust#97423 that broke this. I'll see about a fix.

@kkysen

kkysen commented Aug 11, 2022

Copy link
Copy Markdown
Contributor Author

It might be from here:

(SeqCst, SeqCst) => "",
(SeqCst, Acquire) => "_failacq",
(SeqCst, Relaxed) => "_failrelaxed",
(AcqRel, Acquire) => "_acqrel",
(AcqRel, Relaxed) => "_acqrel_failrelaxed",
(Release, Relaxed) => "_rel",
(Acquire, Acquire) => "_acq",
(Acquire, Relaxed) => "_acq_failrelaxed",
(Relaxed, Relaxed) => "_relaxed",

Comment thread c2rust-transpile/src/translator/atomics.rs
@fw-immunant

fw-immunant commented Aug 11, 2022

Copy link
Copy Markdown
Contributor

Now we hit an ICE on unsupported cast: *mut libc::c_void to usize...

I think it may be that we need a different CastKind in cast_ptr_to_usize.

@spernsteiner

Copy link
Copy Markdown
Collaborator

I think it may be that we need a different CastKind in cast_ptr_to_usize.

Looks like there's a new CastKind::PointerExposeAddress for this, as part of the strict provenance work

@kkysen

kkysen commented Aug 11, 2022

Copy link
Copy Markdown
Contributor Author

Yeah, I was thinking it looked related to strict provenance.

Another thing, I think we shouldn't tie the transpiler to the current rustc version. That is, the rust-toolchain.toml that we write in the generated crate shouldn't be automatically the same as ours; it should be updated separately. That way upgrading rustc won't break the transpiler, and we can upgrade that transpiled code rustc version separately.

@kkysen

kkysen commented Aug 11, 2022

Copy link
Copy Markdown
Contributor Author

Why do we need to cast pointer to usize? Can't we use an opaque pointer and avoid ptr to int casts? Either an extern type (unstable I think but we're using rustc internals anyways) or a pointer to an empty array.

@fw-immunant

fw-immunant commented Aug 12, 2022

Copy link
Copy Markdown
Contributor

./scripts/test_translator.py tests/ --only-directories builtins is also broken now:

Oops, I forgot to save some changes before committing. I'll push a fix.

By the way, these error messages are a bug, right? They're still referring to the old intrinsic names.

They do look wrong, but I think they're caused by the backwards-compatibility aliases which still exist: https://github.com/m-ou-se/rust/blob/4982a59986f7393ace98f63c10e6c435ffba1420/library/core/src/intrinsics.rs#L949-L965

Re: cxchg orderings, I think it's fine to change them in a follow-up PR.

these were missed in the last round of changes
@kkysen

kkysen commented Aug 12, 2022

Copy link
Copy Markdown
Contributor Author

Ah, that's why the error messages are wrong. I already commented on that PR that they are wrong, though, but I do still think they're very misleading as it says nothing about them being re-exported.

@kkysen

kkysen commented Aug 12, 2022

Copy link
Copy Markdown
Contributor Author

For cast_ptr_to_usize, do we want the provenance? That is, do we want .addr() or .expose_addr()? And why not keep it an opaque pointer (with provenance)?

@kkysen

kkysen commented Aug 12, 2022

Copy link
Copy Markdown
Contributor Author

If I just switch CastKind::Misc to CastKind::PointerExposeAddress, I get this error that I'm unsure why is happening:

error: internal compiler error: /rustc/d394408fb38c4de61f765a3ed5189d2731a1da91/compiler/rustc_codegen_ssa/src/mir/operand.rs:120:18: not immediate: OperandRef(Pair(([0 x { [0 x i8]*, i64 }]*:[0 x { [0 x i8]*, i64 }]* bitcast (<{ i8*, [8 x i8] }>* @5 to [0 x { [0 x i8]*, i64 }]*)), (i64:i64 1)) @ TyAndLayout { ty: *const [&str], layout: Layout { size: Size(16 bytes), align: AbiAndPrefAlign { abi: Align(8 bytes), pref: Align(8 bytes) }, abi: ScalarPair(Initialized { value: Pointer, valid_range: 0..=18446744073709551615 }, Initialized { value: Int(I64, false), valid_range: 0..=18446744073709551615 }), fields: Arbitrary { offsets: [Size(0 bytes), Size(8 bytes)], memory_index: [0, 1] }, largest_niche: None, variants: Single { index: 0 } } })

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/d394408fb38c4de61f765a3ed5189d2731a1da91/compiler/rustc_errors/src/lib.rs:1392:9
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: std::panic::panic_any::<rustc_errors::ExplicitBug>
   2: <rustc_errors::HandlerInner>::bug::<&alloc::string::String>
   3: <rustc_errors::Handler>::bug::<&alloc::string::String>
   4: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, ()>::{closure#0}, ()>
   5: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>
   6: rustc_middle::util::bug::bug_fmt
   7: rustc_codegen_ssa::mir::codegen_mir::<rustc_codegen_llvm::builder::Builder>
   8: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
   9: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_span::symbol::Symbol, rustc_codegen_ssa::ModuleCodegen<rustc_codegen_llvm::ModuleLlvm>>
  10: rustc_codegen_llvm::base::compile_codegen_unit
  11: rustc_codegen_ssa::base::codegen_crate::<rustc_codegen_llvm::LlvmCodegenBackend>
  12: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  13: <rustc_session::session::Session>::time::<alloc::boxed::Box<dyn core::any::Any>, rustc_interface::passes::start_codegen::{closure#0}>
  14: <rustc_interface::passes::QueryContext>::enter::<<rustc_interface::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core::result::Result<alloc::boxed::Box<dyn core::any::Any>, rustc_errors::ErrorGuaranteed>>
  15: <rustc_interface::queries::Queries>::ongoing_codegen
  16: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorGuaranteed>>
  17: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
  18: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>
  19: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>

Happening here:
https://github.com/rust-lang/rust/blob/b998821e4c51c44a9ebee395c91323c374236bbb/compiler/rustc_codegen_ssa/src/mir/operand.rs#L115-L122, but I'm unsure why without building and debugging rustc.

@spernsteiner

Copy link
Copy Markdown
Collaborator

Are we trying to cast &T/&mut T directly to usize, without going through *const T/*mut T first? I don't think this was ever supported, but maybe we were getting away with it under the old nightly.

@kkysen

kkysen commented Aug 12, 2022

Copy link
Copy Markdown
Contributor Author

I didn't think so, and the comments say we cast references first to pointers.

@fw-immunant

Copy link
Copy Markdown
Contributor

Based on the error message, it sounds like we're trying to do something illegal with *const [&str] (perhaps casting it to usize?).

@fw-immunant

Copy link
Copy Markdown
Contributor

Adding this assertion seems to pre-empt the later error:

diff --git a/dynamic_instrumentation/src/point/cast.rs b/dynamic_instrumentation/src/point/cast.rs
index 4b5db5fa..25799dba 100644
--- a/dynamic_instrumentation/src/point/cast.rs
+++ b/dynamic_instrumentation/src/point/cast.rs
@@ -29,6 +29,12 @@ pub fn cast_ptr_to_usize<'tcx>(
 
     let arg_ty = arg.inner().ty(locals, tcx);
 
+    assert!(!arg_ty.is_array_slice(),
+        "{:?}: {:?} is a slice ptr",
+        arg,
+        arg_ty
+    );
+
     let ptr = match arg {
         // If we were given an address as a usize, no conversion is necessary
         InstrumentationArg::Op(ArgKind::AddressUsize(_arg)) => {iff

Is it sufficient for instrumentation to only trace scalar accesses? If so, we can add this assertion and also skip tracing these values when collecting instrumentation points.

@spernsteiner

spernsteiner commented Aug 12, 2022

Copy link
Copy Markdown
Collaborator

It would be nice to keep instrumenting slice pointers, just in case. You could have it cast *const [T] to *const T (discarding the length) and from there cast to usize.

@kkysen

kkysen commented Aug 12, 2022

Copy link
Copy Markdown
Contributor Author

Do we need to track both originally raw fat pointers and ones that originally were non-raw fat pointers (e.x. slices)?

@kkysen

kkysen commented Aug 12, 2022

Copy link
Copy Markdown
Contributor Author

I'm not sure why this broke during the update, though, as I would've thought this was an error previously, too.

@kkysen

kkysen commented Aug 12, 2022

Copy link
Copy Markdown
Contributor Author

I managed to fix the fat ptr to usize cast error in 906968b by casting all pointers to *const [(); 0], an opaque pointer. Then this is cast to usize. I think we should use this kind of opaque pointer in the runtime itself and not cast it to a usize at all, but that'd be for another PR.

I haven't updated the snapshot yet as it's quite noisy since changing the MIR length (from PointerExposeAddress instead of Misc) adds a bunch of padding. That's fixed in #610, so I want to merge that one first (it's pretty trivial).

@spernsteiner

Copy link
Copy Markdown
Collaborator

Why *const [(); 0] instead of *const ()? Shouldn't the two be basically equivalent for this purpose?

@kkysen

kkysen commented Aug 12, 2022

Copy link
Copy Markdown
Contributor Author

Why *const [(); 0] instead of *const ()? Shouldn't the two be basically equivalent for this purpose?

I believe it's because () can't be used in FFI sometimes (maybe just without warnings), so the empty array is preferred instead. Ideally extern types would be used but those are unstable.

@spernsteiner

Copy link
Copy Markdown
Collaborator

() can't be used in FFI sometimes (maybe just without warnings)

Does that apply here? If we're immediately casting to usize, then this pointer type won't appear in any FFI signatures. And even if we push the cast into the runtime library, calls into the runtime are ordinary Rust calls, not FFI calls.

@kkysen

kkysen commented Aug 13, 2022

Copy link
Copy Markdown
Contributor Author

Does that apply here? If we're immediately casting to usize, then this pointer type won't appear in any FFI signatures. And even if we push the cast into the runtime library, calls into the runtime are ordinary Rust calls, not FFI calls.

It might not, but I wanted to err on the safe side as it doesn't really matter which opaque pointer type we pick. If a bunch of other Rust code uses this, too, I thought why not copy it. I know they used to recommend using a never type (an uninhabitable enum), but there were concerns with that over UB, so now the recommendation is an empty array.

@kkysen

kkysen commented Aug 16, 2022

Copy link
Copy Markdown
Contributor Author

Works on lighttpd after merging the fixes in #605 from master.

@kkysen kkysen merged commit 55e0e5f into master Aug 16, 2022
@kkysen kkysen deleted the kkysen/update-rustc branch August 16, 2022 18:23
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.

5 participants