Date: Wed, 29 Apr 2020 10:57:22 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r360457 - in stable/12/libexec/rtld-elf: . aarch64 amd64 arm i386 mips powerpc powerpc64 riscv sparc64 Message-ID: <202004291057.03TAvMuJ014937@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kib Date: Wed Apr 29 10:57:21 2020 New Revision: 360457 URL: https://svnweb.freebsd.org/changeset/base/360457 Log: MFC r360091: Align initial-exec TLS segments to the p_vaddr % align. Modified: stable/12/libexec/rtld-elf/aarch64/rtld_machdep.h stable/12/libexec/rtld-elf/amd64/reloc.c stable/12/libexec/rtld-elf/amd64/rtld_machdep.h stable/12/libexec/rtld-elf/arm/rtld_machdep.h stable/12/libexec/rtld-elf/i386/reloc.c stable/12/libexec/rtld-elf/i386/rtld_machdep.h stable/12/libexec/rtld-elf/mips/rtld_machdep.h stable/12/libexec/rtld-elf/powerpc/rtld_machdep.h stable/12/libexec/rtld-elf/powerpc64/rtld_machdep.h stable/12/libexec/rtld-elf/riscv/rtld_machdep.h stable/12/libexec/rtld-elf/rtld.c stable/12/libexec/rtld-elf/sparc64/rtld_machdep.h Directory Properties: stable/12/ (props changed) Modified: stable/12/libexec/rtld-elf/aarch64/rtld_machdep.h ============================================================================== --- stable/12/libexec/rtld-elf/aarch64/rtld_machdep.h Wed Apr 29 10:54:58 2020 (r360456) +++ stable/12/libexec/rtld-elf/aarch64/rtld_machdep.h Wed Apr 29 10:57:21 2020 (r360457) @@ -72,9 +72,9 @@ Elf_Addr reloc_jmpslot(Elf_Addr *where, Elf_Addr targe #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) \ Modified: stable/12/libexec/rtld-elf/amd64/reloc.c ============================================================================== --- stable/12/libexec/rtld-elf/amd64/reloc.c Wed Apr 29 10:54:58 2020 (r360456) +++ stable/12/libexec/rtld-elf/amd64/reloc.c Wed Apr 29 10:57:21 2020 (r360457) @@ -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); +} Modified: stable/12/libexec/rtld-elf/amd64/rtld_machdep.h ============================================================================== --- stable/12/libexec/rtld-elf/amd64/rtld_machdep.h Wed Apr 29 10:54:58 2020 (r360456) +++ stable/12/libexec/rtld-elf/amd64/rtld_machdep.h Wed Apr 29 10:57:21 2020 (r360457) @@ -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 Modified: stable/12/libexec/rtld-elf/arm/rtld_machdep.h ============================================================================== --- stable/12/libexec/rtld-elf/arm/rtld_machdep.h Wed Apr 29 10:54:58 2020 (r360456) +++ stable/12/libexec/rtld-elf/arm/rtld_machdep.h Wed Apr 29 10:57:21 2020 (r360457) @@ -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) \ Modified: stable/12/libexec/rtld-elf/i386/reloc.c ============================================================================== --- stable/12/libexec/rtld-elf/i386/reloc.c Wed Apr 29 10:54:58 2020 (r360456) +++ stable/12/libexec/rtld-elf/i386/reloc.c Wed Apr 29 10:57:21 2020 (r360457) @@ -539,3 +539,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); +} Modified: stable/12/libexec/rtld-elf/i386/rtld_machdep.h ============================================================================== --- stable/12/libexec/rtld-elf/i386/rtld_machdep.h Wed Apr 29 10:54:58 2020 (r360456) +++ stable/12/libexec/rtld-elf/i386/rtld_machdep.h Wed Apr 29 10:57:21 2020 (r360457) @@ -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 Modified: stable/12/libexec/rtld-elf/mips/rtld_machdep.h ============================================================================== --- stable/12/libexec/rtld-elf/mips/rtld_machdep.h Wed Apr 29 10:54:58 2020 (r360456) +++ stable/12/libexec/rtld-elf/mips/rtld_machdep.h Wed Apr 29 10:57:21 2020 (r360457) @@ -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 Modified: stable/12/libexec/rtld-elf/powerpc/rtld_machdep.h ============================================================================== --- stable/12/libexec/rtld-elf/powerpc/rtld_machdep.h Wed Apr 29 10:54:58 2020 (r360456) +++ stable/12/libexec/rtld-elf/powerpc/rtld_machdep.h Wed Apr 29 10:57:21 2020 (r360457) @@ -74,9 +74,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 Modified: stable/12/libexec/rtld-elf/powerpc64/rtld_machdep.h ============================================================================== --- stable/12/libexec/rtld-elf/powerpc64/rtld_machdep.h Wed Apr 29 10:54:58 2020 (r360456) +++ stable/12/libexec/rtld-elf/powerpc64/rtld_machdep.h Wed Apr 29 10:57:21 2020 (r360457) @@ -66,9 +66,9 @@ void reloc_non_plt_self(Elf_Dyn *dynp, Elf_Addr relocb #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 Modified: stable/12/libexec/rtld-elf/riscv/rtld_machdep.h ============================================================================== --- stable/12/libexec/rtld-elf/riscv/rtld_machdep.h Wed Apr 29 10:54:58 2020 (r360456) +++ stable/12/libexec/rtld-elf/riscv/rtld_machdep.h Wed Apr 29 10:57:21 2020 (r360457) @@ -88,9 +88,9 @@ Elf_Addr reloc_jmpslot(Elf_Addr *where, Elf_Addr targe #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 Modified: stable/12/libexec/rtld-elf/rtld.c ============================================================================== --- stable/12/libexec/rtld-elf/rtld.c Wed Apr 29 10:54:58 2020 (r360456) +++ stable/12/libexec/rtld-elf/rtld.c Wed Apr 29 10:57:21 2020 (r360457) @@ -4932,13 +4932,13 @@ allocate_tls(Obj_Entry *objs, void *oldtls, size_t tcb 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; @@ -5004,7 +5004,7 @@ free_tls(void *tls, size_t tcbsize __unused, size_t t 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]; @@ -5062,10 +5062,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 Modified: stable/12/libexec/rtld-elf/sparc64/rtld_machdep.h ============================================================================== --- stable/12/libexec/rtld-elf/sparc64/rtld_machdep.h Wed Apr 29 10:54:58 2020 (r360456) +++ stable/12/libexec/rtld-elf/sparc64/rtld_machdep.h Wed Apr 29 10:57:21 2020 (r360457) @@ -58,9 +58,9 @@ Elf_Addr reloc_jmpslot(Elf_Addr *, Elf_Addr, #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(size, 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) + (size), align) #define calculate_tls_end(off, size) ((off) + (size))
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202004291057.03TAvMuJ014937>