aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorMax Filippov <jcmvbkbc@gmail.com>2017-05-03 13:13:52 -0700
committerMax Filippov <jcmvbkbc@gmail.com>2022-11-28 18:16:12 -0800
commitd0a2cfbd3141dae38498fa077b01ae6bb394462b (patch)
tree8cb6fc2a729622c8b9dd3cbbce771a418e3a088f /bfd
parentcb44f89ce977b1ab2d4063f2487950bddfb75bc7 (diff)
downloadfsf-binutils-gdb-d0a2cfbd3141dae38498fa077b01ae6bb394462b.zip
fsf-binutils-gdb-d0a2cfbd3141dae38498fa077b01ae6bb394462b.tar.gz
fsf-binutils-gdb-d0a2cfbd3141dae38498fa077b01ae6bb394462b.tar.bz2
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 functions xtensa_get_config_v{1,2} that use xtensa_load_config to get structures xtensa_config_v{1,2}, either dynamically configured or the default. bfd/ * Makefile.am (BFD32_BACKENDS, BFD32_BACKENDS_CFILES): Append xtensa-dynconfig.c. * Makefile.in: Regenerate. * configure: Regenerate. * configure.ac (xtensa_elf32_be_vec, xtensa_elf32_le_vec): Add xtensa-dynconfig.lo to the tb. * elf32-xtensa.c (xtensa-config.h): Replace #include with xtensa-dynconfig.h. (XSHAL_ABI, XTHAL_ABI_WINDOWED, XTHAL_ABI_CALL0): Remove definitions. * xtensa-dynconfig.c: New file. * xtensa-isa.c (xtensa-dynconfig.h): New #include. (xtensa_get_modules): New function. (xtensa_isa_init): Call xtensa_get_modules instead of taking address of global xtensa_modules. gas/ * config/tc-xtensa.c (xtensa-config.h): Replace #include with xtensa-dynconfig.h. (XTHAL_ABI_WINDOWED, XTHAL_ABI_CALL0, XTENSA_MARCH_EARLIEST): Remove definitions. * config/tc-xtensa.h (xtensa-config.h): Replace #include with xtensa-dynconfig.h. * config/xtensa-relax.c (xtensa-config.h): Replace #include with xtensa-dynconfig.h. (XCHAL_HAVE_WIDE_BRANCHES): Remove definition. include/ * xtensa-dynconfig.h: New file. ld/ * emultempl/xtensaelf.em (xtensa-config.h): Replace #include with xtensa-dynconfig.h. (XTHAL_ABI_WINDOWED, XTHAL_ABI_CALL0): Remove definitions.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/Makefile.am2
-rw-r--r--bfd/Makefile.in3
-rwxr-xr-xbfd/configure4
-rw-r--r--bfd/configure.ac4
-rw-r--r--bfd/elf32-xtensa.c14
-rw-r--r--bfd/xtensa-dynconfig.c147
-rw-r--r--bfd/xtensa-isa.c14
7 files changed, 170 insertions, 18 deletions
diff --git a/bfd/Makefile.am b/bfd/Makefile.am
index a88c6a0..da55a0b 100644
--- a/bfd/Makefile.am
+++ b/bfd/Makefile.am
@@ -393,6 +393,7 @@ BFD32_BACKENDS = \
wasm-module.lo \
xcofflink.lo \
xsym.lo \
+ xtensa-dynconfig.lo \
xtensa-isa.lo \
xtensa-modules.lo
@@ -526,6 +527,7 @@ BFD32_BACKENDS_CFILES = \
wasm-module.c \
xcofflink.c \
xsym.c \
+ xtensa-dynconfig.c \
xtensa-isa.c \
xtensa-modules.c
diff --git a/bfd/Makefile.in b/bfd/Makefile.in
index d5cc5cb..60252f2 100644
--- a/bfd/Makefile.in
+++ b/bfd/Makefile.in
@@ -862,6 +862,7 @@ BFD32_BACKENDS = \
wasm-module.lo \
xcofflink.lo \
xsym.lo \
+ xtensa-dynconfig.lo \
xtensa-isa.lo \
xtensa-modules.lo
@@ -995,6 +996,7 @@ BFD32_BACKENDS_CFILES = \
wasm-module.c \
xcofflink.c \
xsym.c \
+ xtensa-dynconfig.c \
xtensa-isa.c \
xtensa-modules.c
@@ -1751,6 +1753,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wasm-module.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xcofflink.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xsym.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xtensa-dynconfig.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xtensa-isa.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xtensa-modules.Plo@am__quote@
diff --git a/bfd/configure b/bfd/configure
index 74bc5a1..b532fe7 100755
--- a/bfd/configure
+++ b/bfd/configure
@@ -13863,8 +13863,8 @@ do
x86_64_pei_vec) tb="$tb pei-x86_64.lo pex64igen.lo $coff"; target_size=64 ;;
xgate_elf32_vec) tb="$tb elf32-xgate.lo elf32.lo $elf" ;;
xstormy16_elf32_vec) tb="$tb elf32-xstormy16.lo elf32.lo $elf" ;;
- xtensa_elf32_be_vec) tb="$tb xtensa-isa.lo xtensa-modules.lo elf32-xtensa.lo elf32.lo $elf" ;;
- xtensa_elf32_le_vec) tb="$tb xtensa-isa.lo xtensa-modules.lo elf32-xtensa.lo elf32.lo $elf" ;;
+ xtensa_elf32_be_vec) tb="$tb xtensa-dynconfig.lo xtensa-isa.lo xtensa-modules.lo elf32-xtensa.lo elf32.lo $elf" ;;
+ xtensa_elf32_le_vec) tb="$tb xtensa-dynconfig.lo xtensa-isa.lo xtensa-modules.lo elf32-xtensa.lo elf32.lo $elf" ;;
z80_coff_vec) tb="$tb coff-z80.lo reloc16.lo $coffgen" ;;
z80_elf32_vec) tb="$tb elf32-z80.lo elf32.lo $elf" ;;
z8k_coff_vec) tb="$tb coff-z8k.lo reloc16.lo $coff" ;;
diff --git a/bfd/configure.ac b/bfd/configure.ac
index 5d450a4..45a293d 100644
--- a/bfd/configure.ac
+++ b/bfd/configure.ac
@@ -664,8 +664,8 @@ do
x86_64_pei_vec) tb="$tb pei-x86_64.lo pex64igen.lo $coff"; target_size=64 ;;
xgate_elf32_vec) tb="$tb elf32-xgate.lo elf32.lo $elf" ;;
xstormy16_elf32_vec) tb="$tb elf32-xstormy16.lo elf32.lo $elf" ;;
- xtensa_elf32_be_vec) tb="$tb xtensa-isa.lo xtensa-modules.lo elf32-xtensa.lo elf32.lo $elf" ;;
- xtensa_elf32_le_vec) tb="$tb xtensa-isa.lo xtensa-modules.lo elf32-xtensa.lo elf32.lo $elf" ;;
+ xtensa_elf32_be_vec) tb="$tb xtensa-dynconfig.lo xtensa-isa.lo xtensa-modules.lo elf32-xtensa.lo elf32.lo $elf" ;;
+ xtensa_elf32_le_vec) tb="$tb xtensa-dynconfig.lo xtensa-isa.lo xtensa-modules.lo elf32-xtensa.lo elf32.lo $elf" ;;
z80_coff_vec) tb="$tb coff-z80.lo reloc16.lo $coffgen" ;;
z80_elf32_vec) tb="$tb elf32-z80.lo elf32.lo $elf" ;;
z8k_coff_vec) tb="$tb coff-z8k.lo reloc16.lo $coff" ;;
diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c
index 31e2d74..68eaada 100644
--- a/bfd/elf32-xtensa.c
+++ b/bfd/elf32-xtensa.c
@@ -30,29 +30,17 @@
#include "elf/xtensa.h"
#include "splay-tree.h"
#include "xtensa-isa.h"
-#include "xtensa-config.h"
+#include "xtensa-dynconfig.h"
/* All users of this file have bfd_octets_per_byte (abfd, sec) == 1. */
#define OCTETS_PER_BYTE(ABFD, SEC) 1
#define XTENSA_NO_NOP_REMOVAL 0
-#ifndef XSHAL_ABI
-#define XSHAL_ABI 0
-#endif
-
#ifndef XTHAL_ABI_UNDEFINED
#define XTHAL_ABI_UNDEFINED -1
#endif
-#ifndef XTHAL_ABI_WINDOWED
-#define XTHAL_ABI_WINDOWED 0
-#endif
-
-#ifndef XTHAL_ABI_CALL0
-#define XTHAL_ABI_CALL0 1
-#endif
-
/* Local helper functions. */
static bool add_extra_plt_sections (struct bfd_link_info *, int);
diff --git a/bfd/xtensa-dynconfig.c b/bfd/xtensa-dynconfig.c
new file mode 100644
index 0000000..7c9ada5
--- /dev/null
+++ b/bfd/xtensa-dynconfig.c
@@ -0,0 +1,147 @@
+/* Xtensa configuration settings loader.
+ Copyright (C) 2022 Free Software Foundation, Inc.
+
+ This file is part of BFD, the Binary File Descriptor library.
+
+ 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 "sysdep.h"
+#include "bfd.h"
+#include "libbfd.h"
+
+#define XTENSA_CONFIG_DEFINITION
+#include "xtensa-config.h"
+#include "xtensa-dynconfig.h"
+
+#if defined (HAVE_DLFCN_H)
+#include <dlfcn.h>
+#elif defined (HAVE_WINDOWS_H)
+#include <windows.h>
+#endif
+
+#if !defined (HAVE_DLFCN_H) && defined (HAVE_WINDOWS_H)
+
+#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 (HAVE_WINDOWS_H) */
+
+#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;
+#if BFD_SUPPORTS_PLUGINS
+ 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)
+ {
+ _bfd_error_handler (_("%s is defined but could not be loaded: %s"),
+ CONFIG_ENV_NAME, dlerror ());
+ abort ();
+ }
+ }
+ else if (!handle)
+ {
+ return no_plugin_def;
+ }
+
+ p = dlsym (handle, name);
+ if (!p)
+ {
+ if (no_name_def)
+ return no_name_def;
+
+ _bfd_error_handler (_("%s is loaded but symbol \"%s\" is not found: %s"),
+ CONFIG_ENV_NAME, name, dlerror ());
+ abort ();
+ }
+ return p;
+#else
+ if (!init)
+ {
+ const char *path = getenv (CONFIG_ENV_NAME);
+
+ init = 1;
+ if (path)
+ {
+ _bfd_error_handler (_("%s is defined but plugin support is disabled"),
+ CONFIG_ENV_NAME);
+ abort ();
+ }
+ }
+ return no_plugin_def;
+#endif
+}
+
+XTENSA_CONFIG_INSTANCE_LIST;
+
+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 struct xtensa_config_v2 *xtensa_get_config_v2 (void)
+{
+ static const struct xtensa_config_v2 *config;
+ static const struct xtensa_config_v2 def;
+
+ if (!config)
+ config = (const struct xtensa_config_v2 *) xtensa_load_config ("xtensa_config_v2",
+ &xtensa_config_v2,
+ &def);
+ return config;
+}
diff --git a/bfd/xtensa-isa.c b/bfd/xtensa-isa.c
index 63efbd4..9919195 100644
--- a/bfd/xtensa-isa.c
+++ b/bfd/xtensa-isa.c
@@ -23,6 +23,7 @@
#include "libbfd.h"
#include "xtensa-isa.h"
#include "xtensa-isa-internal.h"
+#include "xtensa-dynconfig.h"
static xtensa_isa_status xtisa_errno;
static char xtisa_error_msg[1024];
@@ -232,10 +233,21 @@ xtensa_insnbuf_from_chars (xtensa_isa isa,
extern xtensa_isa_internal xtensa_modules;
+static xtensa_isa_internal *xtensa_get_modules (void)
+{
+ static xtensa_isa_internal *modules;
+
+ if (!modules)
+ modules = (xtensa_isa_internal *) xtensa_load_config ("xtensa_modules",
+ &xtensa_modules,
+ NULL);
+ return modules;
+}
+
xtensa_isa
xtensa_isa_init (xtensa_isa_status *errno_p, char **error_msg_p)
{
- xtensa_isa_internal *isa = &xtensa_modules;
+ xtensa_isa_internal *isa = xtensa_get_modules ();
int n, is_user;
/* Set up the opcode name lookup table. */