From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.bugs Subject: bug#13342: [PARTIALLY SOLVED] bug#13342: Errors trying to build Guile 2.0.7 Date: Sun, 27 Jan 2013 20:46:22 -0500 Message-ID: <87r4l6krkh.fsf@tines.lan> References: <548C7791-6E30-43A9-9E38-05BEC03CEF8B@me.com> <87r4m22swf.fsf@gnu.org> <69FAB6BC-CFB2-49AC-B103-D57E454091F0@me.com> <877gnsvp49.fsf@gnu.org> <895C23AD-DD0D-40FC-AD5F-6CEF52365444@me.com> <7C7443E9-9DA7-493D-8321-F5859170BAB5@me.com> <87a9ru7m23.fsf@gnu.org> 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 1359337667 19428 80.91.229.3 (28 Jan 2013 01:47:47 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 28 Jan 2013 01:47:47 +0000 (UTC) Cc: 13342@debbugs.gnu.org, Peter Teeson To: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Mon Jan 28 02:48:06 2013 Return-path: Envelope-to: guile-bugs@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 1TzdpM-0007bR-ER for guile-bugs@m.gmane.org; Mon, 28 Jan 2013 02:48:04 +0100 Original-Received: from localhost ([::1]:57166 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tzdp4-00068n-IK for guile-bugs@m.gmane.org; Sun, 27 Jan 2013 20:47:46 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:58812) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tzdoy-00068d-Qq for bug-guile@gnu.org; Sun, 27 Jan 2013 20:47:42 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tzdox-00035k-Jg for bug-guile@gnu.org; Sun, 27 Jan 2013 20:47:40 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:46384) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tzdox-00035g-GL for bug-guile@gnu.org; Sun, 27 Jan 2013 20:47:39 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1TzdpJ-0006l7-Pr for bug-guile@gnu.org; Sun, 27 Jan 2013 20:48:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Mark H Weaver Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-guile@gnu.org Resent-Date: Mon, 28 Jan 2013 01:48:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 13342 X-GNU-PR-Package: guile X-GNU-PR-Keywords: Original-Received: via spool by 13342-submit@debbugs.gnu.org id=B13342.135933762925906 (code B ref 13342); Mon, 28 Jan 2013 01:48:01 +0000 Original-Received: (at 13342) by debbugs.gnu.org; 28 Jan 2013 01:47:09 +0000 Original-Received: from localhost ([127.0.0.1]:51847 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TzdoT-0006jm-8b for submit@debbugs.gnu.org; Sun, 27 Jan 2013 20:47:09 -0500 Original-Received: from world.peace.net ([96.39.62.75]:52558) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TzdoP-0006jd-C6 for 13342@debbugs.gnu.org; Sun, 27 Jan 2013 20:47:07 -0500 Original-Received: from 209-6-91-212.c3-0.smr-ubr1.sbo-smr.ma.cable.rcn.com ([209.6.91.212] helo=tines.lan) by world.peace.net with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1Tzdnt-0006WK-Sm; Sun, 27 Jan 2013 20:46:34 -0500 In-Reply-To: <87a9ru7m23.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Sun, 27 Jan 2013 15:11:32 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.bugs:6715 Archived-At: Hi Ludovic, Thanks for looking into this! I think I understand the problem now. ludo@gnu.org (Ludovic Court=C3=A8s) writes: > Consider this example: > > #include > > int64_t > test_sum (int8_t a, int64_t b) > { > return a + b; > } > > When compiled with GCC 4.6, the assembly is: > > test_sum: > .LFB0: > .cfi_startproc > movsbq %dil, %rdi > leaq (%rdi,%rsi), %rax > ret > .cfi_endproc > > With Clang 3.1, it is: > > test_sum: # @test_sum > .cfi_startproc > # BB#0: > movslq %edi, %rax > addq %rsi, %rax > ret > > The =E2=80=98movsbq=E2=80=99 emitted by GCC arranges to keep only the 8 L= SBs. Clang > does no such thing, thus keeping all the bits of the first operand in > the addition. This is the key revelation, although I've reached a different conclusion about where the bug is. > I looked at Section 3.2.3 (=E2=80=9CParameter Passing=E2=80=9D) of the Sy= sV ABI x86_64 > PS but couldn=E2=80=99t find any evidence as to what the correct behavior= is. I read the same section, and although it is not as clear as I'd prefer, my interpretation is that the caller is responsible for sign-extending signed chars to ints. This is also consistent with something I vaguely remember reading in K&R long ago, namely that 'char' and 'short' arguments are coerced to 'int' before making a function call. Clang strictly requires callers to sign-extend, whereas GCC is tolerant of callers who fail to do so. IMO, both behaviors are permitted by the ABI. The problem is that libffi does *not* sign-extend arguments passed in registers when making calls, which is IMO a bug that has gone (mostly) unnoticed because of the tolerance and ubiquity of GCC. > However, on the caller side, both compilers emit the same code. This > program: > > #include > > extern int64_t test_sum (int8_t a, int64_t b); > > int64_t > foo (void) > { > return test_sum (-1, 123132); > } > > leads to the following assembly with both compilers: > > foo: # @foo > .cfi_startproc > movl $-1, %edi > movl $123132, %esi # imm =3D 0x1E0FC > jmp test_sum # TAILCALL > > (And as we=E2=80=99ve seen, libffi does the same.) No, libffi does *not* do the same. Take a look at the relevant code: https://github.com/atgreen/libffi/blob/master/src/x86/ffi64.c#L488 As you can see in lines 487 and 488, arguments passed in registers are never sign-extended, but rather zero-extended. The register values are then copied whole in the darwin-specific assembly stub: https://github.com/atgreen/libffi/blob/master/src/x86/darwin64.S#L61 Interestingly, arguments passed on the stack *are* sign-extended: https://github.com/atgreen/libffi/blob/master/src/x86/darwin64.S#L120 * * * * * In summary, I think this is a bug in libffi. Note that it has already been reported that the libffi testsuite shows many failures on OS X Lion, and the failures appear to be related to this precise issue: http://sourceware.org/ml/libffi-discuss/2012/msg00162.html The libffi maintainer wrote "I'm going to chalk this up to compiler bugs", based on his observation that the tests worked properly when compiled with -O0. I think it's time to raise this issue again on the libffi-discuss mailing list. In any case, it's certainly not a bug in Guile. The bug is either in LLVM/Clang or libffi, depending on how one chooses to interpret the x86-64 API. Regards, Mark