From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/3681 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: New "portable" crt1.c Date: Thu, 18 Jul 2013 22:17:26 -0400 Message-ID: <20130719021726.GA19068@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="BOKacYhQ+x31HxR3" X-Trace: ger.gmane.org 1374200259 25209 80.91.229.3 (19 Jul 2013 02:17:39 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 19 Jul 2013 02:17:39 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-3685-gllmg-musl=m.gmane.org@lists.openwall.com Fri Jul 19 04:17:41 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 1V00GK-0001fH-Na for gllmg-musl@plane.gmane.org; Fri, 19 Jul 2013 04:17:40 +0200 Original-Received: (qmail 26264 invoked by uid 550); 19 Jul 2013 02:17:40 -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 26253 invoked from network); 19 Jul 2013 02:17:39 -0000 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:3681 Archived-At: --BOKacYhQ+x31HxR3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi all, I've been experimenting with an idea for eliminating most of the asm from the "crt" start files. The basic concept is to have a tiny file-scope __asm__ statement, pulled in from arch/$(ARCH)/crt1.h or similar, which does nothing but calling a portable C version of _start, contained in crt1.c, with the right arguments. The benefits: - We get regular (crt1.o) and PIE (Scrt1.o) versions for free. - Porting to new archs is simpler. - Applying the same technique to crti.o/crtn.o, we can support the new-style init_array/fini_array on all archs without lots of new per-arch asm. Attached is a demo for i386 showing how well this approach works (size increase is less than 16 bytes). I'm open to comments, but my feeling is that we should keep the existing crt asm for archs where it already exists, but replace the empty crt1.c with a version based on this approach, and encourage using the new approach on all new ports. In the future, if maintaining the current asm becomes a burden (e.g. if new requirements are introduced) we could remove the existing asm and switch to the C for all ports. Rich --BOKacYhQ+x31HxR3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="newcrt.c" __asm__("\ .global _start\n\ _start:\n\ xor %ebp,%ebp\n\ mov %esp,%eax\n\ and $-16,%esp\n\ push %eax\n\ push %eax\n\ push %edx\n\ push %eax\n\ call ___start\n\ "); __attribute__((__noreturn__)) int __libc_start_main( int (*)(int, char **, char **), int, char **, int (*)(int, char **, char **), void (*)(void), void (*)(void)); int main(); int _init() __attribute__((__weak__,__visibility__("hidden"))); void _fini() __attribute__((__weak__,__visibility__("hidden"))); void ___start(long *p, void *q) { int argc = p[0]; char **argv = (void *)p[1]; __libc_start_main(main, argc, argv, _init, _fini, q); } --BOKacYhQ+x31HxR3--