openwrt/tools/elfutils/Makefile

108 lines
2.5 KiB
Makefile
Raw Permalink Normal View History

# SPDX-License-Identifier: GPL-2.0-only
include $(TOPDIR)/rules.mk
PKG_NAME:=elfutils
PKG_VERSION:=0.191
PKG_RELEASE:=2
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
PKG_SOURCE_URL:=https://sourceware.org/$(PKG_NAME)/ftp/$(PKG_VERSION)
PKG_HASH:=df76db71366d1d708365fc7a6c60ca48398f14367eb2b8954efc8897147ad871
PKG_LICENSE:=GPL-3.0-or-later
PKG_LICENSE_FILES:=COPYING COPYING-GPLV2 COPYING-LGPLV3
PKG_CPE_ID:=cpe:/a:elfutils_project:elfutils
PKG_FIXUP:=autoreconf
PKG_INSTALL:=1
PKG_PROGRAMS:=elflint findtextrel elfcmp unstrip stack elfcompress elfclassify srcfiles
PKG_SUBDIRS := \
libgnu \
config \
lib \
libelf \
libcpu \
backends \
libebl \
libdwelf \
libdwfl \
libdw \
src
PKG_GNULIB_BASE:=libgnu
PKG_GNULIB_ARGS = \
--dir=$(HOST_BUILD_DIR) \
--local-dir=$(STAGING_DIR_HOST)/share/gnulib \
--source-base=$(PKG_GNULIB_BASE) \
--libtool \
--avoid=reallocarray \
--import
PKG_GNULIB_MODS = \
argp \
fnmatch-gnu \
fts \
obstack \
progname \
strchrnul \
tsearch
include $(INCLUDE_DIR)/host-build.mk
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 <gvalkov@gmail.com> # macOS Signed-off-by: Michael Pratt <mcpratt@pm.me> Link: https://github.com/openwrt/openwrt/pull/15368 Signed-off-by: Robert Marko <robimarko@gmail.com>
2024-05-01 23:47:26 +02:00
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)' \
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 <gvalkov@gmail.com> # macOS Signed-off-by: Michael Pratt <mcpratt@pm.me> Link: https://github.com/openwrt/openwrt/pull/15368 Signed-off-by: Robert Marko <robimarko@gmail.com>
2024-05-01 23:47:26 +02:00
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)
HOST_CFLAGS += -I/opt/homebrew/include
endif
HOST_CFLAGS += -Wno-error -fPIC
tools/elfutils: pass -O2 in HOST_CXXFLAGS Trying to compile elfutils on Fedora 40 with GCC 14.1.1 will fail with: /home/robimarko/Building/AX3600/qualcommax/staging_dir/host/bin/g++ -std=c++11 -D_GNU_SOURCE -DHAVE_CONFIG_H -DLOCALEDIR='"/home/robimarko/Building/AX3600/qualcommax/staging_dir/host/share/locale"' -DDEBUGPRED=0 -DSRCDIR=\"/home/robimarko/Building/AX3600/qualcommax/build_dir/host/elfutils-0.191/src\" -DOBJDIR=\"/home/robimarko/Building/AX3600/qualcommax/build_dir/host/elfutils-0.191/src\" -I. -I.. -I../libgnu -I../libgnu -I. -I. -I../lib -I.. -I./../libelf -I./../libebl -I./../libdw -I./../libdwelf -I./../libdwfl -I./../libasm -I../debuginfod -I/home/robimarko/Building/AX3600/qualcommax/staging_dir/host/include -std=c++11 -Wall -Wshadow -Wtrampolines -Wlogical-op -Wduplicated-cond -Wnull-dereference -Wimplicit-fallthrough=5 -Werror -Wunused -Wextra -Wstack-usage=262144 -D_FORTIFY_SOURCE=3 -c -o srcfiles.o srcfiles.cxx In file included from /usr/include/c++/14/x86_64-redhat-linux/bits/os_defines.h:39, from /usr/include/c++/14/x86_64-redhat-linux/bits/c++config.h:2521, from /usr/include/c++/14/cstdlib:41, from ../libgnu/gettext.h:56, from ../libgnu/eu-config.h:62, from ../config.h:2378, from srcfiles.cxx:31: /usr/include/features.h:414:4: error: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Werror=cpp] 414 | # warning _FORTIFY_SOURCE requires compiling with optimization (-O) | ^~~~~~~ cc1plus: all warnings being treated as errors So, lets do as the error says and pass -O2 in HOST_CXXFLAGS like we already do by default in HOST_CFLAGS. Link: https://github.com/openwrt/openwrt/pull/15368 Signed-off-by: Robert Marko <robimarko@gmail.com>
2024-05-31 15:47:15 +02:00
HOST_CXXFLAGS += -O2
HOST_CONFIGURE_ARGS += \
--without-libintl-prefix \
--without-libiconv-prefix \
--disable-debuginfod \
--disable-libdebuginfod \
--disable-nls \
--disable-shared \
--enable-static \
--without-lzma \
--without-bzlib \
--without-zstd
ifeq ($(HOST_OS),Darwin)
HOST_CONFIGURE_ARGS += --disable-symbol-versioning
endif
Hooks/HostConfigure/Pre := Host/Gnulib $(Hooks/HostConfigure/Pre)
define Host/Gnulib
$(STAGING_DIR_HOST)/bin/gnulib-tool $(PKG_GNULIB_ARGS) $(PKG_GNULIB_MODS);
ln -sf ../lib/eu-config.h $(HOST_BUILD_DIR)/libgnu/;
endef
define Host/Compile
$(call Host/Compile/Default,SUBDIRS='$$$$(wildcard $(PKG_SUBDIRS))')
endef
define Host/Install
$(call Host/Compile/Default,install SUBDIRS='$$$$(wildcard $(PKG_SUBDIRS))')
endef
define Host/Uninstall
-$(call Host/Compile/Default,uninstall)
endef
$(eval $(call HostBuild))