mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Alex Dowad <alexinbeijing@gmail.com>
To: musl@lists.openwall.com
Subject: Question re: dynamic linking in musl
Date: Wed, 27 May 2015 12:08:44 +0200	[thread overview]
Message-ID: <20150527100844.GA306@alex-ThinkPad-L530> (raw)

Hi,

I'm just dealing with a problem whereby rrdtool is spending >90% of its runtime in
musl's dynamic linker (this is on Alpine Linux). This is making it too slow to do
what we need it to do.

After perusing some hotspots in dynlink.c (as measured by callgrind), there is
something which looks like a big opportunity for optimization. I hope I'm not wrong.
I probably am. I don't understand the code very well.

do_relocs is called 3 times for each binary which needs relocation (including the main
program and all its dependencies). Once for all the relocations in .rel.dyn, one
for those in .rel.plt, and one for... something else. Haven't looked it up, not
important right now.

do_relocs iterates through all those relocations, and calls find_sym for each one
to look up where the desired function, or variable, etc. can be found.

find_sym iterates through *each* binary which has been loaded, including *all*
the recursive dependencies, and does a hash lookup in each one to see if the
desired symbol can be found.

(Well, that's not quite right; for certain types of relocations, it skips the
head of the list of binaries.)

NOW: Is there any reason why dso->deps could not be used to search for symbols *only*
in the dependencies of the binary which is currently being relocated?

For example, rrdtool has dependencies on librrd, libxml, pango, libpng, libintl,
libgobject, libharfbuzz, libfontconfig, libfreetype, libX11, libexpat, etc. etc. etc.
When unresolved symbols in libX11 are being looked up, musl will start looking in
librrd, right at the top of the list. But there's no way it will find any of
libX11's relocations in librrd. The dependencies of libX11 are right down close
to the *bottom* of the list.

To add insult to injury, that wasteful lookup process will be repeated for each and
every of the more than 1000 relocations in libX11.

Hoping someone smarter than me can explain things... Thanks, AD


             reply	other threads:[~2015-05-27 10:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-27 10:08 Alex Dowad [this message]
2015-05-27 10:40 ` Alexander Monakov
2015-05-27 11:18   ` Alex Dowad
2015-05-27 13:01     ` Alexander Monakov
2015-05-27 13:09       ` Timo Teras
2015-05-27 13:15         ` Alex Dowad
2015-05-27 13:23           ` Timo Teras
2015-05-27 14:06             ` Szabolcs Nagy
2015-05-27 14:06             ` Rich Felker
2015-05-28 14:03               ` Natanael Copa
2015-05-27 13:06     ` Szabolcs Nagy

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=20150527100844.GA306@alex-ThinkPad-L530 \
    --to=alexinbeijing@gmail.com \
    --cc=musl@lists.openwall.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).