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: 1673812 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Xyd6EI/j; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MKPX00D4Cz1yhK for ; Sat, 3 Sep 2022 16:10:08 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0B5943856DDF for ; Sat, 3 Sep 2022 06:10:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0B5943856DDF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662185406; 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=Xyd6EI/jISIGSYFN6O3g8CKHV8HbYYP9bDc5aTbTJ7KzlYgJZ2Cx/KfNZg5rQup+R OBcyXV1RK6Jx3Clh44Elhz/n9CZNQM1Jv4g1TYzAOtODUx5YFa8GtpnHHXP09runJQ AYChcQfBIyW72w4e4xDI8+ic2o3YO1b0UwuGsYZc= 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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.