Skip to content

Commit 1e3d339

Browse files
committed
Auto merge of #128209 - beetrees:no-macos-10.10, r=<try>
Remove macOS 10.10 dynamic linker bug workaround Rust's current minimum macOS version is 10.12, so the hack can be removed. This PR also updates the `remove_dir_all` docs to reflect that all supported macOS versions are protected against TOCTOU race conditions (the fallback implementation was already removed in #127683). try-job: dist-x86_64-apple try-job: dist-aarch64-apple try-job: dist-apple-various try-job: aarch64-apple try-job: x86_64-apple-1
2 parents 842d6fc + 81b0b96 commit 1e3d339

File tree

2 files changed

+6
-59
lines changed

2 files changed

+6
-59
lines changed

compiler/rustc_codegen_llvm/src/consts.rs

-52
Original file line numberDiff line numberDiff line change
@@ -442,58 +442,6 @@ impl<'ll> CodegenCx<'ll, '_> {
442442

443443
if attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL) {
444444
llvm::set_thread_local_mode(g, self.tls_model);
445-
446-
// Do not allow LLVM to change the alignment of a TLS on macOS.
447-
//
448-
// By default a global's alignment can be freely increased.
449-
// This allows LLVM to generate more performant instructions
450-
// e.g., using load-aligned into a SIMD register.
451-
//
452-
// However, on macOS 10.10 or below, the dynamic linker does not
453-
// respect any alignment given on the TLS (radar 24221680).
454-
// This will violate the alignment assumption, and causing segfault at runtime.
455-
//
456-
// This bug is very easy to trigger. In `println!` and `panic!`,
457-
// the `LOCAL_STDOUT`/`LOCAL_STDERR` handles are stored in a TLS,
458-
// which the values would be `mem::replace`d on initialization.
459-
// The implementation of `mem::replace` will use SIMD
460-
// whenever the size is 32 bytes or higher. LLVM notices SIMD is used
461-
// and tries to align `LOCAL_STDOUT`/`LOCAL_STDERR` to a 32-byte boundary,
462-
// which macOS's dyld disregarded and causing crashes
463-
// (see issues #51794, #51758, #50867, #48866 and #44056).
464-
//
465-
// To workaround the bug, we trick LLVM into not increasing
466-
// the global's alignment by explicitly assigning a section to it
467-
// (equivalent to automatically generating a `#[link_section]` attribute).
468-
// See the comment in the `GlobalValue::canIncreaseAlignment()` function
469-
// of `lib/IR/Globals.cpp` for why this works.
470-
//
471-
// When the alignment is not increased, the optimized `mem::replace`
472-
// will use load-unaligned instructions instead, and thus avoiding the crash.
473-
//
474-
// We could remove this hack whenever we decide to drop macOS 10.10 support.
475-
if self.tcx.sess.target.is_like_osx {
476-
// The `inspect` method is okay here because we checked for provenance, and
477-
// because we are doing this access to inspect the final interpreter state
478-
// (not as part of the interpreter execution).
479-
//
480-
// FIXME: This check requires that the (arbitrary) value of undefined bytes
481-
// happens to be zero. Instead, we should only check the value of defined bytes
482-
// and set all undefined bytes to zero if this allocation is headed for the
483-
// BSS.
484-
let all_bytes_are_zero = alloc.provenance().ptrs().is_empty()
485-
&& alloc
486-
.inspect_with_uninit_and_ptr_outside_interpreter(0..alloc.len())
487-
.iter()
488-
.all(|&byte| byte == 0);
489-
490-
let sect_name = if all_bytes_are_zero {
491-
c"__DATA,__thread_bss"
492-
} else {
493-
c"__DATA,__thread_data"
494-
};
495-
llvm::LLVMSetSection(g, sect_name.as_ptr());
496-
}
497445
}
498446

499447
// Wasm statics with custom link sections get special treatment as they

library/std/src/fs.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -2471,16 +2471,15 @@ pub fn remove_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
24712471
/// # Platform-specific behavior
24722472
///
24732473
/// This function currently corresponds to `openat`, `fdopendir`, `unlinkat` and `lstat` functions
2474-
/// on Unix (except for macOS before version 10.10 and REDOX) and the `CreateFileW`,
2475-
/// `GetFileInformationByHandleEx`, `SetFileInformationByHandle`, and `NtCreateFile` functions on
2476-
/// Windows. Note that, this [may change in the future][changes].
2474+
/// on Unix (except for REDOX) and the `CreateFileW`, `GetFileInformationByHandleEx`,
2475+
/// `SetFileInformationByHandle`, and `NtCreateFile` functions on Windows. Note that, this
2476+
/// [may change in the future][changes].
24772477
///
24782478
/// [changes]: io#platform-specific-behavior
24792479
///
2480-
/// On macOS before version 10.10 and REDOX, as well as when running in Miri for any target, this
2481-
/// function is not protected against time-of-check to time-of-use (TOCTOU) race conditions, and
2482-
/// should not be used in security-sensitive code on those platforms. All other platforms are
2483-
/// protected.
2480+
/// On REDOX, as well as when running in Miri for any target, this function is not protected against
2481+
/// time-of-check to time-of-use (TOCTOU) race conditions, and should not be used in
2482+
/// security-sensitive code on those platforms. All other platforms are protected.
24842483
///
24852484
/// # Errors
24862485
///

0 commit comments

Comments
 (0)