public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 4/5] Don't use dlopen() for libebl modules
  2019-07-06  0:35 [PATCH 0/5] elfutils: don't use dlopen() for libebl modules Omar Sandoval
  2019-07-06  0:35 ` [PATCH 5/5] libdw: export libebl symbols Omar Sandoval
@ 2019-07-06  0:35 ` Omar Sandoval
  2019-07-06  0:35 ` [PATCH 2/5] libcpu: merge libcpu_{i386,x86_64,bpf} into one library Omar Sandoval
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Omar Sandoval @ 2019-07-06  0:35 UTC (permalink / raw)
  To: elfutils-devel

From: Omar Sandoval <osandov@fb.com>

Currently, architecture-specific code for libebl exists in separate
libebl_$ARCH.so libraries which libebl loads with dlopen() at runtime.
This makes it impossible to have standalone, statically-linked binaries
which use libdwfl if they depend on any architecture-specific
functionality. Additionally, when these libraries cannot be found, the
failure modes are non-obvious. So, let's get rid of libebl_$arch.so and
move it all into libdw.so/libdw.a, which simplifies things considerably.

Signed-off-by: Omar Sandoval <osandov@fb.com>
---
 ChangeLog                |   6 +
 Makefile.am              |   4 +-
 backends/ChangeLog       |   1 +
 backends/Makefile.am     |  98 +++-----------
 configure.ac             |  12 +-
 libdw/ChangeLog          |   4 +
 libdw/Makefile.am        |  21 ++-
 libebl/ChangeLog         |   6 +
 libebl/Makefile.am       |   1 -
 libebl/eblclosebackend.c |   4 -
 libebl/eblopenbackend.c  | 267 +++++++++++++++------------------------
 libebl/libebl.h          |   8 +-
 libebl/libeblP.h         |   3 -
 src/ChangeLog            |   7 +
 src/Makefile.am          |  20 +--
 tests/ChangeLog          |   5 +
 tests/Makefile.am        |  36 +++---
 tests/test-subr.sh       |   4 +-
 18 files changed, 200 insertions(+), 307 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5c45cccf..49e7c858 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2017-07-05  Omar Sandoval  <osandov@fb.com>
+
+	* configure.ac: Get rid of --enable-libebl-subdir.
+	* Makefile.am (SUBDIRS): Reorder backends and libcpu before libebl to
+	satisfy build dependencies.
+
 2019-02-14  Mark Wielaard  <mark@klomp.org>
 
 	* configure.ac: Set version to 0.176.
diff --git a/Makefile.am b/Makefile.am
index 2ff444e7..51f54552 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -27,8 +27,8 @@ AM_MAKEFLAGS = --no-print-directory
 pkginclude_HEADERS = version.h
 
 # Add doc back when we have some real content.
-SUBDIRS = config m4 lib libelf libebl libdwelf libdwfl libdw libcpu libasm \
-	  backends src po tests
+SUBDIRS = config m4 lib libelf libcpu backends libebl libdwelf libdwfl libdw \
+	  libasm src po tests
 
 EXTRA_DIST = elfutils.spec GPG-KEY NOTES CONTRIBUTING \
 	     COPYING COPYING-GPLV2 COPYING-LGPLV3
diff --git a/backends/ChangeLog b/backends/ChangeLog
index d631417f..f104e8ec 100644
--- a/backends/ChangeLog
+++ b/backends/ChangeLog
@@ -2,6 +2,7 @@
 
 	* Makefile.am: Replace libcpu_{i386,x86_64,bpf}.a with libcpu.a.
 	Replace libcpu.a with libcpu_pic.a.
+	Combine libebl_CPU.so modules into libebl_backends{,_pic}.a.
 
 2019-04-14  Mark Wielaard  <mark@klomp.org>
 
diff --git a/backends/Makefile.am b/backends/Makefile.am
index d1275206..f0ecc405 100644
--- a/backends/Makefile.am
+++ b/backends/Makefile.am
@@ -28,95 +28,60 @@
 ## the GNU Lesser General Public License along with this program.  If
 ## not, see <http://www.gnu.org/licenses/>.
 include $(top_srcdir)/config/eu.am
+if BUILD_STATIC
+AM_CFLAGS += $(fpic_CFLAGS)
+endif
 AM_CPPFLAGS += -I$(top_srcdir)/libebl -I$(top_srcdir)/libasm \
 	   -I$(top_srcdir)/libelf -I$(top_srcdir)/libdw
 
+noinst_LIBRARIES = libebl_backends.a libebl_backends_pic.a
 
 modules = i386 sh x86_64 ia64 alpha arm aarch64 sparc ppc ppc64 s390 \
 	  tilegx m68k bpf riscv
-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_aarch64_pic.a libebl_sparc_pic.a libebl_ppc_pic.a \
-	     libebl_ppc64_pic.a libebl_s390_pic.a libebl_tilegx_pic.a \
-	     libebl_m68k_pic.a libebl_bpf_pic.a libebl_riscv_pic.a
-noinst_LIBRARIES = $(libebl_pic)
-noinst_DATA = $(libebl_pic:_pic.a=.so)
-
-
-libcpu = ../libcpu/libcpu_pic.a
-libelf = ../libelf/libelf.so
-libdw = ../libdw/libdw.so
-libeu = ../lib/libeu.a
 
 i386_SRCS = i386_init.c i386_symbol.c i386_corenote.c i386_cfi.c \
 	    i386_retval.c i386_regs.c i386_auxv.c i386_syscall.c \
 	    i386_initreg.c i386_unwind.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 sh_corenote.c sh_regs.c sh_retval.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_cfi.c \
-	      x86_64_retval.c x86_64_regs.c i386_auxv.c x86_64_syscall.c \
-	      x86_64_initreg.c x86_64_unwind.c x32_corenote.c
-libebl_x86_64_pic_a_SOURCES = $(x86_64_SRCS)
-am_libebl_x86_64_pic_a_OBJECTS = $(x86_64_SRCS:.c=.os)
+	      x86_64_retval.c x86_64_regs.c x86_64_syscall.c x86_64_initreg.c \
+	      x86_64_unwind.c x32_corenote.c
+
 
 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 alpha_regs.c \
 	     alpha_corenote.c alpha_auxv.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 arm_regs.c arm_corenote.c \
 	   arm_auxv.c arm_attrs.c arm_retval.c arm_cfi.c arm_initreg.c
-libebl_arm_pic_a_SOURCES = $(arm_SRCS)
-am_libebl_arm_pic_a_OBJECTS = $(arm_SRCS:.c=.os)
 
 aarch64_SRCS = aarch64_init.c aarch64_regs.c aarch64_symbol.c	\
 	       aarch64_corenote.c aarch64_retval.c aarch64_cfi.c \
 	       aarch64_initreg.c aarch64_unwind.c
-libebl_aarch64_pic_a_SOURCES = $(aarch64_SRCS)
-am_libebl_aarch64_pic_a_OBJECTS = $(aarch64_SRCS:.c=.os)
 
 sparc_SRCS = sparc_init.c sparc_symbol.c sparc_regs.c sparc_retval.c \
 	     sparc_corenote.c sparc64_corenote.c sparc_auxv.c sparc_attrs.c \
              sparc_cfi.c sparc_initreg.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 \
 	   ppc_corenote.c ppc_auxv.c ppc_attrs.c ppc_syscall.c \
 	   ppc_cfi.c ppc_initreg.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 \
-	     ppc64_corenote.c ppc_regs.c ppc_auxv.c ppc_attrs.c ppc_syscall.c \
-	     ppc_cfi.c ppc_initreg.c ppc64_unwind.c ppc64_resolve_sym.c
-libebl_ppc64_pic_a_SOURCES = $(ppc64_SRCS)
-am_libebl_ppc64_pic_a_OBJECTS = $(ppc64_SRCS:.c=.os)
+ppc64_SRCS = ppc64_init.c ppc64_symbol.c ppc64_retval.c ppc64_corenote.c \
+	     ppc64_unwind.c ppc64_resolve_sym.c
 
 s390_SRCS = s390_init.c s390_symbol.c s390_regs.c s390_retval.c \
 	    s390_corenote.c s390x_corenote.c s390_cfi.c s390_initreg.c \
 	    s390_unwind.c
-libebl_s390_pic_a_SOURCES = $(s390_SRCS)
-am_libebl_s390_pic_a_OBJECTS = $(s390_SRCS:.c=.os)
 
 tilegx_SRCS = tilegx_init.c tilegx_symbol.c tilegx_regs.c \
               tilegx_retval.c tilegx_corenote.c
-libebl_tilegx_pic_a_SOURCES = $(tilegx_SRCS)
-am_libebl_tilegx_pic_a_OBJECTS = $(tilegx_SRCS:.c=.os)
 
 m68k_SRCS = m68k_init.c m68k_symbol.c m68k_regs.c \
 	    m68k_retval.c m68k_corenote.c m68k_cfi.c m68k_initreg.c
-libebl_m68k_pic_a_SOURCES = $(m68k_SRCS)
-am_libebl_m68k_pic_a_OBJECTS = $(m68k_SRCS:.c=.os)
 
 # m68k prstatus core notes are described by a packed structure
 # which has not naturally aligned fields. Since we don't access
@@ -126,43 +91,20 @@ am_libebl_m68k_pic_a_OBJECTS = $(m68k_SRCS:.c=.os)
 m68k_corenote_no_Wpacked_not_aligned = yes
 
 bpf_SRCS = bpf_init.c bpf_regs.c bpf_symbol.c
-libebl_bpf_pic_a_SOURCES = $(bpf_SRCS)
-am_libebl_bpf_pic_a_OBJECTS = $(bpf_SRCS:.c=.os)
 
 riscv_SRCS = riscv_init.c riscv_symbol.c riscv_cfi.c riscv_regs.c \
 	     riscv_initreg.c riscv_corenote.c riscv64_corenote.c riscv_retval.c
-libebl_riscv_pic_a_SOURCES = $(riscv_SRCS)
-am_libebl_riscv_pic_a_OBJECTS = $(riscv_SRCS:.c=.os)
-
-
-libebl_%.so libebl_%.map: libebl_%_pic.a $(libcpu) $(libelf) $(libdw) $(libeu)
-	@rm -f $(@:.so=.map)
-	$(AM_V_at)echo 'ELFUTILS_$(PACKAGE_VERSION) { global: $*_init; local: *; };' \
-	  > $(@:.so=.map)
-	$(AM_V_CCLD)$(LINK) $(dso_LDFLAGS) -o $(@:.map=.so) \
-		-Wl,--whole-archive $< $(libcpu) -Wl,--no-whole-archive \
-		-Wl,--version-script,$(@:.so=.map),--no-undefined \
-		-Wl,--as-needed $(libelf) $(libdw) $(libeu)
-	@$(textrel_check)
-
-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)
+
+libebl_backends_a_SOURCES = $(i386_SRCS) $(sh_SRCS) $(x86_64_SRCS) \
+			    $(ia64_SRCS) $(alpha_SRCS) $(arm_SRCS) \
+			    $(aarch64_SRCS) $(sparc_SRCS) $(ppc_SRCS) \
+			    $(ppc64_SRCS) $(s390_SRCS) $(tilegx_SRCS) \
+			    $(m68k_SRCS) $(bpf_SRCS) $(riscv_SRCS)
+
+libebl_backends_pic_a_SOURCES =
+am_libebl_backends_pic_a_OBJECTS = $(libebl_backends_a_SOURCES:.c=.os)
 
 noinst_HEADERS = libebl_CPU.h common-reloc.c linux-core-note.c x86_corenote.c
-EXTRA_DIST = $(foreach m,$(modules),$($(m)_SRCS)) $(modules:=_reloc.def)
+EXTRA_DIST = $(modules:=_reloc.def)
 
-CLEANFILES += $(foreach m,$(modules),\
-			libebl_$(m).map libebl_$(m).so \
-			$(am_libebl_$(m)_pic_a_OBJECTS))
+MOSTLYCLEANFILES = $(am_libebl_backends_pic_a_OBJECTS)
diff --git a/configure.ac b/configure.ac
index b4e012de..72d7f126 100644
--- a/configure.ac
+++ b/configure.ac
@@ -336,15 +336,6 @@ AS_HELP_STRING([--enable-tests-rpath],[build $ORIGIN-using rpath into tests]),
 	       [tests_use_rpath=$enableval], [tests_use_rpath=no])
 AM_CONDITIONAL(TESTS_RPATH, test "$tests_use_rpath" = yes)
 
-LIBEBL_SUBDIR="$PACKAGE"
-AC_ARG_ENABLE([libebl-subdir],
-AS_HELP_STRING([--enable-libebl-subdir=DIR],
-[install libebl_CPU modules in $(libdir)/DIR]), [dnl
-LIBEBL_SUBDIR="$enable_libebl_subdir"])
-AC_SUBST([LIBEBL_SUBDIR])
-AC_DEFINE_UNQUOTED(LIBEBL_SUBDIR, "$LIBEBL_SUBDIR")
-AH_TEMPLATE([LIBEBL_SUBDIR], [$libdir subdirectory containing libebl modules.])
-
 dnl zlib is mandatory.
 save_LIBS="$LIBS"
 LIBS=
@@ -585,7 +576,7 @@ esac
 eu_version=$(( (eu_version + 999) / 1000 ))
 
 dnl Unique ID for this build.
-MODVERSION="Build for ${LIBEBL_SUBDIR} ${eu_version} ${ac_cv_build}"
+MODVERSION="Build for ${eu_version} ${ac_cv_build}"
 AC_SUBST([MODVERSION])
 AC_DEFINE_UNQUOTED(MODVERSION, "$MODVERSION")
 AH_TEMPLATE([MODVERSION], [Identifier for modules in the build.])
@@ -650,7 +641,6 @@ AC_MSG_NOTICE([
     Program prefix ("eu-" recommended) : ${program_prefix}
     Source code location               : ${srcdir}
     Maintainer mode                    : ${enable_maintainer_mode}
-    libebl modules subdirectory        : ${LIBEBL_SUBDIR}
     build arch                         : ${ac_cv_build}
 
   RECOMMENDED FEATURES (should all be yes)
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index f9bbeee1..4e088688 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,6 +1,10 @@
 2019-07-05  Omar Sandoval  <osandov@fb.com>
 
 	* Makefile.am (libdw_so_LIBS): Replace libebl.a with libebl_pic.a.
+	Move libebl_pic.a to the beginning so that libdw symbols are resolved.
+	(libdw_so_LDLIBS): Remove -ldl.
+	(libdw.so): Remove -rpath.
+	(libdw_a_LIBADD): Add libebl, libebl_backends, and libcpu objects.
 
 2019-05-16  Mark Wielaard  <mark@klomp.org>
 
diff --git a/libdw/Makefile.am b/libdw/Makefile.am
index 7dc4cec0..274571c3 100644
--- a/libdw/Makefile.am
+++ b/libdw/Makefile.am
@@ -105,17 +105,15 @@ endif
 libdw_pic_a_SOURCES =
 am_libdw_pic_a_OBJECTS = $(libdw_a_SOURCES:.c=.os)
 
-libdw_so_LIBS = libdw_pic.a ../libdwelf/libdwelf_pic.a \
-	  ../libdwfl/libdwfl_pic.a ../libebl/libebl_pic.a
+libdw_so_LIBS = ../libebl/libebl_pic.a ../backends/libebl_backends_pic.a \
+		../libcpu/libcpu_pic.a libdw_pic.a ../libdwelf/libdwelf_pic.a \
+		../libdwfl/libdwfl_pic.a
 libdw_so_DEPS = ../lib/libeu.a ../libelf/libelf.so
-libdw_so_LDLIBS = $(libdw_so_DEPS) -ldl -lz $(argp_LDADD) $(zip_LIBS)
+libdw_so_LDLIBS = $(libdw_so_DEPS) -lz $(argp_LDADD) $(zip_LIBS)
 libdw_so_SOURCES =
 libdw.so$(EXEEXT): $(srcdir)/libdw.map $(libdw_so_LIBS) $(libdw_so_DEPS)
-# The rpath is necessary for libebl because its $ORIGIN use will
-# not fly in a setuid executable that links in libdw.
 	$(AM_V_CCLD)$(LINK) $(dso_LDFLAGS) -o $@ \
-		-Wl,--soname,$@.$(VERSION) \
-		-Wl,--enable-new-dtags,-rpath,$(pkglibdir) \
+		-Wl,--soname,$@.$(VERSION),--enable-new-dtags \
 		-Wl,--version-script,$<,--no-undefined \
 		-Wl,--whole-archive $(libdw_so_LIBS) -Wl,--no-whole-archive \
 		$(libdw_so_LDLIBS)
@@ -140,6 +138,15 @@ libdw_a_LIBADD = $(addprefix ../libdwfl/,$(libdwfl_objects))
 libdwelf_objects = $(shell $(AR) t ../libdwelf/libdwelf.a)
 libdw_a_LIBADD += $(addprefix ../libdwelf/,$(libdwelf_objects))
 
+libebl_objects = $(shell $(AR) t ../libebl/libebl.a)
+libdw_a_LIBADD += $(addprefix ../libebl/,$(libebl_objects))
+
+backends_objects = $(shell $(AR) t ../backends/libebl_backends.a)
+libdw_a_LIBADD += $(addprefix ../backends/,$(backends_objects))
+
+libcpu_objects = $(shell $(AR) t ../libcpu/libcpu.a)
+libdw_a_LIBADD += $(addprefix ../libcpu/,$(libcpu_objects))
+
 noinst_HEADERS = libdwP.h memory-access.h dwarf_abbrev_hash.h \
 		 dwarf_sig8_hash.h cfi.h encoded-value.h
 
diff --git a/libebl/ChangeLog b/libebl/ChangeLog
index 6fd83471..e5ab3859 100644
--- a/libebl/ChangeLog
+++ b/libebl/ChangeLog
@@ -2,7 +2,13 @@
 
 	* Makefile.am: Make libebl.a non-PIC by default.
 	Add libebl_pic.a.
+	Remove LIBEBL_SUBDIR definition.
 	(gen_SOURCES): Remove.
+	* eblopenbackend.c (machines): Replace dsoname with init callback.
+	(try_dlopen): Remove.
+	(openbackend): Use machine callback instead of try_dlopen().
+	Don't assign result->dlhandle.
+	* eblclosebackend.c (ebl_closebackend): Remove dlclose() call.
 
 2019-05-30  Mark Wielaard  <mark@klomp.org>
 
diff --git a/libebl/Makefile.am b/libebl/Makefile.am
index b85ead01..8af84633 100644
--- a/libebl/Makefile.am
+++ b/libebl/Makefile.am
@@ -33,7 +33,6 @@ AM_CFLAGS += $(fpic_CFLAGS)
 endif
 AM_CPPFLAGS += -I$(srcdir)/../libelf -I$(srcdir)/../libdw -I$(srcdir)/../libasm
 VERSION = 1
-LIBEBL_SUBDIR = @LIBEBL_SUBDIR@
 
 lib_LIBRARIES = libebl.a
 noinst_LIBRARIES = libebl_pic.a
diff --git a/libebl/eblclosebackend.c b/libebl/eblclosebackend.c
index 67fbdfe9..501e5c7b 100644
--- a/libebl/eblclosebackend.c
+++ b/libebl/eblclosebackend.c
@@ -44,10 +44,6 @@ ebl_closebackend (Ebl *ebl)
       /* Run the destructor.  */
       ebl->destr (ebl);
 
-      /* Close the dynamically loaded object.  */
-      if (ebl->dlhandle != NULL)
-	(void) dlclose (ebl->dlhandle);
-
       /* Free the resources.  */
       free (ebl);
     }
diff --git a/libebl/eblopenbackend.c b/libebl/eblopenbackend.c
index 36a24921..67db1c4e 100644
--- a/libebl/eblopenbackend.c
+++ b/libebl/eblopenbackend.c
@@ -41,6 +41,21 @@
 #include <system.h>
 #include <libeblP.h>
 
+const char *i386_init (Elf *, GElf_Half, Ebl *, size_t);
+const char *sh_init (Elf *, GElf_Half, Ebl *, size_t);
+const char *x86_64_init (Elf *, GElf_Half, Ebl *, size_t);
+const char *ia64_init (Elf *, GElf_Half, Ebl *, size_t);
+const char *alpha_init (Elf *, GElf_Half, Ebl *, size_t);
+const char *arm_init (Elf *, GElf_Half, Ebl *, size_t);
+const char *aarch64_init (Elf *, GElf_Half, Ebl *, size_t);
+const char *sparc_init (Elf *, GElf_Half, Ebl *, size_t);
+const char *ppc_init (Elf *, GElf_Half, Ebl *, size_t);
+const char *ppc64_init (Elf *, GElf_Half, Ebl *, size_t);
+const char *s390_init (Elf *, GElf_Half, Ebl *, size_t);
+const char *tilegx_init (Elf *, GElf_Half, Ebl *, size_t);
+const char *m68k_init (Elf *, GElf_Half, Ebl *, size_t);
+const char *bpf_init (Elf *, GElf_Half, Ebl *, size_t);
+const char *riscv_init (Elf *, GElf_Half, Ebl *, size_t);
 
 /* This table should contain the complete list of architectures as far
    as the ELF specification is concerned.  */
@@ -48,7 +63,7 @@
    arrays to avoid relocations.  */
 static const struct
 {
-  const char *dsoname;
+  ebl_bhinit_t init;
   const char *emulation;
   const char *prefix;
   int prefix_len;
@@ -57,84 +72,84 @@ 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 },
+  { alpha_init, "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 },
+  { tilegx_init, "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, ELFCLASS32, ELFDATA2MSB },
-  { "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 },
-  { "bpf", "elf_bpf", "bpf", 3, EM_BPF, 0, 0 },
-  { "riscv", "elf_riscv", "riscv", 5, EM_RISCV, ELFCLASS64, ELFDATA2LSB },
-  { "riscv", "elf_riscv", "riscv", 5, EM_RISCV, ELFCLASS32, ELFDATA2LSB },
+  { sh_init, "elf_sh", "sh", 2, EM_SH, 0, 0 },
+  { arm_init, "ebl_arm", "arm", 3, EM_ARM, 0, 0 },
+  { sparc_init, "elf_sparcv9", "sparc", 5, EM_SPARCV9, 0, 0 },
+  { sparc_init, "elf_sparc", "sparc", 5, EM_SPARC, 0, 0 },
+  { sparc_init, "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 },
+  { m68k_init, "elf_m68k", "m68k", 4, EM_68K, ELFCLASS32, ELFDATA2MSB },
+  { 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 },
+  { sparc_init, "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 },
+  { m68k_init, "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 },
+  { m68k_init, "elf_68hc16", "68hc16", 6, EM_68HC16, 0, 0 },
+  { m68k_init, "elf_68hc11", "68hc11", 6, EM_68HC11, 0, 0 },
+  { m68k_init, "elf_68hc08", "68hc08", 6, EM_68HC08, 0, 0 },
+  { m68k_init, "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 },
+  { bpf_init, "elf_bpf", "bpf", 3, EM_BPF, 0, 0 },
+  { riscv_init, "elf_riscv", "riscv", 5, EM_RISCV, ELFCLASS64, ELFDATA2LSB },
+  { riscv_init, "elf_riscv", "riscv", 5, EM_RISCV, ELFCLASS32, ELFDATA2LSB },
 };
 #define nmachines (sizeof (machines) / sizeof (machines[0]))
 
@@ -251,51 +266,6 @@ fill_defaults (Ebl *result)
   result->sysvhash_entrysize = sizeof (Elf32_Word);
 }
 
-static Ebl *
-try_dlopen (const char *dsoname, Elf *elf, GElf_Half machine, size_t cnt,
-	    Ebl *result)
-{
-  void *h = dlopen (dsoname, RTLD_LAZY);
-
-  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;
-
-      // We use a static number to help the compiler see we don't
-      // overflow the stack with an arbitrary number.
-      assert (machines[cnt].prefix_len <= MAX_PREFIX_LEN);
-      char symname[MAX_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 NULL;
-}
-
 /* Find an appropriate backend for the file associated with ELF.  */
 static Ebl *
 openbackend (Elf *elf, const char *emulation, GElf_Half machine)
@@ -357,46 +327,18 @@ openbackend (Elf *elf, const char *emulation, GElf_Half machine)
 	    result->data = elf->state.elf32.ehdr->e_ident[EI_DATA];
 	  }
 
-#ifndef LIBEBL_SUBDIR
-# define LIBEBL_SUBDIR PACKAGE
-#endif
-
-/* This works if libebl has been staticly linked into a binary.
-   It might also work for shared libraries when installed in
-   ${prefix}/lib/ or ${prefix}/lib64/, but not for multiarch
-   library installs like ${prefix}/lib/i386-linux-gnu/  */
-#define BINORIGINDIR "$ORIGIN/../$LIB/" LIBEBL_SUBDIR "/"
-
-/* This works if libebl has been linked into a shared library,
-   just look in the subdir.  */
-#define LIBORIGINDIR "$ORIGIN/" LIBEBL_SUBDIR "/"
-
-	/* Give it a try.  At least the machine type matches.  First
-           try to load the module from the (bin) origin path.  */
-	char dsoname[100];
-	strcpy (stpcpy (stpcpy (dsoname, BINORIGINDIR "libebl_"),
-			machines[cnt].dsoname),
-		".so");
-	if (try_dlopen (dsoname, elf, machine, cnt, result) != NULL)
-	  return result;
-
-	/* Retry with the (lib) origin path.  */
-	strcpy (stpcpy (stpcpy (dsoname, LIBORIGINDIR "libebl_"),
-			machines[cnt].dsoname),
-		".so");
-	if (try_dlopen (dsoname, elf, machine, cnt, result) != NULL)
-	  return result;
-
-	/* Try without an explicit path (LD_LIBRARY_PATH or RPATH).  */
-	strcpy (stpcpy (stpcpy (dsoname, "libebl_"),
-			machines[cnt].dsoname),
-		".so");
-	if (try_dlopen (dsoname, elf, machine, cnt, result) != NULL)
-	  return result;
-
-	/* We cannot find a DSO but the emulation/machine ID matches.
+        if (machines[cnt].init &&
+            machines[cnt].init (elf, machine, result, sizeof(Ebl)))
+          {
+            result->elf = elf;
+            /* A few entries are mandatory.  */
+            assert (result->name != NULL);
+            assert (result->destr != NULL);
+            return result;
+          }
+
+	/* We don't have a backend but the emulation/machine ID matches.
 	   Return that information.  */
-	result->dlhandle = NULL;
 	result->elf = elf;
 	result->name = machines[cnt].prefix;
 	fill_defaults (result);
@@ -405,7 +347,6 @@ openbackend (Elf *elf, const char *emulation, GElf_Half machine)
       }
 
   /* Nothing matched.  We use only the default callbacks.   */
-  result->dlhandle = NULL;
   result->elf = elf;
   result->emulation = "<unknown>";
   result->name = "<unknown>";
diff --git a/libebl/libebl.h b/libebl/libebl.h
index 24922eb8..06a14c45 100644
--- a/libebl/libebl.h
+++ b/libebl/libebl.h
@@ -30,13 +30,7 @@
 /* This is the interface for the Elfutils Backend Library.
    It is a completely UNSUPPORTED interface.  Don't use any libebl
    function directly.  These are only for internal elfutils backends
-   and tools.  There is NO source or binary compatible guarantee.
-
-   The ABI of the backend modules is not guaranteed.  Really, no guarantee
-   whatsoever.  We are enforcing this in the code.  The modules and their
-   users must match.  No third-party EBL module are supported or allowed.
-   The only reason there are separate modules is to not have the code for
-   all architectures in all the binaries.  */
+   and tools.  There is NO source or binary compatible guarantee.  */
 
 
 #ifndef _LIBEBL_H
diff --git a/libebl/libeblP.h b/libebl/libeblP.h
index 5b339b31..f1037300 100644
--- a/libebl/libeblP.h
+++ b/libebl/libeblP.h
@@ -80,9 +80,6 @@ struct ebl
      ebl_resolve_sym_value if available for this arch.  */
   GElf_Addr fd_addr;
   Elf_Data *fd_data;
-
-  /* Internal data.  */
-  void *dlhandle;
 };
 
 
diff --git a/src/ChangeLog b/src/ChangeLog
index c78e6fa1..a8b1e267 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,10 @@
+2019-07-05  Omar Sandoval  <osandov@fb.com>
+
+	* Makefile.am: Remove -ldl.
+	(elflint_LDADD): Add $(libdw).
+	(elfcmp_LDADD): Add $(libdw).
+	(objdump_LDADD): Add $(libdw).
+
 2019-06-25  Mark Wielaard  <mark@klomp.org>
 
 	* stack.c (parse_opt): Fix dwfl_core_file_attach error message.
diff --git a/src/Makefile.am b/src/Makefile.am
index 2b1c0dcb..42970da3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -40,14 +40,14 @@ CLEANFILES += make-debug-archive
 
 if BUILD_STATIC
 libasm = ../libasm/libasm.a
-libdw = ../libdw/libdw.a -lz $(zip_LIBS) $(libelf) $(libebl) -ldl
+libdw = ../libdw/libdw.a -lz $(zip_LIBS) $(libelf)
 libelf = ../libelf/libelf.a -lz
 else
 libasm = ../libasm/libasm.so
 libdw = ../libdw/libdw.so
 libelf = ../libelf/libelf.so
 endif
-libebl = ../libebl/libebl.a
+libebl = ../libebl/libebl.a ../backends/libebl_backends.a ../libcpu/libcpu.a
 libeu = ../lib/libeu.a
 
 if DEMANGLE
@@ -67,21 +67,21 @@ ranlib_no_Wstack_usage = yes
 ar_no_Wstack_usage = yes
 unstrip_no_Wstack_usage = yes
 
-readelf_LDADD = $(libdw) $(libebl) $(libelf) $(libeu) $(argp_LDADD) -ldl
-nm_LDADD = $(libdw) $(libebl) $(libelf) $(libeu) $(argp_LDADD) -ldl \
+readelf_LDADD = $(libdw) $(libebl) $(libelf) $(libeu) $(argp_LDADD)
+nm_LDADD = $(libdw) $(libebl) $(libelf) $(libeu) $(argp_LDADD) \
 	   $(demanglelib)
 size_LDADD = $(libelf) $(libeu) $(argp_LDADD)
-strip_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) $(argp_LDADD) -ldl
-elflint_LDADD  = $(libebl) $(libelf) $(libeu) $(argp_LDADD) -ldl
+strip_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) $(argp_LDADD)
+elflint_LDADD  = $(libebl) $(libdw) $(libelf) $(libeu) $(argp_LDADD)
 findtextrel_LDADD = $(libdw) $(libelf) $(libeu) $(argp_LDADD)
 addr2line_LDADD = $(libdw) $(libelf) $(libeu) $(argp_LDADD) $(demanglelib)
-elfcmp_LDADD = $(libebl) $(libelf) $(libeu) $(argp_LDADD) -ldl
-objdump_LDADD  = $(libasm) $(libebl) $(libelf) $(libeu) $(argp_LDADD) -ldl
+elfcmp_LDADD = $(libebl) $(libdw) $(libelf) $(libeu) $(argp_LDADD)
+objdump_LDADD  = $(libasm) $(libebl) $(libdw) $(libelf) $(libeu) $(argp_LDADD)
 ranlib_LDADD = libar.a $(libelf) $(libeu) $(argp_LDADD)
 strings_LDADD = $(libelf) $(libeu) $(argp_LDADD)
 ar_LDADD = libar.a $(libelf) $(libeu) $(argp_LDADD)
-unstrip_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) $(argp_LDADD) -ldl
-stack_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) $(argp_LDADD) -ldl $(demanglelib)
+unstrip_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) $(argp_LDADD)
+stack_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) $(argp_LDADD) $(demanglelib)
 elfcompress_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) $(argp_LDADD)
 
 installcheck-binPROGRAMS: $(bin_PROGRAMS)
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 400588f4..b5de6f4e 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,8 @@
+2019-07-05  Omar Sandoval  <osandov@fb.com>
+
+	* Makefile.am: Remove -ldl.
+	* tests-subr.sh (self_test_files): Remove libebl_{i386,x86_64}.so.
+
 2019-07-01  Mark Wielaard  <mark@klomp.org>
 
 	* run-large-elf-file.sh: Add 2GB to mem_needed when running under
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3d95cf68..9113b32f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -480,7 +480,7 @@ libasm = -lasm
 libebl = -lebl
 else !STANDALONE
 if BUILD_STATIC
-libdw = ../libdw/libdw.a -lz $(zip_LIBS) $(libelf) $(libebl) -ldl
+libdw = ../libdw/libdw.a -lz $(zip_LIBS) $(libelf) $(libebl)
 libelf = ../libelf/libelf.a -lz
 libasm = ../libasm/libasm.a
 else
@@ -488,7 +488,7 @@ libdw = ../libdw/libdw.so
 libelf = ../libelf/libelf.so
 libasm = ../libasm/libasm.so
 endif
-libebl = ../libebl/libebl.a
+libebl = ../libebl/libebl.a ../backends/libebl_backends.a ../libcpu/libcpu.a
 libeu = ../lib/libeu.a
 endif !STANDALONE
 
@@ -525,27 +525,27 @@ funcretval_LDADD = $(libdw) $(argp_LDADD)
 allregs_LDADD = $(libdw) $(argp_LDADD)
 find_prologues_LDADD = $(libdw) $(argp_LDADD)
 #show_ciefde_LDADD = ../libdwarf/libdwarf.so $(libelf)
-asm_tst1_LDADD = $(libasm) $(libebl) $(libelf) $(libdw) -ldl
-asm_tst2_LDADD = $(libasm) $(libebl) $(libelf) $(libdw) -ldl
-asm_tst3_LDADD = $(libasm) $(libebl) $(libelf) $(libdw) -ldl
-asm_tst4_LDADD = $(libasm) $(libebl) $(libelf) $(libdw) -ldl
-asm_tst5_LDADD = $(libasm) $(libebl) $(libelf) $(libdw) -ldl
-asm_tst6_LDADD = $(libasm) $(libebl) $(libelf) $(libdw) -ldl
-asm_tst7_LDADD = $(libasm) $(libebl) $(libelf) $(libdw) -ldl
-asm_tst8_LDADD = $(libasm) $(libebl) $(libelf) $(libdw) -ldl
-asm_tst9_LDADD = $(libasm) $(libebl) $(libelf) $(libdw) -ldl
-dwflmodtest_LDADD = $(libdw) $(libebl) $(libelf) $(argp_LDADD) -ldl
+asm_tst1_LDADD = $(libasm) $(libebl) $(libelf) $(libdw)
+asm_tst2_LDADD = $(libasm) $(libebl) $(libelf) $(libdw)
+asm_tst3_LDADD = $(libasm) $(libebl) $(libelf) $(libdw)
+asm_tst4_LDADD = $(libasm) $(libebl) $(libelf) $(libdw)
+asm_tst5_LDADD = $(libasm) $(libebl) $(libelf) $(libdw)
+asm_tst6_LDADD = $(libasm) $(libebl) $(libelf) $(libdw)
+asm_tst7_LDADD = $(libasm) $(libebl) $(libelf) $(libdw)
+asm_tst8_LDADD = $(libasm) $(libebl) $(libelf) $(libdw)
+asm_tst9_LDADD = $(libasm) $(libebl) $(libelf) $(libdw)
+dwflmodtest_LDADD = $(libdw) $(libebl) $(libelf) $(argp_LDADD)
 rdwrmmap_LDADD = $(libelf)
-dwfl_bug_addr_overflow_LDADD = $(libdw) $(libebl) $(libelf) -ldl
+dwfl_bug_addr_overflow_LDADD = $(libdw) $(libebl) $(libelf)
 arls_LDADD = $(libelf)
-dwfl_bug_fd_leak_LDADD = $(libdw) $(libebl) $(libelf) -ldl
-dwfl_bug_report_LDADD = $(libdw) $(libebl) $(libelf) -ldl
-dwfl_bug_getmodules_LDADD = $(libdw) $(libebl) $(libelf) -ldl
-dwfl_addr_sect_LDADD = $(libdw) $(libebl) $(libelf) $(argp_LDADD) -ldl
+dwfl_bug_fd_leak_LDADD = $(libdw) $(libebl) $(libelf)
+dwfl_bug_report_LDADD = $(libdw) $(libebl) $(libelf)
+dwfl_bug_getmodules_LDADD = $(libdw) $(libebl) $(libelf)
+dwfl_addr_sect_LDADD = $(libdw) $(libebl) $(libelf) $(argp_LDADD)
 dwarf_getmacros_LDADD = $(libdw)
 dwarf_ranges_LDADD = $(libdw)
 dwarf_getstring_LDADD = $(libdw)
-addrcfi_LDADD = $(libdw) $(libebl) $(libelf) $(argp_LDADD) -ldl
+addrcfi_LDADD = $(libdw) $(libebl) $(libelf) $(argp_LDADD)
 dwarfcfi_LDADD = $(libdw) $(libelf)
 test_flag_nobits_LDADD = $(libelf)
 rerequest_tag_LDADD = $(libdw)
diff --git a/tests/test-subr.sh b/tests/test-subr.sh
index 09f428d1..e23a0176 100644
--- a/tests/test-subr.sh
+++ b/tests/test-subr.sh
@@ -121,9 +121,7 @@ ${abs_top_builddir}/src/objdump \
 ${abs_top_builddir}/src/readelf`
 
 self_test_files_lib=`echo ${abs_top_builddir}/libelf/libelf.so \
-${abs_top_builddir}/libdw/libdw.so \
-${abs_top_builddir}/backends/libebl_i386.so \
-${abs_top_builddir}/backends/libebl_x86_64.so`
+${abs_top_builddir}/libdw/libdw.so`
 
 self_test_files_obj=`echo ${abs_top_builddir}/src/size.o \
 ${abs_top_builddir}/src/strip.o`
-- 
2.22.0

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

* [PATCH 0/5] elfutils: don't use dlopen() for libebl modules
@ 2019-07-06  0:35 Omar Sandoval
  2019-07-06  0:35 ` [PATCH 5/5] libdw: export libebl symbols Omar Sandoval
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Omar Sandoval @ 2019-07-06  0:35 UTC (permalink / raw)
  To: elfutils-devel

From: Omar Sandoval <osandov@fb.com>

Hello,

This series is a followup to my RFC [1]. Compared to the RFC patches,
this series adds patch 1 as a trivial cleanup, patch 3 to fix an
oversight in the RFC w.r.t. PIC object files sneaking into libdw.a, and
patch 5 to implement my suggestion for reducing the size of the elfutils
binaries by exporting libebl symbols from libdw.so. After this series,
libebl no longer uses dlopen() to find backends, and the total size of
the package is actually smaller than before (2.1 MB):

44K     ./libasm/libasm.so
672K    ./libdw/libdw.so
120K    ./libelf/libelf.so
52K     ./src/nm
28K     ./src/size
60K     ./src/strip
116K    ./src/elflint
28K     ./src/findtextrel
36K     ./src/addr2line
32K     ./src/elfcmp
40K     ./src/objdump
32K     ./src/strings
48K     ./src/ar
60K     ./src/unstrip
36K     ./src/stack
40K     ./src/elfcompress
32K     ./src/ranlib
236K    ./src/readelf
1.7M    total

If there are no issues, I'd love to see this merged, as it greatly
simplifies using libdw in environments where dlopen() is not supported.

Thanks!

1: https://sourceware.org/ml/elfutils-devel/2019-q3/msg00010.html

Omar Sandoval (5):
  libebl: remove unnecessary variable in Makefile.am
  libcpu: merge libcpu_{i386,x86_64,bpf} into one library
  Add PIC and non-PIC variants of libcpu and libebl
  Don't use dlopen() for libebl modules
  libdw: export libebl symbols

 ChangeLog                |   6 +
 Makefile.am              |   4 +-
 backends/ChangeLog       |   6 +
 backends/Makefile.am     | 104 +++------------
 configure.ac             |  12 +-
 libcpu/ChangeLog         |   6 +
 libcpu/Makefile.am       |  24 ++--
 libdw/ChangeLog          |   9 ++
 libdw/Makefile.am        |  21 ++-
 libdw/libdw.map          |  60 ++++++++-
 libebl/ChangeLog         |  12 ++
 libebl/Makefile.am       |  46 ++++---
 libebl/eblclosebackend.c |   4 -
 libebl/eblopenbackend.c  | 267 +++++++++++++++------------------------
 libebl/libebl.h          |   8 +-
 libebl/libeblP.h         |   3 -
 src/ChangeLog            |  17 +++
 src/Makefile.am          |  21 ++-
 tests/ChangeLog          |   5 +
 tests/Makefile.am        |  36 +++---
 tests/test-subr.sh       |   4 +-
 21 files changed, 331 insertions(+), 344 deletions(-)

-- 
2.22.0

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

* [PATCH 3/5] Add PIC and non-PIC variants of libcpu and libebl
  2019-07-06  0:35 [PATCH 0/5] elfutils: don't use dlopen() for libebl modules Omar Sandoval
                   ` (3 preceding siblings ...)
  2019-07-06  0:35 ` [PATCH 1/5] libebl: remove unnecessary variable in Makefile.am Omar Sandoval
@ 2019-07-06  0:35 ` Omar Sandoval
  4 siblings, 0 replies; 7+ messages in thread
From: Omar Sandoval @ 2019-07-06  0:35 UTC (permalink / raw)
  To: elfutils-devel

From: Omar Sandoval <osandov@fb.com>

Currently, libcpu and libebl are always compiled as PIC. An upcoming
change will add the objects from libcpu.a and libebl.a to libdw.a, which
should not be PIC unless configured that way. So, make libcpu.a and
libebl.a non-PIC and add libcpu_pic.a and libebl_pic.a.

Signed-off-by: Omar Sandoval <osandov@fb.com>
---
 backends/ChangeLog   |  1 +
 backends/Makefile.am |  2 +-
 libcpu/ChangeLog     |  2 ++
 libcpu/Makefile.am   | 18 +++++++++++++-----
 libdw/ChangeLog      |  4 ++++
 libdw/Makefile.am    |  2 +-
 libebl/ChangeLog     |  4 +++-
 libebl/Makefile.am   |  8 +++++++-
 8 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/backends/ChangeLog b/backends/ChangeLog
index 219e0702..d631417f 100644
--- a/backends/ChangeLog
+++ b/backends/ChangeLog
@@ -1,6 +1,7 @@
 2019-07-05  Omar Sandoval  <osandov@fb.com>
 
 	* Makefile.am: Replace libcpu_{i386,x86_64,bpf}.a with libcpu.a.
+	Replace libcpu.a with libcpu_pic.a.
 
 2019-04-14  Mark Wielaard  <mark@klomp.org>
 
diff --git a/backends/Makefile.am b/backends/Makefile.am
index 0307da07..d1275206 100644
--- a/backends/Makefile.am
+++ b/backends/Makefile.am
@@ -43,7 +43,7 @@ noinst_LIBRARIES = $(libebl_pic)
 noinst_DATA = $(libebl_pic:_pic.a=.so)
 
 
-libcpu = ../libcpu/libcpu.a
+libcpu = ../libcpu/libcpu_pic.a
 libelf = ../libelf/libelf.so
 libdw = ../libdw/libdw.so
 libeu = ../lib/libeu.a
diff --git a/libcpu/ChangeLog b/libcpu/ChangeLog
index c0ea72ec..883896a2 100644
--- a/libcpu/ChangeLog
+++ b/libcpu/ChangeLog
@@ -1,6 +1,8 @@
 2019-07-05  Omar Sandoval  <osandov@fb.com>
 
 	* Makefile.am: Combine libcpu_{i386,x86_64,bpf}.a into libcpu.a.
+	Make libcpu.a non-PIC by default.
+	Add libcpu_pic.a.
 
 2018-11-04  Mark Wielaard  <mark@klomp.org>
 
diff --git a/libcpu/Makefile.am b/libcpu/Makefile.am
index a7d9f6fd..88717361 100644
--- a/libcpu/Makefile.am
+++ b/libcpu/Makefile.am
@@ -30,15 +30,22 @@
 include $(top_srcdir)/config/eu.am
 AM_CPPFLAGS += -I$(srcdir)/../libelf -I$(srcdir)/../libebl \
 	    -I$(srcdir)/../libdw -I$(srcdir)/../libasm
-AM_CFLAGS += $(fpic_CFLAGS) -fdollars-in-identifiers
+if BUILD_STATIC
+AM_CFLAGS += $(fpic_CFLAGS)
+endif
+AM_CFLAGS += -fdollars-in-identifiers
 LEXCOMPILE = $(LEX) $(LFLAGS) $(AM_LFLAGS) -P$(<F:lex.l=)
 LEX_OUTPUT_ROOT = lex.$(<F:lex.l=)
 AM_YFLAGS = -p$(<F:parse.y=)
 
-noinst_LIBRARIES = libcpu.a
+noinst_LIBRARIES = libcpu.a libcpu_pic.a
+
+noinst_HEADERS = i386_dis.h x86_64_dis.h
+
+libcpu_a_SOURCES = i386_disasm.c x86_64_disasm.c bpf_disasm.c
 
-libcpu_a_SOURCES = i386_disasm.c i386_dis.h x86_64_disasm.c x86_64_dis.h \
-		   bpf_disasm.c
+libcpu_pic_a_SOURCES =
+am_libcpu_pic_a_OBJECTS = $(libcpu_a_SOURCES:.c=.os)
 
 i386_gendis_SOURCES = i386_gendis.c i386_lex.l i386_parse.y
 
@@ -50,7 +57,7 @@ x86_64_disasm.o: x86_64.mnemonics $(srcdir)/x86_64_dis.h
 	$(AM_V_at)mv -f $@T $@
 
 if MAINTAINER_MODE
-noinst_HEADERS = memory-access.h i386_parse.h i386_data.h
+noinst_HEADERS += memory-access.h i386_parse.h i386_data.h
 
 noinst_PROGRAMS = i386_gendis$(EXEEXT)
 
@@ -86,5 +93,6 @@ bpf_disasm_CFLAGS = -Wno-format-nonliteral
 
 EXTRA_DIST = defs/i386
 
+MOSTLYCLEANFILES = $(am_libcpu_pic_a_OBJECTS)
 CLEANFILES += $(foreach P,i386 x86_64,$P_defs $P.mnemonics)
 MAINTAINERCLEANFILES = $(foreach P,i386 x86_64, $P_dis.h)
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 4760f9de..f9bbeee1 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,7 @@
+2019-07-05  Omar Sandoval  <osandov@fb.com>
+
+	* Makefile.am (libdw_so_LIBS): Replace libebl.a with libebl_pic.a.
+
 2019-05-16  Mark Wielaard  <mark@klomp.org>
 
 	* dwarf.h: Add DW_AT_GNU_numerator, DW_AT_GNU_denominator and
diff --git a/libdw/Makefile.am b/libdw/Makefile.am
index 7a3d5322..7dc4cec0 100644
--- a/libdw/Makefile.am
+++ b/libdw/Makefile.am
@@ -106,7 +106,7 @@ libdw_pic_a_SOURCES =
 am_libdw_pic_a_OBJECTS = $(libdw_a_SOURCES:.c=.os)
 
 libdw_so_LIBS = libdw_pic.a ../libdwelf/libdwelf_pic.a \
-	  ../libdwfl/libdwfl_pic.a ../libebl/libebl.a
+	  ../libdwfl/libdwfl_pic.a ../libebl/libebl_pic.a
 libdw_so_DEPS = ../lib/libeu.a ../libelf/libelf.so
 libdw_so_LDLIBS = $(libdw_so_DEPS) -ldl -lz $(argp_LDADD) $(zip_LIBS)
 libdw_so_SOURCES =
diff --git a/libebl/ChangeLog b/libebl/ChangeLog
index 9510f9d5..6fd83471 100644
--- a/libebl/ChangeLog
+++ b/libebl/ChangeLog
@@ -1,6 +1,8 @@
 2019-07-05  Omar Sandoval  <osandov@fb.com>
 
-	* Makefile.am (gen_SOURCES): Remove.
+	* Makefile.am: Make libebl.a non-PIC by default.
+	Add libebl_pic.a.
+	(gen_SOURCES): Remove.
 
 2019-05-30  Mark Wielaard  <mark@klomp.org>
 
diff --git a/libebl/Makefile.am b/libebl/Makefile.am
index ccc1a31a..b85ead01 100644
--- a/libebl/Makefile.am
+++ b/libebl/Makefile.am
@@ -28,12 +28,15 @@
 ## not, see <http://www.gnu.org/licenses/>.
 ##
 include $(top_srcdir)/config/eu.am
+if BUILD_STATIC
 AM_CFLAGS += $(fpic_CFLAGS)
+endif
 AM_CPPFLAGS += -I$(srcdir)/../libelf -I$(srcdir)/../libdw -I$(srcdir)/../libasm
 VERSION = 1
 LIBEBL_SUBDIR = @LIBEBL_SUBDIR@
 
 lib_LIBRARIES = libebl.a
+noinst_LIBRARIES = libebl_pic.a
 
 pkginclude_HEADERS = libebl.h
 
@@ -57,6 +60,9 @@ libebl_a_SOURCES = eblopenbackend.c eblclosebackend.c eblreloctypename.c \
 		   eblresolvesym.c eblcheckreloctargettype.c \
 		   ebl_data_marker_symbol.c
 
+libebl_pic_a_SOURCES =
+am_libebl_pic_a_OBJECTS = $(libebl_a_SOURCES:.c=.os)
+
 noinst_HEADERS = libeblP.h ebl-hooks.h
 
-CLEANFILES += $(am_libebl_pic_a_OBJECTS)
+MOSTLYCLEANFILES = $(am_libebl_pic_a_OBJECTS)
-- 
2.22.0

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

* [PATCH 1/5] libebl: remove unnecessary variable in Makefile.am
  2019-07-06  0:35 [PATCH 0/5] elfutils: don't use dlopen() for libebl modules Omar Sandoval
                   ` (2 preceding siblings ...)
  2019-07-06  0:35 ` [PATCH 2/5] libcpu: merge libcpu_{i386,x86_64,bpf} into one library Omar Sandoval
@ 2019-07-06  0:35 ` Omar Sandoval
  2019-07-06  0:35 ` [PATCH 3/5] Add PIC and non-PIC variants of libcpu and libebl Omar Sandoval
  4 siblings, 0 replies; 7+ messages in thread
From: Omar Sandoval @ 2019-07-06  0:35 UTC (permalink / raw)
  To: elfutils-devel

From: Omar Sandoval <osandov@fb.com>

gen_SOURCES is assigned to libebl_a_SOURCES and never used again. Get
rid of it.

Signed-off-by: Omar Sandoval <osandov@fb.com>
---
 libebl/ChangeLog   |  4 ++++
 libebl/Makefile.am | 39 +++++++++++++++++++--------------------
 2 files changed, 23 insertions(+), 20 deletions(-)

diff --git a/libebl/ChangeLog b/libebl/ChangeLog
index 8a7d177f..9510f9d5 100644
--- a/libebl/ChangeLog
+++ b/libebl/ChangeLog
@@ -1,3 +1,7 @@
+2019-07-05  Omar Sandoval  <osandov@fb.com>
+
+	* Makefile.am (gen_SOURCES): Remove.
+
 2019-05-30  Mark Wielaard  <mark@klomp.org>
 
 	* eblopenbackend.c (try_dlopen): New function extracted from
diff --git a/libebl/Makefile.am b/libebl/Makefile.am
index 737de6b0..ccc1a31a 100644
--- a/libebl/Makefile.am
+++ b/libebl/Makefile.am
@@ -37,26 +37,25 @@ lib_LIBRARIES = libebl.a
 
 pkginclude_HEADERS = libebl.h
 
-gen_SOURCES = eblopenbackend.c eblclosebackend.c \
-	      eblreloctypename.c eblsegmenttypename.c \
-	      eblsectiontypename.c eblmachineflagname.c \
-	      eblsymboltypename.c ebldynamictagname.c eblsectionname.c \
-	      eblsymbolbindingname.c eblbackendname.c eblosabiname.c \
-	      eblmachineflagcheck.c eblmachinesectionflagcheck.c \
-	      eblreloctypecheck.c eblrelocvaliduse.c eblrelocsimpletype.c \
-	      ebldynamictagcheck.c eblcorenotetypename.c eblobjnotetypename.c \
-	      eblcorenote.c eblobjnote.c ebldebugscnp.c \
-	      eblgotpcreloccheck.c eblcopyrelocp.c eblsectionstripp.c \
-	      eblelfclass.c eblelfdata.c eblelfmachine.c \
-	      ebl_check_special_symbol.c eblbsspltp.c eblretval.c \
-	      eblreginfo.c eblnonerelocp.c eblrelativerelocp.c \
-	      eblsysvhashentrysize.c eblauxvinfo.c eblcheckobjattr.c \
-	      ebl_check_special_section.c ebl_syscall_abi.c eblabicfi.c \
-	      eblstother.c eblinitreg.c ebldwarftoregno.c eblnormalizepc.c \
-	      eblunwind.c eblresolvesym.c eblcheckreloctargettype.c \
-	      ebl_data_marker_symbol.c
-
-libebl_a_SOURCES = $(gen_SOURCES)
+libebl_a_SOURCES = eblopenbackend.c eblclosebackend.c eblreloctypename.c \
+		   eblsegmenttypename.c eblsectiontypename.c \
+		   eblmachineflagname.c eblsymboltypename.c \
+		   ebldynamictagname.c eblsectionname.c \
+		   eblsymbolbindingname.c eblbackendname.c eblosabiname.c \
+		   eblmachineflagcheck.c eblmachinesectionflagcheck.c \
+		   eblreloctypecheck.c eblrelocvaliduse.c \
+		   eblrelocsimpletype.c ebldynamictagcheck.c \
+		   eblcorenotetypename.c eblobjnotetypename.c eblcorenote.c \
+		   eblobjnote.c ebldebugscnp.c eblgotpcreloccheck.c \
+		   eblcopyrelocp.c eblsectionstripp.c eblelfclass.c \
+		   eblelfdata.c eblelfmachine.c ebl_check_special_symbol.c \
+		   eblbsspltp.c eblretval.c eblreginfo.c eblnonerelocp.c \
+		   eblrelativerelocp.c eblsysvhashentrysize.c eblauxvinfo.c \
+		   eblcheckobjattr.c ebl_check_special_section.c \
+		   ebl_syscall_abi.c eblabicfi.c eblstother.c eblinitreg.c \
+		   ebldwarftoregno.c eblnormalizepc.c eblunwind.c \
+		   eblresolvesym.c eblcheckreloctargettype.c \
+		   ebl_data_marker_symbol.c
 
 noinst_HEADERS = libeblP.h ebl-hooks.h
 
-- 
2.22.0

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

* [PATCH 2/5] libcpu: merge libcpu_{i386,x86_64,bpf} into one library
  2019-07-06  0:35 [PATCH 0/5] elfutils: don't use dlopen() for libebl modules Omar Sandoval
  2019-07-06  0:35 ` [PATCH 5/5] libdw: export libebl symbols Omar Sandoval
  2019-07-06  0:35 ` [PATCH 4/5] Don't use dlopen() for libebl modules Omar Sandoval
@ 2019-07-06  0:35 ` Omar Sandoval
  2019-07-06  0:35 ` [PATCH 1/5] libebl: remove unnecessary variable in Makefile.am Omar Sandoval
  2019-07-06  0:35 ` [PATCH 3/5] Add PIC and non-PIC variants of libcpu and libebl Omar Sandoval
  4 siblings, 0 replies; 7+ messages in thread
From: Omar Sandoval @ 2019-07-06  0:35 UTC (permalink / raw)
  To: elfutils-devel

From: Omar Sandoval <osandov@fb.com>

In preparation for combining the libebl backend modules, combine all of
the libcpu backends into libcpu.a.

Signed-off-by: Omar Sandoval <osandov@fb.com>
---
 backends/ChangeLog   |  4 ++++
 backends/Makefile.am | 12 +++---------
 libcpu/ChangeLog     |  4 ++++
 libcpu/Makefile.am   | 12 +++++-------
 4 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/backends/ChangeLog b/backends/ChangeLog
index 6c2b47a9..219e0702 100644
--- a/backends/ChangeLog
+++ b/backends/ChangeLog
@@ -1,3 +1,7 @@
+2019-07-05  Omar Sandoval  <osandov@fb.com>
+
+	* Makefile.am: Replace libcpu_{i386,x86_64,bpf}.a with libcpu.a.
+
 2019-04-14  Mark Wielaard  <mark@klomp.org>
 
 	* riscv_cfi.c: Fix BACKEND define.
diff --git a/backends/Makefile.am b/backends/Makefile.am
index 2126a2ec..0307da07 100644
--- a/backends/Makefile.am
+++ b/backends/Makefile.am
@@ -43,6 +43,7 @@ noinst_LIBRARIES = $(libebl_pic)
 noinst_DATA = $(libebl_pic:_pic.a=.so)
 
 
+libcpu = ../libcpu/libcpu.a
 libelf = ../libelf/libelf.so
 libdw = ../libdw/libdw.so
 libeu = ../lib/libeu.a
@@ -50,7 +51,6 @@ libeu = ../lib/libeu.a
 i386_SRCS = i386_init.c i386_symbol.c i386_corenote.c i386_cfi.c \
 	    i386_retval.c i386_regs.c i386_auxv.c i386_syscall.c \
 	    i386_initreg.c i386_unwind.c
-cpu_i386 = ../libcpu/libcpu_i386.a
 libebl_i386_pic_a_SOURCES = $(i386_SRCS)
 am_libebl_i386_pic_a_OBJECTS = $(i386_SRCS:.c=.os)
 
@@ -61,7 +61,6 @@ 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_cfi.c \
 	      x86_64_retval.c x86_64_regs.c i386_auxv.c x86_64_syscall.c \
 	      x86_64_initreg.c x86_64_unwind.c x32_corenote.c
-cpu_x86_64 = ../libcpu/libcpu_x86_64.a
 libebl_x86_64_pic_a_SOURCES = $(x86_64_SRCS)
 am_libebl_x86_64_pic_a_OBJECTS = $(x86_64_SRCS:.c=.os)
 
@@ -127,7 +126,6 @@ am_libebl_m68k_pic_a_OBJECTS = $(m68k_SRCS:.c=.os)
 m68k_corenote_no_Wpacked_not_aligned = yes
 
 bpf_SRCS = bpf_init.c bpf_regs.c bpf_symbol.c
-cpu_bpf = ../libcpu/libcpu_bpf.a
 libebl_bpf_pic_a_SOURCES = $(bpf_SRCS)
 am_libebl_bpf_pic_a_OBJECTS = $(bpf_SRCS:.c=.os)
 
@@ -137,20 +135,16 @@ libebl_riscv_pic_a_SOURCES = $(riscv_SRCS)
 am_libebl_riscv_pic_a_OBJECTS = $(riscv_SRCS:.c=.os)
 
 
-libebl_%.so libebl_%.map: libebl_%_pic.a $(libelf) $(libdw) $(libeu)
+libebl_%.so libebl_%.map: libebl_%_pic.a $(libcpu) $(libelf) $(libdw) $(libeu)
 	@rm -f $(@:.so=.map)
 	$(AM_V_at)echo 'ELFUTILS_$(PACKAGE_VERSION) { global: $*_init; local: *; };' \
 	  > $(@:.so=.map)
 	$(AM_V_CCLD)$(LINK) $(dso_LDFLAGS) -o $(@:.map=.so) \
-		-Wl,--whole-archive $< $(cpu_$*) -Wl,--no-whole-archive \
+		-Wl,--whole-archive $< $(libcpu) -Wl,--no-whole-archive \
 		-Wl,--version-script,$(@:.so=.map),--no-undefined \
 		-Wl,--as-needed $(libelf) $(libdw) $(libeu)
 	@$(textrel_check)
 
-libebl_i386.so: $(cpu_i386)
-libebl_x86_64.so: $(cpu_x86_64)
-libebl_bpf.so: $(cpu_bpf)
-
 install: install-am install-ebl-modules
 install-ebl-modules:
 	$(mkinstalldirs) $(DESTDIR)$(libdir)/$(LIBEBL_SUBDIR)
diff --git a/libcpu/ChangeLog b/libcpu/ChangeLog
index adebbef8..c0ea72ec 100644
--- a/libcpu/ChangeLog
+++ b/libcpu/ChangeLog
@@ -1,3 +1,7 @@
+2019-07-05  Omar Sandoval  <osandov@fb.com>
+
+	* Makefile.am: Combine libcpu_{i386,x86_64,bpf}.a into libcpu.a.
+
 2018-11-04  Mark Wielaard  <mark@klomp.org>
 
 	* bpf_disasm.c (bpf_disasm): Recognize BPF_JLT, BPF_JLE, BPF_JSLT
diff --git a/libcpu/Makefile.am b/libcpu/Makefile.am
index 4c8778d1..a7d9f6fd 100644
--- a/libcpu/Makefile.am
+++ b/libcpu/Makefile.am
@@ -35,20 +35,16 @@ LEXCOMPILE = $(LEX) $(LFLAGS) $(AM_LFLAGS) -P$(<F:lex.l=)
 LEX_OUTPUT_ROOT = lex.$(<F:lex.l=)
 AM_YFLAGS = -p$(<F:parse.y=)
 
-noinst_LIBRARIES = libcpu_i386.a libcpu_x86_64.a
+noinst_LIBRARIES = libcpu.a
 
-libcpu_i386_a_SOURCES = i386_disasm.c i386_dis.h
-libcpu_x86_64_a_SOURCES = x86_64_disasm.c x86_64_dis.h
+libcpu_a_SOURCES = i386_disasm.c i386_dis.h x86_64_disasm.c x86_64_dis.h \
+		   bpf_disasm.c
 
 i386_gendis_SOURCES = i386_gendis.c i386_lex.l i386_parse.y
 
 i386_disasm.o: i386.mnemonics $(srcdir)/i386_dis.h
 x86_64_disasm.o: x86_64.mnemonics $(srcdir)/x86_64_dis.h
 
-noinst_LIBRARIES += libcpu_bpf.a
-libcpu_bpf_a_SOURCES = bpf_disasm.c
-libcpu_bpf_a_CFLAGS = $(AM_CFLAGS) -Wno-format-nonliteral
-
 %_defs: $(srcdir)/defs/i386
 	$(AM_V_GEN)m4 -D$* -DDISASSEMBLER $< > $@T
 	$(AM_V_at)mv -f $@T $@
@@ -86,6 +82,8 @@ i386_gendis_LDADD = $(libeu) -lm
 
 i386_parse.h: i386_parse.c ;
 
+bpf_disasm_CFLAGS = -Wno-format-nonliteral
+
 EXTRA_DIST = defs/i386
 
 CLEANFILES += $(foreach P,i386 x86_64,$P_defs $P.mnemonics)
-- 
2.22.0

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

* [PATCH 5/5] libdw: export libebl symbols
  2019-07-06  0:35 [PATCH 0/5] elfutils: don't use dlopen() for libebl modules Omar Sandoval
@ 2019-07-06  0:35 ` Omar Sandoval
  2019-07-08 21:14   ` Mark Wielaard
  2019-07-06  0:35 ` [PATCH 4/5] Don't use dlopen() for libebl modules Omar Sandoval
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 7+ messages in thread
From: Omar Sandoval @ 2019-07-06  0:35 UTC (permalink / raw)
  To: elfutils-devel

From: Omar Sandoval <osandov@fb.com>

The main downside of the previous change to build in all libebl backend
modules statically is that the total installed size of elfutils
increased (from 2.1 MB to 3.5 MB in my case). This is because we have to
statically link libebl and its backends into every binary. Instead,
since libebl is already linked into libdw.so, we can simply export the
libebl symbols in libdw.so for the binaries to use. This shrinks the
total size to 1.7 MB, which is smaller than where we started.

This doesn't change the status of libebl: it is still considered
internal and the API/ABI are still subject to change.

Signed-off-by: Omar Sandoval <osandov@fb.com>
---
 libdw/ChangeLog |  1 +
 libdw/libdw.map | 60 ++++++++++++++++++++++++++++++++++++++++++++++++-
 src/ChangeLog   | 10 +++++++++
 src/Makefile.am | 19 ++++++++--------
 4 files changed, 79 insertions(+), 11 deletions(-)

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 4e088688..84e03699 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -5,6 +5,7 @@
 	(libdw_so_LDLIBS): Remove -ldl.
 	(libdw.so): Remove -rpath.
 	(libdw_a_LIBADD): Add libebl, libebl_backends, and libcpu objects.
+	* libdw.map (ELFUTILS_0.177): New section. Add libebl symbols.
 
 2019-05-16  Mark Wielaard  <mark@klomp.org>
 
diff --git a/libdw/libdw.map b/libdw/libdw.map
index 55482d58..c9f69d32 100644
--- a/libdw/libdw.map
+++ b/libdw/libdw.map
@@ -360,4 +360,62 @@ ELFUTILS_0.173 {
 ELFUTILS_0.175 {
   global:
     dwelf_elf_begin;
-} ELFUTILS_0.173;
\ No newline at end of file
+} ELFUTILS_0.173;
+
+ELFUITLS_0.177 {
+  global:
+    ebl_openbackend;
+    ebl_openbackend_machine;
+    ebl_openbackend_emulation;
+    ebl_closebackend;
+    ebl_get_elfmachine;
+    ebl_get_elfclass;
+    ebl_get_elfdata;
+    ebl_backend_name;
+    ebl_reloc_type_name;
+    ebl_reloc_type_check;
+    ebl_reloc_valid_use;
+    ebl_reloc_simple_type;
+    ebl_gotpc_reloc_check;
+    ebl_segment_type_name;
+    ebl_section_type_name;
+    ebl_section_name;
+    ebl_machine_flag_name;
+    ebl_machine_flag_check;
+    ebl_machine_section_flag_check;
+    ebl_check_special_section;
+    ebl_symbol_type_name;
+    ebl_symbol_binding_name;
+    ebl_dynamic_tag_name;
+    ebl_dynamic_tag_check;
+    ebl_check_special_symbol;
+    ebl_data_marker_symbol;
+    ebl_check_st_other_bits;
+    ebl_osabi_name;
+    ebl_core_note_type_name;
+    ebl_object_note_type_name;
+    ebl_object_note;
+    ebl_check_object_attribute;
+    ebl_check_reloc_target_type;
+    ebl_debugscn_p;
+    ebl_copy_reloc_p;
+    ebl_none_reloc_p;
+    ebl_relative_reloc_p;
+    ebl_section_strip_p;
+    ebl_bss_plt_p;
+    ebl_sysvhash_entrysize;
+    ebl_return_value_location;
+    ebl_register_info;
+    ebl_syscall_abi;
+    ebl_abi_cfi;
+    ebl_core_note;
+    ebl_auxv_info;
+    ebl_set_initial_registers_tid;
+    ebl_frame_nregs;
+    ebl_ra_offset;
+    ebl_func_addr_mask;
+    ebl_dwarf_to_regno;
+    ebl_normalize_pc;
+    ebl_unwind;
+    ebl_resolve_sym_value;
+} ELFUTILS_0.175;
diff --git a/src/ChangeLog b/src/ChangeLog
index a8b1e267..2ce39db0 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,9 +1,19 @@
 2019-07-05  Omar Sandoval  <osandov@fb.com>
 
 	* Makefile.am: Remove -ldl.
+	Remove libebl definition.
+	(readelf_LDADD): Remove $(libebl).
+	(nm_LDADD): Remove $(libebl).
+	(strip_LDADD): Remove $(libebl).
 	(elflint_LDADD): Add $(libdw).
+	Remove $(libebl).
 	(elfcmp_LDADD): Add $(libdw).
+	Remove $(libebl).
 	(objdump_LDADD): Add $(libdw).
+	Remove $(libebl).
+	(unstrip_LDADD): Remove $(libebl).
+	(stack_LDADD): Remove $(libebl).
+	(elfcompress_LDADD): Remove $(libebl).
 
 2019-06-25  Mark Wielaard  <mark@klomp.org>
 
diff --git a/src/Makefile.am b/src/Makefile.am
index 42970da3..d219e8fe 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -47,7 +47,6 @@ libasm = ../libasm/libasm.so
 libdw = ../libdw/libdw.so
 libelf = ../libelf/libelf.so
 endif
-libebl = ../libebl/libebl.a ../backends/libebl_backends.a ../libcpu/libcpu.a
 libeu = ../lib/libeu.a
 
 if DEMANGLE
@@ -67,22 +66,22 @@ ranlib_no_Wstack_usage = yes
 ar_no_Wstack_usage = yes
 unstrip_no_Wstack_usage = yes
 
-readelf_LDADD = $(libdw) $(libebl) $(libelf) $(libeu) $(argp_LDADD)
-nm_LDADD = $(libdw) $(libebl) $(libelf) $(libeu) $(argp_LDADD) \
+readelf_LDADD = $(libdw) $(libelf) $(libeu) $(argp_LDADD)
+nm_LDADD = $(libdw) $(libelf) $(libeu) $(argp_LDADD) \
 	   $(demanglelib)
 size_LDADD = $(libelf) $(libeu) $(argp_LDADD)
-strip_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) $(argp_LDADD)
-elflint_LDADD  = $(libebl) $(libdw) $(libelf) $(libeu) $(argp_LDADD)
+strip_LDADD = $(libelf) $(libdw) $(libeu) $(argp_LDADD)
+elflint_LDADD  = $(libdw) $(libelf) $(libeu) $(argp_LDADD)
 findtextrel_LDADD = $(libdw) $(libelf) $(libeu) $(argp_LDADD)
 addr2line_LDADD = $(libdw) $(libelf) $(libeu) $(argp_LDADD) $(demanglelib)
-elfcmp_LDADD = $(libebl) $(libdw) $(libelf) $(libeu) $(argp_LDADD)
-objdump_LDADD  = $(libasm) $(libebl) $(libdw) $(libelf) $(libeu) $(argp_LDADD)
+elfcmp_LDADD = $(libdw) $(libelf) $(libeu) $(argp_LDADD)
+objdump_LDADD  = $(libasm) $(libdw) $(libelf) $(libeu) $(argp_LDADD)
 ranlib_LDADD = libar.a $(libelf) $(libeu) $(argp_LDADD)
 strings_LDADD = $(libelf) $(libeu) $(argp_LDADD)
 ar_LDADD = libar.a $(libelf) $(libeu) $(argp_LDADD)
-unstrip_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) $(argp_LDADD)
-stack_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) $(argp_LDADD) $(demanglelib)
-elfcompress_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) $(argp_LDADD)
+unstrip_LDADD = $(libelf) $(libdw) $(libeu) $(argp_LDADD)
+stack_LDADD = $(libelf) $(libdw) $(libeu) $(argp_LDADD) $(demanglelib)
+elfcompress_LDADD = $(libelf) $(libdw) $(libeu) $(argp_LDADD)
 
 installcheck-binPROGRAMS: $(bin_PROGRAMS)
 	bad=0; pid=$$$$; list="$(bin_PROGRAMS)"; for p in $$list; do \
-- 
2.22.0

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

* Re: [PATCH 5/5] libdw: export libebl symbols
  2019-07-06  0:35 ` [PATCH 5/5] libdw: export libebl symbols Omar Sandoval
@ 2019-07-08 21:14   ` Mark Wielaard
  0 siblings, 0 replies; 7+ messages in thread
From: Mark Wielaard @ 2019-07-08 21:14 UTC (permalink / raw)
  To: Omar Sandoval, elfutils-devel

Hi,

On Fri, 2019-07-05 at 17:34 -0700, Omar Sandoval wrote:
> The main downside of the previous change to build in all libebl backend
> modules statically is that the total installed size of elfutils
> increased (from 2.1 MB to 3.5 MB in my case). This is because we have to
> statically link libebl and its backends into every binary. Instead,
> since libebl is already linked into libdw.so, we can simply export the
> libebl symbols in libdw.so for the binaries to use. This shrinks the
> total size to 1.7 MB, which is smaller than where we started.
> 
> This doesn't change the status of libebl: it is still considered
> internal and the API/ABI are still subject to change.

The status is the same, but by exporting them explicitly I am afraid
people will just start using them as if they are supported API. So if
at all possible I rather not have them exported from libdw.so.

> +ELFUITLS_0.177 {
> +  global:
> +    ebl_openbackend;
> +    ebl_openbackend_machine;
> +    ebl_openbackend_emulation;
> +    ebl_closebackend;
> +    ebl_get_elfmachine;
> +    ebl_get_elfclass;
> +    ebl_get_elfdata;
> +    ebl_backend_name;
> +    ebl_reloc_type_name;
> +    ebl_reloc_type_check;
> +    ebl_reloc_valid_use;
> +    ebl_reloc_simple_type;
> +    ebl_gotpc_reloc_check;
> +    ebl_segment_type_name;
> +    ebl_section_type_name;
> +    ebl_section_name;
> +    ebl_machine_flag_name;
> +    ebl_machine_flag_check;
> +    ebl_machine_section_flag_check;
> +    ebl_check_special_section;
> +    ebl_symbol_type_name;
> +    ebl_symbol_binding_name;
> +    ebl_dynamic_tag_name;
> +    ebl_dynamic_tag_check;
> +    ebl_check_special_symbol;
> +    ebl_data_marker_symbol;
> +    ebl_check_st_other_bits;
> +    ebl_osabi_name;
> +    ebl_core_note_type_name;
> +    ebl_object_note_type_name;
> +    ebl_object_note;
> +    ebl_check_object_attribute;
> +    ebl_check_reloc_target_type;
> +    ebl_debugscn_p;
> +    ebl_copy_reloc_p;
> +    ebl_none_reloc_p;
> +    ebl_relative_reloc_p;
> +    ebl_section_strip_p;
> +    ebl_bss_plt_p;
> +    ebl_sysvhash_entrysize;
> +    ebl_return_value_location;
> +    ebl_register_info;
> +    ebl_syscall_abi;
> +    ebl_abi_cfi;
> +    ebl_core_note;
> +    ebl_auxv_info;
> +    ebl_set_initial_registers_tid;
> +    ebl_frame_nregs;
> +    ebl_ra_offset;
> +    ebl_func_addr_mask;
> +    ebl_dwarf_to_regno;
> +    ebl_normalize_pc;
> +    ebl_unwind;
> +    ebl_resolve_sym_value;
> +} ELFUTILS_0.175;

But this is a nice starting point to see which functions could be
cleaned up and properly supported/exported.

And some can probably just be removed.
ebl_openbackend_machine is only use in a couple of tests.
ebl_openbackend_emulation doesn't seem to be used at all.

ebl_get_elfmachine can probably be replaced by simply checking
ehdr.e_machine? Likewise ebl_get_elfclass with ehdr.e_class?

The various _name functions can probably be cleaned up and exposed
(although I am not sure about the char buffer/length thing, I like them
to just return static strings).

The _check functions are only used by eu-elflint. Maybe just move them
into elflint?

ebl_syscall_abi is never used, but actually seems useful.

Not saying we should immediately do that, but the above would be some
functions that deserve some attention before we make them public.

Cheers,

Mark

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

end of thread, other threads:[~2019-07-08 21:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-06  0:35 [PATCH 0/5] elfutils: don't use dlopen() for libebl modules Omar Sandoval
2019-07-06  0:35 ` [PATCH 5/5] libdw: export libebl symbols Omar Sandoval
2019-07-08 21:14   ` Mark Wielaard
2019-07-06  0:35 ` [PATCH 4/5] Don't use dlopen() for libebl modules Omar Sandoval
2019-07-06  0:35 ` [PATCH 2/5] libcpu: merge libcpu_{i386,x86_64,bpf} into one library Omar Sandoval
2019-07-06  0:35 ` [PATCH 1/5] libebl: remove unnecessary variable in Makefile.am Omar Sandoval
2019-07-06  0:35 ` [PATCH 3/5] Add PIC and non-PIC variants of libcpu and libebl Omar Sandoval

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