public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: Nick Clifton <nickc@redhat.com>, binutils@sourceware.org
Cc: amulhern@redhat.com
Subject: Re: RFC: Can static executables contain relocations against symbols ?
Date: Wed, 29 Mar 2023 17:47:02 +0200	[thread overview]
Message-ID: <11c2f379ec297bc8368e5381b044e983008161ed.camel@klomp.org> (raw)
In-Reply-To: <87v8ijmxjh.fsf@redhat.com>

Hi Nick,

On Wed, 2023-03-29 at 15:39 +0100, Nick Clifton wrote:
>   Can static executables contain relocations against symbols ?

I see nothing in the standard that says they cannot, but also nothing
that says that if there are no relocations against symbols (which is
the case in the issue below) that a relocation section is required to
point to a symbol table.

>   This question has come up in Fedora as part of the investigation into
>   a problem linking some binaries compiled with the Rust compiler:
> 
> https://bugzilla.redhat.com/show_bug.cgi?id=2166149
> 
>   The issue appears to be that static-pie executables are being created
>   with a .rela.got section that has an sh_link field set to point to the
>   .symtab section.  This in turns means that running strip on the
>   executables will not remove the .symtab section, which is then being
>   flagged as an error by the build system.
> 
>   The problem is not happening for x86_64 binaries because they contain
>   a .dynsym section, and the code in bfd/elf.c:assign_section_numbers
>   will preferentially use that section if it exists.  (It is not clear
>   to me *why* x86_64 static pie binaries contain a .dynsym section, but
>   they do).

Note that the x86_64 .dynsym table actually is empty (contains a single
null symbol). I think it makes sense that if you refer from an
allocated relocation section to reference an allocated .dynsym section
(even if it is empty) instead of referencing an unallocated .symtab
section (because that won't be available at runtime).

>   It is possible for static executables to contain relocations - for
>   ifuncs for example - but I think that they should always be absolute.
>   So my question is: is it safe to set the sh_link field for relocation
>   sections in static executables to 0 ?

I think it is safe if you make sure there are no symbol references.
Otherwise it seems it must point to an allocated .dynsym section and
not an unallocated .symtab section.

Cheers,

Mark

  reply	other threads:[~2023-03-29 15:47 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 [this message]
2023-03-29 16:00 ` Michael Matz
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=11c2f379ec297bc8368e5381b044e983008161ed.camel@klomp.org \
    --to=mark@klomp.org \
    --cc=amulhern@redhat.com \
    --cc=binutils@sourceware.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).