catap created this revision. catap added a reviewer: chandlerc. catap added projects: clang, LLVM. Herald added subscribers: dexonsmith, JDevlieghere. catap requested review of this revision. Herald added subscribers: llvm-commits, cfe-commits.
The first version of macOS which had TLV inside DYLD was macOS 10.7 and llvm/clang can't compile code: __thread int x; void use_x() { x = 7; } on macOS before 10.7 as: .section __TEXT,__text,regular,pure_instructions .macosx_version_min 10, 6 .globl _use_x ## -- Begin function use_x .p2align 4, 0x90 _use_x: ## @use_x .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset %rbp, -16 movq %rsp, %rbp .cfi_def_cfa_register %rbp leaq ___emutls_v.x(%rip), %rdi callq ___emutls_get_address movl $7, (%rax) popq %rbp retq .cfi_endproc ## -- End function .section __DATA,__data .globl ___emutls_v.x ## @__emutls_v.x .p2align 3 ___emutls_v.x: .quad 4 ## 0x4 .quad 4 ## 0x4 .quad 0 .quad 0 .subsections_via_symbols Which allows me to build rust for macOS 10.6 for example. This changes effectively reverts an assumption that was introduced at least at 25 Jun 2010 in commit https://github.com/llvm/llvm-project/commit/17c7b89054639ad3cd86f917ad11a50377c8de17 I guess it isn't the only place, but it shown how deep ago it was. This patch was tested on all MacPorts users for quite a while since it was firstly introduced on 13 Dec 2018 at commit https://github.com/macports/macports-ports/commit/5949e6264728ac7f74625c9eaf5b41d2852d07e6 Co-authored-by: Ken Cunningham <ken.cunningham.web...@gmail.com> Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D115250 Files: clang/lib/Basic/Targets/OSTargets.h clang/lib/CodeGen/ItaniumCXXABI.cpp llvm/include/llvm/ADT/Triple.h Index: llvm/include/llvm/ADT/Triple.h =================================================================== --- llvm/include/llvm/ADT/Triple.h +++ llvm/include/llvm/ADT/Triple.h @@ -839,7 +839,7 @@ /// Tests whether the target uses emulated TLS as default. bool hasDefaultEmulatedTLS() const { - return isAndroid() || isOSOpenBSD() || isWindowsCygwinEnvironment(); + return isAndroid() || isOSOpenBSD() || isWindowsCygwinEnvironment() || isMacOSXVersionLT(10, 7); } /// Tests whether the target uses -data-sections as default. Index: clang/lib/CodeGen/ItaniumCXXABI.cpp =================================================================== --- clang/lib/CodeGen/ItaniumCXXABI.cpp +++ clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -2580,7 +2580,7 @@ const char *Name = "__cxa_atexit"; if (TLS) { const llvm::Triple &T = CGF.getTarget().getTriple(); - Name = T.isOSDarwin() ? "_tlv_atexit" : "__cxa_thread_atexit"; + Name = (T.isOSDarwin() && !T.isMacOSXVersionLT(10, 7)) ? "_tlv_atexit" : "__cxa_thread_atexit"; } // We're assuming that the destructor function is something we can Index: clang/lib/Basic/Targets/OSTargets.h =================================================================== --- clang/lib/Basic/Targets/OSTargets.h +++ clang/lib/Basic/Targets/OSTargets.h @@ -91,7 +91,7 @@ this->TLSSupported = false; if (Triple.isMacOSX()) - this->TLSSupported = !Triple.isMacOSXVersionLT(10, 7); + this->TLSSupported = !Triple.isMacOSXVersionLT(10, 4); else if (Triple.isiOS()) { // 64-bit iOS supported it from 8 onwards, 32-bit device from 9 onwards, // 32-bit simulator from 10 onwards.
Index: llvm/include/llvm/ADT/Triple.h =================================================================== --- llvm/include/llvm/ADT/Triple.h +++ llvm/include/llvm/ADT/Triple.h @@ -839,7 +839,7 @@ /// Tests whether the target uses emulated TLS as default. bool hasDefaultEmulatedTLS() const { - return isAndroid() || isOSOpenBSD() || isWindowsCygwinEnvironment(); + return isAndroid() || isOSOpenBSD() || isWindowsCygwinEnvironment() || isMacOSXVersionLT(10, 7); } /// Tests whether the target uses -data-sections as default. Index: clang/lib/CodeGen/ItaniumCXXABI.cpp =================================================================== --- clang/lib/CodeGen/ItaniumCXXABI.cpp +++ clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -2580,7 +2580,7 @@ const char *Name = "__cxa_atexit"; if (TLS) { const llvm::Triple &T = CGF.getTarget().getTriple(); - Name = T.isOSDarwin() ? "_tlv_atexit" : "__cxa_thread_atexit"; + Name = (T.isOSDarwin() && !T.isMacOSXVersionLT(10, 7)) ? "_tlv_atexit" : "__cxa_thread_atexit"; } // We're assuming that the destructor function is something we can Index: clang/lib/Basic/Targets/OSTargets.h =================================================================== --- clang/lib/Basic/Targets/OSTargets.h +++ clang/lib/Basic/Targets/OSTargets.h @@ -91,7 +91,7 @@ this->TLSSupported = false; if (Triple.isMacOSX()) - this->TLSSupported = !Triple.isMacOSXVersionLT(10, 7); + this->TLSSupported = !Triple.isMacOSXVersionLT(10, 4); else if (Triple.isiOS()) { // 64-bit iOS supported it from 8 onwards, 32-bit device from 9 onwards, // 32-bit simulator from 10 onwards.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits