diff mbox series

elf: Support at least 32-byte alignment in static dlopen

Message ID 87y2nrw1za.fsf@oldenburg2.str.redhat.com
State Committed
Headers show
Series elf: Support at least 32-byte alignment in static dlopen | expand

Commit Message

Florian Weimer July 10, 2020, 8:26 p.m. UTC
Otherwise loading a dynamically linked libc with rseq support fails,
as result of the __rseq_abi TLS variable, which has an alignment
of 32 bytes.

---
 csu/libc-tls.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Carlos O'Donell July 10, 2020, 8:49 p.m. UTC | #1
On 7/10/20 4:26 PM, Florian Weimer via Libc-alpha wrote:
> Otherwise loading a dynamically linked libc with rseq support fails,
> as result of the __rseq_abi TLS variable, which has an alignment
> of 32 bytes.

OK for 2.32.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>

> ---
>  csu/libc-tls.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/csu/libc-tls.c b/csu/libc-tls.c
> index 06e76bd395..3f1655f264 100644
> --- a/csu/libc-tls.c
> +++ b/csu/libc-tls.c
> @@ -112,6 +112,12 @@ __libc_setup_tls (void)
>    size_t tcb_offset;
>    const ElfW(Phdr) *phdr;
>  
> +  /* libc.so with rseq has TLS with 32-byte alignment.  Static dlopen
> +     requires at least 32-byte alignment as well, otherwise loading
> +     libc.so will always fail.  */
> +  if (max_align < 32)
> +    max_align = 32;

OK. Same problem as the previous discuss, namely that you'd need to look
over all the modules you're going to dlopen first to compute a value
that is large enough. All we're doing here is papering over a design problem,
but that is OK for 2.32. Eventually we're going to need to do some kind of
redesign here to make this more reliable.

> +
>    struct link_map *main_map = GL(dl_ns)[LM_ID_BASE]._ns_loaded;
>  
>    /* Look through the TLS segment if there is any.  */
>
Vineet Gupta July 10, 2020, 9:19 p.m. UTC | #2
On 7/10/20 1:49 PM, Carlos O'Donell via Libc-alpha wrote:
> On 7/10/20 4:26 PM, Florian Weimer via Libc-alpha wrote:
>> Otherwise loading a dynamically linked libc with rseq support fails,
>> as result of the __rseq_abi TLS variable, which has an alignment
>> of 32 bytes.
> 
> OK for 2.32.
> 
> Reviewed-by: Carlos O'Donell <carlos@redhat.com>

Fixes most of the ARC issues.

Tested-by: Vineet Gupta <vgupta@synopsys.com>


>> ---
>>  csu/libc-tls.c | 6 ++++++
>>  1 file changed, 6 insertions(+)
>>
>> diff --git a/csu/libc-tls.c b/csu/libc-tls.c
>> index 06e76bd395..3f1655f264 100644
>> --- a/csu/libc-tls.c
>> +++ b/csu/libc-tls.c
>> @@ -112,6 +112,12 @@ __libc_setup_tls (void)
>>    size_t tcb_offset;
>>    const ElfW(Phdr) *phdr;
>>  
>> +  /* libc.so with rseq has TLS with 32-byte alignment.  Static dlopen
>> +     requires at least 32-byte alignment as well, otherwise loading
>> +     libc.so will always fail.  */
>> +  if (max_align < 32)
>> +    max_align = 32;
> 
> OK. Same problem as the previous discuss, namely that you'd need to look
> over all the modules you're going to dlopen first to compute a value
> that is large enough. All we're doing here is papering over a design problem,
> but that is OK for 2.32. Eventually we're going to need to do some kind of
> redesign here to make this more reliable.
> 
>> +
>>    struct link_map *main_map = GL(dl_ns)[LM_ID_BASE]._ns_loaded;
>>  
>>    /* Look through the TLS segment if there is any.  */
>>
> 
>
Alistair Francis July 12, 2020, 3:31 p.m. UTC | #3
On Fri, Jul 10, 2020 at 1:29 PM Florian Weimer via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
> Otherwise loading a dynamically linked libc with rseq support fails,
> as result of the __rseq_abi TLS variable, which has an alignment
> of 32 bytes.

Fixes the RV32 regressions:

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Tested-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

>
> ---
>  csu/libc-tls.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/csu/libc-tls.c b/csu/libc-tls.c
> index 06e76bd395..3f1655f264 100644
> --- a/csu/libc-tls.c
> +++ b/csu/libc-tls.c
> @@ -112,6 +112,12 @@ __libc_setup_tls (void)
>    size_t tcb_offset;
>    const ElfW(Phdr) *phdr;
>
> +  /* libc.so with rseq has TLS with 32-byte alignment.  Static dlopen
> +     requires at least 32-byte alignment as well, otherwise loading
> +     libc.so will always fail.  */
> +  if (max_align < 32)
> +    max_align = 32;
> +
>    struct link_map *main_map = GL(dl_ns)[LM_ID_BASE]._ns_loaded;
>
>    /* Look through the TLS segment if there is any.  */
>
Florian Weimer July 12, 2020, 3:55 p.m. UTC | #4
* Alistair Francis:

> On Fri, Jul 10, 2020 at 1:29 PM Florian Weimer via Libc-alpha
> <libc-alpha@sourceware.org> wrote:
>>
>> Otherwise loading a dynamically linked libc with rseq support fails,
>> as result of the __rseq_abi TLS variable, which has an alignment
>> of 32 bytes.
>
> Fixes the RV32 regressions:
>
> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
> Tested-by: Alistair Francis <alistair.francis@wdc.com>

Thanks, now pushed.

Florian
diff mbox series

Patch

diff --git a/csu/libc-tls.c b/csu/libc-tls.c
index 06e76bd395..3f1655f264 100644
--- a/csu/libc-tls.c
+++ b/csu/libc-tls.c
@@ -112,6 +112,12 @@  __libc_setup_tls (void)
   size_t tcb_offset;
   const ElfW(Phdr) *phdr;
 
+  /* libc.so with rseq has TLS with 32-byte alignment.  Static dlopen
+     requires at least 32-byte alignment as well, otherwise loading
+     libc.so will always fail.  */
+  if (max_align < 32)
+    max_align = 32;
+
   struct link_map *main_map = GL(dl_ns)[LM_ID_BASE]._ns_loaded;
 
   /* Look through the TLS segment if there is any.  */