Skip to content

Commit 81b0b96

Browse files
committed
Remove macOS 10.10 dynamic linker bug workaround
1 parent aa877bc commit 81b0b96

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
@@ -440,58 +440,6 @@ impl<'ll> CodegenCx<'ll, '_> {
440440

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

497445
// 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)