[LLVMdev] Wrong calling convention?

Óscar Fuentes
Wed, 26 Mar 2008 16:02:38 -0000

Duncan Sands <baldrick at free.fr> writes:

>> But you put me on the right track. The problem is that the class is
>> returned on the stack.

Correction: The class is returned on the FP stack:

>> 0x6e08b5b5 <_ZN3Foo6GetFooEv+17>:       fldl   -0x8(%ebp)
>> 0x6e08b5b8 <_ZN3Foo6GetFooEv+20>:       leave
>> 0x6e08b5b9 <_ZN3Foo6GetFooEv+21>:       ret
>> End of assembler dump.
>>
>> I guess that g++ exploits its knowledge of Foo's internals for
deciding
>> how to return the class.
>
> How Foo is returned is specified by the platform ABI.  It is not really a
> feature of g++.

This is C++ land, so there is no "platform ABI", although static
methods
usually follow C calling convention. I've checked that wrapping the
class definition with extern "C" changes nothing, so maybe it is
following the platform ABI, after all.

BTW, -fpcc-struct-return solves the case that motivated this thread.

>> But my compiler knows nothing about Foo, so I
>> must disable this "feature" of g++. Suggestions welcome.
>
> It is not possible to correctly codegen parameter passing/result returning
> without knowing the type (though not all details of the type are relevant).
> Your compiler needs to know something about Foo.

I'm afraid you are right. Current available information includes the
specific type (if it is fundamental), and type size (if it is
derived). It also knows the default constructor, copier and destructor
of each type. I hope that this, together with -fpcc-struct-return, is
enough to complete my C++ <-> LLVM interface, which only has to deal
with static methods.

--
Oscar