[cfe-dev] Hack for FreeBSD ABI support

Jonathan Gray jsg at goblin.cx
Mon Aug 17 11:45:48 PDT 2009


On Mon, Aug 17, 2009 at 07:02:47PM +0100, David Chisnall wrote:
> On 17 Aug 2009, at 06:36, Anton Korobeynikov wrote:
>
>> Hello, Eli
>>
>>> Note that by "ABI" here only includes the calling convention, and  
>>> that
>>> makes it sound like FreeBSD is a lot closer to the Darwin calling
>>> convention than the Linux one...
>> But vector stuff is purely linux, so I'd say - "something in the  
>> middle" :)
>
> The attached patch is a bit less of an hack.  It changes the isDarwin  
> flag to specify whether we should use the Darwin calling convention for 
> vectors (I don't think this calling convention is used elsewhere, but it 
> might be...) and adds a second flag to specify whether small structures 
> are returned in registers or on the stack.  This is set to true for 
> FreeBSD and Darwin and no for other operating systems (I've no idea what 
> it should be for Net/OpenBSD; someone with access to these operating 
> systems on x86 should run my test program and see if it breaks with 
> current clang compiling one file and gcc compiling the others).  Since 
> DragonFly is a fork of Free, I believe it should also have this flag set, 
> but (again) I don't have a machine I can test this on.  I'm a bit 
> surprised no one running FreeBSD or DragonFly BSD has encountered this 
> problem before...  Apparently it's also the default on MinGW, so maybe 
> this test should be inverted; it seems that only GNU/Linux defaults to 
> returning these structures on the stack, so possibly we should just test 
> for "linux" in the triple and clear the flag in this case?
>
> This second flag should, in future, be overridden by the -fpcc-struct- 
> return / -freg-struct-return flags.  These are used by GCC to override  
> the host platform calling convention, so they're not widely used  
> (although there's a kernel by some Finnish guy which apparently uses - 
> freg-struct-return).
>
> With this applied, I believe we get the correct calling convention for  
> everything on FreeBSD.  Please let me know if it breaks any other  
> platforms before I commit (and if anyone wants to let me know what the  
> correct values are for other *BSDs, I'll integrate those at the same  
> time).

you can of course derive this information from looking at the gcc
config dir, but the short answer is

beos-elf.h:#define DEFAULT_PCC_STRUCT_RETURN 1
linux.h:#define DEFAULT_PCC_STRUCT_RETURN 1
lynx.h:#define DEFAULT_PCC_STRUCT_RETURN 1
nto.h:#define DEFAULT_PCC_STRUCT_RETURN 1
netbsd-elf.h:#define DEFAULT_PCC_STRUCT_RETURN 1

cygming.h:#define DEFAULT_PCC_STRUCT_RETURN 0
darwin.h:#define DEFAULT_PCC_STRUCT_RETURN 0
freebsd.h:#define DEFAULT_PCC_STRUCT_RETURN 0
netware.h:#define DEFAULT_PCC_STRUCT_RETURN 0
openbsd.h:#define DEFAULT_PCC_STRUCT_RETURN 0

for non x86 archs it differs.



More information about the cfe-dev mailing list