From: Keith Packard <keithp@keithp.com>
To: gcc-patches@gcc.gnu.org
Cc: Keith Packard <keithp@keithp.com>,
Andrew Pinski <pinskia@gmail.com>,
Kito Cheng <kito.cheng@gmail.com>,
Richard Sandiford <richard.sandiford@arm.com>,
Sebastian Huber <sebastian.huber@embedded-brains.de>
Subject: [PATCH 1/3] Allow default libc to be specified to configure
Date: Sat, 4 Feb 2023 23:10:34 -0800 [thread overview]
Message-ID: <0fc05b2872263eec6df97393edb4912dcf6d3cc6.1675579641.git.keithp@keithp.com> (raw)
In-Reply-To: <cover.1675579641.git.keithp@keithp.com>
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 <keithp@keithp.com>
---
gcc/config.gcc | 48 ++++++++++++++++++++++++++++++++++++++++--------
gcc/configure.ac | 4 ++++
2 files changed, 44 insertions(+), 8 deletions(-)
diff --git a/gcc/config.gcc b/gcc/config.gcc
index f0958e1c959..0679a76bebb 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -663,6 +663,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 \
@@ -869,16 +871,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
@@ -987,7 +989,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
@@ -1651,13 +1654,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
;;
*)
@@ -3037,7 +3040,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*)
@@ -5862,3 +5865,32 @@ 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 62bc908b991..c30e3c7ae72 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -2481,6 +2481,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.
--
2.39.0
next prev parent reply other threads:[~2023-02-05 7:10 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-24 18:04 [PATCH 0/3] picolibc: Add picolibc linking help Keith Packard
2022-08-24 18:04 ` [PATCH 1/3] picolibc: Allow default libc to be specified to configure Keith Packard
2022-08-24 18:04 ` [PATCH 2/3] picolibc: Add newlib and picolibc as default C library choices Keith Packard
2022-08-24 18:04 ` [PATCH 3/3] picolibc: Add '--oslib=' option when default C library is picolibc Keith Packard
2022-08-24 18:24 ` [PATCH 0/3] picolibc: Add picolibc linking help Andrew Pinski
2022-08-24 19:32 ` Keith Packard
2022-08-25 7:16 ` Kito Cheng
2022-08-25 17:38 ` Keith Packard
2022-09-02 12:36 ` Richard Sandiford
2022-09-03 6:02 ` Keith Packard
2022-09-03 6:07 ` Keith Packard
2022-09-03 6:07 ` [PATCH 1/3] Allow default libc to be specified to configure Keith Packard
2022-09-03 6:07 ` [PATCH 2/3] Add newlib and picolibc as default C library choices Keith Packard
2022-09-03 6:07 ` [PATCH 3/3] Add '--oslib=' option when default C library is picolibc Keith Packard
2022-11-21 7:11 ` Sebastian Huber
2023-02-05 7:10 ` [PATCH 0/3] picolibc: Add picolibc linking help (v3) Keith Packard
2023-02-05 7:10 ` Keith Packard [this message]
2023-02-05 7:10 ` [PATCH 2/3] Add newlib and picolibc as default C library choices Keith Packard
2023-02-05 7:10 ` [PATCH 3/3] Add '--oslib=' option when default C library is picolibc Keith Packard
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=0fc05b2872263eec6df97393edb4912dcf6d3cc6.1675579641.git.keithp@keithp.com \
--to=keithp@keithp.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=kito.cheng@gmail.com \
--cc=pinskia@gmail.com \
--cc=richard.sandiford@arm.com \
--cc=sebastian.huber@embedded-brains.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).