From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12238 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] split __libc_start_main.c into two files (Wasm) Date: Thu, 14 Dec 2017 23:19:25 -0500 Message-ID: <20171215041925.GG1627@brightrain.aerifal.cx> References: <20171207170356.GX1627@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1513311579 18184 195.159.176.226 (15 Dec 2017 04:19:39 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 15 Dec 2017 04:19:39 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-12254-gllmg-musl=m.gmane.org@lists.openwall.com Fri Dec 15 05:19:34 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1ePhTB-0004Q4-Ct for gllmg-musl@m.gmane.org; Fri, 15 Dec 2017 05:19:33 +0100 Original-Received: (qmail 16257 invoked by uid 550); 15 Dec 2017 04:19:38 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 16224 invoked from network); 15 Dec 2017 04:19:37 -0000 Content-Disposition: inline In-Reply-To: <20171207170356.GX1627@brightrain.aerifal.cx> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:12238 Archived-At: On Thu, Dec 07, 2017 at 12:03:56PM -0500, Rich Felker wrote: > On Thu, Dec 07, 2017 at 02:51:31PM +0000, Nicholas Wilson wrote: > > Hi, > > > > I've got some more patches to try and get in for Wasm support. > > > > Here's one that should be fairly straightforward? In Musl, most > > (non-static) functions are in a file of their own, which is good > > from a linkage point of view. > > > > I'd like to have __libc_start_main.c split into two files, because > > for Wasm I'd like to be able to call __libc_start_init (from within > > the CRT directory) but without having to link in exit(), since many > > Wasm applications will never call exit() and won't necessarily use > > main. > > > > There's no pollution of the codebase, it's purely splitting a file. > > > > Patch below. > > __libc_start_init is intentionally not a public interface but part of > musl internals. There is no reason to assume it will continue to exist > with the same name or interface in future versions of musl. The public > interface for the entry point is __libc_start_main. > > exit() is literally 9 instructions on x86_64, and likely comparably > small elsewhere. I don't see how trying to optimize it out makes > sense. The bulk of the code that runs at exit() when there's > nontrivial work to do at exit time is linked through dependencies from > other sources like stdio and atexit, and would be linked even if you > succeeded in optimizing exit out. Another bug I overlooked here was that, by moving the code to a new file, it would no longer be affected by $(NOSSP_SRCS) in Makefile, thereby breaking builds with -fstack-protector or where the compiler has it on by default. That could have been fixed if needed; I just bring it up to show that there are subtle possibilities for breakage like this that we should really either document rig up some sort of static assertion to catch if there's a regression. Rich