public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 0/3] Espressif xtensa chips multilib
@ 2023-07-20 14:34 Alexey Lapshin
  2023-07-20 14:35 ` [PATCH 1/3] gcc: xtensa: add mdynconfig option Alexey Lapshin
                   ` (5 more replies)
  0 siblings, 6 replies; 17+ messages in thread
From: Alexey Lapshin @ 2023-07-20 14:34 UTC (permalink / raw)
  To: gcc-patches; +Cc: Alexey Gerenkov, Ivan Grokhotkov, jcmvbkbc

This patch series introduces multilib support for Espressif XTENSA chips in gcc.
The addition of the "-mdynconfig=" option was necessary because the existing
environment variable XTENSA_GNU_CONFIG cannot be utilized for implementing multilib.
This is because multilib operates with gcc options rather than environment variables.

It is not possible to use full path in "-mdynconfig=" because it could be different
on users machines and because multilib syntax already reserves the directory
delimiter character. So, it designed to contain dynconfig filename which would not
change in toolchain.

Also, the XTENSA_GNU_CONFIG environment variable usage was changed to include both
the dynconfig file fullpath or dynconfigs directory. This change was made to overcome
the limitations of modifying LD_LIBRARY_PATH on macOS host machines.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 1/3] gcc: xtensa: add mdynconfig option
  2023-07-20 14:34 [PATCH 0/3] Espressif xtensa chips multilib Alexey Lapshin
@ 2023-07-20 14:35 ` Alexey Lapshin
  2023-07-20 14:37 ` [PATCH 2/3] gcc: xtensa: use dynconfig settings as builtin-macros Alexey Lapshin
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 17+ messages in thread
From: Alexey Lapshin @ 2023-07-20 14:35 UTC (permalink / raw)
  To: gcc-patches; +Cc: Alexey Gerenkov, Ivan Grokhotkov, jcmvbkbc

gcc/
        * config/xtensa/elf.h (ASM_SPEC, LINK_SPEC): Pass dynconfig to
        assembler/linker.
        * config/xtensa/linux.h (ASM_SPEC, LINK_SPEC): Likewise.
        * config/xtensa/uclinux.h (ASM_SPEC, LINK_SPEC): Likewise.
        * config/xtensa/xtensa-dynconfig.cc: May build dynconfig path with
          dir in XTENSA_GNU_CONFIG and filename in mdynconfig option.
        * doc/invoke.texi: Add XTENSA_GNU_CONFIG and mdynconfig doc.
---
 gcc/config/xtensa/elf.h               |  6 ++-
 gcc/config/xtensa/linux.h             |  6 ++-
 gcc/config/xtensa/uclinux.h           |  6 ++-
 gcc/config/xtensa/xtensa-dynconfig.cc | 55 ++++++++++++++++++++++++++-
 gcc/config/xtensa/xtensa.opt          |  4 ++
 gcc/doc/invoke.texi                   | 14 +++++++
 6 files changed, 83 insertions(+), 8 deletions(-)

diff --git a/gcc/config/xtensa/elf.h b/gcc/config/xtensa/elf.h
index 715b3a0b1d2..6683edea1de 100644
--- a/gcc/config/xtensa/elf.h
+++ b/gcc/config/xtensa/elf.h
@@ -49,7 +49,8 @@ along with GCC; see the file COPYING3.  If not see
   %{mauto-litpools:--auto-litpools} \
   %{mno-auto-litpools:--no-auto-litpools} \
   %{mabi=windowed:--abi-windowed} \
-  %{mabi=call0:--abi-call0}"
+  %{mabi=call0:--abi-call0} \
+  %{mdynconfig=*:--dynconfig=%*}"
 
 #undef LIB_SPEC
 #define LIB_SPEC "-lc -lsim -lc -lhandlers-sim -lhal"
@@ -69,7 +70,8 @@ along with GCC; see the file COPYING3.  If not see
       %{rdynamic:-export-dynamic} \
     %{static:-static}}} \
   %{mabi=windowed:--abi-windowed} \
-  %{mabi=call0:--abi-call0}"
+  %{mabi=call0:--abi-call0} \
+  %{mdynconfig=*:--dynconfig=%*}"
 
 #undef LOCAL_LABEL_PREFIX
 #define LOCAL_LABEL_PREFIX	"."
diff --git a/gcc/config/xtensa/linux.h b/gcc/config/xtensa/linux.h
index e684e7deebf..928e8c36923 100644
--- a/gcc/config/xtensa/linux.h
+++ b/gcc/config/xtensa/linux.h
@@ -46,7 +46,8 @@ along with GCC; see the file COPYING3.  If not see
   %{mauto-litpools:--auto-litpools} \
   %{mno-auto-litpools:--no-auto-litpools} \
   %{mabi=windowed:--abi-windowed} \
-  %{mabi=call0:--abi-call0}"
+  %{mabi=call0:--abi-call0} \
+  %{mdynconfig=*:--dynconfig=%*}"
 
 #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
 
@@ -60,7 +61,8 @@ along with GCC; see the file COPYING3.  If not see
     %{static-pie:-static -pie --no-dynamic-linker -z text} \
     %{static:-static}} \
   %{mabi=windowed:--abi-windowed} \
-  %{mabi=call0:--abi-call0}"
+  %{mabi=call0:--abi-call0} \
+  %{mdynconfig=*:--dynconfig=%*}"
 
 #undef LOCAL_LABEL_PREFIX
 #define LOCAL_LABEL_PREFIX	"."
diff --git a/gcc/config/xtensa/uclinux.h b/gcc/config/xtensa/uclinux.h
index da9e619fb05..68c209bbebb 100644
--- a/gcc/config/xtensa/uclinux.h
+++ b/gcc/config/xtensa/uclinux.h
@@ -53,13 +53,15 @@ along with GCC; see the file COPYING3.  If not see
   %{mauto-litpools:--auto-litpools} \
   %{mno-auto-litpools:--no-auto-litpools} \
   %{mabi=windowed:--abi-windowed} \
-  %{mabi=call0:--abi-call0}"
+  %{mabi=call0:--abi-call0} \
+  %{mdynconfig=*:--dynconfig=%*}"
 
 #undef LINK_SPEC
 #define LINK_SPEC \
  "%{!no-elf2flt:%{!elf2flt*:-elf2flt}} \
   %{mabi=windowed:--abi-windowed} \
-  %{mabi=call0:--abi-call0}"
+  %{mabi=call0:--abi-call0} \
+  %{mdynconfig=*:--dynconfig=%*}"
 
 #undef LOCAL_LABEL_PREFIX
 #define LOCAL_LABEL_PREFIX	"."
diff --git a/gcc/config/xtensa/xtensa-dynconfig.cc b/gcc/config/xtensa/xtensa-dynconfig.cc
index 9aea9f253c2..3d6938a134b 100644
--- a/gcc/config/xtensa/xtensa-dynconfig.cc
+++ b/gcc/config/xtensa/xtensa-dynconfig.cc
@@ -22,6 +22,7 @@
 #include "coretypes.h"
 #include "diagnostic.h"
 #include "intl.h"
+#include "options.h"
 #define XTENSA_CONFIG_DEFINITION
 #include "xtensa-config.h"
 #include "xtensa-dynconfig.h"
@@ -67,6 +68,55 @@ dlerror (void)
 
 #define CONFIG_ENV_NAME "XTENSA_GNU_CONFIG"
 
+#ifdef ENABLE_PLUGIN
+
+static char *get_xtensa_dynconfig_file (void)
+{
+  const char *xtensa_dynconfig_env = getenv (CONFIG_ENV_NAME);
+  if (!strlen (xtensa_dynconfig_file))
+    {
+      if (xtensa_dynconfig_env && !strlen (lbasename (xtensa_dynconfig_env)))
+	{
+	  /* XTENSA_GNU_CONFIG has directory path, but dynconfig file is not set */
+	  return NULL;
+	}
+      else if (xtensa_dynconfig_env)
+	{
+	  /* XTENSA_GNU_CONFIG has filepath */
+	  return xstrdup (xtensa_dynconfig_env);
+	}
+      /* dynconfig is not set */
+      return NULL;
+    }
+  if (!xtensa_dynconfig_env)
+    {
+      /* XTENSA_GNU_CONFIG has filepath */
+      return xstrdup (xtensa_dynconfig_file);
+    }
+  if (!strlen (lbasename (xtensa_dynconfig_env)))
+    {
+      /* XTENSA_GNU_CONFIG has directory path and dynconfig file is set */
+      const size_t len = strlen (xtensa_dynconfig_env) +
+                         strlen (xtensa_dynconfig_file) + 1;
+      char *path = ( char *) xmalloc (len);
+      strcpy (path, xtensa_dynconfig_env);
+      strcat (path, xtensa_dynconfig_file);
+      return path;
+    }
+  if (strcmp (lbasename (xtensa_dynconfig_env),
+              lbasename (xtensa_dynconfig_file)))
+    {
+      fatal_error (input_location,
+                   "Both %qs and \"-dynconfig=\" specified but pointed different files: \"%qs\" \"%qs\"",
+                   CONFIG_ENV_NAME, xtensa_dynconfig_env, xtensa_dynconfig_file);
+      exit (FATAL_EXIT_CODE);
+    }
+  /* XTENSA_GNU_CONFIG and mdynconfig option point to the same file */
+  return xstrdup (xtensa_dynconfig_env);
+}
+
+#endif /* ENABLE_PLUGIN  */
+
 const void *xtensa_load_config (const char *name ATTRIBUTE_UNUSED,
 				const void *no_plugin_def,
 				const void *no_name_def ATTRIBUTE_UNUSED)
@@ -78,12 +128,13 @@ const void *xtensa_load_config (const char *name ATTRIBUTE_UNUSED,
 
   if (!init)
     {
-      const char *path = getenv (CONFIG_ENV_NAME);
+      char *path = get_xtensa_dynconfig_file();
 
       init = 1;
       if (!path)
 	return no_plugin_def;
       handle = dlopen (path, RTLD_LAZY);
+      free (path);
       if (!handle)
 	{
 	  fatal_error (input_location,
@@ -119,7 +170,7 @@ const void *xtensa_load_config (const char *name ATTRIBUTE_UNUSED,
 #else
   if (!init)
     {
-      const char *path = getenv (CONFIG_ENV_NAME);
+      const char *path = strcmp(xtensa_dynconfig_file, "") ? xtensa_dynconfig_file : getenv (CONFIG_ENV_NAME);
 
       init = 1;
       if (path)
diff --git a/gcc/config/xtensa/xtensa.opt b/gcc/config/xtensa/xtensa.opt
index 3a129a4c039..62959fc76c7 100644
--- a/gcc/config/xtensa/xtensa.opt
+++ b/gcc/config/xtensa/xtensa.opt
@@ -64,3 +64,7 @@ Use call0 ABI.
 mabi=windowed
 Target RejectNegative Var(xtensa_windowed_abi, 1)
 Use windowed registers ABI.
+
+mdynconfig=
+Target RejectNegative Joined Var(xtensa_dynconfig_file) Init("")
+Directory or path to dynconfig library.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index a38547f53e5..c8bc5c40f49 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -34258,6 +34258,14 @@ Choose startup files and linker script suitable for the simulator.
 These options are supported for Xtensa targets:
 
 @table @gcctabopt
+
+@vindex XTENSA_GNU_CONFIG
+@item XTENSA_GNU_CONFIG
+@env{XTENSA_GNU_CONFIG} is designed to set dir/fullpath to dynconfig
+library. In case directory is present in @env{XTENSA_GNU_CONFIG}
+filename of dynconfig library must be set in @option{-mdynconfig}.
+Must ends with directory separator in case contains direcrory path.
+
 @opindex mconst16
 @opindex mno-const16
 @item -mconst16
@@ -34394,6 +34402,12 @@ instructions, in clock cycles.  This affects, when optimizing for speed,
 whether loading a constant from literal pool using @code{L32R} or
 synthesizing the constant from a small one with a couple of arithmetic
 instructions.  The default value is 0.
+
+@opindex mdynconfig
+@item -mdynconfig=@var{path}
+Set the filename/path to xtensa dynconfig.
+In case filename is set the directory part must be present in
+@env{XTENSA_GNU_CONFIG} environment variable.
 @end table
 
 @node zSeries Options
-- 
2.34.1


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 2/3] gcc: xtensa: use dynconfig settings as builtin-macros
  2023-07-20 14:34 [PATCH 0/3] Espressif xtensa chips multilib Alexey Lapshin
  2023-07-20 14:35 ` [PATCH 1/3] gcc: xtensa: add mdynconfig option Alexey Lapshin
@ 2023-07-20 14:37 ` Alexey Lapshin
  2023-07-20 15:04   ` Max Filippov
  2023-07-20 14:37 ` [PATCH 3/3] gcc: xtensa: add xtensa*-esp*-elf multilib Alexey Lapshin
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 17+ messages in thread
From: Alexey Lapshin @ 2023-07-20 14:37 UTC (permalink / raw)
  To: gcc-patches; +Cc: Alexey Gerenkov, Ivan Grokhotkov, jcmvbkbc

gcc/
        * config/xtensa/xtensa.h (XCHAL_HAVE_BE, XCHAL_HAVE_DENSITY,
          XCHAL_HAVE_CONST16, XCHAL_HAVE_ABS, XCHAL_HAVE_ADDX,
          XCHAL_HAVE_L32R, XSHAL_USE_ABSOLUTE_LITERALS,
          XSHAL_HAVE_TEXT_SECTION_LITERALS, XCHAL_HAVE_MAC16,
          XCHAL_HAVE_MUL16, XCHAL_HAVE_MUL32, XCHAL_HAVE_MUL32_HIGH,
          XCHAL_HAVE_DIV32, XCHAL_HAVE_NSA, XCHAL_HAVE_MINMAX,
          XCHAL_HAVE_SEXT, XCHAL_HAVE_LOOPS, XCHAL_HAVE_THREADPTR,
          XCHAL_HAVE_RELEASE_SYNC, XCHAL_HAVE_S32C1I,
          XCHAL_HAVE_BOOLEANS, XCHAL_HAVE_FP, XCHAL_HAVE_FP_DIV,
          XCHAL_HAVE_FP_RECIP, XCHAL_HAVE_FP_SQRT,
          XCHAL_HAVE_FP_RSQRT, XCHAL_HAVE_FP_POSTINC, XCHAL_HAVE_DFP,
          XCHAL_HAVE_DFP_DIV, XCHAL_HAVE_DFP_RECIP,
          XCHAL_HAVE_DFP_SQRT, XCHAL_HAVE_DFP_RSQRT,
          XCHAL_HAVE_WINDOWED, XCHAL_NUM_AREGS,
          XCHAL_HAVE_WIDE_BRANCHES, XCHAL_HAVE_PREDICTED_BRANCHES,
          XCHAL_ICACHE_SIZE, XCHAL_DCACHE_SIZE,
          XCHAL_ICACHE_LINESIZE, XCHAL_DCACHE_LINESIZE,
          XCHAL_ICACHE_LINEWIDTH, XCHAL_DCACHE_LINEWIDTH,
          XCHAL_DCACHE_IS_WRITEBACK, XCHAL_HAVE_MMU,
          XCHAL_MMU_MIN_PTE_PAGE_SIZE, XCHAL_HAVE_DEBUG,
          XCHAL_NUM_IBREAK, XCHAL_NUM_DBREAK, XCHAL_DEBUGLEVEL,
          XCHAL_MAX_INSTRUCTION_SIZE, XCHAL_INST_FETCH_WIDTH,
          XSHAL_ABI, XTHAL_ABI_WINDOWED, XTHAL_ABI_CALL0,
          XCHAL_M_STAGE, XTENSA_MARCH_LATEST, XTENSA_MARCH_EARLIEST,
          XCHAL_HAVE_CLAMPS, XCHAL_HAVE_DEPBITS,
          XCHAL_HAVE_EXCLUSIVE, XCHAL_HAVE_XEA3): Add builtin-macros
          with values from dynconfig.
---
 gcc/config/xtensa/xtensa.h | 62 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/gcc/config/xtensa/xtensa.h b/gcc/config/xtensa/xtensa.h
index 8ebf37cab33..a65b674915b 100644
--- a/gcc/config/xtensa/xtensa.h
+++ b/gcc/config/xtensa/xtensa.h
@@ -67,6 +67,7 @@ along with GCC; see the file COPYING3.  If not see
 #endif
 
 \f
+#define XTENSA_CPU_CPP_BUILTIN(OPT) builtin_define_with_int_value (#OPT, OPT)
 /* Target CPU builtins.  */
 #define TARGET_CPU_CPP_BUILTINS()					\
   do {									\
@@ -82,6 +83,67 @@ along with GCC; see the file COPYING3.  If not see
       builtin_define ("__XTENSA_SOFT_FLOAT__");				\
     for (builtin = xtensa_get_config_strings (); *builtin; ++builtin)	\
       builtin_define (*builtin);					\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_BE);						\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_DENSITY);					\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_CONST16);					\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_ABS);						\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_ADDX);					\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_L32R);					\
+    XTENSA_CPU_CPP_BUILTIN(XSHAL_USE_ABSOLUTE_LITERALS);		\
+    XTENSA_CPU_CPP_BUILTIN(XSHAL_HAVE_TEXT_SECTION_LITERALS);	\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_MAC16);					\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_MUL16);					\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_MUL32);					\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_MUL32_HIGH);				\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_DIV32);					\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_NSA);						\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_MINMAX);					\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_SEXT);					\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_LOOPS);					\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_THREADPTR);				\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_RELEASE_SYNC);			\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_S32C1I);					\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_BOOLEANS);				\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_FP);						\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_FP_DIV);					\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_FP_RECIP);				\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_FP_SQRT);					\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_FP_RSQRT);				\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_FP_POSTINC);				\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_DFP);						\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_DFP_DIV);					\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_DFP_RECIP);				\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_DFP_SQRT);				\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_DFP_RSQRT);				\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_WINDOWED);				\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_NUM_AREGS);					\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_WIDE_BRANCHES);			\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_PREDICTED_BRANCHES);		\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_ICACHE_SIZE);					\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_DCACHE_SIZE);					\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_ICACHE_LINESIZE);				\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_DCACHE_LINESIZE);				\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_ICACHE_LINEWIDTH);				\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_DCACHE_LINEWIDTH);				\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_DCACHE_IS_WRITEBACK);			\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_MMU);						\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_MMU_MIN_PTE_PAGE_SIZE);		\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_DEBUG);					\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_NUM_IBREAK);					\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_NUM_DBREAK);					\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_DEBUGLEVEL);					\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_MAX_INSTRUCTION_SIZE);			\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_INST_FETCH_WIDTH);				\
+    XTENSA_CPU_CPP_BUILTIN(XSHAL_ABI);							\
+    XTENSA_CPU_CPP_BUILTIN(XTHAL_ABI_WINDOWED);					\
+    XTENSA_CPU_CPP_BUILTIN(XTHAL_ABI_CALL0);					\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_M_STAGE);						\
+    XTENSA_CPU_CPP_BUILTIN(XTENSA_MARCH_LATEST);				\
+    XTENSA_CPU_CPP_BUILTIN(XTENSA_MARCH_EARLIEST);				\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_CLAMPS);					\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_DEPBITS);					\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_EXCLUSIVE);				\
+    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_XEA3);					\
   } while (0)
 
 #define CPP_SPEC " %(subtarget_cpp_spec) "
-- 
2.34.1


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 3/3] gcc: xtensa: add xtensa*-esp*-elf multilib
  2023-07-20 14:34 [PATCH 0/3] Espressif xtensa chips multilib Alexey Lapshin
  2023-07-20 14:35 ` [PATCH 1/3] gcc: xtensa: add mdynconfig option Alexey Lapshin
  2023-07-20 14:37 ` [PATCH 2/3] gcc: xtensa: use dynconfig settings as builtin-macros Alexey Lapshin
@ 2023-07-20 14:37 ` Alexey Lapshin
  2023-12-11  7:35 ` [PATCH 0/3] Espressif xtensa chips multilib Alexey Lapshin
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 17+ messages in thread
From: Alexey Lapshin @ 2023-07-20 14:37 UTC (permalink / raw)
  To: gcc-patches; +Cc: Alexey Gerenkov, Ivan Grokhotkov, jcmvbkbc

gcc/
        * config.gcc: Add xtensa*-esp*-elf target.
        * config/xtensa/t-esp-multilib: New file.
---
 gcc/config.gcc                   |  6 ++++++
 gcc/config/xtensa/t-esp-multilib | 20 ++++++++++++++++++++
 2 files changed, 26 insertions(+)
 create mode 100644 gcc/config/xtensa/t-esp-multilib

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 6fd1594480a..f972c71a0b2 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -3512,6 +3512,12 @@ xstormy16-*-elf)
 xtensa*-*-elf*)
 	tm_file="${tm_file} elfos.h newlib-stdint.h xtensa/elf.h"
 	extra_options="${extra_options} xtensa/elf.opt"
+	tmake_file="${tmake_file} xtensa/t-xtensa"
+	case ${target} in
+	xtensa*-esp-elf*)
+		tmake_file="${tmake_file} xtensa/t-esp-multilib"
+		;;
+	esac
 	;;
 xtensa*-*-linux*)
 	tm_file="${tm_file} elfos.h gnu-user.h linux.h glibc-stdint.h xtensa/linux.h"
diff --git a/gcc/config/xtensa/t-esp-multilib b/gcc/config/xtensa/t-esp-multilib
new file mode 100644
index 00000000000..dfc0ac0e04c
--- /dev/null
+++ b/gcc/config/xtensa/t-esp-multilib
@@ -0,0 +1,20 @@
+# Copyright (C) 2023 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/>.
+
+MULTILIB_OPTIONS = mdynconfig=xtensa_esp32.so/mdynconfig=xtensa_esp32s2.so/mdynconfig=xtensa_esp32s3.so fno-rtti
+MULTILIB_DIRNAMES = esp32 esp32s2 esp32s3 no-rtti
-- 
2.34.1

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/3] gcc: xtensa: use dynconfig settings as builtin-macros
  2023-07-20 14:37 ` [PATCH 2/3] gcc: xtensa: use dynconfig settings as builtin-macros Alexey Lapshin
@ 2023-07-20 15:04   ` Max Filippov
  2023-07-20 15:12     ` Alexey Lapshin
  0 siblings, 1 reply; 17+ messages in thread
From: Max Filippov @ 2023-07-20 15:04 UTC (permalink / raw)
  To: Alexey Lapshin; +Cc: gcc-patches, Alexey Gerenkov, Ivan Grokhotkov

On Thu, Jul 20, 2023 at 7:37 AM Alexey Lapshin
<alexey.lapshin@espressif.com> wrote:
>
> gcc/
>         * config/xtensa/xtensa.h (XCHAL_HAVE_BE, XCHAL_HAVE_DENSITY,
>           XCHAL_HAVE_CONST16, XCHAL_HAVE_ABS, XCHAL_HAVE_ADDX,
>           XCHAL_HAVE_L32R, XSHAL_USE_ABSOLUTE_LITERALS,
>           XSHAL_HAVE_TEXT_SECTION_LITERALS, XCHAL_HAVE_MAC16,
>           XCHAL_HAVE_MUL16, XCHAL_HAVE_MUL32, XCHAL_HAVE_MUL32_HIGH,
>           XCHAL_HAVE_DIV32, XCHAL_HAVE_NSA, XCHAL_HAVE_MINMAX,
>           XCHAL_HAVE_SEXT, XCHAL_HAVE_LOOPS, XCHAL_HAVE_THREADPTR,
>           XCHAL_HAVE_RELEASE_SYNC, XCHAL_HAVE_S32C1I,
>           XCHAL_HAVE_BOOLEANS, XCHAL_HAVE_FP, XCHAL_HAVE_FP_DIV,
>           XCHAL_HAVE_FP_RECIP, XCHAL_HAVE_FP_SQRT,
>           XCHAL_HAVE_FP_RSQRT, XCHAL_HAVE_FP_POSTINC, XCHAL_HAVE_DFP,
>           XCHAL_HAVE_DFP_DIV, XCHAL_HAVE_DFP_RECIP,
>           XCHAL_HAVE_DFP_SQRT, XCHAL_HAVE_DFP_RSQRT,
>           XCHAL_HAVE_WINDOWED, XCHAL_NUM_AREGS,
>           XCHAL_HAVE_WIDE_BRANCHES, XCHAL_HAVE_PREDICTED_BRANCHES,
>           XCHAL_ICACHE_SIZE, XCHAL_DCACHE_SIZE,
>           XCHAL_ICACHE_LINESIZE, XCHAL_DCACHE_LINESIZE,
>           XCHAL_ICACHE_LINEWIDTH, XCHAL_DCACHE_LINEWIDTH,
>           XCHAL_DCACHE_IS_WRITEBACK, XCHAL_HAVE_MMU,
>           XCHAL_MMU_MIN_PTE_PAGE_SIZE, XCHAL_HAVE_DEBUG,
>           XCHAL_NUM_IBREAK, XCHAL_NUM_DBREAK, XCHAL_DEBUGLEVEL,
>           XCHAL_MAX_INSTRUCTION_SIZE, XCHAL_INST_FETCH_WIDTH,
>           XSHAL_ABI, XTHAL_ABI_WINDOWED, XTHAL_ABI_CALL0,
>           XCHAL_M_STAGE, XTENSA_MARCH_LATEST, XTENSA_MARCH_EARLIEST,
>           XCHAL_HAVE_CLAMPS, XCHAL_HAVE_DEPBITS,
>           XCHAL_HAVE_EXCLUSIVE, XCHAL_HAVE_XEA3): Add builtin-macros
>           with values from dynconfig.
> ---
>  gcc/config/xtensa/xtensa.h | 62 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 62 insertions(+)
>
> diff --git a/gcc/config/xtensa/xtensa.h b/gcc/config/xtensa/xtensa.h
> index 8ebf37cab33..a65b674915b 100644
> --- a/gcc/config/xtensa/xtensa.h
> +++ b/gcc/config/xtensa/xtensa.h
> @@ -67,6 +67,7 @@ along with GCC; see the file COPYING3.  If not see
>  #endif
>
>
> +#define XTENSA_CPU_CPP_BUILTIN(OPT) builtin_define_with_int_value (#OPT, OPT)
>  /* Target CPU builtins.  */
>  #define TARGET_CPU_CPP_BUILTINS()                                      \
>    do {                                                                 \
> @@ -82,6 +83,67 @@ along with GCC; see the file COPYING3.  If not see
>        builtin_define ("__XTENSA_SOFT_FLOAT__");                                \
>      for (builtin = xtensa_get_config_strings (); *builtin; ++builtin)  \
>        builtin_define (*builtin);                                       \

The loop above already does the same thing, doesn't it?

> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_BE);                                             \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_DENSITY);                                        \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_CONST16);                                        \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_ABS);                                            \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_ADDX);                                   \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_L32R);                                   \
> +    XTENSA_CPU_CPP_BUILTIN(XSHAL_USE_ABSOLUTE_LITERALS);               \
> +    XTENSA_CPU_CPP_BUILTIN(XSHAL_HAVE_TEXT_SECTION_LITERALS);  \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_MAC16);                                  \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_MUL16);                                  \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_MUL32);                                  \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_MUL32_HIGH);                             \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_DIV32);                                  \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_NSA);                                            \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_MINMAX);                                 \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_SEXT);                                   \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_LOOPS);                                  \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_THREADPTR);                              \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_RELEASE_SYNC);                   \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_S32C1I);                                 \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_BOOLEANS);                               \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_FP);                                             \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_FP_DIV);                                 \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_FP_RECIP);                               \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_FP_SQRT);                                        \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_FP_RSQRT);                               \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_FP_POSTINC);                             \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_DFP);                                            \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_DFP_DIV);                                        \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_DFP_RECIP);                              \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_DFP_SQRT);                               \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_DFP_RSQRT);                              \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_WINDOWED);                               \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_NUM_AREGS);                                   \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_WIDE_BRANCHES);                  \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_PREDICTED_BRANCHES);             \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_ICACHE_SIZE);                                 \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_DCACHE_SIZE);                                 \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_ICACHE_LINESIZE);                             \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_DCACHE_LINESIZE);                             \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_ICACHE_LINEWIDTH);                            \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_DCACHE_LINEWIDTH);                            \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_DCACHE_IS_WRITEBACK);                 \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_MMU);                                            \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_MMU_MIN_PTE_PAGE_SIZE);               \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_DEBUG);                                  \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_NUM_IBREAK);                                  \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_NUM_DBREAK);                                  \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_DEBUGLEVEL);                                  \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_MAX_INSTRUCTION_SIZE);                        \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_INST_FETCH_WIDTH);                            \
> +    XTENSA_CPU_CPP_BUILTIN(XSHAL_ABI);                                                 \
> +    XTENSA_CPU_CPP_BUILTIN(XTHAL_ABI_WINDOWED);                                        \
> +    XTENSA_CPU_CPP_BUILTIN(XTHAL_ABI_CALL0);                                   \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_M_STAGE);                                             \
> +    XTENSA_CPU_CPP_BUILTIN(XTENSA_MARCH_LATEST);                               \
> +    XTENSA_CPU_CPP_BUILTIN(XTENSA_MARCH_EARLIEST);                             \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_CLAMPS);                                 \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_DEPBITS);                                        \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_EXCLUSIVE);                              \
> +    XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_XEA3);                                   \
>    } while (0)
>
>  #define CPP_SPEC " %(subtarget_cpp_spec) "
> --
> 2.34.1
>


-- 
Thanks.
-- Max

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/3] gcc: xtensa: use dynconfig settings as builtin-macros
  2023-07-20 15:04   ` Max Filippov
@ 2023-07-20 15:12     ` Alexey Lapshin
  2023-07-20 15:25       ` Max Filippov
  0 siblings, 1 reply; 17+ messages in thread
From: Alexey Lapshin @ 2023-07-20 15:12 UTC (permalink / raw)
  To: jcmvbkbc; +Cc: gcc-patches, Alexey Gerenkov, Ivan Grokhotkov

Oops, missed this loop while implementing...

I had a problem with building esp chips multilib until added my changes.

This loop looks like just defines a macro without value.
But the value must be set to make it work correctly.
It uses builtin_define() instead builtin_define_with_int_value()

I will check how it could be soved with the loop approach.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/3] gcc: xtensa: use dynconfig settings as builtin-macros
  2023-07-20 15:12     ` Alexey Lapshin
@ 2023-07-20 15:25       ` Max Filippov
  2023-07-20 16:10         ` Alexey Lapshin
  2023-07-20 17:45         ` Alexey Lapshin
  0 siblings, 2 replies; 17+ messages in thread
From: Max Filippov @ 2023-07-20 15:25 UTC (permalink / raw)
  To: Alexey Lapshin; +Cc: gcc-patches, Alexey Gerenkov, Ivan Grokhotkov

On Thu, Jul 20, 2023 at 8:12 AM Alexey Lapshin
<alexey.lapshin@espressif.com> wrote:
>
> Oops, missed this loop while implementing...
>
> I had a problem with building esp chips multilib until added my changes.
>
> This loop looks like just defines a macro without value.

But it defines them with their respective values.
Just notice that it adds two leading underscores in front of the names.

> But the value must be set to make it work correctly.
> It uses builtin_define() instead builtin_define_with_int_value()
>
> I will check how it could be soved with the loop approach.

-- 
Thanks.
-- Max

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/3] gcc: xtensa: use dynconfig settings as builtin-macros
  2023-07-20 15:25       ` Max Filippov
@ 2023-07-20 16:10         ` Alexey Lapshin
  2023-07-20 17:43           ` Max Filippov
  2023-07-20 17:45         ` Alexey Lapshin
  1 sibling, 1 reply; 17+ messages in thread
From: Alexey Lapshin @ 2023-07-20 16:10 UTC (permalink / raw)
  To: jcmvbkbc; +Cc: gcc-patches, Alexey Gerenkov, Ivan Grokhotkov

I see now, thanks for the explanation, I will try to rebuild toolchain without this particular patch.

BTW, what do you thing about placing config from newlib overlay to dynconfig?

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/3] gcc: xtensa: use dynconfig settings as builtin-macros
  2023-07-20 16:10         ` Alexey Lapshin
@ 2023-07-20 17:43           ` Max Filippov
  2023-07-20 17:52             ` Alexey Lapshin
  0 siblings, 1 reply; 17+ messages in thread
From: Max Filippov @ 2023-07-20 17:43 UTC (permalink / raw)
  To: Alexey Lapshin; +Cc: gcc-patches, Alexey Gerenkov, Ivan Grokhotkov

On Thu, Jul 20, 2023 at 9:10 AM Alexey Lapshin
<alexey.lapshin@espressif.com> wrote:
> I see now, thanks for the explanation, I will try to rebuild toolchain without this particular patch.
> BTW, what do you thing about placing config from newlib overlay to dynconfig?

That's the right thing to do. Bonus points for keeping backwards
compatibility with the overlay-based configuration method (:
I did the same for the uClibc, but the change is still in my queue:
  https://github.com/jcmvbkbc/uclibc-ng-xtensa/commit/842aede0537812a0d2158433c5e048ee87324075

-- 
Thanks.
-- Max

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/3] gcc: xtensa: use dynconfig settings as builtin-macros
  2023-07-20 15:25       ` Max Filippov
  2023-07-20 16:10         ` Alexey Lapshin
@ 2023-07-20 17:45         ` Alexey Lapshin
  2023-07-20 17:55           ` Max Filippov
  1 sibling, 1 reply; 17+ messages in thread
From: Alexey Lapshin @ 2023-07-20 17:45 UTC (permalink / raw)
  To: jcmvbkbc; +Cc: gcc-patches, Alexey Gerenkov, Ivan Grokhotkov

On Thu, 2023-07-20 at 08:25 -0700, Max Filippov wrote:
> But it defines them with their respective values.
> Just notice that it adds two leading underscores in front of the names.

Why builtin macros were defined with prefix?
With this approach I also need define it somewhere:

#define XTHAL_ABI_WINDOWED  __XTHAL_ABI_WINDOWED
#define XTHAL_ABI_CALL0     __XTHAL_ABI_CALL0
.....


Or add prefix to macros in existing code that also looks not good..

I want to get idea why toolchain can't have builtin macros with the same names?

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/3] gcc: xtensa: use dynconfig settings as builtin-macros
  2023-07-20 17:43           ` Max Filippov
@ 2023-07-20 17:52             ` Alexey Lapshin
  2023-07-20 17:54               ` Alexey Lapshin
  0 siblings, 1 reply; 17+ messages in thread
From: Alexey Lapshin @ 2023-07-20 17:52 UTC (permalink / raw)
  To: jcmvbkbc; +Cc: gcc-patches, Alexey Gerenkov, Ivan Grokhotkov

On Thu, 2023-07-20 at 10:43 -0700, Max Filippov wrote:
> Bonus points for keeping backwards
> compatibility with the overlay-based configuration method (:

Got you, thanks!

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/3] gcc: xtensa: use dynconfig settings as builtin-macros
  2023-07-20 17:52             ` Alexey Lapshin
@ 2023-07-20 17:54               ` Alexey Lapshin
  2023-07-20 17:58                 ` Max Filippov
  0 siblings, 1 reply; 17+ messages in thread
From: Alexey Lapshin @ 2023-07-20 17:54 UTC (permalink / raw)
  To: jcmvbkbc; +Cc: gcc-patches, Alexey Gerenkov, Ivan Grokhotkov

Please consider to review another two pathes then.
This would be nice to have it in upstream

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/3] gcc: xtensa: use dynconfig settings as builtin-macros
  2023-07-20 17:45         ` Alexey Lapshin
@ 2023-07-20 17:55           ` Max Filippov
  0 siblings, 0 replies; 17+ messages in thread
From: Max Filippov @ 2023-07-20 17:55 UTC (permalink / raw)
  To: Alexey Lapshin; +Cc: gcc-patches, Alexey Gerenkov, Ivan Grokhotkov

On Thu, Jul 20, 2023 at 10:45 AM Alexey Lapshin
<alexey.lapshin@espressif.com> wrote:
>
> On Thu, 2023-07-20 at 08:25 -0700, Max Filippov wrote:
> > But it defines them with their respective values.
> > Just notice that it adds two leading underscores in front of the names.
>
> Why builtin macros were defined with prefix?
> With this approach I also need define it somewhere:
>
> #define XTHAL_ABI_WINDOWED  __XTHAL_ABI_WINDOWED
> #define XTHAL_ABI_CALL0     __XTHAL_ABI_CALL0
> .....
>
> Or add prefix to macros in existing code that also looks not good..
>
> I want to get idea why toolchain can't have builtin macros with the same names?

Because 1) it will break existing code and 2) it's just not nice to pollute
the namespace.

-- 
Thanks.
-- Max

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/3] gcc: xtensa: use dynconfig settings as builtin-macros
  2023-07-20 17:54               ` Alexey Lapshin
@ 2023-07-20 17:58                 ` Max Filippov
  0 siblings, 0 replies; 17+ messages in thread
From: Max Filippov @ 2023-07-20 17:58 UTC (permalink / raw)
  To: Alexey Lapshin; +Cc: gcc-patches, Alexey Gerenkov, Ivan Grokhotkov

On Thu, Jul 20, 2023 at 10:54 AM Alexey Lapshin
<alexey.lapshin@espressif.com> wrote:
> Please consider to review another two pathes then.
> This would be nice to have it in upstream

Sure, it's going to take some time though as I need to take a good look,
and maybe I'll come back with some change proposals.

-- 
Thanks.
-- Max

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 0/3] Espressif xtensa chips multilib
  2023-07-20 14:34 [PATCH 0/3] Espressif xtensa chips multilib Alexey Lapshin
                   ` (2 preceding siblings ...)
  2023-07-20 14:37 ` [PATCH 3/3] gcc: xtensa: add xtensa*-esp*-elf multilib Alexey Lapshin
@ 2023-12-11  7:35 ` Alexey Lapshin
  2024-04-01 12:16 ` [PATCH v2 1/2] gcc: xtensa: add mdynconfig option Alexey Lapshin
  2024-04-01 12:16 ` [PATCH v2 2/2] gcc: xtensa: add xtensa*-esp*-elf multilib Alexey Lapshin
  5 siblings, 0 replies; 17+ messages in thread
From: Alexey Lapshin @ 2023-12-11  7:35 UTC (permalink / raw)
  To: jcmvbkbc; +Cc: gcc-patches, Alexey Gerenkov, Ivan Grokhotkov

Hi Max!

Could you please consider to merge patch 1 and patch 3?
Along with https://sourceware.org/pipermail/binutils/2023-July/128478.html

Regards,
Alexey

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v2 1/2] gcc: xtensa: add mdynconfig option
  2023-07-20 14:34 [PATCH 0/3] Espressif xtensa chips multilib Alexey Lapshin
                   ` (3 preceding siblings ...)
  2023-12-11  7:35 ` [PATCH 0/3] Espressif xtensa chips multilib Alexey Lapshin
@ 2024-04-01 12:16 ` Alexey Lapshin
  2024-04-01 12:16 ` [PATCH v2 2/2] gcc: xtensa: add xtensa*-esp*-elf multilib Alexey Lapshin
  5 siblings, 0 replies; 17+ messages in thread
From: Alexey Lapshin @ 2024-04-01 12:16 UTC (permalink / raw)
  To: gcc-patches; +Cc: Alexey Gerenkov, Ivan Grokhotkov, jcmvbkbc

gcc/
        * config/xtensa/elf.h (ASM_SPEC, LINK_SPEC): Pass dynconfig to
        assembler/linker.
        * config/xtensa/linux.h (ASM_SPEC, LINK_SPEC): Likewise.
        * config/xtensa/uclinux.h (ASM_SPEC, LINK_SPEC): Likewise.
        * config/xtensa/xtensa-dynconfig.cc: May build dynconfig path with
          dir in XTENSA_GNU_CONFIG and filename in mdynconfig option.
        * doc/invoke.texi: Add XTENSA_GNU_CONFIG and mdynconfig doc.
---
 gcc/config/xtensa/elf.h               |  6 ++-
 gcc/config/xtensa/linux.h             |  6 ++-
 gcc/config/xtensa/uclinux.h           |  6 ++-
 gcc/config/xtensa/xtensa-dynconfig.cc | 55 ++++++++++++++++++++++++++-
 gcc/config/xtensa/xtensa.opt          |  4 ++
 gcc/doc/invoke.texi                   | 14 +++++++
 6 files changed, 83 insertions(+), 8 deletions(-)

diff --git a/gcc/config/xtensa/elf.h b/gcc/config/xtensa/elf.h
index aa14f9d0134..dd20cb310d0 100644
--- a/gcc/config/xtensa/elf.h
+++ b/gcc/config/xtensa/elf.h
@@ -49,7 +49,8 @@ along with GCC; see the file COPYING3.  If not see
   %{mauto-litpools:--auto-litpools} \
   %{mno-auto-litpools:--no-auto-litpools} \
   %{mabi=windowed:--abi-windowed} \
-  %{mabi=call0:--abi-call0}"
+  %{mabi=call0:--abi-call0} \
+  %{mdynconfig=*:--dynconfig=%*}"
 
 #undef LIB_SPEC
 #define LIB_SPEC "-lc -lsim -lc -lhandlers-sim -lhal"
@@ -69,7 +70,8 @@ along with GCC; see the file COPYING3.  If not see
       %{rdynamic:-export-dynamic} \
     %{static:-static}}} \
   %{mabi=windowed:--abi-windowed} \
-  %{mabi=call0:--abi-call0}"
+  %{mabi=call0:--abi-call0} \
+  %{mdynconfig=*:--dynconfig=%*}"
 
 #undef LOCAL_LABEL_PREFIX
 #define LOCAL_LABEL_PREFIX	"."
diff --git a/gcc/config/xtensa/linux.h b/gcc/config/xtensa/linux.h
index 03ec8e7254a..5a19af13dd3 100644
--- a/gcc/config/xtensa/linux.h
+++ b/gcc/config/xtensa/linux.h
@@ -46,7 +46,8 @@ along with GCC; see the file COPYING3.  If not see
   %{mauto-litpools:--auto-litpools} \
   %{mno-auto-litpools:--no-auto-litpools} \
   %{mabi=windowed:--abi-windowed} \
-  %{mabi=call0:--abi-call0}"
+  %{mabi=call0:--abi-call0} \
+  %{mdynconfig=*:--dynconfig=%*}"
 
 #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
 
@@ -60,7 +61,8 @@ along with GCC; see the file COPYING3.  If not see
     %{static-pie:-static -pie --no-dynamic-linker -z text} \
     %{static:-static}} \
   %{mabi=windowed:--abi-windowed} \
-  %{mabi=call0:--abi-call0}"
+  %{mabi=call0:--abi-call0} \
+  %{mdynconfig=*:--dynconfig=%*}"
 
 #undef LOCAL_LABEL_PREFIX
 #define LOCAL_LABEL_PREFIX	"."
diff --git a/gcc/config/xtensa/uclinux.h b/gcc/config/xtensa/uclinux.h
index 062e9640d64..7dd868e074a 100644
--- a/gcc/config/xtensa/uclinux.h
+++ b/gcc/config/xtensa/uclinux.h
@@ -53,13 +53,15 @@ along with GCC; see the file COPYING3.  If not see
   %{mauto-litpools:--auto-litpools} \
   %{mno-auto-litpools:--no-auto-litpools} \
   %{mabi=windowed:--abi-windowed} \
-  %{mabi=call0:--abi-call0}"
+  %{mabi=call0:--abi-call0} \
+  %{mdynconfig=*:--dynconfig=%*}"
 
 #undef LINK_SPEC
 #define LINK_SPEC \
  "%{!no-elf2flt:%{!elf2flt*:-elf2flt}} \
   %{mabi=windowed:--abi-windowed} \
-  %{mabi=call0:--abi-call0}"
+  %{mabi=call0:--abi-call0} \
+  %{mdynconfig=*:--dynconfig=%*}"
 
 #undef LOCAL_LABEL_PREFIX
 #define LOCAL_LABEL_PREFIX	"."
diff --git a/gcc/config/xtensa/xtensa-dynconfig.cc b/gcc/config/xtensa/xtensa-dynconfig.cc
index 3bd2760e4d8..fe2559e1ed7 100644
--- a/gcc/config/xtensa/xtensa-dynconfig.cc
+++ b/gcc/config/xtensa/xtensa-dynconfig.cc
@@ -22,6 +22,7 @@
 #include "coretypes.h"
 #include "diagnostic.h"
 #include "intl.h"
+#include "options.h"
 #define XTENSA_CONFIG_DEFINITION
 #include "xtensa-config.h"
 #include "xtensa-dynconfig.h"
@@ -67,6 +68,55 @@ dlerror (void)
 
 #define CONFIG_ENV_NAME "XTENSA_GNU_CONFIG"
 
+#ifdef ENABLE_PLUGIN
+
+static char *get_xtensa_dynconfig_file (void)
+{
+  const char *xtensa_dynconfig_env = getenv (CONFIG_ENV_NAME);
+  if (!strlen (xtensa_dynconfig_file))
+    {
+      if (xtensa_dynconfig_env && !strlen (lbasename (xtensa_dynconfig_env)))
+	{
+	  /* XTENSA_GNU_CONFIG has directory path, but dynconfig file is not set */
+	  return NULL;
+	}
+      else if (xtensa_dynconfig_env)
+	{
+	  /* XTENSA_GNU_CONFIG has filepath */
+	  return xstrdup (xtensa_dynconfig_env);
+	}
+      /* dynconfig is not set */
+      return NULL;
+    }
+  if (!xtensa_dynconfig_env)
+    {
+      /* XTENSA_GNU_CONFIG has filepath */
+      return xstrdup (xtensa_dynconfig_file);
+    }
+  if (!strlen (lbasename (xtensa_dynconfig_env)))
+    {
+      /* XTENSA_GNU_CONFIG has directory path and dynconfig file is set */
+      const size_t len = strlen (xtensa_dynconfig_env) +
+                         strlen (xtensa_dynconfig_file) + 1;
+      char *path = ( char *) xmalloc (len);
+      strcpy (path, xtensa_dynconfig_env);
+      strcat (path, xtensa_dynconfig_file);
+      return path;
+    }
+  if (strcmp (lbasename (xtensa_dynconfig_env),
+              lbasename (xtensa_dynconfig_file)))
+    {
+      fatal_error (input_location,
+                   "Both %qs and \"-dynconfig=\" specified but pointed different files: \"%qs\" \"%qs\"",
+                   CONFIG_ENV_NAME, xtensa_dynconfig_env, xtensa_dynconfig_file);
+      exit (FATAL_EXIT_CODE);
+    }
+  /* XTENSA_GNU_CONFIG and mdynconfig option point to the same file */
+  return xstrdup (xtensa_dynconfig_env);
+}
+
+#endif /* ENABLE_PLUGIN  */
+
 const void *xtensa_load_config (const char *name ATTRIBUTE_UNUSED,
 				const void *no_plugin_def,
 				const void *no_name_def ATTRIBUTE_UNUSED)
@@ -78,12 +128,13 @@ const void *xtensa_load_config (const char *name ATTRIBUTE_UNUSED,
 
   if (!init)
     {
-      const char *path = getenv (CONFIG_ENV_NAME);
+      char *path = get_xtensa_dynconfig_file();
 
       init = 1;
       if (!path)
 	return no_plugin_def;
       handle = dlopen (path, RTLD_LAZY);
+      free (path);
       if (!handle)
 	{
 	  fatal_error (input_location,
@@ -119,7 +170,7 @@ const void *xtensa_load_config (const char *name ATTRIBUTE_UNUSED,
 #else
   if (!init)
     {
-      const char *path = getenv (CONFIG_ENV_NAME);
+      const char *path = strcmp(xtensa_dynconfig_file, "") ? xtensa_dynconfig_file : getenv (CONFIG_ENV_NAME);
 
       init = 1;
       if (path)
diff --git a/gcc/config/xtensa/xtensa.opt b/gcc/config/xtensa/xtensa.opt
index b653e99d189..0f073791cc3 100644
--- a/gcc/config/xtensa/xtensa.opt
+++ b/gcc/config/xtensa/xtensa.opt
@@ -71,3 +71,7 @@ Use windowed registers ABI.
 mstrict-align
 Target Var(xtensa_strict_alignment) Init(XTENSA_STRICT_ALIGNMENT_UNDEFINED)
 Do not use unaligned memory references.
+
+mdynconfig=
+Target RejectNegative Joined Var(xtensa_dynconfig_file) Init("")
+Directory or path to dynconfig library.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 942103c23f5..153db7853de 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -36329,6 +36329,14 @@ Choose startup files and linker script suitable for the simulator.
 These options are supported for Xtensa targets:
 
 @table @gcctabopt
+
+@vindex XTENSA_GNU_CONFIG
+@item XTENSA_GNU_CONFIG
+@env{XTENSA_GNU_CONFIG} is designed to set dir/fullpath to dynconfig
+library. In case directory is present in @env{XTENSA_GNU_CONFIG}
+filename of dynconfig library must be set in @option{-mdynconfig}.
+Must ends with directory separator in case contains direcrory path.
+
 @opindex mconst16
 @opindex mno-const16
 @item -mconst16
@@ -36476,6 +36484,12 @@ The default is @option{-mno-strict-align} for cores that support both
 unaligned loads and stores in hardware and @option{-mstrict-align} for all
 other cores.
 
+@opindex mdynconfig
+@item -mdynconfig=@var{path}
+Set the filename/path to xtensa dynconfig.
+In case filename is set the directory part must be present in
+@env{XTENSA_GNU_CONFIG} environment variable.
+
 @end table
 
 @node zSeries Options
-- 
2.34.1


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v2 2/2] gcc: xtensa: add xtensa*-esp*-elf multilib
  2023-07-20 14:34 [PATCH 0/3] Espressif xtensa chips multilib Alexey Lapshin
                   ` (4 preceding siblings ...)
  2024-04-01 12:16 ` [PATCH v2 1/2] gcc: xtensa: add mdynconfig option Alexey Lapshin
@ 2024-04-01 12:16 ` Alexey Lapshin
  5 siblings, 0 replies; 17+ messages in thread
From: Alexey Lapshin @ 2024-04-01 12:16 UTC (permalink / raw)
  To: gcc-patches; +Cc: Alexey Gerenkov, Ivan Grokhotkov, jcmvbkbc

gcc/
        * config.gcc: Add xtensa*-esp*-elf target.
        * config/xtensa/t-esp-multilib: New file.
---
 gcc/config.gcc                   |  6 ++++++
 gcc/config/xtensa/t-esp-multilib | 20 ++++++++++++++++++++
 2 files changed, 26 insertions(+)
 create mode 100644 gcc/config/xtensa/t-esp-multilib

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 17873ac2103..702ddf09f17 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -3587,6 +3587,12 @@ xstormy16-*-elf)
 xtensa*-*-elf*)
 	tm_file="${tm_file} elfos.h newlib-stdint.h xtensa/elf.h"
 	extra_options="${extra_options} xtensa/elf.opt"
+	tmake_file="${tmake_file} xtensa/t-xtensa"
+	case ${target} in
+	xtensa*-esp-elf*)
+		tmake_file="${tmake_file} xtensa/t-esp-multilib"
+		;;
+	esac
 	;;
 xtensa*-*-linux*)
 	tm_file="${tm_file} elfos.h gnu-user.h linux.h glibc-stdint.h xtensa/linux.h"
diff --git a/gcc/config/xtensa/t-esp-multilib b/gcc/config/xtensa/t-esp-multilib
new file mode 100644
index 00000000000..dfc0ac0e04c
--- /dev/null
+++ b/gcc/config/xtensa/t-esp-multilib
@@ -0,0 +1,20 @@
+# Copyright (C) 2023 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/>.
+
+MULTILIB_OPTIONS = mdynconfig=xtensa_esp32.so/mdynconfig=xtensa_esp32s2.so/mdynconfig=xtensa_esp32s3.so fno-rtti
+MULTILIB_DIRNAMES = esp32 esp32s2 esp32s3 no-rtti
-- 
2.34.1



^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2024-04-01 12:16 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-20 14:34 [PATCH 0/3] Espressif xtensa chips multilib Alexey Lapshin
2023-07-20 14:35 ` [PATCH 1/3] gcc: xtensa: add mdynconfig option Alexey Lapshin
2023-07-20 14:37 ` [PATCH 2/3] gcc: xtensa: use dynconfig settings as builtin-macros Alexey Lapshin
2023-07-20 15:04   ` Max Filippov
2023-07-20 15:12     ` Alexey Lapshin
2023-07-20 15:25       ` Max Filippov
2023-07-20 16:10         ` Alexey Lapshin
2023-07-20 17:43           ` Max Filippov
2023-07-20 17:52             ` Alexey Lapshin
2023-07-20 17:54               ` Alexey Lapshin
2023-07-20 17:58                 ` Max Filippov
2023-07-20 17:45         ` Alexey Lapshin
2023-07-20 17:55           ` Max Filippov
2023-07-20 14:37 ` [PATCH 3/3] gcc: xtensa: add xtensa*-esp*-elf multilib Alexey Lapshin
2023-12-11  7:35 ` [PATCH 0/3] Espressif xtensa chips multilib Alexey Lapshin
2024-04-01 12:16 ` [PATCH v2 1/2] gcc: xtensa: add mdynconfig option Alexey Lapshin
2024-04-01 12:16 ` [PATCH v2 2/2] gcc: xtensa: add xtensa*-esp*-elf multilib Alexey Lapshin

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).