Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp34527344rwd; Sun, 9 Jul 2023 14:15:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlHWA8uH2S2c4r1Lld4CSnuQyu9mOOi1PDmc/YoEs/r1TJJbtQs35JkOwBwCELdXiSMQLunh X-Received: by 2002:a05:6a00:1f18:b0:668:8ad5:778f with SMTP id be24-20020a056a001f1800b006688ad5778fmr18825823pfb.17.1688937311559; Sun, 09 Jul 2023 14:15:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688937311; cv=none; d=google.com; s=arc-20160816; b=Socu+Yi7WABnaz7DlaFGhQgJT/+s2awI4nXGziyxD6o7OGtBBNmtayhFdCiMhKPmn+ Qh2vNkSzC1cB2IvUumy8BSiZ9QNYKMuuZT6p9dGZ6CT3NAp2bckNhmQwSTLUVV/kb+L6 N0K+mKTf+VDdx0vtc8+sx+57g22Xyf+reOgewYUlw7O28zYF6vpWhyBVV6hIQGcNQHdT vFJUoeXEcGqqC+yfE37/dAoSwiJBQ3tJxbLB9uxrl0i9zoLA+xMvNwWGfSUqu7pPZ5Vm uFsBTxo9BRlhyB5wJZcsuVizWKFXYmJmp3Ap+ULSoc99qVk2kKoM63Xi9OtErYPNsLLj wexw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=3brEnMhro87DWQjPsOeifrNfV5hTHdn3EhcGrUYqVbc=; fh=w/aFR0RmDXi+lP42kXVQr3sgcXBpqVhGy2uSRpJTTV0=; b=A3SfiPy6Q2qbuvVxCfqC5UoRCxD8IQwvXIn8moNjoEMVGiMEK9rmKUHIp52jD0XqUe g8q05wXOdTF+uEPaoWmOxZ5vpLWp5y2sAtJsIppmSfx4I2lvSqZTpeDu4VLrS7ipimk6 B1Uh4db2QtonfNekVs8xT49WDt59wj0jhY9ti84BB/1ui8dpPCHvIYl3+yCAoCazUI/5 LrMfxZYcXmT6lRJJBqjfmKLyoqX/3Nx5UWWxfdkwgoZUIsKiI1ml341QcXanACepbIy4 FydggX/JspWu/rj0qpKqeKgi1AIRJTWwTsKhJjogE45tH3y6VnMVjYTWXsJW7wtw8giv D1fA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@t-8ch.de header.s=mail header.b="BBUa/fdW"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w2-20020aa78582000000b006778c5e02afsi7369503pfn.362.2023.07.09.14.14.59; Sun, 09 Jul 2023 14:15:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@t-8ch.de header.s=mail header.b="BBUa/fdW"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230137AbjGIVAr (ORCPT + 99 others); Sun, 9 Jul 2023 17:00:47 -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> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 */