[3/3] Add '--oslib=' option when default C library is picolibc
Commit Message
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 <keithp@keithp.com>
---
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
Comments
On 03/09/2022 08:07, Keith Packard via Gcc-patches wrote:
> 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
> +
Can't you add a gcc/config/picolibc.h (similar to gcc/config/rtems.h)
which is placed in gcc/config.gcc with something like this:
picolibc)
default_libc=LIBC_PICOLIBC
tm_file="${tm_file} picolibc.h"
;;
In this header place:
#undef LIB_SPEC
#define LIB_SPEC "--start-group %(libgcc) -lc %{-oslib=*:-l%*} --end-group"
#endif
This avoids having to modify all the ELF-specific files.
@@ -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
@@ -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
+
@@ -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"
new file mode 100644
@@ -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
+; <http://www.gnu.org/licenses/>.
+
+-oslib
+Driver Separate Alias(-oslib=)
+
+-oslib=
+Driver Joined
+Specify an OS support library to load after libc.
@@ -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"
@@ -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