All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vineet Gupta <vineet.gupta@linux.dev>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
	bpf <bpf@vger.kernel.org>
Cc: "Jose E. Marchesi" <jemarch@gnu.org>,
	bpf@gcc.gnu.org, Alexei Starovoitov <ast@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	Andrew Pinski <andrew.pinski@oss.qualcomm.com>
Subject: Re: Function Return ABI (was Re: Argument passing and ABI: GCC vs clang)
Date: Thu, 19 Feb 2026 19:38:23 -0800	[thread overview]
Message-ID: <057c2e5f-7dd4-4080-8550-a48e82d20cdb@linux.dev> (raw)
In-Reply-To: <CAADnVQLKXawH8nuSkXGcafS9d66hYfLF_zjKCVdO5WoQ8TxrGw@mail.gmail.com>

On 2/19/26 6:41 PM, Alexei Starovoitov wrote:
>> It seems the existing clang ABI is not symmetrical. The function
>> arguments promotion is handled in callee, but function return is handled
>> in caller [1] which is a bit atypical IMO and would need to be handled
>> in gcc as well.


Ignore this as it is clearly wrong (my jetlag and waking up at 3 am is 
to blame :-)

With PR/124171 gcc-bpf will promote args in caller same as llvm (not 
callee)


> hmm. I thought we already concluded that for clang-x86 and clang-bpf
> argument extension is handled in*caller*.
> The same thing for returns. It's a caller responsibility.
> gcc-bpf doing args in the callee only is broken and has to be fixed.


Correct, agreed.


>> Since we are on the topic of ABI change, I wanted to surface that as
>> well before we go off and tackle that.
>>
>> Simple example
>>
>> _Bool bar_bool(void);
>>
>> int ret_caller(void) {
>>         if (bar_bool() != 1) return 0; else return 1;
>> }
>>
>> char ret_callee(my_t *s)
>> {
>>       return s->c;    // c is a char in a struct
>> }
>>
>> ret_caller:
>>       call    bar_bool
>>       r0 &= 0xff        <-- ret promotion in caller
>>       exit
>>
>> ret_callee:
>>       r0 = *(u8 *) (r1+6) <-- no ret promotion in callee
>>       exit
> Exactly as it should be because x86 will populate 8-bit sub
> registers in the callee and bpf side has to do r0 &= 0xff
> in the caller.

      reply	other threads:[~2026-02-20  3:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87fr7e15l0.fsf@gnu.org>
     [not found] ` <6ac7e425-cf75-4706-9906-4c23eb4f0f41@linux.dev>
     [not found]   ` <b77afbde-b6d6-4728-9090-af31027846b2@linux.dev>
2026-02-20  2:41     ` Function Return ABI (was Re: Argument passing and ABI: GCC vs clang) Alexei Starovoitov
2026-02-20  3:38       ` Vineet Gupta [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=057c2e5f-7dd4-4080-8550-a48e82d20cdb@linux.dev \
    --to=vineet.gupta@linux.dev \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrew.pinski@oss.qualcomm.com \
    --cc=ast@kernel.org \
    --cc=bpf@gcc.gnu.org \
    --cc=bpf@vger.kernel.org \
    --cc=jemarch@gnu.org \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.