@@ -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
0 commit comments