From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/3195 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: Best place to discuss other lightweight libraries? Date: Thu, 25 Apr 2013 08:40:58 +0200 Message-ID: <20130425064058.GE12689@port70.net> References: <1366683267.18069.155@driftwood> <5176FE83.3010301@gentoo.org> <20130424114852.GA99797@intma.in> <20130424154726.GD12689@port70.net> <20130424191735.GI20323@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1366872067 672 80.91.229.3 (25 Apr 2013 06:41:07 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 25 Apr 2013 06:41:07 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-3199-gllmg-musl=m.gmane.org@lists.openwall.com Thu Apr 25 08:41:11 2013 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 1UVFrj-0001od-8x for gllmg-musl@plane.gmane.org; Thu, 25 Apr 2013 08:41:11 +0200 Original-Received: (qmail 3314 invoked by uid 550); 25 Apr 2013 06:41:10 -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 3306 invoked from network); 25 Apr 2013 06:41:10 -0000 Content-Disposition: inline In-Reply-To: <20130424191735.GI20323@brightrain.aerifal.cx> User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:3195 Archived-At: * Rich Felker [2013-04-24 15:17:35 -0400]: > On Wed, Apr 24, 2013 at 05:47:26PM +0200, Szabolcs Nagy wrote: > > (there are some caveats in go as well: it does not call > > __libc_start_main on startup nor exit on exit so eg atexit > > handlers wont get called) > > The idea of calling functions in libc without __libc_start_main ever > having been called sounds highly misguided and potentially dangerous. > In musl it might mostly work, but with glibc I don't see how it could > possibly work. it works because _init is called by the loader before the entry point and that does enough setup (when cgo is used then the interpreter is set to /lib/ld-linux.so.2 in the elf header and it calls _init when it loads libc which is listed in the dynamic section the entry point is the go runtime which checks if it is in cgo mode and sets up a separate pthread with libc managed stack and runs c code there the elf binary is prepared by the go toolchain, the go world is statically linked including the wrapper, but there is an object in the wrapper that is compiled with gcc and references the extern symbols and uses the c abi, with a trick the go toolchain knows about all the extern symbols and needed libraries which get into the dynamic section so the c world is dynamically linked there are some other runtime details to allow calling from go into c and then calling back to go from c, bridging the difference in abi and calling convenion, but basically this is how cgo works)