svn commit: r339897 - head/libexec/rtld-elf/amd64

Konstantin Belousov kib at FreeBSD.org
Mon Oct 29 23:59:27 UTC 2018


Author: kib
Date: Mon Oct 29 23:59:26 2018
New Revision: 339897
URL: https://svnweb.freebsd.org/changeset/base/339897

Log:
  Remove rtld use of libc amd64_set_fsbase().
  
  One less non-trivial dependency of rtld on libc.  Also,
  amd64_set_fsbase() is to be converted to ifunc, which I do not want to
  support inside rtld.
  
  Sponsored by:	The FreeBSD Foundation
  MFC after:	1 week

Modified:
  head/libexec/rtld-elf/amd64/reloc.c

Modified: head/libexec/rtld-elf/amd64/reloc.c
==============================================================================
--- head/libexec/rtld-elf/amd64/reloc.c	Mon Oct 29 23:56:39 2018	(r339896)
+++ head/libexec/rtld-elf/amd64/reloc.c	Mon Oct 29 23:59:26 2018	(r339897)
@@ -35,8 +35,9 @@
 
 #include <sys/param.h>
 #include <sys/mman.h>
-#include <machine/sysarch.h>
 #include <machine/cpufunc.h>
+#include <machine/specialreg.h>
+#include <machine/sysarch.h>
 
 #include <dlfcn.h>
 #include <err.h>
@@ -495,17 +496,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)


More information about the svn-src-all mailing list