From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/5929 Path: news.gmane.org!not-for-mail From: "piranna@gmail.com" Newsgroups: gmane.linux.lib.musl.general Subject: static build and dlopen Date: Wed, 27 Aug 2014 16:14:07 +0200 Message-ID: Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1409148890 14676 80.91.229.3 (27 Aug 2014 14:14:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 27 Aug 2014 14:14:50 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-5936-gllmg-musl=m.gmane.org@lists.openwall.com Wed Aug 27 16:14:45 2014 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1XMdzo-0003V5-6i for gllmg-musl@plane.gmane.org; Wed, 27 Aug 2014 16:14:44 +0200 Original-Received: (qmail 25794 invoked by uid 550); 27 Aug 2014 14:14:43 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 25786 invoked from network); 27 Aug 2014 14:14:43 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type :content-transfer-encoding; bh=UWQ0pG9duoU9L3T+3KMIxKdU/Kv5UtepYywkjdvpqtE=; b=DBt8nEpLFYDAUXHz9Mx/vy9VrTvC3Vk5u2yBADjM1WwQiAgT+lvbMBBm65cpcrOflO iWc0t1INFVv0ZIoY8DdnC1zoVfCvPvSo0rKHPJRnc2cR2Hsb2fLtk214B6lhxOGvsQPt OdGIaoHv7WDSfWRE0rc5rkNTHgkD9JGN1IjA63rDoT4t1LQdwDCBw1BrgjDFf17Ww7Wn 9APUYIrROHx6Y+YYX0Bg0HMlWHJ3On1eyQgOqkWEYHE7VVinx4PBrZgzx4mrf79ogMv8 pirmov4LXr3Y3K2szRJoplZm4u47nutM1wbgBsgH9NcqlspCTZp7L/bBQRZgCwg+w9Cb qEew== X-Received: by 10.180.101.65 with SMTP id fe1mr29246075wib.53.1409148868017; Wed, 27 Aug 2014 07:14:28 -0700 (PDT) Xref: news.gmane.org gmane.linux.lib.musl.general:5929 Archived-At: 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. (/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 --=20 "Si quieres viajar alrededor del mundo y ser invitado a hablar en un monton de sitios diferentes, simplemente escribe un sistema operativo Unix." =E2=80=93 Linus Tordvals, creador del sistema operativo Linux