From patchwork Sat Sep 3 06:07:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Packard X-Patchwork-Id: 945 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp1046197wro; Fri, 2 Sep 2022 23:10:29 -0700 (PDT) X-Google-Smtp-Source: AA6agR6taEWPGP1C3KpyZdJAZQu7ArfnB3ybrcyt0/uivN+gzcwZQyX5MWeILXHg9O/WWQftaKtU X-Received: by 2002:a17:907:6e29:b0:73d:6894:e668 with SMTP id sd41-20020a1709076e2900b0073d6894e668mr29140427ejc.453.1662185429710; Fri, 02 Sep 2022 23:10:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662185429; cv=none; d=google.com; s=arc-20160816; b=Xxt3fGvv0+rxhQW81W5pPH+/Tn1gIiFKacj8MpHqm0uBjCVJ2utxQFHZI5BtyYUbZU TH/oPS+Ai79NFgA0aVqI2vFUxDCptPhh7o3f9NYP5HJt46ecrOIsFcAGIQncfHlbNRZp 5Cg2tSUFPmZqRZs3u4ovjQC8fIhdzqrwI9T9MzfEVxMwqCGWCAkcnQDYUzQBqm9UfR+R 4deIMl6pRNoHLpwakFpy0n0Nzd6RWZlqfbHl7sg/CKoWolL9yEniKAzZOnYAZeYoinMp cnIU9YQ+qp7b7GWw3MEOza/wd9E2gItCjfU5whVj+fxvoS3EBCKdjXUZPCfx0s6rjoVZ Uiag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=gmmKEXc+jS1Hp2j4+j0mEL2UpuRr72U4BKyJKJRSFhY=; b=vmmGm9XCmVn+yiyqn5bmWEbbLseZxjj7idJIx1RFyewmtTQhO47kE5HsW4cbdn1OZ0 PKb6gWhzLUhHGBjBBQVftFh3TR+iDQN7b1zdGLszkO0Cc8QS+YWwH0G5guABsvJxwrgX 2/DrsMKECmBComj+rijxX42FoomsyI9kFDGhk7ZywWfl+HPtcZ7qWsOmhB35RHqZVG+J V6BxSIFhlHd7AQWQWU9lVlnVyNmXKdzavAhk6VvE17Olcr+pg0v1hLN52ml21/UbvbLa /mZftJGE4R80mZIh6O638UYVhGnsD3RjWg2qFYI0Ht4b3UZv6D+9Tn7TM/XFW/O7doM/ xqOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Z6CYaj+2; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id dr22-20020a170907721600b0074151fdd5c1si3059095ejc.129.2022.09.02.23.10.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 23:10:29 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Z6CYaj+2; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A3DA5385AC3B for ; Sat, 3 Sep 2022 06:10:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A3DA5385AC3B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662185428; bh=gmmKEXc+jS1Hp2j4+j0mEL2UpuRr72U4BKyJKJRSFhY=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Z6CYaj+2/x/rQUiFVzNx6eVpDuzXo5jKcBaugy74g3entDhbhm1sBmSSmWZyN2HO6 g1A1GjqPYWbk8vlP7PTnZfLYe5QuCgrZdhdIYMdbfQUmQW0/1v05kS1P/oiccVBEWj Q4kCdJCymll1f07NtZ7bxP8azaPXf35si//zZ1DY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from elaine.keithp.com (home.keithp.com [63.227.221.253]) by sourceware.org (Postfix) with ESMTPS id 4790C385AC2A for ; Sat, 3 Sep 2022 06:07:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4790C385AC2A Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id EBF183F32FE6; Fri, 2 Sep 2022 23:07:50 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at keithp.com Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id UsHOn9v4MW1K; Fri, 2 Sep 2022 23:07:46 -0700 (PDT) Received: from keithp.com (unknown [204.134.242.194]) by elaine.keithp.com (Postfix) with ESMTPSA id 286473F32F78; Fri, 2 Sep 2022 23:07:46 -0700 (PDT) Received: by keithp.com (Postfix, from userid 1000) id BFB341E600C7; Fri, 2 Sep 2022 23:07:34 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH 1/3] Allow default libc to be specified to configure Date: Fri, 2 Sep 2022 23:07:05 -0700 Message-Id: <20220903060707.1622470-2-keithp@keithp.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220903060707.1622470-1-keithp@keithp.com> References: <20220824180426.820576-1-keithp@keithp.com> <20220903060707.1622470-1-keithp@keithp.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, 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 server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Keith Packard via Gcc-patches From: Keith Packard Reply-To: Keith Packard Cc: Richard Sandiford Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1742927749288427462?= X-GMAIL-MSGID: =?utf-8?q?1742927749288427462?= The default C library is normally computed based on the target triplet. However, for embedded systems, it can be useful to leave the triplet alone while changing which C library is used by default. Other C libraries may still be available on the system so the compiler and can be used by specifying suitable include and library paths at build time. If an unknown --with-default-libc= value is provided, emit an error and stop. Signed-off-by: Keith Packard --- gcc/config.gcc | 46 ++++++++++++++++++++++++++++++++++++++-------- gcc/configure.ac | 4 ++++ 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/gcc/config.gcc b/gcc/config.gcc index f4e757bd853..bf838b1545d 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -644,6 +644,8 @@ esac # Common C libraries. tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3 LIBC_MUSL=4" +default_libc="" + # 32-bit x86 processors supported by --with-arch=. Each processor # MUST be separated by exactly one space. x86_archs="athlon athlon-4 athlon-fx athlon-mp athlon-tbird \ @@ -849,16 +851,16 @@ case ${target} in esac case $target in *-*-*android*) - tm_defines="$tm_defines DEFAULT_LIBC=LIBC_BIONIC" + default_libc=LIBC_BIONIC ;; *-*-*uclibc* | *-*-uclinuxfdpiceabi) - tm_defines="$tm_defines DEFAULT_LIBC=LIBC_UCLIBC" + default_libc=LIBC_UCLIBC ;; *-*-*musl*) - tm_defines="$tm_defines DEFAULT_LIBC=LIBC_MUSL" + default_libc=LIBC_MUSL ;; *) - tm_defines="$tm_defines DEFAULT_LIBC=LIBC_GLIBC" + default_libc=LIBC_GLIBC ;; esac # Assume that glibc or uClibc or Bionic are being used and so __cxa_atexit @@ -951,7 +953,8 @@ case ${target} in case ${enable_threads} in "" | yes | posix) thread_file='posix' ;; esac - tm_defines="$tm_defines DEFAULT_LIBC=LIBC_UCLIBC SINGLE_LIBC" + tm_defines="$tm_defines SINGLE_LIBC" + default_libc=LIBC_UCLIBC ;; *-*-rdos*) use_gcc_stdint=wrap @@ -1603,13 +1606,13 @@ csky-*-*) case ${target} in csky-*-linux-gnu*) - tm_defines="$tm_defines DEFAULT_LIBC=LIBC_GLIBC" + default_libc=LIBC_GLIBC # Force .init_array support. The configure script cannot always # automatically detect that GAS supports it, yet we require it. gcc_cv_initfini_array=yes ;; csky-*-linux-uclibc*) - tm_defines="$tm_defines DEFAULT_LIBC=LIBC_UCLIBC" + default_libc=LIBC_UCLIBC default_use_cxa_atexit=no ;; *) @@ -2982,7 +2985,7 @@ powerpc*-wrs-vxworks7r*) tmake_file="${tmake_file} t-linux rs6000/t-linux64 rs6000/t-fprules rs6000/t-ppccomm" tmake_file="${tmake_file} rs6000/t-vxworks" - tm_defines="$tm_defines DEFAULT_LIBC=LIBC_GLIBC" + default_libc=LIBC_GLIBC extra_objs="$extra_objs linux.o rs6000-linux.o" ;; powerpc-wrs-vxworks*) @@ -5772,3 +5775,30 @@ i[34567]86-*-* | x86_64-*-*) fi ;; esac + +case "${with_default_libc}" in +glibc) + default_libc=LIBC_GLIBC + ;; +uclibc) + default_libc=LIBC_UCLIBC + ;; +bionic) + default_libc=LIBC_BIONIC + ;; +musl) + default_libc=LIBC_MUSL + ;; +*) + echo "Unknown libc in --with-default-libc=$with_default_libc" 1>&2 + exit 1 + ;; +esac + +case "$default_libc" in +"") + ;; +*) + tm_defines="$tm_defines DEFAULT_LIBC=$default_libc" + ;; +esac diff --git a/gcc/configure.ac b/gcc/configure.ac index 50bb61c1b61..7302c987282 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -2472,6 +2472,10 @@ if { { test x$host != x$target && test "x$with_sysroot" = x ; } || fi AC_SUBST(inhibit_libc) +AC_ARG_WITH(default-libc, + [AS_HELP_STRING([--with-default-libc], + [Use specified default C library])]) + # When building gcc with a cross-compiler, we need to adjust things so # that the generator programs are still built with the native compiler. # Also, we cannot run fixincludes. From patchwork Sat Sep 3 06:07:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Packard X-Patchwork-Id: 943 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp1045558wro; Fri, 2 Sep 2022 23:08:39 -0700 (PDT) X-Google-Smtp-Source: AA6agR6AUADmJJVq31yriAvt11wUQYg60bHFJPXoAr4Epvgb6oIV31WuQN3PYOxXqjyH+9snD0ax X-Received: by 2002:a17:907:20d1:b0:731:5169:106b with SMTP id qq17-20020a17090720d100b007315169106bmr30303489ejb.667.1662185319543; Fri, 02 Sep 2022 23:08:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662185319; cv=none; d=google.com; s=arc-20160816; b=Xyh5aQrrcsGNr5aLcwL2sBZ7DWFbXjyudE18YTdjcpXSqDyoeFgBqXUMb7fgSSxhm4 7HviJwYnEOQcpjm4xHU+A92bHS++tNDtD080kQNdu+R4zwPnCZWyPTTzOFpDB3GjKIY3 fhgi/oUKFAfCCK+wvj6hHJlGh1yu/rQYxrNU+VxUeYbcESazzGhEelmGxOsgnVrH0ixv GaqS1ViCnyaQsclRvw5URqFioXTgjc2+Y5L2YMqn6xayfnC/a/D7z0/LF2QkLjP2PKDH DnSddNNSZqIsahrLEU6YG6CGZc1EdQV7f7Q3xrPpH0D+VyxClOgu5p+jUEUTx8pDXCKO I0IA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=M7g/qOY+NWCqfzBUEa3qrsLtWQzWQ3K5YFkmmL2pOeQ=; b=X3QySSDj7Bqkt0UKsuOIr14h4viWd6k4JhZ1U7lWdZay7L0A6bFiov06spePl3Ykim NCeB0TSVMuqeCdx1s1ohnFfjpYA7JikXzTaJ4hEaX8r0zPFtIbQN9jhA+ZXxVymPrVsu 1jPgGgkI7qDPh9WWKrl3bK1O+2wXPFmv2MTL3rO964SHRtC5LSMQUAtRaJeiXlhv8EiQ z6hNMi5u92ib5lF1Da5wB4fQBQyLWvr/lMDElQPJRmLCK4Vh3UeL2K/4EjH9vp/8FGht TsEs3jVjEdVOZ1PEYLvEJMj+tBQUzWn3qnvfKz+BKlhPcWSBZ1gp45taAZ0m7HtZCiX6 U84A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=qijGUPD1; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id a73-20020a509ecf000000b004478fecbfe1si3040257edf.298.2022.09.02.23.08.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 23:08:39 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=qijGUPD1; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 406FE385AE5D for ; Sat, 3 Sep 2022 06:08:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 406FE385AE5D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662185315; bh=M7g/qOY+NWCqfzBUEa3qrsLtWQzWQ3K5YFkmmL2pOeQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=qijGUPD15sN3HXypTlJUVpUIttMvOEUGXzit8TNNLHyX0rznG5m/ZVfw4KaoKWKh7 WkYlud4v8wAG8Hk1iGCpygfPq02gyRvQqdvn6t6e/A0euqAPSVtgzNSwtFAuqRikUE t4H4yBFVAhLpLYtL9Cn1WkCV4ut/fM322ZRLCHSE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from elaine.keithp.com (home.keithp.com [63.227.221.253]) by sourceware.org (Postfix) with ESMTPS id 4736F3858418 for ; Sat, 3 Sep 2022 06:07:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4736F3858418 Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id 5C1973F32F78; Fri, 2 Sep 2022 23:07:51 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at keithp.com Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id jE8aVAFJlmZz; Fri, 2 Sep 2022 23:07:51 -0700 (PDT) Received: from keithp.com (unknown [204.134.242.194]) by elaine.keithp.com (Postfix) with ESMTPSA id 32D8B3F32FC4; Fri, 2 Sep 2022 23:07:46 -0700 (PDT) Received: by keithp.com (Postfix, from userid 1000) id C2E3A1E600C9; Fri, 2 Sep 2022 23:07:34 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/3] Add newlib and picolibc as default C library choices Date: Fri, 2 Sep 2022 23:07:06 -0700 Message-Id: <20220903060707.1622470-3-keithp@keithp.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220903060707.1622470-1-keithp@keithp.com> References: <20220824180426.820576-1-keithp@keithp.com> <20220903060707.1622470-1-keithp@keithp.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, 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 server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Keith Packard via Gcc-patches From: Keith Packard Reply-To: Keith Packard Cc: Richard Sandiford Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1742927633521251042?= X-GMAIL-MSGID: =?utf-8?q?1742927633521251042?= Don't set the DEFAULT_LIBC variable for newlib configurations as that is how it currently works for systems using newlib as the default. Signed-off-by: Keith Packard --- gcc/config.gcc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/gcc/config.gcc b/gcc/config.gcc index bf838b1545d..6f8f13a811a 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -642,7 +642,7 @@ case ${target} in esac # Common C libraries. -tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3 LIBC_MUSL=4" +tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3 LIBC_MUSL=4 LIBC_NEWLIB=5 LIBC_PICOLIBC=6" default_libc="" @@ -5789,6 +5789,17 @@ bionic) musl) default_libc=LIBC_MUSL ;; +newlib) + + # Newlib configurations don't set the DEFAULT_LIBC variable, so + # avoid changing those allowing --with-default-libc=newlib but + # don't actually set the DEFAULT_LIBC variable. + + default_libc= + ;; +picolibc) + default_libc=LIBC_PICOLIBC + ;; *) echo "Unknown libc in --with-default-libc=$with_default_libc" 1>&2 exit 1 From patchwork Sat Sep 3 06:07:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Packard X-Patchwork-Id: 944 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp1045927wro; Fri, 2 Sep 2022 23:09:33 -0700 (PDT) X-Google-Smtp-Source: AA6agR7rS2iV+I/wTsmOjOMnmU5cf7KQUGYegUvQ1IOxbUkaYIvGQD6Re1Ys/XlCoensnBKTHLgq X-Received: by 2002:a05:6402:51d1:b0:448:bed1:269c with SMTP id r17-20020a05640251d100b00448bed1269cmr18138058edd.205.1662185373389; Fri, 02 Sep 2022 23:09:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662185373; cv=none; d=google.com; s=arc-20160816; b=er5IqZx4gIplvcOOcZEI7OzWVyKURo4gu1JJ0T2skIynyjOsFEyVz52nnzOJHa+Xyn ktwPdtJkIjkV7+1VCkfzBRKbdMhpI0reUtJoGxyLzh7pSIDiPRkwlL8xlflT4xSrGUJF 0P5iZzadLqgl/Cv7u5RLqGlK2VfGIAqmKidLMHCJT2hKcPW7EqIqpLLw6SlB2JH3Uwxg mBwkS5nbiz6wbKFdYGhc8Db8v+gIG5SURJP1Blgp5jLgDJzFrQsCS5PY+imQWTJADQS5 Tf1KmAq9nomQWWPNRYZGspgqf2ruHoLbAWKtjx/3/BumbS64EPtc/wCnRiKP0RbdYzN9 3ssw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=f4qZtEK2M+DsJd4YU5Tf0W+ct7gzq9Rk/CTyJ7Cj6Jg=; b=sWvloHLeckGaLMjyXD1C7vr+pop7NpPswIDSN8gfKzm21Lc/z5tkrAXBXpz7Wnr22l meumkTAX+rdSZZeUnrh4YHJjbACahXS0AAKOneDHkDKLFdG486XT+HFaEIfJbILWsz0b TCGQlI/DvrxiuZf/ORO9iWPxNzt+nOHbQZ2nBXuwqiAOX48QEUxAu4cx9Nmv4Rf3vOfy DJctr5x3ZuGuT4ATPxKXZ0x3ZlrOyxXhYPDWCWPppbyK+1LWRFoaXDR6ifjoZmsB7w5j GUhOYhw64bUOEKGJh+pssoRM7KT+4oqn8/fn0LguTrX8thX6m0S/J3HCzeOgDqnGRxPk HD8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=aE2U51Z5; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id ne5-20020a1709077b8500b00743d1a1dddfsi3655720ejc.337.2022.09.02.23.09.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 23:09:33 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=aE2U51Z5; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 36E843856DCD for ; Sat, 3 Sep 2022 06:09:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 36E843856DCD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662185372; bh=f4qZtEK2M+DsJd4YU5Tf0W+ct7gzq9Rk/CTyJ7Cj6Jg=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=aE2U51Z5mrOSEZ7gZ89x4SHs6s8zwxbDBj0kfM8VRpjJJGZSZSaBaIZQ4g2idU+bu v+mqYtjG4egyGdx0U+LVnUsdE95XKcb2+SF48akv0sN6w/ReGt2QJzR6N8GR4Tp3Pa dPdyU4QyIASOtXeUYKk2RjIP0AagEERDphq6bO4E= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from elaine.keithp.com (home.keithp.com [63.227.221.253]) by sourceware.org (Postfix) with ESMTPS id 501A1385AC36 for ; Sat, 3 Sep 2022 06:07:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 501A1385AC36 Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id 7665C3F32FE9; Fri, 2 Sep 2022 23:07:51 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at keithp.com Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id IwGbQ2KV1k6U; Fri, 2 Sep 2022 23:07:51 -0700 (PDT) Received: from keithp.com (unknown [204.134.242.194]) by elaine.keithp.com (Postfix) with ESMTPSA id 3A2933F32FE0; Fri, 2 Sep 2022 23:07:46 -0700 (PDT) Received: by keithp.com (Postfix, from userid 1000) id C5F1F1E600CC; Fri, 2 Sep 2022 23:07:34 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH 3/3] Add '--oslib=' option when default C library is picolibc Date: Fri, 2 Sep 2022 23:07:07 -0700 Message-Id: <20220903060707.1622470-4-keithp@keithp.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220903060707.1622470-1-keithp@keithp.com> References: <20220824180426.820576-1-keithp@keithp.com> <20220903060707.1622470-1-keithp@keithp.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP, 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 server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Keith Packard via Gcc-patches From: Keith Packard Reply-To: Keith Packard Cc: Richard Sandiford Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1742927689991202040?= X-GMAIL-MSGID: =?utf-8?q?1742927689991202040?= This option allows targets to insert an OS library after the C library in the LIB_PATH spec file fragment. This library maps a few POSIX APIs used by picolibc to underlying system capabilities. For example, picolibc provides 'libsemihost' on various targets which maps these APIs to semihosting capabilities. This would be used with this option by specifying --oslib=semihost This patch enables --oslib= on arm, nds32, riscv and sh. Signed-off-by: Keith Packard --- gcc/config.gcc | 6 ++++++ gcc/config/arm/elf.h | 5 +++++ gcc/config/nds32/elf.h | 4 ++++ gcc/config/picolibc.opt | 26 ++++++++++++++++++++++++++ gcc/config/riscv/elf.h | 4 ++++ gcc/config/sh/embed-elf.h | 5 +++++ 6 files changed, 50 insertions(+) create mode 100644 gcc/config/picolibc.opt diff --git a/gcc/config.gcc b/gcc/config.gcc index 6f8f13a811a..9bb45ec85ab 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -5813,3 +5813,9 @@ case "$default_libc" in tm_defines="$tm_defines DEFAULT_LIBC=$default_libc" ;; esac + +case "$default_libc" in + LIBC_PICOLIBC) + extra_options="${extra_options} picolibc.opt" + ;; +esac diff --git a/gcc/config/arm/elf.h b/gcc/config/arm/elf.h index 3d111433ede..dc5b9374814 100644 --- a/gcc/config/arm/elf.h +++ b/gcc/config/arm/elf.h @@ -150,3 +150,8 @@ #undef L_floatundisf #endif +#if DEFAULT_LIBC == LIBC_PICOLIBC +#undef LIB_SPEC +#define LIB_SPEC "--start-group %(libgcc) -lc %{-oslib=*:-l%*} --end-group" +#endif + diff --git a/gcc/config/nds32/elf.h b/gcc/config/nds32/elf.h index ebdc18cee2a..b9d2f2485e8 100644 --- a/gcc/config/nds32/elf.h +++ b/gcc/config/nds32/elf.h @@ -34,8 +34,12 @@ " %{shared:-shared}" \ NDS32_RELAX_SPEC +#if DEFAULT_LIBC == LIBC_PICOLIBC +#define LIB_SPEC "--start-group %(libgcc) -lc %{-oslib=*:-l%*} --end-group" +#else #define LIB_SPEC \ " -lc -lgloss" +#endif #define LIBGCC_SPEC \ " -lgcc" diff --git a/gcc/config/picolibc.opt b/gcc/config/picolibc.opt new file mode 100644 index 00000000000..194b3362b03 --- /dev/null +++ b/gcc/config/picolibc.opt @@ -0,0 +1,26 @@ +; Processor-independent options for picolibc. +; +; Copyright (C) 2022 Free Software Foundation, Inc. +; +; This file is part of GCC. +; +; GCC is free software; you can redistribute it and/or modify it under +; the terms of the GNU General Public License as published by the Free +; Software Foundation; either version 3, or (at your option) any later +; version. +; +; GCC is distributed in the hope that it will be useful, but WITHOUT ANY +; WARRANTY; without even the implied warranty of MERCHANTABILITY or +; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +; for more details. +; +; You should have received a copy of the GNU General Public License +; along with GCC; see the file COPYING3. If not see +; . + +-oslib +Driver Separate Alias(-oslib=) + +-oslib= +Driver Joined +Specify an OS support library to load after libc. diff --git a/gcc/config/riscv/elf.h b/gcc/config/riscv/elf.h index f3d767c6d42..57471cee702 100644 --- a/gcc/config/riscv/elf.h +++ b/gcc/config/riscv/elf.h @@ -27,9 +27,13 @@ along with GCC; see the file COPYING3. If not see /* Link against Newlib libraries, because the ELF backend assumes Newlib. Handle the circular dependence between libc and libgloss. */ #undef LIB_SPEC +#if DEFAULT_LIBC == LIBC_PICOLIBC +#define LIB_SPEC "--start-group %(libgcc) -lc %{-oslib=*:-l%*} --end-group" +#else #define LIB_SPEC \ "--start-group -lc %{!specs=nosys.specs:-lgloss} --end-group " \ "%{!nostartfiles:%{!nodefaultlibs:%{!nolibc:%{!nostdlib:%:riscv_multi_lib_check()}}}}" +#endif #undef STARTFILE_SPEC #define STARTFILE_SPEC "crt0%O%s crtbegin%O%s" diff --git a/gcc/config/sh/embed-elf.h b/gcc/config/sh/embed-elf.h index 21e51dd0bb9..093bf2800db 100644 --- a/gcc/config/sh/embed-elf.h +++ b/gcc/config/sh/embed-elf.h @@ -34,3 +34,8 @@ along with GCC; see the file COPYING3. If not see %{Os: -lgcc-Os-4-200} \ -lgcc \ %{!Os: -lgcc-Os-4-200}" + +#if DEFAULT_LIBC == LIBC_PICOLIBC +#undef LIB_SPEC +#define LIB_SPEC "--start-group %(libgcc) -lc %{-oslib=*:-l%*} --end-group" +#endif