public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alexandre Oliva <oliva@adacore.com>
To: Fangrui Song <maskray@google.com>
Cc: Alan Modra <amodra@gmail.com>, Joseph Myers <josmyers@redhat.com>,
	binutils@sourceware.org, Fangrui Song <maskray@gcc.gnu.org>
Subject: Re: [PATCH v2] sh: Make protected symbols local for FDPIC -shared
Date: Wed, 06 Mar 2024 17:12:08 -0300	[thread overview]
Message-ID: <orcys7glwn.fsf@lxoliva.fsfla.org> (raw)
In-Reply-To: <20240305004339.1353851-1-maskray@google.com> (Fangrui Song's message of "Mon, 4 Mar 2024 16:43:39 -0800")

On Mar  4, 2024, Fangrui Song <maskray@google.com> wrote:

>     __attribute__((visibility("protected"))) void protected_fun() {}
>     void *get_protected_fun() { return protected_fun; }

> links fine in the non-FDPIC mode but not in the FDPIC mode:

>     R_SH_GOTOFFFUNCDESC relocation against external symbol "protected_fun"

This appears to be in line with the comment over SYMBOL_FUNCDESC_LOCAL:

>  /* Decide whether a reference to a symbol can be resolved locally or
>     not.  If the symbol is protected, we want the local address, but
>     its function descriptor must be assigned by the dynamic linker.  */

If the comment is wrong as your proposed change suggests, it ought to be
fixed along with the patch that changes this behavior.


But I'd also consider the possibility that it is wrong for the compiler
to expect a GOTOFF-accessible FD, when the FD is only expected to be
created at run time by the DL.

A protected symbol is visible by name outside its loadable object, so
other objects may refer to it and get a dynamic linker-created function
descriptor that needs to be the canonical one for that symbol.  Which
implies that the relocation to the function descriptor cannot be at a
link-time constant GOT offset.

OTOH, it might seem to make sense to create a local noncanonical FD for
the locally-bound function, to be used only to call the function rather
than as the function address, like a non-canonical PLT entry, but then,
if it's only for local calls, we don't need a FD for calls, we could
just call the function directly.


But the quoted C testcase above makes it clear that what is expected is
indeed the canonical function descriptor, so I think this patch is
papering over a bug in the compiler, that should be generating code to
load the canonical FD address from the GOT rather than assuming the
canonical FD is local to the module just because the symbol binds
locally.


Am I making any sense?

-- 
Alexandre Oliva, happy hacker            https://FSFLA.org/blogs/lxo/
   Free Software Activist                   GNU Toolchain Engineer
More tolerance and less prejudice are key for inclusion and diversity
Excluding neuro-others for not behaving ""normal"" is *not* inclusive

  reply	other threads:[~2024-03-06 20:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-05  0:43 Fangrui Song
2024-03-06 20:12 ` Alexandre Oliva [this message]
2024-03-07  8:32   ` Fangrui Song
2024-03-09  5:07     ` Alexandre Oliva

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=orcys7glwn.fsf@lxoliva.fsfla.org \
    --to=oliva@adacore.com \
    --cc=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=josmyers@redhat.com \
    --cc=maskray@gcc.gnu.org \
    --cc=maskray@google.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).