Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c45dee5

Browse files
committedApr 17, 2024
Auto merge of rust-lang#124084 - matthiaskrgr:rollup-h42psbx, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#116957 (meta: notify #t-rustdoc Zulip stream on backport nominations) - rust-lang#122201 (Document overrides of `clone_from()` in core/std) - rust-lang#122723 (Use same file permissions for ar_archive_writer as the LLVM archive writer) - rust-lang#124030 (interpret: pass MemoryKind to adjust_alloc_base_pointer) - rust-lang#124037 (Don't ascend into parent bodies when collecting stmts for possible return suggestion) - rust-lang#124049 (Stabilize `const_io_structs`) - rust-lang#124062 (Add another expression to weird-exprs.rs) - rust-lang#124066 (Don't error on subtyping of equal types) - rust-lang#124073 (Remove libc from rust_get_test_int uses) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 00ed4ed + abbe0d0 commit c45dee5

File tree

48 files changed

+402
-162
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+402
-162
lines changed
 

‎compiler/rustc_codegen_ssa/src/back/archive.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use object::read::macho::FatArch;
1313
use tempfile::Builder as TempFileBuilder;
1414

1515
use std::error::Error;
16-
use std::fs::File;
16+
use std::fs::{self, File};
1717
use std::io::{self, Write};
1818
use std::path::{Path, PathBuf};
1919

@@ -280,22 +280,33 @@ impl<'a> ArArchiveBuilder<'a> {
280280
// This prevents programs (including rustc) from attempting to read a partial archive.
281281
// It also enables writing an archive with the same filename as a dependency on Windows as
282282
// required by a test.
283-
let mut archive_tmpfile = TempFileBuilder::new()
283+
// The tempfile crate currently uses 0o600 as mode for the temporary files and directories
284+
// it creates. We need it to be the default mode for back compat reasons however. (See
285+
// #107495) To handle this we are telling tempfile to create a temporary directory instead
286+
// and then inside this directory create a file using File::create.
287+
let archive_tmpdir = TempFileBuilder::new()
284288
.suffix(".temp-archive")
285-
.tempfile_in(output.parent().unwrap_or_else(|| Path::new("")))
286-
.map_err(|err| io_error_context("couldn't create a temp file", err))?;
289+
.tempdir_in(output.parent().unwrap_or_else(|| Path::new("")))
290+
.map_err(|err| {
291+
io_error_context("couldn't create a directory for the temp file", err)
292+
})?;
293+
let archive_tmpfile_path = archive_tmpdir.path().join("tmp.a");
294+
let mut archive_tmpfile = File::create_new(&archive_tmpfile_path)
295+
.map_err(|err| io_error_context("couldn't create the temp file", err))?;
287296

288-
write_archive_to_stream(archive_tmpfile.as_file_mut(), &entries, archive_kind, false)?;
297+
write_archive_to_stream(&mut archive_tmpfile, &entries, archive_kind, false)?;
289298

290299
let any_entries = !entries.is_empty();
291300
drop(entries);
292301
// Drop src_archives to unmap all input archives, which is necessary if we want to write the
293302
// output archive to the same location as an input archive on Windows.
294303
drop(self.src_archives);
295304

296-
archive_tmpfile
297-
.persist(output)
298-
.map_err(|err| io_error_context("failed to rename archive file", err.error))?;
305+
fs::rename(archive_tmpfile_path, output)
306+
.map_err(|err| io_error_context("failed to rename archive file", err))?;
307+
archive_tmpdir
308+
.close()
309+
.map_err(|err| io_error_context("failed to remove temporary directory", err))?;
299310

300311
Ok(any_entries)
301312
}

‎compiler/rustc_const_eval/src/interpret/machine.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -288,28 +288,19 @@ pub trait Machine<'mir, 'tcx: 'mir>: Sized {
288288
}
289289

290290
/// Return the `AllocId` for the given thread-local static in the current thread.
291-
fn thread_local_static_base_pointer(
291+
fn thread_local_static_pointer(
292292
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
293293
def_id: DefId,
294294
) -> InterpResult<'tcx, Pointer<Self::Provenance>> {
295295
throw_unsup!(ThreadLocalStatic(def_id))
296296
}
297297

298-
/// Return the root pointer for the given `extern static`.
299-
fn extern_static_base_pointer(
298+
/// Return the `AllocId` for the given `extern static`.
299+
fn extern_static_pointer(
300300
ecx: &InterpCx<'mir, 'tcx, Self>,
301301
def_id: DefId,
302302
) -> InterpResult<'tcx, Pointer<Self::Provenance>>;
303303

304-
/// Return a "base" pointer for the given allocation: the one that is used for direct
305-
/// accesses to this static/const/fn allocation, or the one returned from the heap allocator.
306-
///
307-
/// Not called on `extern` or thread-local statics (those use the methods above).
308-
fn adjust_alloc_base_pointer(
309-
ecx: &InterpCx<'mir, 'tcx, Self>,
310-
ptr: Pointer,
311-
) -> InterpResult<'tcx, Pointer<Self::Provenance>>;
312-
313304
/// "Int-to-pointer cast"
314305
fn ptr_from_addr_cast(
315306
ecx: &InterpCx<'mir, 'tcx, Self>,
@@ -336,6 +327,8 @@ pub trait Machine<'mir, 'tcx: 'mir>: Sized {
336327

337328
/// Called to adjust allocations to the Provenance and AllocExtra of this machine.
338329
///
330+
/// If `alloc` contains pointers, then they are all pointing to globals.
331+
///
339332
/// The way we construct allocations is to always first construct it without extra and then add
340333
/// the extra. This keeps uniform code paths for handling both allocations created by CTFE for
341334
/// globals, and allocations created by Miri during evaluation.
@@ -354,6 +347,19 @@ pub trait Machine<'mir, 'tcx: 'mir>: Sized {
354347
kind: Option<MemoryKind<Self::MemoryKind>>,
355348
) -> InterpResult<'tcx, Cow<'b, Allocation<Self::Provenance, Self::AllocExtra, Self::Bytes>>>;
356349

350+
/// Return a "root" pointer for the given allocation: the one that is used for direct
351+
/// accesses to this static/const/fn allocation, or the one returned from the heap allocator.
352+
///
353+
/// Not called on `extern` or thread-local statics (those use the methods above).
354+
///
355+
/// `kind` is the kind of the allocation the pointer points to; it can be `None` when
356+
/// it's a global and `GLOBAL_KIND` is `None`.
357+
fn adjust_alloc_root_pointer(
358+
ecx: &InterpCx<'mir, 'tcx, Self>,
359+
ptr: Pointer,
360+
kind: Option<MemoryKind<Self::MemoryKind>>,
361+
) -> InterpResult<'tcx, Pointer<Self::Provenance>>;
362+
357363
/// Evaluate the inline assembly.
358364
///
359365
/// This should take care of jumping to the next block (one of `targets`) when asm goto
@@ -592,7 +598,7 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
592598
Ok(alloc)
593599
}
594600

595-
fn extern_static_base_pointer(
601+
fn extern_static_pointer(
596602
ecx: &InterpCx<$mir, $tcx, Self>,
597603
def_id: DefId,
598604
) -> InterpResult<$tcx, Pointer> {
@@ -601,9 +607,10 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
601607
}
602608

603609
#[inline(always)]
604-
fn adjust_alloc_base_pointer(
610+
fn adjust_alloc_root_pointer(
605611
_ecx: &InterpCx<$mir, $tcx, Self>,
606612
ptr: Pointer<CtfeProvenance>,
613+
_kind: Option<MemoryKind<Self::MemoryKind>>,
607614
) -> InterpResult<$tcx, Pointer<CtfeProvenance>> {
608615
Ok(ptr)
609616
}

0 commit comments

Comments
 (0)
This repository has been archived.