From eb07c9490519e65c2137d9d31d24b4d31a2ee04f Mon Sep 17 00:00:00 2001 From: kib Date: Sun, 18 Nov 2018 10:22:42 +0000 Subject: [PATCH] MFC r339897: Remove rtld use of libc amd64_set_fsbase(). --- libexec/rtld-elf/amd64/reloc.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/libexec/rtld-elf/amd64/reloc.c b/libexec/rtld-elf/amd64/reloc.c index 59f62b8f814..83e64ea3576 100644 --- a/libexec/rtld-elf/amd64/reloc.c +++ b/libexec/rtld-elf/amd64/reloc.c @@ -33,8 +33,9 @@ #include #include -#include #include +#include +#include #include #include @@ -490,17 +491,26 @@ pre_init(void) } +int __getosreldate(void); + void allocate_initial_tls(Obj_Entry *objs) { - /* - * Fix the size of the static TLS block by using the maximum - * offset allocated so far and adding a bit for dynamic modules to - * use. - */ - tls_static_space = tls_last_offset + RTLD_STATIC_TLS_EXTRA; - amd64_set_fsbase(allocate_tls(objs, 0, - 3*sizeof(Elf_Addr), sizeof(Elf_Addr))); + void *addr; + + /* + * Fix the size of the static TLS block by using the maximum + * offset allocated so far and adding a bit for dynamic + * modules to use. + */ + tls_static_space = tls_last_offset + RTLD_STATIC_TLS_EXTRA; + + addr = allocate_tls(objs, 0, 3 * sizeof(Elf_Addr), sizeof(Elf_Addr)); + if (__getosreldate() >= P_OSREL_WRFSBASE && + (cpu_stdext_feature & CPUID_STDEXT_FSGSBASE) != 0) + wrfsbase((uintptr_t)addr); + else + sysarch(AMD64_SET_FSBASE, &addr); } void *__tls_get_addr(tls_index *ti) -- 2.45.0