Build the libebl_* backends as static libraries instead of dynamic ones. 

openbackend was converted to use the statically linked init functions instead
of dynamically loading the libebl_*.so files.

In the .c files:
  dlhandle was removed from struct Ebl, since it's not needed any more.
  
  The solution with get_init_functions is a bit fragile vs. changes to the
  order of entires in machines[]. Directly adding the info to machines (via an
  additional struct member .init) doesn't work well however, since the *_init
  functions can't be used in the initializer (since they are no compiletime
  constant).
  
  I was thinking about a small script under debian/ (or inside of debian/rules)
  to check for such kind of stuff (and also for the consistency backends <->
  extern declaration in libebl).

In libebl/Makefile.am
  Two flavors are built, one ment to be compiled with -fPIC and one without that
  flag. We need both, because we need 2 libebl.a too. A non-PIC one to go into
  libebl-dev, and a PIC one for use in other elfutils shared libs.
  
  The _LIBADD stuff can't use the backend .a files directly, as they would end
  up as .a inside the .a. So it looks at the *backend*.a and manually includes
  those files.



Index: elfutils-0.123.mod/backends/Makefile.am
===================================================================
--- elfutils-0.123.mod.orig/backends/Makefile.am	2006-09-01 05:19:23.000000000 +0200
+++ elfutils-0.123.mod/backends/Makefile.am	2006-09-01 05:21:01.000000000 +0200
@@ -40,12 +40,10 @@
 
 
 modules = i386 sh x86_64 ia64 alpha arm sparc ppc ppc64 s390
-libebl_pic = libebl_i386_pic.a libebl_sh_pic.a libebl_x86_64_pic.a \
-	     libebl_ia64_pic.a libebl_alpha_pic.a libebl_arm_pic.a \
-	     libebl_sparc_pic.a libebl_ppc_pic.a libebl_ppc64_pic.a \
-	     libebl_s390_pic.a
-noinst_LIBRARIES = $(libebl_pic)
-noinst_DATA = $(libebl_pic:_pic.a=.so)
+libebl_pic = libebl_backend_pic.a
+libebl_nopic = libebl_backend_nopic.a
+
+noinst_LIBRARIES = $(libebl_pic) $(libebl_nopic)
 
 
 if MUDFLAP
@@ -58,87 +56,39 @@
 libmudflap =
 endif
 
-
-textrel_check = if readelf -d $@ | fgrep -q TEXTREL; then exit 1; fi
-
-libebl_%.so: libebl_%_pic.a libebl_%.map $(libelf) $(libdw)
-	$(LINK) -shared -o $@ -Wl,--whole-archive,$<,--no-whole-archive \
-		-Wl,--version-script,$(word 2,$^) \
-		-Wl,-z,defs $(LD_AS_NEEDED) $(libelf) $(libdw) $(libmudflap)
-	$(textrel_check)
-
-libebl_%.map: Makefile
-	echo 'ELFUTILS_$(PACKAGE_VERSION) { global: $*_init; local: *; };' > $@
-
-
 i386_SRCS = i386_init.c i386_symbol.c i386_corenote.c \
 	    i386_retval.c i386_regs.c
-libebl_i386_pic_a_SOURCES = $(i386_SRCS)
-am_libebl_i386_pic_a_OBJECTS = $(i386_SRCS:.c=.os)
-
 sh_SRCS = sh_init.c sh_symbol.c
-libebl_sh_pic_a_SOURCES = $(sh_SRCS)
-am_libebl_sh_pic_a_OBJECTS = $(sh_SRCS:.c=.os)
-
 x86_64_SRCS = x86_64_init.c x86_64_symbol.c x86_64_corenote.c \
 	      x86_64_retval.c x86_64_regs.c
-libebl_x86_64_pic_a_SOURCES = $(x86_64_SRCS)
-am_libebl_x86_64_pic_a_OBJECTS = $(x86_64_SRCS:.c=.os)
-
 ia64_SRCS = ia64_init.c ia64_symbol.c ia64_regs.c ia64_retval.c
-libebl_ia64_pic_a_SOURCES = $(ia64_SRCS)
-am_libebl_ia64_pic_a_OBJECTS = $(ia64_SRCS:.c=.os)
-
 alpha_SRCS = alpha_init.c alpha_symbol.c alpha_retval.c
-libebl_alpha_pic_a_SOURCES = $(alpha_SRCS)
-am_libebl_alpha_pic_a_OBJECTS = $(alpha_SRCS:.c=.os)
-
 arm_SRCS = arm_init.c arm_symbol.c
-libebl_arm_pic_a_SOURCES = $(arm_SRCS)
-am_libebl_arm_pic_a_OBJECTS = $(arm_SRCS:.c=.os)
-
 sparc_SRCS = sparc_init.c sparc_symbol.c sparc_regs.c
-libebl_sparc_pic_a_SOURCES = $(sparc_SRCS)
-am_libebl_sparc_pic_a_OBJECTS = $(sparc_SRCS:.c=.os)
-
 ppc_SRCS = ppc_init.c ppc_symbol.c ppc_retval.c ppc_regs.c
-libebl_ppc_pic_a_SOURCES = $(ppc_SRCS)
-am_libebl_ppc_pic_a_OBJECTS = $(ppc_SRCS:.c=.os)
-
 ppc64_SRCS = ppc64_init.c ppc64_symbol.c ppc64_retval.c ppc_regs.c
-libebl_ppc64_pic_a_SOURCES = $(ppc64_SRCS)
-am_libebl_ppc64_pic_a_OBJECTS = $(ppc64_SRCS:.c=.os)
-
 s390_SRCS = s390_init.c s390_symbol.c s390_regs.c s390_retval.c
-libebl_s390_pic_a_SOURCES = $(s390_SRCS)
-am_libebl_s390_pic_a_OBJECTS = $(s390_SRCS:.c=.os)
 
+all_SRCS = $(shell echo \
+	   $(i386_SRCS) $(sh_SRCS) $(x86_64_SRCS) $(ia64_SRCS) $(alpha_SRCS) \
+	   $(arm_SRCS) $(sparc_SRCS) $(ppc_SRCS) $(ppc64_SRCS) $(s390_SRCS) \
+	   | tr -s ' ' '\n' | sort -u)
+
+libebl_backend_pic_a_SOURCES = $(all_SRCS)
+am_libebl_backend_pic_a_OBJECTS = $(all_SRCS:.c=.os)
 
-%.os: %.c
+libebl_backend_nopic_a_SOURCES = $(all_SRCS)
+am_libebl_backend_nopic_a_OBJECTS = $(all_SRCS:.c=.o)
+
+%.os: %.c %.o
 	if $(COMPILE) -c -o $@ -fpic -DPIC -DSHARED -MT $@ -MD -MP \
 	  -MF "$(DEPDIR)/$*.Tpo" `test -f '$<' || echo '$(srcdir)/'`$<; \
 	then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; \
 	else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
 	fi
 
-install: install-am install-ebl-modules
-install-ebl-modules:
-	$(mkinstalldirs) $(DESTDIR)$(libdir)/$(LIBEBL_SUBDIR)
-	for m in $(modules); do \
-	  $(INSTALL_PROGRAM) libebl_$${m}.so $(DESTDIR)$(libdir)/$(LIBEBL_SUBDIR)/libebl_$${m}-$(PACKAGE_VERSION).so; \
-	  ln -fs libebl_$${m}-$(PACKAGE_VERSION).so $(DESTDIR)$(libdir)/$(LIBEBL_SUBDIR)/libebl_$${m}.so; \
-	done
-
-uninstall: uninstall-am
-	for m in $(modules); do \
-	  rm -f $(DESTDIR)$(libdir)/$(LIBEBL_SUBDIR)/libebl_$${m}-$(PACKAGE_VERSION).so; \
-	  rm -f $(DESTDIR)$(libdir)/$(LIBEBL_SUBDIR)/libebl_$${m}.so; \
-	done
-	rmdir --ignore-fail-on-non-empty $(DESTDIR)$(libdir)/$(LIBEBL_SUBDIR)
-
 noinst_HEADERS = libebl_CPU.h common-reloc.c
 EXTRA_DIST = $(foreach m,$(modules),$($(m)_SRCS)) $(modules:=_reloc.def)
 
-CLEANFILES = *.gcno *.gcda \
-	     $(foreach m,$(modules),\
-		       libebl_$(m).so $(am_libebl_$(m)_pic_a_OBJECTS))
+CLEANFILES = *.gcno *.gcda $(am_libebl_backend_nopic_a_OBJECTS) \
+	     $(am_libebl_backend_pic_a_OBJECTS)
Index: elfutils-0.123.mod/Makefile.am
===================================================================
--- elfutils-0.123.mod.orig/Makefile.am	2006-09-01 05:18:05.000000000 +0200
+++ elfutils-0.123.mod/Makefile.am	2006-09-01 05:19:24.000000000 +0200
@@ -29,7 +29,7 @@
 
 mini_SUBDIRS = config m4 lib libelf libelf-po
 # Add doc back when we have some real content.
-all_SUBDIRS = libebl libdwfl libdw libcpu libasm backends src po tests
+all_SUBDIRS = backends libebl libdwfl libdw libcpu libasm src po tests
 SUBDIRS = $(mini_SUBDIRS) $(all_SUBDIRS)
 
 EXTRA_DIST = elfutils.spec GPG-KEY NOTES
Index: elfutils-0.123.mod/libebl/Makefile.am
===================================================================
--- elfutils-0.123.mod.orig/libebl/Makefile.am	2006-09-01 05:19:23.000000000 +0200
+++ elfutils-0.123.mod/libebl/Makefile.am	2006-09-01 05:21:01.000000000 +0200
@@ -40,7 +40,7 @@
 PACKAGE_VERSION = @PACKAGE_VERSION@
 LIBEBL_SUBDIR = @LIBEBL_SUBDIR@
 
-lib_LIBRARIES = libebl.a
+noinst_LIBRARIES = libebl.a libebl_nopic.a
 
 pkginclude_HEADERS = libebl.h
 
@@ -61,6 +61,14 @@
 	      eblsysvhashentrysize.c
 
 libebl_a_SOURCES = $(gen_SOURCES)
+am_libebl_a_OBJECTS = $(gen_SOURCES:.c=.os)
+libebl_libadd_pic = $(shell ar t $(top_srcdir)/backends/libebl_backend_pic.a)
+libebl_a_LIBADD = $(foreach file,$(libebl_libadd_pic),$(top_srcdir)/backends/$(file))
+
+libebl_nopic_a_SOURCES = $(gen_SOURCES)
+am_libebl_nopic_a_OBJECTS = $(gen_SOURCES:.c=.o)
+libebl_libadd_nopic = $(shell ar t $(top_srcdir)/backends/libebl_backend_nopic.a)
+libebl_nopic_a_LIBADD = $(foreach file,$(libebl_libadd_nopic),$(top_srcdir)/backends/$(file))
 
 
 %.os: %.c %.o
@@ -71,6 +79,14 @@
 	else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
 	fi
 
+install: install-am
+	$(mkinstalldirs) $(DESTDIR)$(libdir)
+	$(INSTALL_PROGRAM) libebl_nopic.a $(DESTDIR)$(libdir)/libebl.a
+
+uninstall: uninstall-am
+	rm -f $(DESTDIR)$(libdir)/libebl.a
+	rmdir --ignore-fail-on-non-empty $(DESTDIR)$(libdir)
+
 noinst_HEADERS = libeblP.h ebl-hooks.h
 
-CLEANFILES = $(am_libebl_pic_a_OBJECTS) *.gcno *.gcda
+CLEANFILES = $(am_libebl_a_OBJECTS) $(am_libebl_pic_a_OBJECTS) *.gcno *.gcda
Index: elfutils-0.123.mod/libebl/eblclosebackend.c
===================================================================
--- elfutils-0.123.mod.orig/libebl/eblclosebackend.c	2006-09-01 05:18:05.000000000 +0200
+++ elfutils-0.123.mod/libebl/eblclosebackend.c	2006-09-01 05:19:24.000000000 +0200
@@ -65,10 +65,6 @@
       /* Run the destructor.  */
       ebl->destr (ebl);
 
-      /* Close the dynamically loaded object.  */
-      if (ebl->dlhandle != NULL)
-	(void) dlclose (ebl->dlhandle);
-
       /* Free the resources.  */
       free (ebl);
     }
Index: elfutils-0.123.mod/libebl/eblopenbackend.c
===================================================================
--- elfutils-0.123.mod.orig/libebl/eblopenbackend.c	2006-09-01 05:18:05.000000000 +0200
+++ elfutils-0.123.mod/libebl/eblopenbackend.c	2006-09-01 05:33:45.000000000 +0200
@@ -61,6 +61,20 @@
 
 #include <libeblP.h>
 
+enum ebl_backend_type {
+    EBL_i386 = 1,
+    EBL_ia64,
+    EBL_alpha,
+    EBL_x86_64,
+    EBL_ppc,
+    EBL_ppc64,
+    EBL_sh,
+    EBL_arm,
+    EBL_sparc,
+    EBL_s390,
+    EBL_mips,
+    EBL_parisc,
+};
 
 /* This table should contain the complete list of architectures as far
    as the ELF specification is concerned.  */
@@ -68,7 +82,7 @@
    arrays to avoid relocations.  */
 static const struct
 {
-  const char *dsoname;
+  enum ebl_backend_type backend;
   const char *emulation;
   const char *prefix;
   int prefix_len;
@@ -77,79 +91,79 @@
   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 },
+  { EBL_i386, "elf_i386", "i386", 4, EM_386, ELFCLASS32, ELFDATA2LSB },
+  { EBL_ia64, "elf_ia64", "ia64", 4, EM_IA_64, ELFCLASS64, ELFDATA2LSB },
+  { EBL_alpha, "elf_alpha", "alpha", 5, EM_ALPHA, ELFCLASS64, ELFDATA2LSB },
+  { EBL_x86_64, "elf_x86_64", "x86_64", 6, EM_X86_64, ELFCLASS64, ELFDATA2LSB },
+  { EBL_ppc, "elf_ppc", "ppc", 3, EM_PPC, ELFCLASS32, ELFDATA2MSB },
+  { EBL_ppc64, "elf_ppc64", "ppc64", 5, EM_PPC64, ELFCLASS64, ELFDATA2MSB },
   // 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 },
+  { EBL_sh, "elf_sh", "sh", 2, EM_SH, 0, 0 },
+  { EBL_arm, "ebl_arm", "arm", 3, EM_ARM, 0, 0 },
+  { EBL_sparc, "elf_sparcv9", "sparc", 5, EM_SPARCV9, 0, 0 },
+  { EBL_sparc, "elf_sparc", "sparc", 5, EM_SPARC, 0, 0 },
+  { EBL_sparc, "elf_sparcv8plus", "sparc", 5, EM_SPARC32PLUS, 0, 0 },
+  { EBL_s390, "ebl_s390", "s390", 4, EM_S390, 0, 0 },
+
+  { 0, "elf_m32", "m32", 3, EM_M32, 0, 0 },
+  { 0, "elf_m68k", "m68k", 4, EM_68K, 0, 0 },
+  { 0, "elf_m88k", "m88k", 4, EM_88K, 0, 0 },
+  { 0, "elf_i860", "i860", 4, EM_860, 0, 0 },
+  { 0, "ebl_s370", "s370", 4, EM_S370, 0, 0 },
+  { EBL_parisc, "elf_parisc", "parisc", 6, EM_PARISC, 0, 0 },
+  { 0, "elf_vpp500", "vpp500", 5, EM_VPP500, 0, 0 },
+  { EBL_sparc, "elf_v8plus", "v8plus", 6, EM_SPARC32PLUS, 0, 0 },
+  { 0, "elf_i960", "i960", 4, EM_960, 0, 0 },
+  { 0, "ebl_v800", "v800", 4, EM_V800, 0, 0 },
+  { 0, "ebl_fr20", "fr20", 4, EM_FR20, 0, 0 },
+  { 0, "ebl_rh32", "rh32", 4, EM_RH32, 0, 0 },
+  { 0, "ebl_rce", "rce", 3, EM_RCE, 0, 0 },
+  { 0, "elf_tricore", "tricore", 7, EM_TRICORE, 0, 0 },
+  { 0, "elf_arc", "arc", 3, EM_ARC, 0, 0 },
+  { 0, "elf_h8_300", "h8_300", 6, EM_H8_300, 0, 0 },
+  { 0, "elf_h8_300h", "h8_300h", 6, EM_H8_300H, 0, 0 },
+  { 0, "elf_h8s", "h8s", 6, EM_H8S, 0, 0 },
+  { 0, "elf_h8_500", "h8_500", 6, EM_H8_500, 0, 0 },
+  { 0, "elf_coldfire", "coldfire", 8, EM_COLDFIRE, 0, 0 },
+  { 0, "elf_68hc12", "68hc12", 6, EM_68HC12, 0, 0 },
+  { 0, "elf_mma", "mma", 3, EM_MMA, 0, 0 },
+  { 0, "elf_pcp", "pcp", 3, EM_PCP, 0, 0 },
+  { 0, "elf_ncpu", "ncpu", 4, EM_NCPU, 0, 0 },
+  { 0, "elf_ndr1", "ndr1", 4, EM_NDR1, 0, 0 },
+  { 0, "elf_starcore", "starcore", 8, EM_STARCORE, 0, 0 },
+  { 0, "elf_me16", "em16", 4, EM_ME16, 0, 0 },
+  { 0, "elf_st100", "st100", 5, EM_ST100, 0, 0 },
+  { 0, "elf_tinyj", "tinyj", 5, EM_TINYJ, 0, 0 },
+  { 0, "elf_pdsp", "pdsp", 4, EM_PDSP, 0, 0 },
+  { 0, "elf_fx66", "fx66", 4, EM_FX66, 0, 0 },
+  { 0, "elf_st9plus", "st9plus", 7, EM_ST9PLUS, 0, 0 },
+  { 0, "elf_st7", "st7", 3, EM_ST7, 0, 0 },
+  { 0, "elf_68hc16", "68hc16", 6, EM_68HC16, 0, 0 },
+  { 0, "elf_68hc11", "68hc11", 6, EM_68HC11, 0, 0 },
+  { 0, "elf_68hc08", "68hc08", 6, EM_68HC08, 0, 0 },
+  { 0, "elf_68hc05", "68hc05", 6, EM_68HC05, 0, 0 },
+  { 0, "elf_svx", "svx", 3, EM_SVX, 0, 0 },
+  { 0, "elf_st19", "st19", 4, EM_ST19, 0, 0 },
+  { 0, "elf_vax", "vax", 3, EM_VAX, 0, 0 },
+  { 0, "elf_cris", "cris", 4, EM_CRIS, 0, 0 },
+  { 0, "elf_javelin", "javelin", 7, EM_JAVELIN, 0, 0 },
+  { 0, "elf_firepath", "firepath", 8, EM_FIREPATH, 0, 0 },
+  { 0, "elf_zsp", "zsp", 3, EM_ZSP, 0, 0 },
+  { 0, "elf_mmix", "mmix", 4, EM_MMIX, 0, 0 },
+  { 0, "elf_huany", "huany", 5, EM_HUANY, 0, 0 },
+  { 0, "elf_prism", "prism", 5, EM_PRISM, 0, 0 },
+  { 0, "elf_avr", "avr", 3, EM_AVR, 0, 0 },
+  { 0, "elf_fr30", "fr30", 4, EM_FR30, 0, 0 },
+  { 0, "elf_dv10", "dv10", 4, EM_D10V, 0, 0 },
+  { 0, "elf_dv30", "dv30", 4, EM_D30V, 0, 0 },
+  { 0, "elf_v850", "v850", 4, EM_V850, 0, 0 },
+  { 0, "elf_m32r", "m32r", 4, EM_M32R, 0, 0 },
+  { 0, "elf_mn10300", "mn10300", 7, EM_MN10300, 0, 0 },
+  { 0, "elf_mn10200", "mn10200", 7, EM_MN10200, 0, 0 },
+  { 0, "elf_pj", "pj", 2, EM_PJ, 0, 0 },
+  { 0, "elf_openrisc", "openrisc", 8, EM_OPENRISC, 0, 0 },
+  { 0, "elf_arc_a5", "arc_a5", 6, EM_ARC_A5, 0, 0 },
+  { 0, "elf_xtensa", "xtensa", 6, EM_XTENSA, 0, 0 },
 };
 #define nmachines (sizeof (machines) / sizeof (machines[0]))
 
@@ -241,6 +255,28 @@
   result->sysvhash_entrysize = sizeof (Elf32_Word);
 }
 
+typedef const char *(fn_bhinit_t) (Elf *, GElf_Half, Ebl *, size_t);
+extern fn_bhinit_t i386_init, ia64_init, alpha_init, x86_64_init, ppc_init,
+        ppc64_init, sh_init, arm_init, sparc_init, s390_init;
+
+static ebl_bhinit_t
+get_init_function(cnt)
+    size_t cnt;
+{
+  switch(machines[cnt].backend) {
+      case EBL_i386: return i386_init;
+      case EBL_ia64: return ia64_init;
+      case EBL_alpha: return alpha_init;
+      case EBL_x86_64: return x86_64_init;
+      case EBL_ppc: return ppc_init;
+      case EBL_ppc64: return ppc64_init;
+      case EBL_sh: return sh_init;
+      case EBL_arm: return arm_init;
+      case EBL_sparc: return sparc_init;
+      case EBL_s390: return s390_init;
+      default: return (ebl_bhinit_t) NULL;
+  }
+}
 
 /* Find an appropriate backend for the file associated with ELF.  */
 static Ebl *
@@ -306,63 +342,28 @@
 	    result->data = elf->state.elf32.ehdr->e_ident[EI_DATA];
 	  }
 
-#ifndef LIBEBL_SUBDIR
-# define LIBEBL_SUBDIR PACKAGE
-#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 the init function */
+        static const char version[] = MODVERSION;
+        const char *modversion;
+        ebl_bhinit_t initp;
+
+        initp = get_init_function(cnt);
+        if (initp != NULL
+            && (modversion = initp (elf, machine, result, sizeof (Ebl)))
+            && strcmp (version, modversion) == 0)
+          {
+            /* We found a module to handle our file.  */
+            result->elf = elf;
+
+            /* A few entries are mandatory.  */
+            assert (result->name != NULL);
+            assert (result->destr != NULL);
 
-	  /* Try without an explicit path.  */
-	if (h != NULL)
-	  {
-	    /* 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->elf = elf;
-
-		/* A few entries are mandatory.  */
-		assert (result->name != NULL);
-		assert (result->destr != NULL);
-
-		return result;
-	      }
-
-	    /* Not the module we need.  */
-	    (void) dlclose (h);
-	  }
+            return result;
+          }
 
 	/* We cannot find a DSO but the emulation/machine ID matches.
 	   Return that information.  */
-	result->dlhandle = NULL;
 	result->elf = elf;
 	result->name = machines[cnt].prefix;
 	fill_defaults (result);
@@ -371,7 +372,6 @@
       }
 
   /* Nothing matched.  We use only the default callbacks.   */
-  result->dlhandle = NULL;
   result->elf = elf;
   result->emulation = "<unknown>";
   result->name = "<unknown>";
Index: elfutils-0.123.mod/libebl/libeblP.h
===================================================================
--- elfutils-0.123.mod.orig/libebl/libeblP.h	2006-09-01 05:18:05.000000000 +0200
+++ elfutils-0.123.mod/libebl/libeblP.h	2006-09-01 05:19:24.000000000 +0200
@@ -80,8 +80,6 @@
   /* Size of entry in Sysv-style hash table.  */
   int sysvhash_entrysize;
 
-  /* Internal data.  */
-  void *dlhandle;
 };
 
 
Index: elfutils-0.123.mod/src/Makefile.am
===================================================================
--- elfutils-0.123.mod.orig/src/Makefile.am	2006-09-01 05:19:23.000000000 +0200
+++ elfutils-0.123.mod/src/Makefile.am	2006-09-01 05:21:01.000000000 +0200
@@ -106,18 +106,18 @@
 readelf_LDADD = $(libdw) $(libebl) $(libelf) $(libeu) $(libmudflap) -ldl
 nm_LDADD = $(libdw) $(libebl) $(libelf) $(libeu) $(libmudflap) -ldl
 size_LDADD = $(libelf) $(libeu) $(libmudflap)
-strip_LDADD = $(libebl) $(libelf) $(libeu) $(libmudflap) -ldl
-ld_LDADD = $(libebl) $(libelf) $(libeu) $(libmudflap) -ldl
+strip_LDADD = $(libdw) $(libebl) $(libelf) $(libeu) $(libmudflap) -ldl
+ld_LDADD = $(libdw) $(libebl) $(libelf) $(libeu) $(libmudflap) -ldl
 if NATIVE_LD
 # -ldl is always needed for libebl.
 ld_LDADD += libld_elf.a
 endif
 ld_LDFLAGS = -rdynamic
-elflint_LDADD  = $(libebl) $(libelf) $(libeu) $(libmudflap) -ldl
+elflint_LDADD  = $(libdw) $(libebl) $(libelf) $(libeu) $(libmudflap) -ldl
 findtextrel_LDADD = $(libdw) $(libelf) $(libmudflap)
 addr2line_LDADD = $(libdw) $(libmudflap)
-elfcmp_LDADD = $(libebl) $(libelf) $(libmudflap) -ldl
-objdump_LDADD  = $(libebl) $(libelf) $(libeu) $(libmudflap) -ldl
+elfcmp_LDADD = $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl
+objdump_LDADD  = $(libdw) $(libebl) $(libelf) $(libeu) $(libmudflap) -ldl
 ranlib_LDADD = $(libelf) $(libeu) $(libmudflap)
 strings_LDADD = $(libelf) $(libeu) $(libmudflap)
 
Index: elfutils-0.123.mod/tests/Makefile.am
===================================================================
--- elfutils-0.123.mod.orig/tests/Makefile.am	2006-09-01 05:19:23.000000000 +0200
+++ elfutils-0.123.mod/tests/Makefile.am	2006-09-01 05:19:24.000000000 +0200
@@ -187,15 +187,15 @@
 allregs_LDADD = $(libdw) $(libmudflap)
 find_prologues_LDADD = $(libdw) $(libmudflap)
 #show_ciefde_LDADD = ../libdwarf/libdwarf.so $(libelf) $(libmudflap)
-asm_tst1_LDADD = $(libasm) $(libebl) $(libelf) $(libmudflap) -ldl
-asm_tst2_LDADD = $(libasm) $(libebl) $(libelf) $(libmudflap) -ldl
-asm_tst3_LDADD = $(libasm) $(libebl) $(libelf) $(libmudflap) -ldl
-asm_tst4_LDADD = $(libasm) $(libebl) $(libelf) $(libmudflap) -ldl
-asm_tst5_LDADD = $(libasm) $(libebl) $(libelf) $(libmudflap) -ldl
-asm_tst6_LDADD = $(libasm) $(libebl) $(libelf) $(libmudflap) -ldl
-asm_tst7_LDADD = $(libasm) $(libebl) $(libelf) $(libmudflap) -ldl
-asm_tst8_LDADD = $(libasm) $(libebl) $(libelf) $(libmudflap) -ldl
-asm_tst9_LDADD = $(libasm) $(libebl) $(libelf) $(libmudflap) -ldl
+asm_tst1_LDADD = $(libasm) $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl
+asm_tst2_LDADD = $(libasm) $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl
+asm_tst3_LDADD = $(libasm) $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl
+asm_tst4_LDADD = $(libasm) $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl
+asm_tst5_LDADD = $(libasm) $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl
+asm_tst6_LDADD = $(libasm) $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl
+asm_tst7_LDADD = $(libasm) $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl
+asm_tst8_LDADD = $(libasm) $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl
+asm_tst9_LDADD = $(libasm) $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl
 dwflmodtest_LDADD = $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl
 rdwrmmap_LDADD = $(libelf)
 

