public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Carlos O'Donell <carlos@redhat.com>
To: Szabolcs Nagy <szabolcs.nagy@arm.com>,
	Yury Gribov <y.gribov@samsung.com>, d wk <dwksrc@gmail.com>
Cc: nd@arm.com, libc-alpha@sourceware.org,
	Jakub Jelinek <jakub@redhat.com>,
	Kostya Serebryany <kcc@google.com>
Subject: Re: [PATCH] Support -z initfirst for multiple shared libraries
Date: Thu, 28 Apr 2016 19:55:00 -0000	[thread overview]
Message-ID: <57226ABA.4030409@redhat.com> (raw)
In-Reply-To: <5722323B.6030108@arm.com>

On 04/28/2016 11:54 AM, Szabolcs Nagy wrote:
> On 28/04/16 16:27, Carlos O'Donell wrote:
>> On 04/27/2016 01:22 PM, Yury Gribov wrote:
>>> Yeah. It seems that initfirst is a crude hack which bypasses all
>>> dependency tracking. I wonder if there's a place for another,
>>> hopefully saner, dependency-respecting flag.
>>
>> What use cases do you need to support?
>>
>> How would a dependency-respecting initfirst-like flag work given the
>> conflicting requirements to initialize in dependency order and yet
>> not initialize in dependency order?
>>
> 
> may be use a topological sort order where the
> flagged module comes earliest possible?

That makes sense.

>> Today we have:
>>
>> - Library initializers and finalizers (Run in dep order)
>> - Library constructors and destructors (Run in dep order)
>> - Prioritized constructors and destructors (Run in dep order, and # order)
>> - LD_PRELOAD initializer run last before the application is initialized.
>> - Non-zero initialized data from .data in the ELF image.
>>
>> Dependency ordering also include symbol dependencies and relocation 
>> dependencies, sorting all objects into a linear list and breaking
> 
> if that was done correctly then i think LD_PRELOAD
> libs would come before the modules using the interposed
> symbols.

I *thought* this was what was implemented by _dl_lookup_symbol_x,
add_dependency, and link_map->l_reldeps, but after reviewing the code
and writing some test case it doesn't work for all use cases.

We have add_dependency which is called from _dl_lookup_symbol_x
which adds symbol binding information, but it isn't used properly
to sort constructors in the -Wl,-z,now case (you can't do this in
lazy mode).

For destructors though, in _dl_sort_fini, we do use l_reldeps to move
dependencies such that objects which are the target a symbol binding
are destructed later (if possible).

For dlclose we prevent unloading a shared library that is the target
of a bound symbol used by another shared library (see the common
problem with STB_GNU_UNIQUE making C++ plugins unloadable).

>> cycles where appropriate at deterministic points (though we need
>> a better ldd to show these problems).
>>
>> It might be better if we had some kind of invariant assertions like
>> "abort if I'm not initialized before library SONAME" that then allowed
>> developers to realize their invariant is wrong and restructure the
>> application. Alternatively if we had some better tooling that might
>> help also (I'm working on an alternate eu-ldd and deterministic
>> cycle breaking in ld.so, but it's a long way off).
>>
> 
> depending on elf ctor ordering sounds broken to me.
> (incompatible with static linking)

What we are talking about today is adding features to work around
existing design issues in applications.

Properly designed applications don't have these problems because they
don't rely on constructor ordering outside of a translation unit.

> depending on deterministic ordering in the presence
> of cycles sounds even more nonsensical.
> (the dynamic linker shouldn't try to solve np hard
> problems.)

Sorry, that's not what I wanted to imply.

All I wanted to say is that cycles should be broken following some
fixed set of rules that we can then test ourselves (without giving
users any guarantees) with regression tests, simply to validate
the dynamic loader is behaving as we expect.

I *do* think we need to provide a tool that shows users what the
ctor/dtor ordering is going to look like and why, for the given
installed loader. This could be used by support to diagnose problems
and remind users not to rely on ctor/dtor ordering.

-- 
Cheers,
Carlos.

  parent reply	other threads:[~2016-04-28 19:55 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-26 20:58 d wk
2016-04-26 21:04 ` d wk
2016-04-27  7:03 ` Yury Gribov
2016-04-27 13:57   ` d wk
2016-04-27 17:23     ` Yury Gribov
2016-04-28 15:27       ` Carlos O'Donell
2016-04-28 15:54         ` Szabolcs Nagy
2016-04-28 16:58           ` Yury Gribov
2016-04-28 19:14             ` d wk
2016-04-28 19:55           ` Carlos O'Donell [this message]
     [not found]       ` <CAN=P9pjS1j480qBzy9xu9ZToyFA=xXgZmiLeFu_jkKDp3j87Rg@mail.gmail.com>
2016-04-28 16:57         ` Yury Gribov
     [not found]           ` <CAN=P9pgK4+fcFAUYEXpmRhr=V=UWhnLemu=yt407dh_nU=h_tA@mail.gmail.com>
2016-04-29  6:47             ` Yury Gribov
2016-04-28 14:12 ` Carlos O'Donell
2016-04-28 18:47   ` d wk
2016-05-07  0:22     ` d wk
2016-05-02  8:06 ` Florian Weimer
2016-05-04  7:00   ` Yury Gribov

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=57226ABA.4030409@redhat.com \
    --to=carlos@redhat.com \
    --cc=dwksrc@gmail.com \
    --cc=jakub@redhat.com \
    --cc=kcc@google.com \
    --cc=libc-alpha@sourceware.org \
    --cc=nd@arm.com \
    --cc=szabolcs.nagy@arm.com \
    --cc=y.gribov@samsung.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).