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
This commit is contained in:
parent
d98351e13c
commit
e5c3405ce8
@ -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) \
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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) \
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user