From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14E0BC001B0 for ; Sun, 9 Jul 2023 21:00:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230162AbjGIVAt (ORCPT ); Sun, 9 Jul 2023 17:00:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229884AbjGIVAq (ORCPT ); Sun, 9 Jul 2023 17:00:46 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [IPv6:2a01:4f8:c010:41de::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A21B811C; Sun, 9 Jul 2023 14:00:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=t-8ch.de; s=mail; t=1688936443; bh=i/i0SbwFNl82wivugo29PcbwTwUwrR/WslbHxkZwClc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=BBUa/fdWIVhuEbJc5lYvH7nntb+LPgf/20rNY6UZ5Ua8pCZvcbl83VnBTUn3XQp6f 02s8ILkEQfo+lz0BBHEB/O2ZcsV+UcQ92zMXsVV2h8u4kzuwIZwJKsCbHGSjfLJTYC E/3t5QYDNeW9CszN8j8A0BIixIfGEWgPdMWAT/kY= Date: Sun, 9 Jul 2023 23:00:40 +0200 From: Thomas =?utf-8?Q?Wei=C3=9Fschuh?= To: Zhangjin Wu Cc: w@1wt.eu, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH v2 04/12] tools/nolibc: crt.h: add _start_c Message-ID: <90fdd255-32f4-4caf-90ff-06456b53dac3@t-8ch.de> References: <4e23cc1c-2fe0-413e-9fe1-a9428c0861b9@t-8ch.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4e23cc1c-2fe0-413e-9fe1-a9428c0861b9@t-8ch.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023-07-09 20:49:10+0200, Thomas Weißschuh wrote: > On 2023-07-08 23:29:58+0800, Zhangjin Wu wrote: > [..] > > --- > > tools/include/nolibc/crt.h | 44 ++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 44 insertions(+) > > > > diff --git a/tools/include/nolibc/crt.h b/tools/include/nolibc/crt.h > > index 221b7c5346ca..b269294e9664 100644 > > --- a/tools/include/nolibc/crt.h > > +++ b/tools/include/nolibc/crt.h > > @@ -13,4 +13,48 @@ > [..] > > const unsigned long *_auxv __attribute__((weak)); > > > > +int main(int argc, char *argv[], char **envp); > > This will lead to conflicting declarations if the users use a different > signature. I'm not (yet?) sure how to work around this. > > Also how is the case handled where main() returns "void"? > I'm not sure how this is currently handled or if the compiler takes core > of returning 0 in this case. I looked into this some more. The diff below allows it to accept different signatures for main(). (Maybe you can improve the naming) Implicit return values seem to be handled by the compiler automatically. In C89 mode we get garbage values, in C2X/C23 we get zero. As per the respective C specs. diff --git a/tools/include/nolibc/crt.h b/tools/include/nolibc/crt.h index b269294e9664..dba40bc9413f 100644 --- a/tools/include/nolibc/crt.h +++ b/tools/include/nolibc/crt.h @@ -13,7 +13,6 @@ char **environ __attribute__((weak)); const unsigned long *_auxv __attribute__((weak)); -int main(int argc, char *argv[], char **envp); static void exit(int); void _start_c(long *sp) @@ -21,6 +20,7 @@ void _start_c(long *sp) int argc, i; char **argv; char **envp; + int _nolibc_main_alias(int, char**, char**) __asm__("main"); /* * sp : argc <-- argument count, required by main() @@ -54,7 +54,7 @@ void _start_c(long *sp) _auxv = (void *)(envp + i + 1); /* go to application */ - exit(main(argc, argv, envp)); + exit(_nolibc_main_alias(argc, argv, envp)); } #endif /* _NOLIBC_CRT_H */