mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Max Filippov <jcmvbkbc@gmail.com>
Cc: musl@lists.openwall.com
Subject: Re: [musl] [RFC v2 0/2] xtensa FDPIC port
Date: Wed, 3 Apr 2024 16:55:56 -0400	[thread overview]
Message-ID: <20240403205555.GO4163@brightrain.aerifal.cx> (raw)
In-Reply-To: <CAMo8Bf+4gHy-ndptG-zG5oVFU0oEp+f2HxHk0zaoo9-uv75BQQ@mail.gmail.com>

On Tue, Apr 02, 2024 at 07:30:57PM -0700, Max Filippov wrote:
> On Thu, Mar 28, 2024 at 6:48 PM Rich Felker <dalias@libc.org> wrote:
> > On Thu, Mar 28, 2024 at 05:48:50PM -0700, Max Filippov wrote:
> > > On Thu, Mar 28, 2024 at 4:00 PM Rich Felker <dalias@libc.org> wrote:
> > > > On Thu, Mar 28, 2024 at 01:03:17PM -0700, Max Filippov wrote:
> > > > > functional/dlopen fails with the
> > > > >   src/functional/dlopen.c:39: dlsym main failed: (null)
> > > > > There's no failure in the dlsym call, but the pointers don't match.
> > > >
> > > > Is this something related to canonical function descriptors? Is it
> > > > musl's fault or a bug in the tooling? I suspect the latter.
> > >
> > > Yes, dlsym() returns the pointer into def.dso->funcdescs,
> > > but (void *)main returns the pointer to the canonical function
> > > descriptor. I understand that the linker must use the
> > > R_XTENSA_FUNCDESC relocation for the locally defined
> > > global symbol instead of the .rofixup entries.
> >
> > If the xtensa FDPIC ABI is going to be that the linker makes canonical
> > function descriptors, I think that's workable, but the dynamic linker
> > would need a way to find and usee them. I'm not sure how that would
> > work.
> >
> > The simple (but probably less efficient) way is to copy what SH did
> > and have the dynamic linker always be responsible for them (load
> > descriptor address from GOT).
> 
> I've built and tested SH FDPIC toolchain, it fails this test in exactly
> the same way: pointer loaded directly does not match the pointer
> returned by dlsym().

Yes, I've been able to reproduce this and it's a clear bug. There does
not seem to be any way the dynamic linker could find these GOTFUNCDESC
slots to use them as a canonical address for the function, and
moreover, they're not even unique; there would be one per library.

The code path for legitimize_pic_address in sh.c that emits
GOTFUNCDESC has the wrong logic. A simple fix would be just making
that path never be taken, but I'm not sure if that would break use of
GOTFUNCDESC for pure-call purposes.

The condition should probably be something like: if it's just used for
a call (if this is even needed; pure call is probably handled
elsewhere) or if the function is static or hidden, use GOTFUNCDESC;
otherwise, use GOT.

I might try patching it and see what happens.

Rich

  reply	other threads:[~2024-04-03 20:55 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-28 20:03 Max Filippov
2024-03-28 20:03 ` [musl] [RFC v2 1/2] xtensa: add port Max Filippov
2024-03-28 20:03 ` [musl] [RFC v2 2/2] WIP xtensa bits Max Filippov
2024-03-28 23:01 ` [musl] [RFC v2 0/2] xtensa FDPIC port Rich Felker
2024-03-29  0:48   ` Max Filippov
2024-03-29  1:48     ` Rich Felker
2024-04-03  2:30       ` Max Filippov
2024-04-03 20:55         ` Rich Felker [this message]
2024-04-03 21:45           ` Rich Felker
2024-04-04  8:44             ` Max Filippov
2024-04-04 14:01               ` Rich Felker
2024-04-04 15:00                 ` Rich Felker
2024-04-08 14:41                   ` Rich Felker
2024-04-08 15:32                     ` Rich Felker
2024-05-06 14:48                       ` Rich Felker
2024-05-06 17:35                         ` Max Filippov
2024-04-04  8:56           ` Max Filippov

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=20240403205555.GO4163@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=jcmvbkbc@gmail.com \
    --cc=musl@lists.openwall.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).