Skip to content

Commit bf6389f

Browse files
Rollup merge of #128209 - beetrees:no-macos-10.10, r=jieyouxu
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 fb46739 + 0444056 commit bf6389f

File tree

3 files changed

+6
-86
lines changed

3 files changed

+6
-86
lines changed

compiler/rustc_codegen_llvm/src/consts.rs

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

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

500448
// 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
@@ -2473,16 +2473,15 @@ pub fn remove_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
24732473
/// # Platform-specific behavior
24742474
///
24752475
/// This function currently corresponds to `openat`, `fdopendir`, `unlinkat` and `lstat` functions
2476-
/// on Unix (except for macOS before version 10.10 and REDOX) and the `CreateFileW`,
2477-
/// `GetFileInformationByHandleEx`, `SetFileInformationByHandle`, and `NtCreateFile` functions on
2478-
/// Windows. Note that, this [may change in the future][changes].
2476+
/// on Unix (except for REDOX) and the `CreateFileW`, `GetFileInformationByHandleEx`,
2477+
/// `SetFileInformationByHandle`, and `NtCreateFile` functions on Windows. Note that, this
2478+
/// [may change in the future][changes].
24792479
///
24802480
/// [changes]: io#platform-specific-behavior
24812481
///
2482-
/// On macOS before version 10.10 and REDOX, as well as when running in Miri for any target, this
2483-
/// function is not protected against time-of-check to time-of-use (TOCTOU) race conditions, and
2484-
/// should not be used in security-sensitive code on those platforms. All other platforms are
2485-
/// protected.
2482+
/// On REDOX, as well as when running in Miri for any target, this function is not protected against
2483+
/// time-of-check to time-of-use (TOCTOU) race conditions, and should not be used in
2484+
/// security-sensitive code on those platforms. All other platforms are protected.
24862485
///
24872486
/// # Errors
24882487
///

tests/codegen/issues/issue-44056-macos-tls-align.rs

-27
This file was deleted.

0 commit comments

Comments
 (0)