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 08:25:10 -0700	[thread overview]
Message-ID: <CAMo8BfKsdDW+r-pe-5w+jW3FfPyg5fxS=z0zSJpUyOonw64L+A@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:
> > > > diff --git a/ldso/dlstart.c b/ldso/dlstart.c
> > > > index 259f5e18..beca953f 100644
> > > > --- a/ldso/dlstart.c
> > > > +++ b/ldso/dlstart.c
> > > > @@ -90,12 +90,19 @@ hidden void _dlstart_c(size_t *sp, size_t *dynv)
> > > >                               - segs[rel_addr[1]].p_vaddr
> > > >                               + syms[R_SYM(rel[1])].st_value;
> > > >                       rel_addr[1] = dyn[DT_PLTGOT];
> > > > +             } else if (R_TYPE(rel[1]) == REL_RELATIVE) {
> > > > +                     size_t val = *rel_addr;
> > > > +                     for (j=0; val-segs[j].p_vaddr >= segs[j].p_memsz; j++);
> > > > +                     *rel_addr += segs[j].addr - segs[j].p_vaddr;
> > >
> > > So xtensa has a "relative" reloc type that's just adjusted by the load
> > > offset of the segment the relocation lives in, rather than needing to
> > > use a symbolic relocation referencing a section symbol like other
> > > fdpic archs do?
> >
> > I was looking at the ARM BFD code while doing that and
> > my impression was that they do the same.
> > Regardless, I wonder why either relocation form might be preferable?
>
> I think the relative type here is perfectly acceptable. At first I
> thought it was weaker (less capable of representing addresses of
> objects in different segments), but looking again, I don't think
> that's the case.

I found that this treatment of the REL_RELATIVE is not consistent
with the REL_RELATIVE treatment in do_relocs(), where RELA type
relocation is expected to have an addend, and only the addend
matters, not the initial value of the field being relocated.
I just realized that looking at what ARM does might not be a good
idea for the xtensa port, as ARM uses the REL type relocations and
xtensa uses RELA.

Also do_relocs() does not use the DSO load map, so the following
change is required for it to work in the FDPIC case:
               case REL_RELATIVE:
-                       *reloc_addr = (size_t)base + addend;
+                       *reloc_addr = (size_t)laddr(dso, addend);
                       break;

-- 
Thanks.
-- Max

  parent reply	other threads:[~2024-03-19 15:25 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 [this message]
2024-03-19 16:08       ` 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='CAMo8BfKsdDW+r-pe-5w+jW3FfPyg5fxS=z0zSJpUyOonw64L+A@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).