diff options
author | Max Filippov <jcmvbkbc@gmail.com> | 2017-05-08 11:28:21 -0700 |
---|---|---|
committer | Max Filippov <jcmvbkbc@gmail.com> | 2022-12-07 10:00:48 -0800 |
commit | ecb575d09c0ff5314088214c2bb39f1959ad3318 (patch) | |
tree | 79bd0f681a406b7f465a68f3d0d0741906a8fbb3 /gcc | |
parent | 952c8a1dc6235dc49ab207a7f18f63d2bc97fbc9 (diff) | |
download | gcc-ecb575d09c0ff5314088214c2bb39f1959ad3318.zip gcc-ecb575d09c0ff5314088214c2bb39f1959ad3318.tar.gz gcc-ecb575d09c0ff5314088214c2bb39f1959ad3318.tar.bz2 |
gcc: xtensa: allow dynamic configuration
Import include/xtensa-dynconfig.h that defines XCHAL_* macros as fields
of a structure returned from the xtensa_get_config_v<x> function call.
Define that structure and fill it with default parameter values
specified in the include/xtensa-config.h.
Define reusable function xtensa_load_config that tries to load
configuration and return an address of an exported object from it.
Define the function xtensa_get_config_v1 that uses xtensa_load_config
to get structure xtensa_config_v1, either dynamically configured or the
default.
Provide essential XCHAL_* configuration parameters as __XCHAL_* built-in
macros. This way it will be possible to use them in libgcc and libc
without need to patch libgcc or libc source for the specific xtensa core
configuration.
gcc/
* config.gcc (xtensa*-*-*): Add xtensa-dynconfig.o to extra_objs.
* config/xtensa/t-xtensa (TM_H): Add xtensa-dynconfig.h.
(xtensa-dynconfig.o): New rule.
* config/xtensa/xtensa-dynconfig.c: New file.
* config/xtensa/xtensa-protos.h (xtensa_get_config_strings): New
declaration.
* config/xtensa/xtensa.h (xtensa-config.h): Replace #include
with xtensa-dynconfig.h
(XCHAL_HAVE_MUL32_HIGH, XCHAL_HAVE_RELEASE_SYNC)
(XCHAL_HAVE_S32C1I, XCHAL_HAVE_THREADPTR)
(XCHAL_HAVE_FP_POSTINC): Drop definitions.
(TARGET_DIV32): Replace with __XCHAL_HAVE_DIV32.
(TARGET_CPU_CPP_BUILTINS): Add new 'builtin' variable and loop
through string array returned by the xtensa_get_config_strings
function call.
include/
* xtensa-dynconfig.h: New file.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/config.gcc | 1 | ||||
-rw-r--r-- | gcc/config/xtensa/t-xtensa | 8 | ||||
-rw-r--r-- | gcc/config/xtensa/xtensa-dynconfig.c | 170 | ||||
-rw-r--r-- | gcc/config/xtensa/xtensa-protos.h | 1 | ||||
-rw-r--r-- | gcc/config/xtensa/xtensa.h | 22 |
5 files changed, 184 insertions, 18 deletions
diff --git a/gcc/config.gcc b/gcc/config.gcc index b5eda04..9519023 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -561,6 +561,7 @@ tic6x-*-*) ;; xtensa*-*-*) extra_options="${extra_options} fused-madd.opt" + extra_objs="xtensa-dynconfig.o" ;; esac diff --git a/gcc/config/xtensa/t-xtensa b/gcc/config/xtensa/t-xtensa index 6d43b37..4e5b7de 100644 --- a/gcc/config/xtensa/t-xtensa +++ b/gcc/config/xtensa/t-xtensa @@ -16,5 +16,11 @@ # along with GCC; see the file COPYING3. If not see # <http://www.gnu.org/licenses/>. -TM_H += $(srcdir)/../include/xtensa-config.h +TM_H += $(srcdir)/../include/xtensa-config.h \ + $(srcdir)/../include/xtensa-dynconfig.h $(out_object_file): gt-xtensa.h + +xtensa-dynconfig.o: $(srcdir)/config/xtensa/xtensa-dynconfig.c \ + $(CONFIG_H) $(SYSTEM_H) $(srcdir)/../include/xtensa-dynconfig.h \ + $(srcdir)/../include/xtensa-config.h + $(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $< diff --git a/gcc/config/xtensa/xtensa-dynconfig.c b/gcc/config/xtensa/xtensa-dynconfig.c new file mode 100644 index 0000000..056204a --- /dev/null +++ b/gcc/config/xtensa/xtensa-dynconfig.c @@ -0,0 +1,170 @@ +/* Xtensa configuration settings loader. + 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/>. */ + +#include <config.h> +#include <system.h> +#include <coretypes.h> +#include <diagnostic.h> +#include <intl.h> +#define XTENSA_CONFIG_DEFINITION +#include "xtensa-config.h" +#include "xtensa-dynconfig.h" + +#if defined (HAVE_DLFCN_H) +#include <dlfcn.h> +#elif defined (_WIN32) +#include <windows.h> +#define ENABLE_PLUGIN +#endif + +#if !defined (HAVE_DLFCN_H) && defined (_WIN32) + +#define RTLD_LAZY 0 /* Dummy value. */ + +static void * +dlopen (const char *file, int mode ATTRIBUTE_UNUSED) +{ + return LoadLibrary (file); +} + +static void * +dlsym (void *handle, const char *name) +{ + return (void *) GetProcAddress ((HMODULE) handle, name); +} + +static int ATTRIBUTE_UNUSED +dlclose (void *handle) +{ + FreeLibrary ((HMODULE) handle); + return 0; +} + +static const char * +dlerror (void) +{ + return _("Unable to load DLL."); +} + +#endif /* !defined (HAVE_DLFCN_H) && defined (_WIN32) */ + +#define CONFIG_ENV_NAME "XTENSA_GNU_CONFIG" + +const void *xtensa_load_config (const char *name ATTRIBUTE_UNUSED, + const void *no_plugin_def, + const void *no_name_def ATTRIBUTE_UNUSED) +{ + static int init; +#ifdef ENABLE_PLUGIN + static void *handle; + void *p; + + if (!init) + { + const char *path = getenv (CONFIG_ENV_NAME); + + init = 1; + if (!path) + return no_plugin_def; + handle = dlopen (path, RTLD_LAZY); + if (!handle) + { + fatal_error (input_location, + _("%qs is defined but could not be loaded: %s"), + CONFIG_ENV_NAME, dlerror ()); + exit (FATAL_EXIT_CODE); + } + if (dlsym (handle, "plugin_is_GPL_compatible") == NULL) + { + fatal_error (input_location, + _("%qs plugin is not licensed under a GPL-compatible license"), + CONFIG_ENV_NAME); + exit (FATAL_EXIT_CODE); + } + } + else if (!handle) + { + return no_plugin_def; + } + + p = dlsym (handle, name); + if (!p) + { + if (no_name_def) + return no_name_def; + + fatal_error (input_location, + _("%qs is loaded but symbol %qs is not found: %s"), + CONFIG_ENV_NAME, name, dlerror ()); + exit (FATAL_EXIT_CODE); + } + return p; +#else + if (!init) + { + const char *path = getenv (CONFIG_ENV_NAME); + + init = 1; + if (path) + { + fatal_error (input_location, + _("%qs is defined but plugin support is disabled"), + CONFIG_ENV_NAME); + exit (FATAL_EXIT_CODE); + } + } + return no_plugin_def; +#endif +} + +XTENSA_CONFIG_INSTANCE_LIST; + +#define _STRINGIFY(a) #a +#define STRINGIFY(a) _STRINGIFY(a) + +#undef XTENSA_CONFIG_ENTRY +#define XTENSA_CONFIG_ENTRY(a) "__" #a "=" STRINGIFY(a) + +static const char * const xtensa_config_strings[] = { + XTENSA_CONFIG_ENTRY_LIST, + NULL, +}; + +const struct xtensa_config_v1 *xtensa_get_config_v1 (void) +{ + static const struct xtensa_config_v1 *config; + + if (!config) + config = (const struct xtensa_config_v1 *) xtensa_load_config ("xtensa_config_v1", + &xtensa_config_v1, + NULL); + return config; +} + +const char * const *xtensa_get_config_strings (void) +{ + static const char * const *config_strings; + + if (!config_strings) + config_strings = (const char * const *) xtensa_load_config ("xtensa_config_strings", + &xtensa_config_strings, + NULL); + + return config_strings; +} diff --git a/gcc/config/xtensa/xtensa-protos.h b/gcc/config/xtensa/xtensa-protos.h index bc75ad9..91a215e 100644 --- a/gcc/config/xtensa/xtensa-protos.h +++ b/gcc/config/xtensa/xtensa-protos.h @@ -81,5 +81,6 @@ extern void xtensa_expand_epilogue (bool); extern void order_regs_for_local_alloc (void); extern enum reg_class xtensa_regno_to_class (int regno); extern HOST_WIDE_INT xtensa_initial_elimination_offset (int from, int to); +extern const char **xtensa_get_config_strings (void); #endif /* !__XTENSA_PROTOS_H__ */ diff --git a/gcc/config/xtensa/xtensa.h b/gcc/config/xtensa/xtensa.h index 2275fe6..7e19306 100644 --- a/gcc/config/xtensa/xtensa.h +++ b/gcc/config/xtensa/xtensa.h @@ -19,27 +19,12 @@ along with GCC; see the file COPYING3. If not see <http://www.gnu.org/licenses/>. */ /* Get Xtensa configuration settings */ -#include "xtensa-config.h" +#include "xtensa-dynconfig.h" /* External variables defined in xtensa.cc. */ /* Macros used in the machine description to select various Xtensa configuration options. */ -#ifndef XCHAL_HAVE_MUL32_HIGH -#define XCHAL_HAVE_MUL32_HIGH 0 -#endif -#ifndef XCHAL_HAVE_RELEASE_SYNC -#define XCHAL_HAVE_RELEASE_SYNC 0 -#endif -#ifndef XCHAL_HAVE_S32C1I -#define XCHAL_HAVE_S32C1I 0 -#endif -#ifndef XCHAL_HAVE_THREADPTR -#define XCHAL_HAVE_THREADPTR 0 -#endif -#ifndef XCHAL_HAVE_FP_POSTINC -#define XCHAL_HAVE_FP_POSTINC 0 -#endif #define TARGET_BIG_ENDIAN XCHAL_HAVE_BE #define TARGET_DENSITY XCHAL_HAVE_DENSITY #define TARGET_MAC16 XCHAL_HAVE_MAC16 @@ -76,7 +61,7 @@ along with GCC; see the file COPYING3. If not see #endif /* Define this if the target has no hardware divide instructions. */ -#if !TARGET_DIV32 +#if !__XCHAL_HAVE_DIV32 #define TARGET_HAS_NO_HW_DIVIDE #endif @@ -84,6 +69,7 @@ along with GCC; see the file COPYING3. If not see /* Target CPU builtins. */ #define TARGET_CPU_CPP_BUILTINS() \ do { \ + const char **builtin; \ builtin_assert ("cpu=xtensa"); \ builtin_assert ("machine=xtensa"); \ builtin_define ("__xtensa__"); \ @@ -93,6 +79,8 @@ along with GCC; see the file COPYING3. If not see builtin_define (TARGET_BIG_ENDIAN ? "__XTENSA_EB__" : "__XTENSA_EL__"); \ if (!TARGET_HARD_FLOAT) \ builtin_define ("__XTENSA_SOFT_FLOAT__"); \ + for (builtin = xtensa_get_config_strings (); *builtin; ++builtin) \ + builtin_define (*builtin); \ } while (0) #define CPP_SPEC " %(subtarget_cpp_spec) " |