public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Szabolcs Nagy <szabolcs.nagy@arm.com>
To: Fangrui Song <maskray@google.com>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH v2] elf: Remove ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA
Date: Wed, 1 Jun 2022 10:53:21 +0100	[thread overview]
Message-ID: <Ypc3EQ0tBAiFXuff@arm.com> (raw)
In-Reply-To: <20220601073423.ddyb5wuwlo6tpisk@google.com>

The 06/01/2022 00:34, Fangrui Song wrote:
> On 2022-06-01, Szabolcs Nagy wrote:
> > The 05/31/2022 21:50, Fangrui Song wrote:
> > > If an executable has copy relocations for extern protected data, that
> > > can only work if the library containing the definition is built with
> > > assumptions (a) the compiler emits GOT-generating relocations (b) the
> > > linker produces R_*_GLOB_DAT instead of R_*_RELATIVE.  Otherwise the
> > > library uses its own definition directly and the executable accesses a
> > > stale copy.  Note: the GOT relocations defeat the purpose of protected
> > > visibility as an optimization, but allow rtld to make the executable and
> > > library use the same copy when copy relocations are present, but it
> > > turns out this never worked perfectly.
> > > 
> > > ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA has strange semantics when both
> > > a.so and b.so define protected var and the executable copy relocates
> > > var: b.so accesses its own copy even with GLOB_DAT.  The behavior change
> > > is from commit 62da1e3b00b51383ffa7efc89d8addda0502e107 (x86) and then
> > > copied to nios2 (ae5eae7cfc9c4a8297ff82ec6b794faca1976ecc) and arc
> > > (0e7d930c4c11de896fe807f67fa1eb756c9c1e05).
> > > 
> > > Without ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA, b.so accesses the copy
> > > relocated data like a.so.
> > > 
> > > It's extremely unlikely anyone relies on the
> > > ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA behavior, so let's remove it.
> > > 
> > > --
> > > Changes from v1:
> > > * Reword commit message as suggested by Szabolcs Nagy
> > 
> > Please document the interposition change or fix it.
> 
> Does this paragraph count as an explanation?
> "Without ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA, b.so accesses the copy relocated data like a.so."
> 
> Or, what other documentation on the interposition behavior do you expect?

the current commit message implies there is only behaviour
change in presence of copy relocations.

but that's not true: the exe (or a shared lib) can now
interpose a protected variable by another one with the
same name (and no copy relocs).

i originally thought that warning/rejecting copy relocs in
ld is enough to get sane behaviour for protected symbols,
but when multiple definitions are present the behaviour
will depend on ld's decision to use GOT or not.

i think the removed logic tried to ensure that GOT relocs
resolve to the definition within the same shared lib for
protected data. (i.e. ld's decision does not matter.)

if we want to allow ld to not use GOT then i think we need
to keep the logic that makes GOT behave consistently with
that future.

if we instead want to simplify ld.so and handle GOT for
protected symbols more efficiently, then that should be
explained in the commit clearly: why do we choose the
"symbol lookup returns a unique address" over "protected
symbol binds locally" rule when there are multiple
definitions? (maybe because this case should not be
relied on but then we should diagnose it, etc)

  reply	other threads:[~2022-06-01  9:53 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-01  4:50 Fangrui Song
2022-06-01  7:26 ` Szabolcs Nagy
2022-06-01  7:34   ` Fangrui Song
2022-06-01  9:53     ` Szabolcs Nagy [this message]
2022-06-01 10:56       ` Florian Weimer
2022-06-02  5:21         ` Fangrui Song
2022-06-01 17:56       ` [PATCH v3] " Fangrui Song
2022-06-07 13:24         ` Szabolcs Nagy
2022-06-07 17:49           ` Fangrui Song
2022-06-08  9:15             ` Szabolcs Nagy
2022-06-08 17:16               ` Fangrui Song
2022-06-09  8:12                 ` Szabolcs Nagy
2022-06-07 17:49           ` H.J. Lu
2022-06-07 18:21             ` Fangrui Song
2022-06-07 19:21               ` H.J. Lu
2022-06-07 20:00                 ` Fangrui Song
2022-06-07 21:02                   ` H.J. Lu
2022-06-07 23:57                     ` Fangrui Song
2022-06-08  1:51                       ` H.J. Lu
2022-06-08  3:42                         ` Fangrui Song

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=Ypc3EQ0tBAiFXuff@arm.com \
    --to=szabolcs.nagy@arm.com \
    --cc=libc-alpha@sourceware.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).