public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Fangrui Song <maskray@google.com>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH] dlsym: Make RTLD_NEXT prefer default version definition [#BZ #14932]
Date: Fri, 27 May 2022 22:38:29 +0200	[thread overview]
Message-ID: <87leumd83e.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <20220527203202.r5vmk5ssufem4jga@google.com> (Fangrui Song's message of "Fri, 27 May 2022 13:32:02 -0700")

* Fangrui Song:

> I suspect the code (from 199x) has a hidden assumption that for a stem
> symbol (say foo), the .dynsym entries (say foo@v1, foo@v2, foo@@v3) are
> ordered by the version node indices (in .gnu.version_d).

Right, the code clearly has this assumption.  There has to be some
ordering because we don't want to do a topological sort to find the
lowest and highest versions.

> If so:
>
> * (flags & DL_LOOKUP_RETURN_NEWEST) == 0 => the symbol with
>     verstab[symidx]==2 will skip the check and be returned
> * (flags & DL_LOOKUP_RETURN_NEWEST) != 0 => only the default version
>   symbol gets assigned in `*versioned_sym = sym`
>
> Unfortunately, this assumption hold for none of GNU ld, gold, and
> ld.lld (seems unrelated to --hash-style=):
>
> ```
> % ld.bfd @response.txt && readelf -W --dyn-syms nextmod3.so | grep foo@
>      5: 0000000000001100     6 FUNC    GLOBAL DEFAULT   13 foo@v1
>      8: 0000000000001120     6 FUNC    GLOBAL DEFAULT   13 foo@@v3
>      9: 0000000000001110     6 FUNC    GLOBAL DEFAULT   13 foo@v2
> % gold @response.txt && readelf -W --dyn-syms nextmod3.so | grep foo@
>      7: 00000000000007c0     6 FUNC    GLOBAL DEFAULT   14 foo@@v3
>      9: 00000000000007a0     6 FUNC    GLOBAL DEFAULT   14 foo@v1
>     10: 00000000000007b0     6 FUNC    GLOBAL DEFAULT   14 foo@v2
> % ld.lld @response.txt && readelf -W --dyn-syms nextmod3.so | grep foo@
>      7: 0000000000001740     6 FUNC    GLOBAL DEFAULT   13 foo@@v3
>      8: 0000000000001720     6 FUNC    GLOBAL DEFAULT   13 foo@v1
>      9: 0000000000001730     6 FUNC    GLOBAL DEFAULT   13 foo@v2

The order of symbols in the symbol table is not what counts here, it's
the order in the list for the hash bucket.

I'm not sure if it's possible to dump this with readelf.  I'm writing a
custom dumper for this.

Thanks,
Florian


  reply	other threads:[~2022-05-27 20:38 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-20  8:35 Fangrui Song
2022-05-20 11:27 ` Adhemerval Zanella
2022-05-20 14:22   ` Florian Weimer
2022-05-22 18:54     ` Fāng-ruì Sòng
2022-05-27 16:59       ` Adhemerval Zanella
2022-05-27 11:03 ` Florian Weimer
2022-05-27 19:24   ` Fangrui Song
2022-05-27 20:32     ` Fangrui Song
2022-05-27 20:38       ` Florian Weimer [this message]
2022-05-27 21:03         ` Fangrui Song
2022-05-27 21:15           ` Adhemerval Zanella
2022-05-27 22:04             ` 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=87leumd83e.fsf@oldenburg.str.redhat.com \
    --to=fweimer@redhat.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).