svn commit: r360091 - in head/libexec/rtld-elf: . aarch64 amd64 arm i386 mips powerpc powerpc64 riscv
Konstantin Belousov
kib at FreeBSD.org
Sun Apr 19 09:29:02 UTC 2020
Author: kib
Date: Sun Apr 19 09:28:59 2020
New Revision: 360091
URL: https://svnweb.freebsd.org/changeset/base/360091
Log:
Align initial-exec TLS segments to the p_vaddr % align.
This is continuation of D21163/r359634, which handled the alignment
for global mode.
Non-x86 arches are not handled, maintainers are welcomed.
Tested by: emaste
Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Differential revision: https://reviews.freebsd.org/D24366
Modified:
head/libexec/rtld-elf/aarch64/rtld_machdep.h
head/libexec/rtld-elf/amd64/reloc.c
head/libexec/rtld-elf/amd64/rtld_machdep.h
head/libexec/rtld-elf/arm/rtld_machdep.h
head/libexec/rtld-elf/i386/reloc.c
head/libexec/rtld-elf/i386/rtld_machdep.h
head/libexec/rtld-elf/mips/rtld_machdep.h
head/libexec/rtld-elf/powerpc/rtld_machdep.h
head/libexec/rtld-elf/powerpc64/rtld_machdep.h
head/libexec/rtld-elf/riscv/rtld_machdep.h
head/libexec/rtld-elf/rtld.c
Modified: head/libexec/rtld-elf/aarch64/rtld_machdep.h
==============================================================================
--- head/libexec/rtld-elf/aarch64/rtld_machdep.h Sun Apr 19 07:27:12 2020 (r360090)
+++ head/libexec/rtld-elf/aarch64/rtld_machdep.h Sun Apr 19 09:28:59 2020 (r360091)
@@ -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: head/libexec/rtld-elf/amd64/reloc.c
==============================================================================
--- head/libexec/rtld-elf/amd64/reloc.c Sun Apr 19 07:27:12 2020 (r360090)
+++ head/libexec/rtld-elf/amd64/reloc.c Sun Apr 19 09:28:59 2020 (r360091)
@@ -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: head/libexec/rtld-elf/amd64/rtld_machdep.h
==============================================================================
--- head/libexec/rtld-elf/amd64/rtld_machdep.h Sun Apr 19 07:27:12 2020 (r360090)
+++ head/libexec/rtld-elf/amd64/rtld_machdep.h Sun Apr 19 09:28:59 2020 (r360091)
@@ -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: head/libexec/rtld-elf/arm/rtld_machdep.h
==============================================================================
--- head/libexec/rtld-elf/arm/rtld_machdep.h Sun Apr 19 07:27:12 2020 (r360090)
+++ head/libexec/rtld-elf/arm/rtld_machdep.h Sun Apr 19 09:28:59 2020 (r360091)
@@ -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: head/libexec/rtld-elf/i386/reloc.c
==============================================================================
--- head/libexec/rtld-elf/i386/reloc.c Sun Apr 19 07:27:12 2020 (r360090)
+++ head/libexec/rtld-elf/i386/reloc.c Sun Apr 19 09:28:59 2020 (r360091)
@@ -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);
+}
Modified: head/libexec/rtld-elf/i386/rtld_machdep.h
==============================================================================
--- head/libexec/rtld-elf/i386/rtld_machdep.h Sun Apr 19 07:27:12 2020 (r360090)
+++ head/libexec/rtld-elf/i386/rtld_machdep.h Sun Apr 19 09:28:59 2020 (r360091)
@@ -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: head/libexec/rtld-elf/mips/rtld_machdep.h
==============================================================================
--- head/libexec/rtld-elf/mips/rtld_machdep.h Sun Apr 19 07:27:12 2020 (r360090)
+++ head/libexec/rtld-elf/mips/rtld_machdep.h Sun Apr 19 09:28:59 2020 (r360091)
@@ -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: head/libexec/rtld-elf/powerpc/rtld_machdep.h
==============================================================================
--- head/libexec/rtld-elf/powerpc/rtld_machdep.h Sun Apr 19 07:27:12 2020 (r360090)
+++ head/libexec/rtld-elf/powerpc/rtld_machdep.h Sun Apr 19 09:28:59 2020 (r360091)
@@ -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
Modified: head/libexec/rtld-elf/powerpc64/rtld_machdep.h
==============================================================================
--- head/libexec/rtld-elf/powerpc64/rtld_machdep.h Sun Apr 19 07:27:12 2020 (r360090)
+++ head/libexec/rtld-elf/powerpc64/rtld_machdep.h Sun Apr 19 09:28:59 2020 (r360091)
@@ -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
Modified: head/libexec/rtld-elf/riscv/rtld_machdep.h
==============================================================================
--- head/libexec/rtld-elf/riscv/rtld_machdep.h Sun Apr 19 07:27:12 2020 (r360090)
+++ head/libexec/rtld-elf/riscv/rtld_machdep.h Sun Apr 19 09:28:59 2020 (r360091)
@@ -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: head/libexec/rtld-elf/rtld.c
==============================================================================
--- head/libexec/rtld-elf/rtld.c Sun Apr 19 07:27:12 2020 (r360090)
+++ head/libexec/rtld-elf/rtld.c Sun Apr 19 09:28:59 2020 (r360091)
@@ -4979,13 +4979,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;
@@ -5051,7 +5051,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];
@@ -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
More information about the svn-src-all
mailing list