Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sun, 9 Dec 2012 02:04:43 +0200
From: Paul Schutte <sjpschutte@...il.com>
To: musl@...ts.openwall.com
Subject: Re: static linking and dlopen

On Sun, Dec 9, 2012 at 1:23 AM, Rich Felker <dalias@...ifal.cx> wrote:

> I think it depends a lot on what you're using dlopen for. A lot of
> programs these days use it as a ridiculous part of the development
> model rather than for any real purpose; in my book, this is among the
> highest levels of Considered Harmful. There's really no reason for any
> code that's internal to an application (developed in the same tree, by
> the same authors, and built at the same time) to be dynamically linked
> at all, much less dynamically loaded. All this accomplishes is making
> the program a lot slower and more bloated.
>
> I can not agree with you more on this.


> On the flip side, the main legitimate uses for dynamic linking and
> loading are (1) sharing code that's used by a wide range of
> applications and allowing it to be upgraded system-wide all at once,
> and (2) facilitating the extension of an application with third-party
> code. Usage 1 applies mostly to dynamic linking; 2 mostly to dynamic
> loading (dlopen).
>

Point 1 is probably the reason why most libraries end up as dynamic
libraries.

I was wondering about distributing all libraries as static libraries and
then have the package manager link the application statically as the final
step of the installation. This way the package manager can keep track
of dependencies and re-link them if a library change.

Distributions like Gentoo who install from source is actually in a very
good position to take advantage of static linking.

But I can see a lot of compiling/linking happening with this approach.

Another idea would be to just install a stub where the binary would be.
First time you run this stub, it will link the binary and store it on the
disk in some sort of cache. Then just do an exec of that binary. Second
time that you run this stub, it will check in this cache, link it again if
it is not there or just exec it if found. This way only the stuff that gets
used will be re-linked. You can force a re-link by clearing the cache. This
what made me wonder about programs that use dlopen.

I also wonder if the gain would be worth the trouble. I have seen a
reduction of up to 50% RSS usage on programs that has a lot of shared
libraries. It should improve responsiveness as there will be less paging.

Thanks for all the answers.

Regards
Paul

Content of type "text/html" skipped

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.