summaryrefslogtreecommitdiffstats
path: root/libebl/eblopenbackend.c
diff options
context:
space:
mode:
authorPetr Machata <[email protected]>2012-08-17 21:21:31 +0200
committerMark Wielaard <[email protected]>2014-05-20 22:41:13 +0200
commita57d93f9154a40de6a5ac978164ea691fc87dbc1 (patch)
treea1bf915c2b48c8f0c947691f409f5f7e83563d32 /libebl/eblopenbackend.c
parent4cd77d68f327dae1609bd6fd2dd5c5be5f602522 (diff)
Don't rely on dlopen for EBL backends
- EBL was modified to avoid dlopen and instead relies on all supported backends being linked in. - backends/libebl_static_pic.a and libcpu/libcpu_static_pic.a contain selected backends to be linked statically together with libebl.a - libdw/libdw_static_pic.a is a minimal subset of libdw containing symbols that the above two archives reference. Binaries that don't link libdw but use libebl need to link in libdw_static_pic. This only for internal uses, externally we only support libdw. - Test cases that excercise EBL on unsupported platforms were disabled Signed-off-by: Mark Wielaard <[email protected]>
Diffstat (limited to 'libebl/eblopenbackend.c')
-rw-r--r--libebl/eblopenbackend.c191
1 files changed, 85 insertions, 106 deletions
diff --git a/libebl/eblopenbackend.c b/libebl/eblopenbackend.c
index bd947599..64619fb3 100644
--- a/libebl/eblopenbackend.c
+++ b/libebl/eblopenbackend.c
@@ -41,6 +41,13 @@
#include <libeblP.h>
+const char *i386_init (Elf *elf, GElf_Half machine, Ebl *eh, size_t ehlen);
+const char *x86_64_init (Elf *elf, GElf_Half machine, Ebl *eh, size_t ehlen);
+const char *ppc_init (Elf *elf, GElf_Half machine, Ebl *eh, size_t ehlen);
+const char *ppc64_init (Elf *elf, GElf_Half machine, Ebl *eh, size_t ehlen);
+const char *ia64_init (Elf *elf, GElf_Half machine, Ebl *eh, size_t ehlen);
+const char *s390_init (Elf *elf, GElf_Half machine, Ebl *eh, size_t ehlen);
+const char *aarch64_init (Elf *elf, GElf_Half machine, Ebl *eh, size_t ehlen);
/* This table should contain the complete list of architectures as far
as the ELF specification is concerned. */
@@ -48,7 +55,7 @@
arrays to avoid relocations. */
static const struct
{
- const char *dsoname;
+ ebl_bhinit_t initptr;
const char *emulation;
const char *prefix;
int prefix_len;
@@ -57,81 +64,81 @@ static const struct
int data;
} machines[] =
{
- { "i386", "elf_i386", "i386", 4, EM_386, ELFCLASS32, ELFDATA2LSB },
- { "ia64", "elf_ia64", "ia64", 4, EM_IA_64, ELFCLASS64, ELFDATA2LSB },
- { "alpha", "elf_alpha", "alpha", 5, EM_ALPHA, ELFCLASS64, ELFDATA2LSB },
- { "x86_64", "elf_x86_64", "x86_64", 6, EM_X86_64, ELFCLASS64, ELFDATA2LSB },
- { "ppc", "elf_ppc", "ppc", 3, EM_PPC, ELFCLASS32, ELFDATA2MSB },
- { "ppc64", "elf_ppc64", "ppc64", 5, EM_PPC64, ELFCLASS64, ELFDATA2MSB },
- { "tilegx", "elf_tilegx", "tilegx", 6, EM_TILEGX, ELFCLASS64, ELFDATA2LSB },
+ { i386_init, "elf_i386", "i386", 4, EM_386, ELFCLASS32, ELFDATA2LSB },
+ { ia64_init, "elf_ia64", "ia64", 4, EM_IA_64, ELFCLASS64, ELFDATA2LSB },
+ { NULL, "elf_alpha", "alpha", 5, EM_ALPHA, ELFCLASS64, ELFDATA2LSB },
+ { x86_64_init, "elf_x86_64", "x86_64", 6, EM_X86_64, ELFCLASS64, ELFDATA2LSB },
+ { ppc_init, "elf_ppc", "ppc", 3, EM_PPC, ELFCLASS32, ELFDATA2MSB },
+ { ppc64_init, "elf_ppc64", "ppc64", 5, EM_PPC64, ELFCLASS64, ELFDATA2MSB },
+ { NULL, "elf_tilegx", "tilegx", 6, EM_TILEGX, ELFCLASS64, ELFDATA2LSB },
// XXX class and machine fields need to be filled in for all archs.
- { "sh", "elf_sh", "sh", 2, EM_SH, 0, 0 },
- { "arm", "ebl_arm", "arm", 3, EM_ARM, 0, 0 },
- { "sparc", "elf_sparcv9", "sparc", 5, EM_SPARCV9, 0, 0 },
- { "sparc", "elf_sparc", "sparc", 5, EM_SPARC, 0, 0 },
- { "sparc", "elf_sparcv8plus", "sparc", 5, EM_SPARC32PLUS, 0, 0 },
- { "s390", "ebl_s390", "s390", 4, EM_S390, 0, 0 },
-
- { "m32", "elf_m32", "m32", 3, EM_M32, 0, 0 },
- { "m68k", "elf_m68k", "m68k", 4, EM_68K, 0, 0 },
- { "m88k", "elf_m88k", "m88k", 4, EM_88K, 0, 0 },
- { "i860", "elf_i860", "i860", 4, EM_860, 0, 0 },
- { "s370", "ebl_s370", "s370", 4, EM_S370, 0, 0 },
- { "parisc", "elf_parisc", "parisc", 6, EM_PARISC, 0, 0 },
- { "vpp500", "elf_vpp500", "vpp500", 5, EM_VPP500, 0, 0 },
- { "sparc", "elf_v8plus", "v8plus", 6, EM_SPARC32PLUS, 0, 0 },
- { "i960", "elf_i960", "i960", 4, EM_960, 0, 0 },
- { "v800", "ebl_v800", "v800", 4, EM_V800, 0, 0 },
- { "fr20", "ebl_fr20", "fr20", 4, EM_FR20, 0, 0 },
- { "rh32", "ebl_rh32", "rh32", 4, EM_RH32, 0, 0 },
- { "rce", "ebl_rce", "rce", 3, EM_RCE, 0, 0 },
- { "tricore", "elf_tricore", "tricore", 7, EM_TRICORE, 0, 0 },
- { "arc", "elf_arc", "arc", 3, EM_ARC, 0, 0 },
- { "h8", "elf_h8_300", "h8_300", 6, EM_H8_300, 0, 0 },
- { "h8", "elf_h8_300h", "h8_300h", 6, EM_H8_300H, 0, 0 },
- { "h8", "elf_h8s", "h8s", 6, EM_H8S, 0, 0 },
- { "h8", "elf_h8_500", "h8_500", 6, EM_H8_500, 0, 0 },
- { "coldfire", "elf_coldfire", "coldfire", 8, EM_COLDFIRE, 0, 0 },
- { "m68k", "elf_68hc12", "68hc12", 6, EM_68HC12, 0, 0 },
- { "mma", "elf_mma", "mma", 3, EM_MMA, 0, 0 },
- { "pcp", "elf_pcp", "pcp", 3, EM_PCP, 0, 0 },
- { "ncpu", "elf_ncpu", "ncpu", 4, EM_NCPU, 0, 0 },
- { "ndr1", "elf_ndr1", "ndr1", 4, EM_NDR1, 0, 0 },
- { "starcore", "elf_starcore", "starcore", 8, EM_STARCORE, 0, 0 },
- { "me16", "elf_me16", "em16", 4, EM_ME16, 0, 0 },
- { "st100", "elf_st100", "st100", 5, EM_ST100, 0, 0 },
- { "tinyj", "elf_tinyj", "tinyj", 5, EM_TINYJ, 0, 0 },
- { "pdsp", "elf_pdsp", "pdsp", 4, EM_PDSP, 0, 0 },
- { "fx66", "elf_fx66", "fx66", 4, EM_FX66, 0, 0 },
- { "st9plus", "elf_st9plus", "st9plus", 7, EM_ST9PLUS, 0, 0 },
- { "st7", "elf_st7", "st7", 3, EM_ST7, 0, 0 },
- { "m68k", "elf_68hc16", "68hc16", 6, EM_68HC16, 0, 0 },
- { "m68k", "elf_68hc11", "68hc11", 6, EM_68HC11, 0, 0 },
- { "m68k", "elf_68hc08", "68hc08", 6, EM_68HC08, 0, 0 },
- { "m68k", "elf_68hc05", "68hc05", 6, EM_68HC05, 0, 0 },
- { "svx", "elf_svx", "svx", 3, EM_SVX, 0, 0 },
- { "st19", "elf_st19", "st19", 4, EM_ST19, 0, 0 },
- { "vax", "elf_vax", "vax", 3, EM_VAX, 0, 0 },
- { "cris", "elf_cris", "cris", 4, EM_CRIS, 0, 0 },
- { "javelin", "elf_javelin", "javelin", 7, EM_JAVELIN, 0, 0 },
- { "firepath", "elf_firepath", "firepath", 8, EM_FIREPATH, 0, 0 },
- { "zsp", "elf_zsp", "zsp", 3, EM_ZSP, 0, 0 },
- { "mmix", "elf_mmix", "mmix", 4, EM_MMIX, 0, 0 },
- { "hunay", "elf_huany", "huany", 5, EM_HUANY, 0, 0 },
- { "prism", "elf_prism", "prism", 5, EM_PRISM, 0, 0 },
- { "avr", "elf_avr", "avr", 3, EM_AVR, 0, 0 },
- { "fr30", "elf_fr30", "fr30", 4, EM_FR30, 0, 0 },
- { "dv10", "elf_dv10", "dv10", 4, EM_D10V, 0, 0 },
- { "dv30", "elf_dv30", "dv30", 4, EM_D30V, 0, 0 },
- { "v850", "elf_v850", "v850", 4, EM_V850, 0, 0 },
- { "m32r", "elf_m32r", "m32r", 4, EM_M32R, 0, 0 },
- { "mn10300", "elf_mn10300", "mn10300", 7, EM_MN10300, 0, 0 },
- { "mn10200", "elf_mn10200", "mn10200", 7, EM_MN10200, 0, 0 },
- { "pj", "elf_pj", "pj", 2, EM_PJ, 0, 0 },
- { "openrisc", "elf_openrisc", "openrisc", 8, EM_OPENRISC, 0, 0 },
- { "arc", "elf_arc_a5", "arc_a5", 6, EM_ARC_A5, 0, 0 },
- { "xtensa", "elf_xtensa", "xtensa", 6, EM_XTENSA, 0, 0 },
- { "aarch64", "elf_aarch64", "aarch64", 7, EM_AARCH64, ELFCLASS64, 0 },
+ { NULL, "elf_sh", "sh", 2, EM_SH, 0, 0 },
+ { NULL, "ebl_arm", "arm", 3, EM_ARM, 0, 0 },
+ { NULL, "elf_sparcv9", "sparc", 5, EM_SPARCV9, 0, 0 },
+ { NULL, "elf_sparc", "sparc", 5, EM_SPARC, 0, 0 },
+ { NULL, "elf_sparcv8plus", "sparc", 5, EM_SPARC32PLUS, 0, 0 },
+ { s390_init, "ebl_s390", "s390", 4, EM_S390, 0, 0 },
+
+ { NULL, "elf_m32", "m32", 3, EM_M32, 0, 0 },
+ { NULL, "elf_m68k", "m68k", 4, EM_68K, 0, 0 },
+ { NULL, "elf_m88k", "m88k", 4, EM_88K, 0, 0 },
+ { NULL, "elf_i860", "i860", 4, EM_860, 0, 0 },
+ { NULL, "ebl_s370", "s370", 4, EM_S370, 0, 0 },
+ { NULL, "elf_parisc", "parisc", 6, EM_PARISC, 0, 0 },
+ { NULL, "elf_vpp500", "vpp500", 5, EM_VPP500, 0, 0 },
+ { NULL, "elf_v8plus", "v8plus", 6, EM_SPARC32PLUS, 0, 0 },
+ { NULL, "elf_i960", "i960", 4, EM_960, 0, 0 },
+ { NULL, "ebl_v800", "v800", 4, EM_V800, 0, 0 },
+ { NULL, "ebl_fr20", "fr20", 4, EM_FR20, 0, 0 },
+ { NULL, "ebl_rh32", "rh32", 4, EM_RH32, 0, 0 },
+ { NULL, "ebl_rce", "rce", 3, EM_RCE, 0, 0 },
+ { NULL, "elf_tricore", "tricore", 7, EM_TRICORE, 0, 0 },
+ { NULL, "elf_arc", "arc", 3, EM_ARC, 0, 0 },
+ { NULL, "elf_h8_300", "h8_300", 6, EM_H8_300, 0, 0 },
+ { NULL, "elf_h8_300h", "h8_300h", 6, EM_H8_300H, 0, 0 },
+ { NULL, "elf_h8s", "h8s", 6, EM_H8S, 0, 0 },
+ { NULL, "elf_h8_500", "h8_500", 6, EM_H8_500, 0, 0 },
+ { NULL, "elf_coldfire", "coldfire", 8, EM_COLDFIRE, 0, 0 },
+ { NULL, "elf_68hc12", "68hc12", 6, EM_68HC12, 0, 0 },
+ { NULL, "elf_mma", "mma", 3, EM_MMA, 0, 0 },
+ { NULL, "elf_pcp", "pcp", 3, EM_PCP, 0, 0 },
+ { NULL, "elf_ncpu", "ncpu", 4, EM_NCPU, 0, 0 },
+ { NULL, "elf_ndr1", "ndr1", 4, EM_NDR1, 0, 0 },
+ { NULL, "elf_starcore", "starcore", 8, EM_STARCORE, 0, 0 },
+ { NULL, "elf_me16", "em16", 4, EM_ME16, 0, 0 },
+ { NULL, "elf_st100", "st100", 5, EM_ST100, 0, 0 },
+ { NULL, "elf_tinyj", "tinyj", 5, EM_TINYJ, 0, 0 },
+ { NULL, "elf_pdsp", "pdsp", 4, EM_PDSP, 0, 0 },
+ { NULL, "elf_fx66", "fx66", 4, EM_FX66, 0, 0 },
+ { NULL, "elf_st9plus", "st9plus", 7, EM_ST9PLUS, 0, 0 },
+ { NULL, "elf_st7", "st7", 3, EM_ST7, 0, 0 },
+ { NULL, "elf_68hc16", "68hc16", 6, EM_68HC16, 0, 0 },
+ { NULL, "elf_68hc11", "68hc11", 6, EM_68HC11, 0, 0 },
+ { NULL, "elf_68hc08", "68hc08", 6, EM_68HC08, 0, 0 },
+ { NULL, "elf_68hc05", "68hc05", 6, EM_68HC05, 0, 0 },
+ { NULL, "elf_svx", "svx", 3, EM_SVX, 0, 0 },
+ { NULL, "elf_st19", "st19", 4, EM_ST19, 0, 0 },
+ { NULL, "elf_vax", "vax", 3, EM_VAX, 0, 0 },
+ { NULL, "elf_cris", "cris", 4, EM_CRIS, 0, 0 },
+ { NULL, "elf_javelin", "javelin", 7, EM_JAVELIN, 0, 0 },
+ { NULL, "elf_firepath", "firepath", 8, EM_FIREPATH, 0, 0 },
+ { NULL, "elf_zsp", "zsp", 3, EM_ZSP, 0, 0 },
+ { NULL, "elf_mmix", "mmix", 4, EM_MMIX, 0, 0 },
+ { NULL, "elf_huany", "huany", 5, EM_HUANY, 0, 0 },
+ { NULL, "elf_prism", "prism", 5, EM_PRISM, 0, 0 },
+ { NULL, "elf_avr", "avr", 3, EM_AVR, 0, 0 },
+ { NULL, "elf_fr30", "fr30", 4, EM_FR30, 0, 0 },
+ { NULL, "elf_dv10", "dv10", 4, EM_D10V, 0, 0 },
+ { NULL, "elf_dv30", "dv30", 4, EM_D30V, 0, 0 },
+ { NULL, "elf_v850", "v850", 4, EM_V850, 0, 0 },
+ { NULL, "elf_m32r", "m32r", 4, EM_M32R, 0, 0 },
+ { NULL, "elf_mn10300", "mn10300", 7, EM_MN10300, 0, 0 },
+ { NULL, "elf_mn10200", "mn10200", 7, EM_MN10200, 0, 0 },
+ { NULL, "elf_pj", "pj", 2, EM_PJ, 0, 0 },
+ { NULL, "elf_openrisc", "openrisc", 8, EM_OPENRISC, 0, 0 },
+ { NULL, "elf_arc_a5", "arc_a5", 6, EM_ARC_A5, 0, 0 },
+ { NULL, "elf_xtensa", "xtensa", 6, EM_XTENSA, 0, 0 },
+ { aarch64_init, "elf_aarch64", "aarch64", 7, EM_AARCH64, ELFCLASS64, 0 },
};
#define nmachines (sizeof (machines) / sizeof (machines[0]))
@@ -319,42 +326,17 @@ openbackend (elf, emulation, machine)
#endif
#define ORIGINDIR "$ORIGIN/../$LIB/" LIBEBL_SUBDIR "/"
- /* Give it a try. At least the machine type matches. First
- try to load the module. */
- char dsoname[100];
- strcpy (stpcpy (stpcpy (dsoname, ORIGINDIR "libebl_"),
- machines[cnt].dsoname),
- ".so");
-
- void *h = dlopen (dsoname, RTLD_LAZY);
- if (h == NULL)
- {
- strcpy (stpcpy (stpcpy (dsoname, "libebl_"),
- machines[cnt].dsoname),
- ".so");
- h = dlopen (dsoname, RTLD_LAZY);
- }
-
- /* Try without an explicit path. */
- if (h != NULL)
+ ebl_bhinit_t initp = machines[cnt].initptr;
+ if (1)
{
- /* We managed to load the object. Now see whether the
- initialization function likes our file. */
static const char version[] = MODVERSION;
const char *modversion;
- ebl_bhinit_t initp;
- char symname[machines[cnt].prefix_len + sizeof "_init"];
-
- strcpy (mempcpy (symname, machines[cnt].prefix,
- machines[cnt].prefix_len), "_init");
-
- initp = (ebl_bhinit_t) dlsym (h, symname);
if (initp != NULL
&& (modversion = initp (elf, machine, result, sizeof (Ebl)))
&& strcmp (version, modversion) == 0)
{
/* We found a module to handle our file. */
- result->dlhandle = h;
+ result->dlhandle = NULL;
result->elf = elf;
/* A few entries are mandatory. */
@@ -363,9 +345,6 @@ openbackend (elf, emulation, machine)
return result;
}
-
- /* Not the module we need. */
- (void) dlclose (h);
}
/* We cannot find a DSO but the emulation/machine ID matches.