dual result function & ABI (using extra register), e.g. for Go
Paul Brook
paul@codesourcery.com
Mon Nov 1 09:50:00 GMT 2010
> > Does the Go language define a specific ABI convention for returning
> > two values from a function thru registers? If yes, how does GCC
> > implement it? Or is it some future work?
>
> The Go language does not define an ABI for returning multiple values.
> The gccgo frontend implements it by saying that a function which returns
> multiple values returns a struct with fields whose types are the types
> of the result parameter.
>
> It's desirable to make it possible to write C functions which return
> multiple values to Go code. For example, some of the runtime support
> functions work that way. Having the Go return a struct ensures that it
> is easy to write compatible C code.
So the original question becomes "How are structures returned from a
function". The answer depends on the ABI.
If the ABI for your favourite target doesn't behave as you might like I guess
we could invent a target attribute to change this on a per-function basis,
similar to __attribute__((regparm)). Some third party ARM toolchains already
have this.
Paul
More information about the Gcc
mailing list