public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: "H.J. Lu" <hjl.tools@gmail.com>
Cc: Fangrui Song <i@maskray.me>, Cary Coutant <ccoutant@gmail.com>,
	Michael Matz <matz@suse.de>, Florian Weimer <fweimer@redhat.com>,
	Szabolcs Nagy <szabolcs.nagy@arm.com>,
	"binutils@sourceware.org" <binutils@sourceware.org>,
	Fangrui Song <maskray@google.com>
Subject: Re: [PATCH] Allow direct access relocations referencing a protected function symbol
Date: Fri, 18 Jun 2021 11:24:23 +0930	[thread overview]
Message-ID: <YMv8z84Uc412ktmJ@squeak.grove.modra.org> (raw)
In-Reply-To: <CAMe9rOqWJa2FwE0F+Gc3rgRDV7k9yB=rv6hUEWubrzspsqWC+w@mail.gmail.com>

On Thu, Jun 17, 2021 at 10:25:09AM -0700, H.J. Lu wrote:
> On x86-64, function pointers in executable for external funtions may be
> resolved to their PLT entries in executable.  If it happens, function
> pointers of protected funtions in shared libraries must be resolved to
> the PLT entries in executable, not addresses of protected funtions in
> shared libraries.

Yes, but quite plainly we have a broken toolchain at the moment.  With
correct options for generating shared library code, gcc generates
objects that ld.bfd refuses to link.  That's BAD.  At a minimum the ld
error needs to be reduced to a warning, but preferably silenced.

What's more, function pointer comparisons work in many cases when the
executable is a PIE, even on x86.  For example

library:
void __attribute__ ((visibility ("protected")))
protfun (void) { __builtin_printf ("Address in lib is %lx\n", (long) &protfun); }

executable:
extern void protfun (void);
int main (void)
{
  __builtin_printf ("Address in main is %lx\n", (long) &protfun);
  protfun ();
  return 0;
}

And this variant of the executable

extern void protfun (void);
void *const addr = &protfun;

int main (void)
{
  __builtin_printf ("Address in main is %lx\n", (long) addr);
  protfun ();
  return 0;
}

only fails when PIE due to ld.bfd needlessly emitting a dynamic
protfun symbol with non-zero value.  It's not needed when the const
"addr" is in .data.rel.ro, a writable section when ld.so is
relocating.

-- 
Alan Modra
Australia Development Lab, IBM

  parent reply	other threads:[~2021-06-18  1:54 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-13 21:54 Fangrui Song
2021-06-14 13:20 ` Alan Modra
2021-06-14 14:03   ` Michael Matz
2021-06-14 14:48     ` H.J. Lu
2021-06-14 17:43       ` Fangrui Song
2021-06-15  2:46         ` Alan Modra
2021-06-15  3:19           ` Fangrui Song
2021-06-16  3:53             ` Alan Modra
2021-06-16  4:42               ` Fangrui Song
2021-06-16  6:31                 ` Alan Modra
2021-06-16  8:11                   ` Fangrui Song
2021-06-16 14:06                     ` Michael Matz
2021-06-17  2:59                     ` Alan Modra
2021-06-17  4:24                       ` Fangrui Song
2021-06-17 17:25                         ` H.J. Lu
2021-06-17 17:51                           ` Fangrui Song
2021-06-18  1:54                           ` Alan Modra [this message]
2021-06-18  2:41                             ` H.J. Lu

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=YMv8z84Uc412ktmJ@squeak.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=ccoutant@gmail.com \
    --cc=fweimer@redhat.com \
    --cc=hjl.tools@gmail.com \
    --cc=i@maskray.me \
    --cc=maskray@google.com \
    --cc=matz@suse.de \
    --cc=szabolcs.nagy@arm.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).