git: 2aa761055cd1 - stable/13 - rtld: Remove calculate_tls_end

Konstantin Belousov kib at FreeBSD.org
Mon Aug 23 09:21:52 UTC 2021


The branch stable/13 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=2aa761055cd169aff2cd03c909a1256dc09c9f4a

commit 2aa761055cd169aff2cd03c909a1256dc09c9f4a
Author:     Fangrui Song <i at maskray.me>
AuthorDate: 2021-08-14 17:02:09 +0000
Commit:     Konstantin Belousov <kib at FreeBSD.org>
CommitDate: 2021-08-23 09:20:56 +0000

    rtld: Remove calculate_tls_end
    
    (cherry picked from commit 8f63fa78e84afd23fa68c82eabfe64763c92d4f5)
---
 lib/libc/gen/tls.c                        |  8 --------
 libexec/rtld-elf/aarch64/rtld_machdep.h   |  2 +-
 libexec/rtld-elf/amd64/reloc.c            |  6 ------
 libexec/rtld-elf/amd64/rtld_machdep.h     |  2 +-
 libexec/rtld-elf/arm/rtld_machdep.h       |  2 +-
 libexec/rtld-elf/i386/reloc.c             |  6 ------
 libexec/rtld-elf/i386/rtld_machdep.h      |  2 +-
 libexec/rtld-elf/mips/rtld_machdep.h      |  2 +-
 libexec/rtld-elf/powerpc/rtld_machdep.h   |  2 +-
 libexec/rtld-elf/powerpc64/rtld_machdep.h |  2 +-
 libexec/rtld-elf/riscv/rtld_machdep.h     |  2 +-
 libexec/rtld-elf/rtld.c                   | 25 ++++++++++++++++---------
 12 files changed, 24 insertions(+), 37 deletions(-)

diff --git a/lib/libc/gen/tls.c b/lib/libc/gen/tls.c
index 98915ef4ddf7..b5f5dfd4d315 100644
--- a/lib/libc/gen/tls.c
+++ b/lib/libc/gen/tls.c
@@ -81,14 +81,6 @@ void __libc_free_tls(void *tls, size_t tcbsize, size_t tcbalign);
 #error TLS_TCB_ALIGN undefined for target architecture
 #endif
 
-#if defined(__aarch64__) || defined(__arm__) || defined(__mips__) || \
-    defined(__powerpc__) || defined(__riscv)
-#define TLS_VARIANT_I
-#endif
-#if defined(__i386__) || defined(__amd64__)
-#define TLS_VARIANT_II
-#endif
-
 #if defined(__mips__) || defined(__powerpc__) || defined(__riscv)
 #define DTV_OFFSET 0x8000
 #else
diff --git a/libexec/rtld-elf/aarch64/rtld_machdep.h b/libexec/rtld-elf/aarch64/rtld_machdep.h
index bdd5620867ba..585689afe197 100644
--- a/libexec/rtld-elf/aarch64/rtld_machdep.h
+++ b/libexec/rtld-elf/aarch64/rtld_machdep.h
@@ -76,7 +76,6 @@ Elf_Addr reloc_jmpslot(Elf_Addr *where, Elf_Addr target,
 	round(16, align)
 #define	calculate_tls_offset(prev_offset, prev_size, size, align, offset) \
 	round(prev_offset + prev_size, align)
-#define	calculate_tls_end(off, size) 	((off) + (size))
 #define calculate_tls_post_size(align) \
 	round(TLS_TCB_SIZE, align) - TLS_TCB_SIZE
 
@@ -93,6 +92,7 @@ extern void *__tls_get_addr(tls_index *ti);
 
 #define md_abi_variant_hook(x)
 
+#define	TLS_VARIANT_I	1
 #define	TLS_DTV_OFFSET	0
 
 #endif
diff --git a/libexec/rtld-elf/amd64/reloc.c b/libexec/rtld-elf/amd64/reloc.c
index 508ae04a7448..1fec863c063b 100644
--- a/libexec/rtld-elf/amd64/reloc.c
+++ b/libexec/rtld-elf/amd64/reloc.c
@@ -567,9 +567,3 @@ calculate_first_tls_offset(size_t size, size_t align, size_t offset)
 {
 	return (calculate_tls_offset(0, 0, size, align, offset));
 }
-
-size_t
-calculate_tls_end(size_t off, size_t size __unused)
-{
-	return (off);
-}
diff --git a/libexec/rtld-elf/amd64/rtld_machdep.h b/libexec/rtld-elf/amd64/rtld_machdep.h
index 30c82dcb0625..baa926445006 100644
--- a/libexec/rtld-elf/amd64/rtld_machdep.h
+++ b/libexec/rtld-elf/amd64/rtld_machdep.h
@@ -73,10 +73,10 @@ void *__tls_get_addr(tls_index *ti) __exported;
 
 #define md_abi_variant_hook(x)
 
+#define	TLS_VARIANT_II	1
 #define	TLS_DTV_OFFSET	0
 
 size_t calculate_first_tls_offset(size_t size, size_t align, size_t offset);
 size_t calculate_tls_offset(size_t prev_offset, size_t prev_size, size_t size,
     size_t align, size_t offset);
-size_t calculate_tls_end(size_t off, size_t size);
 #endif
diff --git a/libexec/rtld-elf/arm/rtld_machdep.h b/libexec/rtld-elf/arm/rtld_machdep.h
index b333b1f153eb..d890cb377fa3 100644
--- a/libexec/rtld-elf/arm/rtld_machdep.h
+++ b/libexec/rtld-elf/arm/rtld_machdep.h
@@ -68,7 +68,6 @@ typedef struct {
     round(8, align)
 #define calculate_tls_offset(prev_offset, prev_size, size, align, offset) \
     round(prev_offset + prev_size, align)
-#define calculate_tls_end(off, size)    ((off) + (size))
 #define calculate_tls_post_size(align) \
     round(TLS_TCB_SIZE, align) - TLS_TCB_SIZE
 	
@@ -86,6 +85,7 @@ extern void arm_abi_variant_hook(Elf_Auxinfo **);
 #define md_abi_variant_hook(x)
 #endif
 
+#define	TLS_VARIANT_I	1
 #define	TLS_DTV_OFFSET	0
 
 #endif
diff --git a/libexec/rtld-elf/i386/reloc.c b/libexec/rtld-elf/i386/reloc.c
index 69da93347bbb..603a93a2338c 100644
--- a/libexec/rtld-elf/i386/reloc.c
+++ b/libexec/rtld-elf/i386/reloc.c
@@ -558,9 +558,3 @@ calculate_first_tls_offset(size_t size, size_t align, size_t offset)
 {
 	return (calculate_tls_offset(0, 0, size, align, offset));
 }
-
-size_t
-calculate_tls_end(size_t off, size_t size __unused)
-{
-	return (off);
-}
diff --git a/libexec/rtld-elf/i386/rtld_machdep.h b/libexec/rtld-elf/i386/rtld_machdep.h
index 78154a1992d4..33e7d95f966d 100644
--- a/libexec/rtld-elf/i386/rtld_machdep.h
+++ b/libexec/rtld-elf/i386/rtld_machdep.h
@@ -74,10 +74,10 @@ void *__tls_get_addr(tls_index *ti) __exported;
 
 #define md_abi_variant_hook(x)
 
+#define	TLS_VARIANT_II	1
 #define	TLS_DTV_OFFSET	0
 
 size_t calculate_first_tls_offset(size_t size, size_t align, size_t offset);
 size_t calculate_tls_offset(size_t prev_offset, size_t prev_size, size_t size,
     size_t align, size_t offset);
-size_t calculate_tls_end(size_t off, size_t size);
 #endif
diff --git a/libexec/rtld-elf/mips/rtld_machdep.h b/libexec/rtld-elf/mips/rtld_machdep.h
index 041a5d05f9a7..0cb56290152e 100644
--- a/libexec/rtld-elf/mips/rtld_machdep.h
+++ b/libexec/rtld-elf/mips/rtld_machdep.h
@@ -68,7 +68,6 @@ typedef struct {
     TLS_TCB_SIZE
 #define calculate_tls_offset(prev_offset, prev_size, size, align, offset) \
     round(prev_offset + prev_size, align)
-#define calculate_tls_end(off, size)    ((off) + (size))
 #define calculate_tls_post_size(align)  0
 
 extern void *__tls_get_addr(tls_index *ti);
@@ -78,6 +77,7 @@ extern void *__tls_get_addr(tls_index *ti);
 
 #define md_abi_variant_hook(x)
 
+#define	TLS_VARIANT_I	1
 #define	TLS_DTV_OFFSET	0
 
 #endif
diff --git a/libexec/rtld-elf/powerpc/rtld_machdep.h b/libexec/rtld-elf/powerpc/rtld_machdep.h
index a35ac1f4ebf5..c98dc7d3acb5 100644
--- a/libexec/rtld-elf/powerpc/rtld_machdep.h
+++ b/libexec/rtld-elf/powerpc/rtld_machdep.h
@@ -73,6 +73,7 @@ void _rtld_powerpc_pltcall(void);
  * TLS
  */
 
+#define	TLS_VARIANT_I	1
 #define TLS_TP_OFFSET	0x7000
 #define TLS_DTV_OFFSET	0x8000
 #define TLS_TCB_SIZE	8
@@ -83,7 +84,6 @@ void _rtld_powerpc_pltcall(void);
     TLS_TCB_SIZE
 #define calculate_tls_offset(prev_offset, prev_size, size, align, offset) \
     round(prev_offset + prev_size, align)
-#define calculate_tls_end(off, size)    ((off) + (size))
 #define calculate_tls_post_size(align)  0
  
 typedef struct {
diff --git a/libexec/rtld-elf/powerpc64/rtld_machdep.h b/libexec/rtld-elf/powerpc64/rtld_machdep.h
index 486f4ffe95bc..98bdbb33affe 100644
--- a/libexec/rtld-elf/powerpc64/rtld_machdep.h
+++ b/libexec/rtld-elf/powerpc64/rtld_machdep.h
@@ -65,6 +65,7 @@ extern u_long cpu_features2; /* r4 */
  * TLS
  */
 
+#define	TLS_VARIANT_I	1
 #define TLS_TP_OFFSET	0x7000
 #define TLS_DTV_OFFSET	0x8000
 #define TLS_TCB_SIZE	16
@@ -75,7 +76,6 @@ extern u_long cpu_features2; /* r4 */
     TLS_TCB_SIZE
 #define calculate_tls_offset(prev_offset, prev_size, size, align, offset) \
     round(prev_offset + prev_size, align)
-#define calculate_tls_end(off, size)    ((off) + (size))
 #define calculate_tls_post_size(align)  0
  
 typedef struct {
diff --git a/libexec/rtld-elf/riscv/rtld_machdep.h b/libexec/rtld-elf/riscv/rtld_machdep.h
index 43349b4ab403..7a087ca2ab7c 100644
--- a/libexec/rtld-elf/riscv/rtld_machdep.h
+++ b/libexec/rtld-elf/riscv/rtld_machdep.h
@@ -82,6 +82,7 @@ Elf_Addr reloc_jmpslot(Elf_Addr *where, Elf_Addr target,
 /*
  * TLS
  */
+#define	TLS_VARIANT_I	1
 #define	TLS_TP_OFFSET	0x0
 #define	TLS_DTV_OFFSET	0x800
 #define	TLS_TCB_SIZE	16
@@ -92,7 +93,6 @@ Elf_Addr reloc_jmpslot(Elf_Addr *where, Elf_Addr target,
     TLS_TCB_SIZE
 #define calculate_tls_offset(prev_offset, prev_size, size, align, offset) \
     round(prev_offset + prev_size, align)
-#define calculate_tls_end(off, size)    ((off) + (size))
 #define calculate_tls_post_size(align)  0
 
 typedef struct {
diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c
index eaad89339d07..23482e07fc5f 100644
--- a/libexec/rtld-elf/rtld.c
+++ b/libexec/rtld-elf/rtld.c
@@ -4939,8 +4939,7 @@ tls_get_addr_common(Elf_Addr **dtvp, int index, size_t offset)
 	return (tls_get_addr_slow(dtvp, index, offset, false));
 }
 
-#if defined(__aarch64__) || defined(__arm__) || defined(__mips__) || \
-    defined(__powerpc__) || defined(__riscv)
+#ifdef TLS_VARIANT_I
 
 /*
  * Return pointer to allocated TLS block
@@ -5071,9 +5070,9 @@ free_tls(void *tcb, size_t tcbsize, size_t tcbalign __unused)
     free_aligned(get_tls_block_ptr(tcb, tcbsize));
 }
 
-#endif
+#endif	/* TLS_VARIANT_I */
 
-#if defined(__i386__) || defined(__amd64__)
+#ifdef TLS_VARIANT_II
 
 /*
  * Allocate Static TLS using the Variant II method.
@@ -5179,7 +5178,7 @@ free_tls(void *tls, size_t tcbsize  __unused, size_t tcbalign)
     free((void*) dtv);
 }
 
-#endif
+#endif	/* TLS_VARIANT_II */
 
 /*
  * Allocate TLS block for module with given index.
@@ -5227,6 +5226,11 @@ allocate_tls_offset(Obj_Entry *obj)
 	off = calculate_tls_offset(tls_last_offset, tls_last_size,
 	  obj->tlssize, obj->tlsalign, obj->tlspoffset);
 
+    obj->tlsoffset = off;
+#ifdef TLS_VARIANT_I
+    off += obj->tlssize;
+#endif
+
     /*
      * If we have already fixed the size of the static TLS block, we
      * must stay within that size. When allocating the static TLS, we
@@ -5234,13 +5238,13 @@ allocate_tls_offset(Obj_Entry *obj)
      * loading modules which use static TLS.
      */
     if (tls_static_space != 0) {
-	if (calculate_tls_end(off, obj->tlssize) > tls_static_space)
+	if (off > tls_static_space)
 	    return false;
     } else if (obj->tlsalign > tls_static_max_align) {
 	    tls_static_max_align = obj->tlsalign;
     }
 
-    tls_last_offset = obj->tlsoffset = off;
+    tls_last_offset = off;
     tls_last_size = obj->tlssize;
     obj->tls_done = true;
 
@@ -5257,8 +5261,11 @@ free_tls_offset(Obj_Entry *obj)
      * simplistic workaround to allow libGL.so.1 to be loaded and
      * unloaded multiple times.
      */
-    if (calculate_tls_end(obj->tlsoffset, obj->tlssize)
-	== calculate_tls_end(tls_last_offset, tls_last_size)) {
+    size_t off = obj->tlsoffset;
+#ifdef TLS_VARIANT_I
+    off += obj->tlssize;
+#endif
+    if (off == tls_last_offset) {
 	tls_last_offset -= obj->tlssize;
 	tls_last_size = 0;
     }


More information about the dev-commits-src-all mailing list