public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Michael Matz <matz@suse.de>
To: Nick Clifton <nickc@redhat.com>
Cc: binutils@sourceware.org, mjw@fedoraproject.org, amulhern@redhat.com
Subject: Re: RFC: Can static executables contain relocations against symbols ?
Date: Wed, 29 Mar 2023 16:00:12 +0000 (UTC)	[thread overview]
Message-ID: <alpine.LSU.2.20.2303291542520.16810@wotan.suse.de> (raw)
In-Reply-To: <87v8ijmxjh.fsf@redhat.com>

Hello,

On Wed, 29 Mar 2023, Nick Clifton via Binutils wrote:

>   Can static executables contain relocations against symbols ?

Generally I agree with you that they should not.  Only symbol-less 
relocations make sense (not all of them will be absolute, though.  In PIEs 
they will be base-relative, still symbolless of course).  But for the sake 
of discussion let's assume we somehow want to allow symbol-based relocs 
nevertheless.  Then:

In final-linked ELF files symbol headers always have to be optional.  The 
place of relocations, if necessary, (and symbols) needs to be communicated 
in a different way anyway (on dynamic ELF files via the program headers 
and dynamic entries, on static files via some other side channel, like 
hardcoding the offset/addresses of the interesting pieces).

But: there is another observation that makes the Rust output invalid.  An 
allocated (SHF_ALLOC) section (here .got.rela) _must_ only refer to 
allocated sections via its sh_link field.  The .symtab section in the 
example at hand was not SHF_ALLOC.  So that's another bug.

Leaving a sh_link field of an SHT_RELA section to be zero seems a bit 
dubious.  Normally client code would be able to rely on sh_link containing 
an existing section index.  OTOH SHN_UNDEF (i.e. zero) _is_ somewhat of a 
section index, so leaving it as zero might just be fine.

So, even if the above problems would be fixed I think your patch still 
makes sense.  Perhaps add another check to only leave it zero if 
elf_onesymtab is not allocated itself.


Ciao,
Michael.

  parent reply	other threads:[~2023-03-29 16:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-29 14:39 Nick Clifton
2023-03-29 15:47 ` Mark Wielaard
2023-03-29 16:00 ` Michael Matz [this message]
2023-03-30  1:22 ` Alan Modra
2023-03-30  4:54   ` Alan Modra
2023-03-30  8:57     ` Nick Clifton
2023-03-30  9:12       ` Alan Modra

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.LSU.2.20.2303291542520.16810@wotan.suse.de \
    --to=matz@suse.de \
    --cc=amulhern@redhat.com \
    --cc=binutils@sourceware.org \
    --cc=mjw@fedoraproject.org \
    --cc=nickc@redhat.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.
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).