mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Rui Ueyama <rui314@gmail.com>
Cc: musl@lists.openwall.com
Subject: Re: [musl] arm32 tlsdesc bug
Date: Fri, 6 Oct 2023 00:20:25 -0400	[thread overview]
Message-ID: <20231006042025.GI4163@brightrain.aerifal.cx> (raw)
In-Reply-To: <CACKH++Yq3LGXGaUBrR4BupwPkPmH4bDjFrRNEDwbLTh1nKqC1w@mail.gmail.com>

On Fri, Oct 06, 2023 at 01:08:18PM +0900, Rui Ueyama wrote:
> Hi,
> 
> I think there's a bug in musl's TLSDESC implementation for ARM32.
> 
> TLSDESC uses two consecutive GOT slots to store a function pointer and its
> argument. Usually, the function pointer is stored in the first slot and the
> argument in the second. However, on ARM32, the order is reversed; the
> argument is stored in the first slot.
> 
> If a TLSDESC relocation has a non-zero addend, it's applied to the function
> argument and not to the function pointer. That means, for an ABI that uses
> the REL-type relocations (as opposed to RELA-type), the addend should be
> stored to the location where the function argument is stored, and that's
> the first slot on ARM32.
> 
> So, I believe we need something like this.
> 
> diff --git a/ldso/dynlink.c b/ldso/dynlink.c
> index ceca3c98..254fa5b8 100644
> --- a/ldso/dynlink.c
> +++ b/ldso/dynlink.c
> @@ -513,11 +513,17 @@ static void do_relocs(struct dso *dso, size_t *rel,
> size_t rel_size, size_t stri
>                 case REL_TPOFF_NEG:
>                         *reloc_addr = def.dso->tls.offset - tls_val +
> addend;
>                         break;
>  #endif
>                 case REL_TLSDESC:
> -                       if (stride<3) addend = reloc_addr[1];
> +                       if (stride<3) {
> +#ifdef TLSDESC_BACKWARDS
> +                               addend = reloc_addr[0];
> +#else
> +                               addend = reloc_addr[1];
> +#endif
> +                       }
>                         if (def.dso->tls_id > static_tls_cnt) {
>                                 struct td_index *new = malloc(sizeof *new);
>                                 if (!new) {
>                                         error(
>                                         "Error relocating %s: cannot
> allocate TLSDESC for %s",

Thank you!! This almost surely explains the TLSDESC problems we've
encountered on arm (32-bit) that prevented enabling it by default.

Rich

      reply	other threads:[~2023-10-06  4:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-06  4:08 Rui Ueyama
2023-10-06  4:20 ` Rich Felker [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231006042025.GI4163@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    --cc=rui314@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).