From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH 5/6] refactor and simplify ELF loader in objcodes.c Date: Wed, 22 May 2013 23:06:43 +0200 Message-ID: <87a9nm7mho.fsf@gnu.org> References: <1368889540-27139-1-git-send-email-wingo@pobox.com> <1368889540-27139-6-git-send-email-wingo@pobox.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1369257014 11121 80.91.229.3 (22 May 2013 21:10:14 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 22 May 2013 21:10:14 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Wed May 22 23:10:13 2013 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UfGIT-0000BT-5A for guile-devel@m.gmane.org; Wed, 22 May 2013 23:10:09 +0200 Original-Received: from localhost ([::1]:45708 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UfGIS-0000k1-N9 for guile-devel@m.gmane.org; Wed, 22 May 2013 17:10:08 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:34793) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UfGIO-0000ht-5A for guile-devel@gnu.org; Wed, 22 May 2013 17:10:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UfGIM-00013S-Ts for guile-devel@gnu.org; Wed, 22 May 2013 17:10:04 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:39904) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UfGFM-0008Hr-Th for guile-devel@gnu.org; Wed, 22 May 2013 17:06:57 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UfGFK-0006qe-VP for guile-devel@gnu.org; Wed, 22 May 2013 23:06:54 +0200 Original-Received: from reverse-83.fdn.fr ([80.67.176.83]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 22 May 2013 23:06:54 +0200 Original-Received: from ludo by reverse-83.fdn.fr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 22 May 2013 23:06:54 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 59 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: reverse-83.fdn.fr X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 3 Prairial an 221 de la =?utf-8?Q?R=C3=A9volution?= X-PGP-Key-ID: 0xEA52ECF4 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 83C4 F8E5 10A3 3B4C 5BEA D15D 77DD 95E2 EA52 ECF4 X-OS: x86_64-unknown-linux-gnu User-Agent: Gnus/5.130007 (Ma Gnus v0.7) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:IpG7ilotCFWHtqfUFP6OZV0hCiM= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:16413 Archived-At: Andy Wingo skribis: > * libguile/objcodes.c (sniff_elf_alignment, alloc_aligned) > (copy_and_align_elf_data): New helpers for portably re-aligning ELF > data from read(2) or from a bytevector. > (load_thunk_from_memory): Simplify! Now there is only one procedure > that loads ELF, and it does less: it simply receives the whole image > in one array, hopefully from mmap. > > (scm_load_thunk_from_file): Use new map_file_contents helper, and go > through load_thunk_from_memory. > (scm_load_thunk_from_memory): Pass load_thunk_from_memory a piece of > memory that it owns, and that is appropriately aligned. > --- > libguile/objcodes.c | 435 +++++++++++++++++++++++---------------------------- > 1 file changed, 195 insertions(+), 240 deletions(-) Lines removed, cool! ;-) > +static unsigned > +sniff_elf_alignment (const char *data, size_t len) What about: /* Return the alignment required by the ELF at DATA, of LEN bytes. */ static size_t elf_alignment (const char *elf, size_t len) > +/* This function leaks the memory that it allocates. */ > +static char* > +alloc_aligned (size_t len, unsigned alignment) What about using posix_memalign or similar? Alternatively, using scm_gc_malloc_pointerless, which is known to return 8-byte-aligned boundary? Or using ALIGN (malloc (size + 8), 8)? > + /* Given that we are using the read fallback, optimistically assume > + that the .go files were made with 8-byte alignment. > + alignment. */ > + data = malloc (end); > + if (!data) scm_malloc would save you from the if (!data). Would it be OK to use scm_gc_malloc_pointerless here? > + /* If our optimism failed, fall back. */ > + { > + unsigned alignment = sniff_elf_alignment (data, end); > + > + if (alignment != 8) Since .go are only produced by Guile, can it really happen to have .go files without 8-byte alignment? Ludo’.