Skip to content

Commit c480f66

Browse files
author
The rustc-josh-sync Cronjob Bot
committed
Merge ref 'a1dbb443527b' from rust-lang/rust
Pull recent changes from https://github.com/rust-lang/rust via Josh. Upstream ref: a1dbb443527bd126452875eb5d5860c1d001d761 Filtered ref: c2339048a82c55166f9b9ee83fd618be252a6e23 This merge was created using https://github.com/rust-lang/josh-sync.
2 parents bf76e45 + e644bd7 commit c480f66

File tree

90 files changed

+480
-97
lines changed

Some content is hidden

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

90 files changed

+480
-97
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,6 @@ jobs:
6969
sudo apt update
7070
# Install needed packages
7171
sudo apt install $(echo "libatomic1: zlib1g-dev:" | sed 's/:/:${{ matrix.multiarch }}/g')
72-
- name: Install rustup on Windows ARM
73-
if: ${{ matrix.os == 'windows-11-arm' }}
74-
run: |
75-
curl -LOs https://static.rust-lang.org/rustup/dist/aarch64-pc-windows-msvc/rustup-init.exe
76-
./rustup-init.exe -y --no-modify-path
77-
echo "$USERPROFILE/.cargo/bin" >> "$GITHUB_PATH"
7872
- uses: ./.github/workflows/setup
7973
with:
8074
toolchain_flags: "--host ${{ matrix.host_target }}"
@@ -169,7 +163,13 @@ jobs:
169163
run: rustup toolchain install nightly --profile minimal
170164
- name: Install rustup-toolchain-install-master
171165
run: cargo install -f rustup-toolchain-install-master
172-
- name: Push changes to a branch and create PR
166+
# Create a token for the next step so it can create a PR that actually runs CI.
167+
- uses: actions/create-github-app-token@v2
168+
id: app-token
169+
with:
170+
app-id: ${{ vars.APP_CLIENT_ID }}
171+
private-key: ${{ secrets.APP_PRIVATE_KEY }}
172+
- name: pull changes from rustc and create PR
173173
run: |
174174
# Make it easier to see what happens.
175175
set -x
@@ -198,9 +198,9 @@ jobs:
198198
BRANCH="rustup-$(date -u +%Y-%m-%d)"
199199
git switch -c $BRANCH
200200
git push -u origin $BRANCH
201-
gh pr create -B master --title 'Automatic Rustup' --body 'Please close and re-open this PR to trigger CI, then enable auto-merge.'
201+
gh pr create -B master --title 'Automatic Rustup' --body "Update \`rustc\` to https://github.com/rust-lang/rust/commit/$(cat rust-version)."
202202
env:
203-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
203+
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
204204

205205
cron-fail-notify:
206206
name: cronjob failure notification

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ native-lib = ["dep:libffi", "dep:libloading", "dep:capstone", "dep:ipc-channel",
7878

7979
[lints.rust.unexpected_cfgs]
8080
level = "warn"
81+
check-cfg = ['cfg(bootstrap)']
8182

8283
# Be aware that this file is inside a workspace when used via the
8384
# submodule in the rustc repo. That means there are many cargo features

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
733dab558992d902d6d17576de1da768094e2cf3
1+
f605b57042ffeb320d7ae44490113a827139b766

src/diagnostics.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,8 @@ pub fn report_error<'tcx>(
282282
},
283283
TreeBorrowsUb { title: _, details, history } => {
284284
let mut helps = vec![
285-
note!("this indicates a potential bug in the program: it performed an invalid operation, but the Tree Borrows rules it violated are still experimental")
285+
note!("this indicates a potential bug in the program: it performed an invalid operation, but the Tree Borrows rules it violated are still experimental"),
286+
note!("see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/tree-borrows.md for further information"),
286287
];
287288
for m in details {
288289
helps.push(note!("{m}"));

src/machine.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ use rand::rngs::StdRng;
1212
use rand::{Rng, SeedableRng};
1313
use rustc_abi::{Align, ExternAbi, Size};
1414
use rustc_apfloat::{Float, FloatConvert};
15-
use rustc_hir::attrs::InlineAttr;
1615
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1716
#[allow(unused)]
1817
use rustc_data_structures::static_assert_size;
18+
use rustc_hir::attrs::InlineAttr;
19+
use rustc_middle::middle::codegen_fn_attrs::TargetFeatureKind;
1920
use rustc_middle::mir;
2021
use rustc_middle::query::TyCtxtAt;
2122
use rustc_middle::ty::layout::{
@@ -1076,7 +1077,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
10761077
.target_features
10771078
.iter()
10781079
.filter(|&feature| {
1079-
!feature.implied && !ecx.tcx.sess.target_features.contains(&feature.name)
1080+
feature.kind != TargetFeatureKind::Implied && !ecx.tcx.sess.target_features.contains(&feature.name)
10801081
})
10811082
.fold(String::new(), |mut s, feature| {
10821083
if !s.is_empty() {
@@ -1111,6 +1112,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
11111112
) -> InterpResult<'tcx, Option<(&'tcx mir::Body<'tcx>, ty::Instance<'tcx>)>> {
11121113
// For foreign items, try to see if we can emulate them.
11131114
if ecx.tcx.is_foreign_item(instance.def_id()) {
1115+
let _trace = enter_trace_span!("emulate_foreign_item");
11141116
// An external function call that does not have a MIR body. We either find MIR elsewhere
11151117
// or emulate its effect.
11161118
// This will be Ok(None) if we're emulating the intrinsic entirely within Miri (no need
@@ -1123,6 +1125,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
11231125
}
11241126

11251127
// Otherwise, load the MIR.
1128+
let _trace = enter_trace_span!("load_mir");
11261129
interp_ok(Some((ecx.load_mir(instance.def, None)?, instance)))
11271130
}
11281131

@@ -1394,6 +1397,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
13941397
GlobalDataRaceHandler::Genmc(genmc_ctx) =>
13951398
genmc_ctx.memory_load(machine, ptr.addr(), range.size)?,
13961399
GlobalDataRaceHandler::Vclocks(_data_race) => {
1400+
let _trace = enter_trace_span!(data_race::before_memory_read);
13971401
let AllocDataRaceHandler::Vclocks(data_race, weak_memory) = &alloc_extra.data_race
13981402
else {
13991403
unreachable!();
@@ -1429,6 +1433,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
14291433
genmc_ctx.memory_store(machine, ptr.addr(), range.size)?;
14301434
}
14311435
GlobalDataRaceHandler::Vclocks(_global_state) => {
1436+
let _trace = enter_trace_span!(data_race::before_memory_write);
14321437
let AllocDataRaceHandler::Vclocks(data_race, weak_memory) =
14331438
&mut alloc_extra.data_race
14341439
else {
@@ -1465,6 +1470,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
14651470
GlobalDataRaceHandler::Genmc(genmc_ctx) =>
14661471
genmc_ctx.handle_dealloc(machine, ptr.addr(), size, align, kind)?,
14671472
GlobalDataRaceHandler::Vclocks(_global_state) => {
1473+
let _trace = enter_trace_span!(data_race::before_memory_deallocation);
14681474
let data_race = alloc_extra.data_race.as_vclocks_mut().unwrap();
14691475
data_race.write(
14701476
alloc_id,
@@ -1675,6 +1681,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
16751681
local: mir::Local,
16761682
) -> InterpResult<'tcx> {
16771683
if let Some(data_race) = &frame.extra.data_race {
1684+
let _trace = enter_trace_span!(data_race::after_local_read);
16781685
data_race.local_read(local, &ecx.machine);
16791686
}
16801687
interp_ok(())
@@ -1686,6 +1693,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
16861693
storage_live: bool,
16871694
) -> InterpResult<'tcx> {
16881695
if let Some(data_race) = &ecx.frame().extra.data_race {
1696+
let _trace = enter_trace_span!(data_race::after_local_write);
16891697
data_race.local_write(local, storage_live, &ecx.machine);
16901698
}
16911699
interp_ok(())
@@ -1708,6 +1716,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
17081716
if let Some(data_race) =
17091717
&machine.threads.active_thread_stack().last().unwrap().extra.data_race
17101718
{
1719+
let _trace = enter_trace_span!(data_race::after_local_moved_to_memory);
17111720
data_race.local_moved_to_memory(
17121721
local,
17131722
alloc_info.data_race.as_vclocks_mut().unwrap(),

src/operator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
5757
let ptr = left.to_scalar().to_pointer(this)?;
5858
// We do the actual operation with usize-typed scalars.
5959
let left = ImmTy::from_uint(ptr.addr().bytes(), this.machine.layouts.usize);
60-
let result = this.binary_op(bin_op, &left, &right)?;
60+
let result = this.binary_op(bin_op, &left, right)?;
6161
// Construct a new pointer with the provenance of `ptr` (the LHS).
6262
let result_ptr = Pointer::new(
6363
ptr.provenance,

src/shims/extern_static.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'tcx> MiriMachine<'tcx> {
6262
}
6363
"android" => {
6464
Self::null_ptr_extern_statics(ecx, &["bsd_signal"])?;
65-
Self::weak_symbol_extern_statics(ecx, &["signal", "getrandom"])?;
65+
Self::weak_symbol_extern_statics(ecx, &["signal", "getrandom", "gettid"])?;
6666
}
6767
"windows" => {
6868
// "_tls_used"

src/shims/foreign_items.rs

Lines changed: 76 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::path::Path;
55
use rustc_abi::{Align, AlignFromBytesError, CanonAbi, Size};
66
use rustc_apfloat::Float;
77
use rustc_ast::expand::allocator::alloc_error_handler_name;
8+
use rustc_hir::attrs::Linkage;
89
use rustc_hir::def::DefKind;
910
use rustc_hir::def_id::CrateNum;
1011
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
@@ -138,15 +139,21 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
138139
Entry::Occupied(e) => e.into_mut(),
139140
Entry::Vacant(e) => {
140141
// Find it if it was not cached.
141-
let mut instance_and_crate: Option<(ty::Instance<'_>, CrateNum)> = None;
142+
143+
struct SymbolTarget<'tcx> {
144+
instance: ty::Instance<'tcx>,
145+
cnum: CrateNum,
146+
is_weak: bool,
147+
}
148+
let mut symbol_target: Option<SymbolTarget<'tcx>> = None;
142149
helpers::iter_exported_symbols(tcx, |cnum, def_id| {
143150
let attrs = tcx.codegen_fn_attrs(def_id);
144151
// Skip over imports of items.
145152
if tcx.is_foreign_item(def_id) {
146153
return interp_ok(());
147154
}
148155
// Skip over items without an explicitly defined symbol name.
149-
if !(attrs.export_name.is_some()
156+
if !(attrs.symbol_name.is_some()
150157
|| attrs.flags.contains(CodegenFnAttrFlags::NO_MANGLE)
151158
|| attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL))
152159
{
@@ -155,40 +162,80 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
155162

156163
let instance = Instance::mono(tcx, def_id);
157164
let symbol_name = tcx.symbol_name(instance).name;
165+
let is_weak = attrs.linkage == Some(Linkage::WeakAny);
158166
if symbol_name == link_name.as_str() {
159-
if let Some((original_instance, original_cnum)) = instance_and_crate {
160-
// Make sure we are consistent wrt what is 'first' and 'second'.
161-
let original_span = tcx.def_span(original_instance.def_id()).data();
162-
let span = tcx.def_span(def_id).data();
163-
if original_span < span {
164-
throw_machine_stop!(TerminationInfo::MultipleSymbolDefinitions {
165-
link_name,
166-
first: original_span,
167-
first_crate: tcx.crate_name(original_cnum),
168-
second: span,
169-
second_crate: tcx.crate_name(cnum),
170-
});
171-
} else {
172-
throw_machine_stop!(TerminationInfo::MultipleSymbolDefinitions {
173-
link_name,
174-
first: span,
175-
first_crate: tcx.crate_name(cnum),
176-
second: original_span,
177-
second_crate: tcx.crate_name(original_cnum),
178-
});
167+
if let Some(original) = &symbol_target {
168+
// There is more than one definition with this name. What we do now
169+
// depends on whether one or both definitions are weak.
170+
match (is_weak, original.is_weak) {
171+
(false, true) => {
172+
// Original definition is a weak definition. Override it.
173+
174+
symbol_target = Some(SymbolTarget {
175+
instance: ty::Instance::mono(tcx, def_id),
176+
cnum,
177+
is_weak,
178+
});
179+
}
180+
(true, false) => {
181+
// Current definition is a weak definition. Keep the original one.
182+
}
183+
(true, true) | (false, false) => {
184+
// Either both definitions are non-weak or both are weak. In
185+
// either case return an error. For weak definitions we error
186+
// because it is unspecified which definition would have been
187+
// picked by the linker.
188+
189+
// Make sure we are consistent wrt what is 'first' and 'second'.
190+
let original_span =
191+
tcx.def_span(original.instance.def_id()).data();
192+
let span = tcx.def_span(def_id).data();
193+
if original_span < span {
194+
throw_machine_stop!(
195+
TerminationInfo::MultipleSymbolDefinitions {
196+
link_name,
197+
first: original_span,
198+
first_crate: tcx.crate_name(original.cnum),
199+
second: span,
200+
second_crate: tcx.crate_name(cnum),
201+
}
202+
);
203+
} else {
204+
throw_machine_stop!(
205+
TerminationInfo::MultipleSymbolDefinitions {
206+
link_name,
207+
first: span,
208+
first_crate: tcx.crate_name(cnum),
209+
second: original_span,
210+
second_crate: tcx.crate_name(original.cnum),
211+
}
212+
);
213+
}
214+
}
179215
}
216+
} else {
217+
symbol_target = Some(SymbolTarget {
218+
instance: ty::Instance::mono(tcx, def_id),
219+
cnum,
220+
is_weak,
221+
});
180222
}
181-
if !matches!(tcx.def_kind(def_id), DefKind::Fn | DefKind::AssocFn) {
182-
throw_ub_format!(
183-
"attempt to call an exported symbol that is not defined as a function"
184-
);
185-
}
186-
instance_and_crate = Some((ty::Instance::mono(tcx, def_id), cnum));
187223
}
188224
interp_ok(())
189225
})?;
190226

191-
e.insert(instance_and_crate.map(|ic| ic.0))
227+
// Once we identified the instance corresponding to the symbol, ensure
228+
// it is a function. It is okay to encounter non-functions in the search above
229+
// as long as the final instance we arrive at is a function.
230+
if let Some(SymbolTarget { instance, .. }) = symbol_target {
231+
if !matches!(tcx.def_kind(instance.def_id()), DefKind::Fn | DefKind::AssocFn) {
232+
throw_ub_format!(
233+
"attempt to call an exported symbol that is not defined as a function"
234+
);
235+
}
236+
}
237+
238+
e.insert(symbol_target.map(|SymbolTarget { instance, .. }| instance))
192239
}
193240
};
194241
match instance {

src/shims/native_lib/mod.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,9 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
242242

243243
match evt {
244244
AccessEvent::Read(_) => {
245-
// FIXME: ProvenanceMap should have something like get_range().
246-
let p_map = alloc.provenance();
247-
for idx in overlap {
248-
// If a provenance was read by the foreign code, expose it.
249-
if let Some((prov, _idx)) = p_map.get_byte(Size::from_bytes(idx), this) {
250-
this.expose_provenance(prov)?;
251-
}
245+
// If a provenance was read by the foreign code, expose it.
246+
for prov in alloc.provenance().get_range(this, overlap.into()) {
247+
this.expose_provenance(prov)?;
252248
}
253249
}
254250
AccessEvent::Write(_, certain) => {

src/shims/unix/android/foreign_items.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ use rustc_span::Symbol;
44
use rustc_target::callconv::FnAbi;
55

66
use crate::shims::unix::android::thread::prctl;
7+
use crate::shims::unix::env::EvalContextExt as _;
78
use crate::shims::unix::linux_like::epoll::EvalContextExt as _;
89
use crate::shims::unix::linux_like::eventfd::EvalContextExt as _;
910
use crate::shims::unix::linux_like::syscall::syscall;
1011
use crate::*;
1112

12-
pub fn is_dyn_sym(_name: &str) -> bool {
13-
false
13+
pub fn is_dyn_sym(name: &str) -> bool {
14+
matches!(name, "gettid")
1415
}
1516

1617
impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {}
@@ -54,6 +55,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
5455
this.write_scalar(errno_place.to_ref(this).to_scalar(), dest)?;
5556
}
5657

58+
"gettid" => {
59+
let [] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?;
60+
let result = this.unix_gettid(link_name.as_str())?;
61+
this.write_scalar(result, dest)?;
62+
}
63+
5764
// Dynamically invoked syscalls
5865
"syscall" => syscall(this, link_name, abi, args, dest)?,
5966

0 commit comments

Comments
 (0)