Page MenuHomePhabricator

switch to emulated TLV on macOS before 10.7
Needs ReviewPublic

Authored by catap on Dec 7 2021, 7:57 AM.

Details

Summary

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;
}

This patch allows to compile code above 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.

As far as I know it was impossible to run x86_64/i386 on apple hardware before 10.4, and LLVM have some issue with ABI on PowerPC for macOS => I've limited support for 10.4+.

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.webuse@gmail.com>

Diff Detail

Event Timeline

catap created this revision.Dec 7 2021, 7:57 AM
catap requested review of this revision.Dec 7 2021, 7:57 AM
catap updated this revision to Diff 392450.Dec 7 2021, 10:07 AM
catap updated this revision to Diff 392496.Dec 7 2021, 12:08 PM
catap updated this revision to Diff 392531.Dec 7 2021, 1:53 PM
catap updated this revision to Diff 392539.Dec 7 2021, 2:32 PM
catap updated this revision to Diff 392715.Dec 8 2021, 4:47 AM
catap updated this revision to Diff 392731.Dec 8 2021, 5:54 AM
catap updated this revision to Diff 392755.Dec 8 2021, 7:20 AM
catap updated this revision to Diff 392828.Dec 8 2021, 10:34 AM
catap updated this revision to Diff 392865.Dec 8 2021, 12:09 PM
catap edited the summary of this revision. (Show Details)Dec 8 2021, 1:32 PM
catap retitled this revision from switched to emulated TLV on macOS before 10.7 to switch to emulated TLV on macOS before 10.7.Dec 8 2021, 1:37 PM
catap added a comment.Dec 9 2021, 4:57 AM

I have a green light from build and this changes are ready for review.