mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Max Filippov <jcmvbkbc@gmail.com>
To: Rich Felker <dalias@libc.org>
Cc: musl@lists.openwall.com
Subject: Re: [musl] Initial xtensa/fdpic port review
Date: Tue, 19 Mar 2024 09:08:15 -0700	[thread overview]
Message-ID: <CAMo8BfKVnXXOTr0tvXojNDKd5XC8i0eEo3gVFVPEhCQYLLXoFA@mail.gmail.com> (raw)
In-Reply-To: <20240228183032.GO4163@brightrain.aerifal.cx>

On Wed, Feb 28, 2024 at 10:30 AM Rich Felker <dalias@libc.org> wrote:
> On Wed, Feb 28, 2024 at 09:20:33AM -0800, Max Filippov wrote:
> > On Tue, Feb 27, 2024 at 4:12 PM Rich Felker <dalias@libc.org> wrote:
> > > >               } else {
> > > >                       size_t val = syms[R_SYM(rel[1])].st_value;
> > > >                       for (j=0; val-segs[j].p_vaddr >= segs[j].p_memsz; j++);
> > > >                       *rel_addr = rel[2] + segs[j].addr - segs[j].p_vaddr + val;
> > > >               }
> > > >       }
> > > > +#ifdef __xtensa__
> > > > +     ((unsigned long *)dyn[DT_PLTGOT])[3] = segs[0].addr - segs[0].p_vaddr;
> > > > +#endif
> > >
> > > Is this actually needed for anything? Generally musl doesn't use the
> > > reserved GOT slots itself, and on all the other archs I'm aware of,
> > > they're essentially reserved to the dynamic linker implementation so
> > > the dynamic linker is just free not to use them and not to set them
> > > up.
> >
> > xtensa doesn't have relative register jumps and calls, so local jumps
> > and calls to a far off locations need to use absolute target addresses.
> > One possible solution is to have the address in the GOT entry, the
> > other is to calculate the target address using the text segment load
> > offset at runtime. Both have the same instruction count, see
> >   http://wiki.osll.ru/doku.php/etc:users:jcmvbkbc:binutils-xtensa#local_call
> > for the details, but the latter doesn't waste GOT space and that saves
> > a noticeable amount of RAM.
>
> I see. Doesn't this limit you to a single text segment, though? In
> practice it might not matter, but it's more constraining than fdpic
> was designed to be.

Instead of a fixed dedicated GOT entry there can be multiple
entries, one per independent text segment, giving the maximum of
1024 / 4 - 3 = 253 text segments addressable with this technique.
Instead of generating a fixed load from GOT + 12 there would be a
relocation against that load instruction mentioning the target symbol
and the linker would have a chance to allocate GOT space, fix up
offsets in these instructions and add dynamic relocations against
these GOT entries that would produce runtime load offsets for the
corresponding text segments.

-- 
Thanks.
-- Max

      parent reply	other threads:[~2024-03-19 16:08 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-27 23:24 Rich Felker
2024-02-28  0:13 ` Rich Felker
2024-02-28 17:20   ` Max Filippov
2024-02-28 18:30     ` Rich Felker
2024-02-28 18:37       ` Rich Felker
2024-02-28 19:34         ` Max Filippov
2024-02-28 19:41           ` Max Filippov
2024-02-28 20:14             ` Rich Felker
2024-02-28 20:26               ` Rich Felker
2024-02-28 20:37                 ` Rich Felker
2024-02-28 21:28       ` Max Filippov
2024-02-29 12:03         ` Max Filippov
2024-02-29 15:35           ` Rich Felker
2024-02-29 16:25       ` Max Filippov
2024-02-29 18:16         ` Rich Felker
2024-03-19 15:25       ` Max Filippov
2024-03-19 16:08       ` Max Filippov [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=CAMo8BfKVnXXOTr0tvXojNDKd5XC8i0eEo3gVFVPEhCQYLLXoFA@mail.gmail.com \
    --to=jcmvbkbc@gmail.com \
    --cc=dalias@libc.org \
    --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).