diff options
-rw-r--r-- | libexec/rtld-elf/aarch64/rtld_machdep.h | 4 | ||||
-rw-r--r-- | libexec/rtld-elf/amd64/reloc.c | 30 | ||||
-rw-r--r-- | libexec/rtld-elf/amd64/rtld_machdep.h | 12 | ||||
-rw-r--r-- | libexec/rtld-elf/arm/rtld_machdep.h | 4 | ||||
-rw-r--r-- | libexec/rtld-elf/i386/reloc.c | 30 | ||||
-rw-r--r-- | libexec/rtld-elf/i386/rtld_machdep.h | 12 | ||||
-rw-r--r-- | libexec/rtld-elf/mips/rtld_machdep.h | 4 | ||||
-rw-r--r-- | libexec/rtld-elf/powerpc/rtld_machdep.h | 4 | ||||
-rw-r--r-- | libexec/rtld-elf/powerpc64/rtld_machdep.h | 4 | ||||
-rw-r--r-- | libexec/rtld-elf/riscv/rtld_machdep.h | 4 | ||||
-rw-r--r-- | libexec/rtld-elf/rtld.c | 11 |
11 files changed, 86 insertions, 33 deletions
diff --git a/libexec/rtld-elf/aarch64/rtld_machdep.h b/libexec/rtld-elf/aarch64/rtld_machdep.h index 9cc0f2443318..0824219c00c2 100644 --- a/libexec/rtld-elf/aarch64/rtld_machdep.h +++ b/libexec/rtld-elf/aarch64/rtld_machdep.h @@ -72,9 +72,9 @@ Elf_Addr reloc_jmpslot(Elf_Addr *where, Elf_Addr target, #define round(size, align) \ (((size) + (align) - 1) & ~((align) - 1)) -#define calculate_first_tls_offset(size, align) \ +#define calculate_first_tls_offset(size, align, offset) \ round(16, align) -#define calculate_tls_offset(prev_offset, prev_size, size, 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) \ diff --git a/libexec/rtld-elf/amd64/reloc.c b/libexec/rtld-elf/amd64/reloc.c index ae15f6a41dec..4bdda929c0c7 100644 --- a/libexec/rtld-elf/amd64/reloc.c +++ b/libexec/rtld-elf/amd64/reloc.c @@ -552,3 +552,33 @@ void *__tls_get_addr(tls_index *ti) return tls_get_addr_common(&segbase[1], ti->ti_module, ti->ti_offset); } + +size_t +calculate_first_tls_offset(size_t size, size_t align, size_t offset) +{ + size_t res; + + res = roundup(size, align); + offset &= align - 1; + if (offset != 0) + res += align - offset; + return (res); +} + +size_t +calculate_tls_offset(size_t prev_offset, size_t prev_size __unused, size_t size, + size_t align, size_t offset) +{ + size_t res; + + res = roundup(prev_offset + size, align); + offset &= align - 1; + if (offset != 0) + res += align - offset; + return (res); +} +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 0c915b6efe66..86027a04788f 100644 --- a/libexec/rtld-elf/amd64/rtld_machdep.h +++ b/libexec/rtld-elf/amd64/rtld_machdep.h @@ -61,14 +61,6 @@ extern uint32_t cpu_stdext_feature2; (((Elf_Addr (*)(uint32_t, uint32_t, uint32_t, uint32_t))ptr)( \ cpu_feature, cpu_feature2, cpu_stdext_feature, cpu_stdext_feature2)) -#define round(size, align) \ - (((size) + (align) - 1) & ~((align) - 1)) -#define calculate_first_tls_offset(size, align) \ - round(size, align) -#define calculate_tls_offset(prev_offset, prev_size, size, align) \ - round((prev_offset) + (size), align) -#define calculate_tls_end(off, size) (off) - typedef struct { unsigned long ti_module; unsigned long ti_offset; @@ -81,4 +73,8 @@ void *__tls_get_addr(tls_index *ti) __exported; #define md_abi_variant_hook(x) +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 030c83cdc7f4..57420c65593f 100644 --- a/libexec/rtld-elf/arm/rtld_machdep.h +++ b/libexec/rtld-elf/arm/rtld_machdep.h @@ -64,9 +64,9 @@ typedef struct { #define round(size, align) \ (((size) + (align) - 1) & ~((align) - 1)) -#define calculate_first_tls_offset(size, align) \ +#define calculate_first_tls_offset(size, align, offset) \ round(8, align) -#define calculate_tls_offset(prev_offset, prev_size, size, 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) \ diff --git a/libexec/rtld-elf/i386/reloc.c b/libexec/rtld-elf/i386/reloc.c index be4f18197cd8..b4bd09d677b4 100644 --- a/libexec/rtld-elf/i386/reloc.c +++ b/libexec/rtld-elf/i386/reloc.c @@ -543,3 +543,33 @@ void *__tls_get_addr(tls_index *ti) return tls_get_addr_common(&segbase[1], ti->ti_module, ti->ti_offset); } + +size_t +calculate_first_tls_offset(size_t size, size_t align, size_t offset) +{ + size_t res; + + res = roundup(size, align); + offset &= align - 1; + if (offset != 0) + res += align - offset; + return (res); +} + +size_t +calculate_tls_offset(size_t prev_offset, size_t prev_size __unused, size_t size, + size_t align, size_t offset) +{ + size_t res; + + res = roundup(prev_offset + size, align); + offset &= align - 1; + if (offset != 0) + res += align - offset; + return (res); +} +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 69d3fe576523..5116f9707337 100644 --- a/libexec/rtld-elf/i386/rtld_machdep.h +++ b/libexec/rtld-elf/i386/rtld_machdep.h @@ -61,14 +61,6 @@ extern uint32_t cpu_stdext_feature2; (((Elf_Addr (*)(uint32_t, uint32_t, uint32_t, uint32_t))(ptr))( \ cpu_feature, cpu_feature2, cpu_stdext_feature, cpu_stdext_feature2)) -#define round(size, align) \ - (((size) + (align) - 1) & ~((align) - 1)) -#define calculate_first_tls_offset(size, align) \ - round(size, align) -#define calculate_tls_offset(prev_offset, prev_size, size, align) \ - round((prev_offset) + (size), align) -#define calculate_tls_end(off, size) (off) - typedef struct { unsigned long ti_module; unsigned long ti_offset; @@ -82,4 +74,8 @@ void *__tls_get_addr(tls_index *ti) __exported; #define md_abi_variant_hook(x) +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 84a9a651706b..b1556c93c3d6 100644 --- a/libexec/rtld-elf/mips/rtld_machdep.h +++ b/libexec/rtld-elf/mips/rtld_machdep.h @@ -66,9 +66,9 @@ typedef struct { #define round(size, align) \ (((size) + (align) - 1) & ~((align) - 1)) -#define calculate_first_tls_offset(size, align) \ +#define calculate_first_tls_offset(size, align, offset) \ TLS_TCB_SIZE -#define calculate_tls_offset(prev_offset, prev_size, size, 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) 0 diff --git a/libexec/rtld-elf/powerpc/rtld_machdep.h b/libexec/rtld-elf/powerpc/rtld_machdep.h index d02ee277d53c..a35ac1f4ebf5 100644 --- a/libexec/rtld-elf/powerpc/rtld_machdep.h +++ b/libexec/rtld-elf/powerpc/rtld_machdep.h @@ -79,9 +79,9 @@ void _rtld_powerpc_pltcall(void); #define round(size, align) \ (((size) + (align) - 1) & ~((align) - 1)) -#define calculate_first_tls_offset(size, align) \ +#define calculate_first_tls_offset(size, align, offset) \ TLS_TCB_SIZE -#define calculate_tls_offset(prev_offset, prev_size, size, 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) 0 diff --git a/libexec/rtld-elf/powerpc64/rtld_machdep.h b/libexec/rtld-elf/powerpc64/rtld_machdep.h index 40a2328aba0f..486f4ffe95bc 100644 --- a/libexec/rtld-elf/powerpc64/rtld_machdep.h +++ b/libexec/rtld-elf/powerpc64/rtld_machdep.h @@ -71,9 +71,9 @@ extern u_long cpu_features2; /* r4 */ #define round(size, align) \ (((size) + (align) - 1) & ~((align) - 1)) -#define calculate_first_tls_offset(size, align) \ +#define calculate_first_tls_offset(size, align, offset) \ TLS_TCB_SIZE -#define calculate_tls_offset(prev_offset, prev_size, size, 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) 0 diff --git a/libexec/rtld-elf/riscv/rtld_machdep.h b/libexec/rtld-elf/riscv/rtld_machdep.h index 1737fa73ff8b..43349b4ab403 100644 --- a/libexec/rtld-elf/riscv/rtld_machdep.h +++ b/libexec/rtld-elf/riscv/rtld_machdep.h @@ -88,9 +88,9 @@ Elf_Addr reloc_jmpslot(Elf_Addr *where, Elf_Addr target, #define round(size, align) \ (((size) + (align) - 1) & ~((align) - 1)) -#define calculate_first_tls_offset(size, align) \ +#define calculate_first_tls_offset(size, align, offset) \ TLS_TCB_SIZE -#define calculate_tls_offset(prev_offset, prev_size, size, 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) 0 diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index ba076cbe89e7..622d8d373a0a 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -4979,13 +4979,13 @@ allocate_tls(Obj_Entry *objs, void *oldtls, size_t tcbsize, size_t tcbalign) ralign = tcbalign; if (tls_static_max_align > ralign) ralign = tls_static_max_align; - size = round(tls_static_space, ralign) + round(tcbsize, ralign); + size = roundup(tls_static_space, ralign) + roundup(tcbsize, ralign); assert(tcbsize >= 2*sizeof(Elf_Addr)); tls = malloc_aligned(size, ralign, 0 /* XXX */); dtv = xcalloc(tls_max_index + 2, sizeof(Elf_Addr)); - segbase = (Elf_Addr)(tls + round(tls_static_space, ralign)); + segbase = (Elf_Addr)(tls + roundup(tls_static_space, ralign)); ((Elf_Addr*)segbase)[0] = segbase; ((Elf_Addr*)segbase)[1] = (Elf_Addr) dtv; @@ -5051,7 +5051,7 @@ free_tls(void *tls, size_t tcbsize __unused, size_t tcbalign) ralign = tcbalign; if (tls_static_max_align > ralign) ralign = tls_static_max_align; - size = round(tls_static_space, ralign); + size = roundup(tls_static_space, ralign); dtv = ((Elf_Addr**)tls)[1]; dtvsize = dtv[1]; @@ -5109,10 +5109,11 @@ allocate_tls_offset(Obj_Entry *obj) } if (tls_last_offset == 0) - off = calculate_first_tls_offset(obj->tlssize, obj->tlsalign); + off = calculate_first_tls_offset(obj->tlssize, obj->tlsalign, + obj->tlspoffset); else off = calculate_tls_offset(tls_last_offset, tls_last_size, - obj->tlssize, obj->tlsalign); + obj->tlssize, obj->tlsalign, obj->tlspoffset); /* * If we have already fixed the size of the static TLS block, we |