mailing list of musl libc
 help / color / mirror / code / Atom feed
From: "piranna@gmail.com" <piranna@gmail.com>
To: musl@lists.openwall.com
Subject: Re: static build and dlopen
Date: Wed, 27 Aug 2014 19:01:37 +0200	[thread overview]
Message-ID: <CAKfGGh0W2U+d4Ew1YFe=3H8TzR08Wdp=+YsmPzoec2OkXCEhhg@mail.gmail.com> (raw)
In-Reply-To: <20140827152735.GB22308@port70.net>

>> thought libuv is calling to the system dlopen() function, it's said,
>> the musl stub for static builds, making it impossible to load the
>> Node.js compiled modules :-(
>
> dlopen does not work from a statically linked binary
>
> (it can be made to work but it's more complicated than it seems:
> the entire libc should be linked into the application so all
> interfaces are present a loaded module may require which partly
> defeats the purpose of static linking and there are toolchain
> issues with this so it is not implemented)

(facepalm) Ok, didn't though about this use case where the dynamically
loaded module would use components of the host binary.


>> So I ask, does the dlopen() stub really makes sense (the linker is
>> intelligent enought to remove unused code on static builds...)? Is
>> there any alternative I can do? Is there a flag to allow to use the
>> real dlopen() function on static builds, or could it be possible to
>> add it? If not, could I be able to use an external dlopen library (and
>> could I be able to integrate it easily)?
>>
>
> if the loaded modules depend on the libc api (or transitively any
> external dependency) then naive dlopen cannot work with static
> linking and there is no way around this
>
> (btw the same applies to all module systems that can load libraries
> written in c, eg. if you tried a statically linked python you would
> have the same issue: it works if all dependencies are linked in, it
> fails if you load libraries at runtime)

The de-facto standard in Node.js is that all the compiled modules are
static ones (.a files) with no external dependencies at all, just to
make it simpler to move to another environments. This contrast to how
Python works, where compiled modules are dynamic ones (.so). I'm
honestly not sure what are the low-level details of Node.js compiled
modules, but the general idea of Node.js modules is make them as
independent as possible and left to Node.js require() function to
manage the dependencies, so probably this would also apply to compiled
ones... Only point left here is if in fact .node files are in fact .a
files with a different extension or if they are wrapped someway, so in
that case dlopen() is efectively loading .a files (that would be a
surprise to me, but would left open the door to solve this problem...)


>> Oh, and if you are thinking about it: yes, this is a farily similar
>> use case as when compiling OS kernels (at least hybrid ones, like
>> Linux) where you need to compile them statically so it can boot and
>> also has support to load compiled modules on runtime, since in this
>> case, Node.js is in fact the "kernel" and Linux is just a somewhat HAL
>> layer :-P
>
> neither the kernel nor the loaded kernel modules depend on the libc

They don't depend on general-purpose libc, but they are compiled with
klibc or other stripped down versions... :-D


-- 
"Si quieres viajar alrededor del mundo y ser invitado a hablar en un
monton de sitios diferentes, simplemente escribe un sistema operativo
Unix."
– Linus Tordvals, creador del sistema operativo Linux


  reply	other threads:[~2014-08-27 17:01 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-27 14:14 piranna
2014-08-27 15:27 ` Szabolcs Nagy
2014-08-27 17:01   ` piranna [this message]
2014-08-27 17:20     ` Justin Cormack
2014-08-27 20:07       ` piranna
2014-08-27 16:43 ` Rich Felker
2014-08-27 17:10   ` piranna
2014-08-27 18:48     ` Laurent Bercot
2014-08-27 20:19       ` piranna
2014-08-27 20:51         ` Rich Felker
2014-08-27 20:59         ` Laurent Bercot
2014-08-27 21:04           ` Rich Felker
2014-08-27 22:54           ` Kurt H Maier
2014-08-27 23:24             ` Laurent Bercot
2014-08-27 23:36               ` Brent Cook
2014-09-01 23:38                 ` piranna
2014-09-02  0:38                   ` Rich Felker
2014-09-02  0:49                     ` piranna

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='CAKfGGh0W2U+d4Ew1YFe=3H8TzR08Wdp=+YsmPzoec2OkXCEhhg@mail.gmail.com' \
    --to=piranna@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).