mailing list of musl libc
 help / color / mirror / code / Atom feed
* static build and dlopen
@ 2014-08-27 14:14 piranna
  2014-08-27 15:27 ` Szabolcs Nagy
  2014-08-27 16:43 ` Rich Felker
  0 siblings, 2 replies; 18+ messages in thread
From: piranna @ 2014-08-27 14:14 UTC (permalink / raw)
  To: musl

I have read that when an executable is compiled fully statically
linked with musl, a stub dlopen() is used instead of the real function
(http://www.openwall.com/lists/musl/2012/12/09/19), and seems it's
done in purpose since normally if you compile an executable as
statically linked is because you don't want to load dynamica libraries
(http://openwall.com/lists/musl/2012/12/08/4), but I've achieved an
use case where I need to do both things.

I'm working with others as a hobby on NodeOS (http://node-os.com/), an
operating system where Node.js is running on top of a naked Linux
kernel. To be able to use Node.js from the begging (as the '/init'
executable) it needs to be compiled as a fully statically linked
executable, and except for the OpenSSL support, so far so good thanks
to musl I was able to do it and worked as a charm :-)

Problem came when trying to use a Node.js compiled module ('.node'
files) so /init could be able to capture zombie processes
(https://github.com/piranna/node-century), since it was throwing an
error:


module.js:355
  Module._extensions[extension](this, filename);
                               ^
Error: Module did not self-register.
    at Error (native)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/tmp/ROOT/lib/node_modules/century/demo.js:3:15)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)


Since I had installed in my machine the same version of Node.js that I
compiled statically with musl (an Ubuntu package one, compiled
dynamically with glibc) and it worked, digging down I get to the point
that the problem was on the Node.js module loader
(https://github.com/joyent/node/blob/master/lib/module.js#L355), and
looking for the error message
(https://github.com/joyent/node/blob/master/src/node.cc#L2092), I
found it was the Node.js DLOpen() function
(https://github.com/joyent/node/blob/master/src/node.cc#L2056), that
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 :-(

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)?

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



-- 
"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


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2014-09-02  0:49 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-27 14:14 static build and dlopen piranna
2014-08-27 15:27 ` Szabolcs Nagy
2014-08-27 17:01   ` piranna
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

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).