public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "Maciej W. Rozycki" <macro@orcam.me.uk>
To: YunQiang Su <syq@gcc.gnu.org>
Cc: Hans-Peter Nilsson <hp@bitrange.com>,
	Nick Clifton <nickc@redhat.com>,
	 binutils@sourceware.org, xry111@xry111.site
Subject: Re: [PATCH v6] MIPS: Reject branch absolute relocs for PIC for linking
Date: Thu, 22 Feb 2024 13:13:17 +0000 (GMT)	[thread overview]
Message-ID: <alpine.DEB.2.21.2402221223540.61493@angie.orcam.me.uk> (raw)
In-Reply-To: <CAKcpw6W0S0JshQamEkx1pJuVzSwSZ9UMb1M3oNsiiHWcZVO77Q@mail.gmail.com>

On Thu, 22 Feb 2024, YunQiang Su wrote:

> > > +               howto = MIPS_ELF_RTYPE_TO_HOWTO (abfd, r_type, NEWABI_P (abfd));
> > > +               info->callbacks->einfo
> > > +                 /* xgettext:c-format */
> > > +                 (_("%X%H: relocation %s against `*ABS*' cannot be used"
> >
> > There's no "*ABS*" in the source and IMHO that'd look confusing
> > to innocent users.  How about "...against an absolute value"?
> > Or "...against an absolute value or absolute symbol"?  Perhaps
> > the latter is a bit too wordy, but also more complete.
> >
> 
> Good idea. I think that we should use "...against an absolute value".
> "absolute symbol"  is not included in this code, as it's r_symndx is
> not STN_UNDEF.

 Well code says otherwise:

+	      if (branch_reloc_p (r_type) && r_symndx == STN_UNDEF)

did you mean "the relocation's r_symndx is STN_UNDEF"?

 But it can be a relocation against an absolute symbol, for example if the 
symbol referred to by a relocation is supplied by another module in the 
link or a linker script and said symbol is absolute.  This case has to be 
covered in testing as well, as I infer from your code it won't be handled 
correctly.

 In fact this situation is not unique to branch relocations, because no 
PC-relative relocation against an absolute symbol or value can be resolved 
at link time for PIC/PIE links.  So you need to make your code generic for 
any relocations that have the `pc_relative' flag set in their howto unless 
we have a way to make a dynamic relocation out of such a relocation (which 
is none right now, as we still only have R_MIPS_REL32 as the sole dynamic 
relocation, except for TLS stuff).

 Extra test cases will be appreciated if you can come up with ones.

  Maciej

  reply	other threads:[~2024-02-22 13:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-21 14:52 YunQiang Su
2024-02-22  3:13 ` Hans-Peter Nilsson
2024-02-22  6:29   ` YunQiang Su
2024-02-22 13:13     ` Maciej W. Rozycki [this message]
2024-02-25 14:08       ` YunQiang Su
2024-03-01 17:23         ` Maciej W. Rozycki

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=alpine.DEB.2.21.2402221223540.61493@angie.orcam.me.uk \
    --to=macro@orcam.me.uk \
    --cc=binutils@sourceware.org \
    --cc=hp@bitrange.com \
    --cc=nickc@redhat.com \
    --cc=syq@gcc.gnu.org \
    --cc=xry111@xry111.site \
    /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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).