From: Michael Pratt Date: Wed, 1 May 2024 21:47:26 +0000 (-0400) Subject: tools/elfutils: do not directly link gnulib to libelf X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=5f47ccc0ea596248fdb458b933ef8a406f574f8a;p=openwrt%2Fstaging%2Fansuel.git tools/elfutils: do not directly link gnulib to libelf The compiled library resulting from importing gnulib has been linked to libelf in order to easily cover other link dependencies. However, this is not appropriate for linking libelf to other programs as it bloats the resulting libelf library, and may result in multiple defintions of symbols based on whether or not certain modules from gnulib are included while elfutils already has it's own definition of a function. This is not a problem while building elfutils, because gnulib has it's own way of creating function aliases and special declarations that allow the linker to ignore the original function definitions, however, when libelf is used to link to something else, this results in an error at link time. The gnulib manual recommended linking the libraries directly, but those who have written it may not have considered how this can affect the ability to link that library in other builds, they likely assume the build targets would not be a dependency. Fix this by removing the linking between gnulib and libelf and instead overriding Make variables in order to add linking between gnulib and each of the binaries provided by elfutils, using Make functions to avoid applying it to other subdirectories. The function tdestroy() would still be missing on macOS, but the existence of the gnulib tsearch object having been built is an indicator of whether or not it is needed because it is only built conditionally by gnulib, so include linking that object only when it exists. Block the unnecessary replacement of some functions by gnulib so that future linking with libelf doesn't require the associated gnulib "rpl" prefixed functions. These replacements are very strict in order to correct minor bugs that don't have a real impact in almost all cases or new standards requirements that are not yet in effect or used. Tested-by: Georgi Valkov # macOS Signed-off-by: Michael Pratt Link: https://github.com/openwrt/openwrt/pull/15368 Signed-off-by: Robert Marko --- diff --git a/tools/elfutils/Makefile b/tools/elfutils/Makefile index b66d064e2b..39e7f80b4a 100644 --- a/tools/elfutils/Makefile +++ b/tools/elfutils/Makefile @@ -53,8 +53,14 @@ PKG_GNULIB_MODS = \ include $(INCLUDE_DIR)/host-build.mk +export $(PKG_GNULIB_BASE)=$(HOST_BUILD_DIR)/$(PKG_GNULIB_BASE)/$(PKG_GNULIB_BASE).la +export $(PKG_GNULIB_BASE)_tsearch=$(HOST_BUILD_DIR)/$(PKG_GNULIB_BASE)/$(PKG_GNULIB_BASE)_la-tsearch.lo + HOST_MAKE_FLAGS += \ AM_LDFLAGS='$$$$(STACK_USAGE_NO_ERROR)' \ + LIBS+='$$$$(if $$$$(findstring $(lastword $(PKG_SUBDIRS)),$$$$(subdir)), $$$$($(PKG_GNULIB_BASE)))' \ + LIBS+='$$$$(wildcard $$$$($(PKG_GNULIB_BASE)_tsearch))' \ + REPLACE_FCNTL=0 REPLACE_FREE=0 REPLACE_FSTAT=0 REPLACE_OPEN=0 \ bin_PROGRAMS='$(PKG_PROGRAMS)' EXEEXT= ifeq ($(HOST_OS),Darwin) diff --git a/tools/elfutils/patches/100-portability.patch b/tools/elfutils/patches/100-portability.patch index 980b117f21..09ee8daf1f 100644 --- a/tools/elfutils/patches/100-portability.patch +++ b/tools/elfutils/patches/100-portability.patch @@ -198,7 +198,7 @@ pkginclude_HEADERS = elf-knowledge.h -libelf_a_SOURCES = elf_version.c elf_hash.c elf_error.c elf_fill.c \ -+libelf_la_LIBADD = ../libgnu/libgnu.la ../lib/libeu.la -lz $(zstd_LIBS) -lpthread ++libelf_la_LIBADD = ../lib/libeu.la -lz $(zstd_LIBS) -lpthread +libelf_la_SOURCES = elf_version.c elf_hash.c elf_error.c \ elf_begin.c elf_next.c elf_rand.c elf_end.c elf_kind.c \ gelf_getclass.c elf_getbase.c elf_getident.c \