From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32342 invoked by alias); 18 Dec 2015 23:10:35 -0000 Mailing-List: contact libffi-discuss-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libffi-discuss-owner@sourceware.org Received: (qmail 32328 invoked by uid 89); 18 Dec 2015 23:10:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.7 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=intricacies, our, H*Ad:U*libffi-discuss X-HELO: mail-wm0-f54.google.com Received: from mail-wm0-f54.google.com (HELO mail-wm0-f54.google.com) (74.125.82.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 18 Dec 2015 23:10:33 +0000 Received: by mail-wm0-f54.google.com with SMTP id l126so3494400wml.0 for ; Fri, 18 Dec 2015 15:10:32 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.28.195.138 with SMTP id t132mr5539813wmf.86.1450480230241; Fri, 18 Dec 2015 15:10:30 -0800 (PST) Received: by 10.194.185.74 with HTTP; Fri, 18 Dec 2015 15:10:30 -0800 (PST) In-Reply-To: <567487A1.4040803@redhat.com> References: <5673E92C.7090400@redhat.com> <567466D0.5020305@redhat.com> <063E0A50-A359-4F85-8DCF-AFD3B5504973@gmail.com> <567487A1.4040803@redhat.com> Date: Fri, 18 Dec 2015 23:10:00 -0000 Message-ID: Subject: Re: does it matter how I construct an aggregate struct type if its size is the same? From: Hayden Livingston To: Andrew Haley Cc: libffi-discuss@sourceware.org Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2015/txt/msg00113.txt.bz2 Thanks for this, Andrew. I've now read up a bit more and can safely say that I agree with you AND understand it. Also realizing that intricacies of compiler differences and ABI issues that people often prefer to keep their public APIs are pointer size or less. On Fri, Dec 18, 2015 at 2:24 PM, Andrew Haley wrote: > On 18/12/15 22:15, Hayden Livingston wrote: >> Sorry, I should have been clearer -- I'm absolutely talking about >> passing by value. But isn't it on a per argument basis and on its >> size? If you have a data structure that is 9 bytes, after alignment >> let's say it's 12, isn't that all that matters? > > No. > >> I mean I'm new to this but it seems that if you have a function >> compiled by compiler 1, and let's say it is "exported", i.e. some body >> else can call into this code via dlopen/loadlibrary you can't >> arbitrarily decide how things should be passed right? It has to be on >> an ABI-level, and the ABI I'm guessing says parameter 1 if it's size < >> X can be passed on the stack, or use some registers, but does an ABI >> also specify that struct member 1 if is less than X size can be passed >> in register? > > Yes, it often does exactly that. So if you have an arg which is 2 > ints then the 2 ints get passed in 2 registers. Float members get > passed in float registers, etc. These days that's the way things are > usually done, with some exceptions such as legacy 32-bit x86. > > The ABI really does need to know what is inside the struct. > >> This would mean you have to use only 1 compiler. > > Huh? Its the ABI. > >> While typing this email, a thought occurred to me that probably we >> programmers know this, and therefore never make our public >> dlopen/loadlibrary APIs take structs that are not completely opaque? >> >> Sorry I'm formulating some of my thoughts .. but I'm new to this. > > Fair enough. > > Andrew.