diff --git a/pkgs/by-name/el/elfutils/cxx-header-collision.patch b/pkgs/by-name/el/elfutils/cxx-header-collision.patch index 3e123b1a62ba9..e22141ea3d508 100644 --- a/pkgs/by-name/el/elfutils/cxx-header-collision.patch +++ b/pkgs/by-name/el/elfutils/cxx-header-collision.patch @@ -1,35 +1,31 @@ -From: Tristan Ross -Date: Wed, 31 Jul 2024 04:03:03 +0000 (-0700) -Subject: Prevent binaries in src from colliding with libc++ headers -X-Git-Url: https://sourceware.org/git/?p=elfutils.git;a=commitdiff_plain;h=232b9ede92cbecabbd61291c2fc9aaf3fc61061f;hp=87a60d22299c4ba7b94cbce04a32c2abf015f98a +commit 014dd313f994768b41ea982089c43e555b4aa220 +Author: Tristan Ross +Date: Wed Jun 4 19:48:16 2025 -0700 -Prevent binaries in src from colliding with libc++ headers - -Discovered with Nix and LLVM 17. Headers inside of libc++ can easily -collide with binaries being linked in src. This results in clang trying -to include a binary as a header. - -Fix this by removing '-I.' and '-I$(srcdir)' from AM_CPPFLAGS and -DEFAULT_INCLUDES in src/Makefile.am. - -To facilitate this config/eu.am has been refactored. New file -config/eu-common.am contains all of the old eu.am but with the -AM_CPPFLAGS definition removed. eu.am now includes eu-common.am and -contains the old AM_CPPFLAGS definition. - -eu.am functionality does not change, but src/Makefile.am can instead -include eu-common.am and define its own AM_CPPFLAGS without causing a -"multiply defined" warning during autoreconf. - -Signed-off-by: Tristan Ross ---- + Prevent binaries in src from colliding with libc++ headers + + Discovered with Nix and LLVM 17. Headers inside of libc++ can easily + collide with binaries being linked in src. This results in clang trying + to include a binary as a header. + + Fix this by removing '-I.' and '-I$(srcdir)' from AM_CPPFLAGS and + DEFAULT_INCLUDES in src/Makefile.am. + + To facilitate this config/eu.am has been refactored. New file + config/eu-common.am contains all of the old eu.am but with the + AM_CPPFLAGS definition removed. eu.am now includes eu-common.am and + contains the old AM_CPPFLAGS definition. + + eu.am functionality does not change, but src/Makefile.am can instead + include eu-common.am and define its own AM_CPPFLAGS without causing a + "multiply defined" warning during autoreconf. diff --git a/config/eu-common.am b/config/eu-common.am new file mode 100644 -index 00000000..9cc7f696 +index 00000000..06249478 --- /dev/null +++ b/config/eu-common.am -@@ -0,0 +1,148 @@ +@@ -0,0 +1,156 @@ +## Common automake fragments for elfutils subdirectory makefiles. +## +## Copyright (C) 2010, 2014, 2016 Red Hat, Inc. @@ -125,7 +121,7 @@ index 00000000..9cc7f696 +USE_AFTER_FREE3_WARNING= +endif + -+AM_CFLAGS = -std=gnu99 -Wall -Wshadow -Wformat=2 \ ++AM_CFLAGS = -Wall -Wshadow -Wformat=2 \ + -Wold-style-definition -Wstrict-prototypes $(TRAMPOLINES_WARNING) \ + $(LOGICAL_OP_WARNING) $(DUPLICATED_COND_WARNING) \ + $(NULL_DEREFERENCE_WARNING) $(IMPLICIT_FALLTHROUGH_WARNING) \ @@ -166,7 +162,15 @@ index 00000000..9cc7f696 + $(AM_V_CC)$(COMPILE.os) -c -o $@ $(fpic_CFLAGS) $(DEFS.os) $< +endif + -+CLEANFILES = *.gcno *.gcda ++COVERAGE_OUTPUT_DIRECTORY = coverage ++COVERAGE_OUTPUT_FILE = $(PACKAGE_NAME).lcov ++ ++.PHONY: clean-coverage coverage ++ ++clean-local: clean-coverage ++clean-coverage: ++ -rm -rf $(COVERAGE_OUTPUT_DIRECTORY) ++ -rm -f $(COVERAGE_OUTPUT_FILE) *.gcno *.gcda + +textrel_msg = echo "WARNING: TEXTREL found in '$@'" +if FATAL_TEXTREL @@ -179,22 +183,15 @@ index 00000000..9cc7f696 +print-%: + @echo $*=$($*) diff --git a/config/eu.am b/config/eu.am -index 0b7dab5b..3aa6048a 100644 +index 5157a34e..6b1425d6 100644 --- a/config/eu.am +++ b/config/eu.am -@@ -1,4 +1,5 @@ --## Common automake fragments for elfutils subdirectory makefiles. -+## Common automake fragments for elfutils subdirectory makefiles -+## with AM_CPPFLAGS set. - ## - ## Copyright (C) 2010, 2014, 2016 Red Hat, Inc. - ## Copyright (C) 2023, Mark J. Wielaard -@@ -30,120 +31,5 @@ +@@ -30,128 +30,5 @@ ## not, see . ## -DEFS = -D_GNU_SOURCE -DHAVE_CONFIG_H -DLOCALEDIR='"${localedir}"' --AM_CPPFLAGS = -iquote . -I$(srcdir) -I$(top_srcdir)/lib -I.. + AM_CPPFLAGS = -iquote . -I$(srcdir) -I$(top_srcdir)/lib -I.. - -# Drop the 'u' flag that automake adds by default. It is incompatible -# with deterministic archives. @@ -257,7 +254,7 @@ index 0b7dab5b..3aa6048a 100644 -USE_AFTER_FREE3_WARNING= -endif - --AM_CFLAGS = -std=gnu99 -Wall -Wshadow -Wformat=2 \ +-AM_CFLAGS = -Wall -Wshadow -Wformat=2 \ - -Wold-style-definition -Wstrict-prototypes $(TRAMPOLINES_WARNING) \ - $(LOGICAL_OP_WARNING) $(DUPLICATED_COND_WARNING) \ - $(NULL_DEREFERENCE_WARNING) $(IMPLICIT_FALLTHROUGH_WARNING) \ @@ -298,7 +295,15 @@ index 0b7dab5b..3aa6048a 100644 - $(AM_V_CC)$(COMPILE.os) -c -o $@ $(fpic_CFLAGS) $(DEFS.os) $< -endif - --CLEANFILES = *.gcno *.gcda +-COVERAGE_OUTPUT_DIRECTORY = coverage +-COVERAGE_OUTPUT_FILE = $(PACKAGE_NAME).lcov +- +-.PHONY: clean-coverage coverage +- +-clean-local: clean-coverage +-clean-coverage: +- -rm -rf $(COVERAGE_OUTPUT_DIRECTORY) +- -rm -f $(COVERAGE_OUTPUT_FILE) *.gcno *.gcda - -textrel_msg = echo "WARNING: TEXTREL found in '$@'" -if FATAL_TEXTREL @@ -310,13 +315,12 @@ index 0b7dab5b..3aa6048a 100644 - -print-%: - @echo $*=$($*) -+AM_CPPFLAGS = -I. -I$(srcdir) -I$(top_srcdir)/lib -I.. +include $(top_srcdir)/config/eu-common.am diff --git a/src/Makefile.am b/src/Makefile.am -index 97a0c61a..5bb8c078 100644 +index 4a3fb957..8b9e2758 100644 --- a/src/Makefile.am +++ b/src/Makefile.am -@@ -16,14 +16,15 @@ +@@ -16,15 +16,21 @@ ## You should have received a copy of the GNU General Public License ## along with this program. If not, see . ## @@ -328,11 +332,19 @@ index 97a0c61a..5bb8c078 100644 -DEFAULT_INCLUDES = -AM_CPPFLAGS += -I$(srcdir)/../libelf -I$(srcdir)/../libebl \ - -I$(srcdir)/../libdw -I$(srcdir)/../libdwelf \ -- -I$(srcdir)/../libdwfl -I$(srcdir)/../libasm -I../debuginfod +- -I$(srcdir)/../libdwfl -I$(srcdir)/../libdwfl_stacktrace \ +- -I$(srcdir)/../libasm -I../debuginfod +DEFAULT_INCLUDES = -I$(top_builddir) -+AM_CPPFLAGS = -I$(top_srcdir)/lib -I.. \ -+ -I$(srcdir)/../libelf -I$(srcdir)/../libebl \ -+ -I$(srcdir)/../libdw -I$(srcdir)/../libdwelf \ -+ -I$(srcdir)/../libdwfl -I$(srcdir)/../libasm -I../debuginfod ++AM_CPPFLAGS = -I$(top_srcdir)/lib \ ++ -I.. \ ++ -I$(srcdir)/../libelf \ ++ -I$(srcdir)/../libebl \ ++ -I$(srcdir)/../libdw \ ++ -I$(srcdir)/../libdwelf \ ++ -I$(srcdir)/../libdwfl \ ++ -I$(srcdir)/../libdwfl_stacktrace \ ++ -I$(srcdir)/../libasm \ ++ -I../debuginfod AM_LDFLAGS = -Wl,-rpath-link,../libelf:../libdw $(STACK_USAGE_NO_ERROR) + diff --git a/pkgs/by-name/el/elfutils/nonlinux-perf.patch b/pkgs/by-name/el/elfutils/nonlinux-perf.patch new file mode 100644 index 0000000000000..146197843cd19 --- /dev/null +++ b/pkgs/by-name/el/elfutils/nonlinux-perf.patch @@ -0,0 +1,53 @@ +diff --git a/libdwfl_stacktrace/dwflst_perf_frame.c b/libdwfl_stacktrace/dwflst_perf_frame.c +index dc274e8e..9776bee8 100644 +--- a/libdwfl_stacktrace/dwflst_perf_frame.c ++++ b/libdwfl_stacktrace/dwflst_perf_frame.c +@@ -120,6 +120,7 @@ sample_getthread (Dwfl *dwfl __attribute__ ((unused)), pid_t tid, + else \ + memcpy ((result), (d), sizeof (uint32_t)); + ++#if defined(__linux__) + #define copy_word(result, d, abi) \ + if ((abi) == PERF_SAMPLE_REGS_ABI_64) \ + { copy_word_64((result), (d)); } \ +@@ -127,6 +128,12 @@ sample_getthread (Dwfl *dwfl __attribute__ ((unused)), pid_t tid, + { copy_word_32((result), (d)); } \ + else \ + *(result) = 0; ++#else ++#define copy_word(result, d, abi) \ ++ (void)d; \ ++ (void)abi; \ ++ *(result) = 0; ++#endif + + static bool + elf_memory_read (Dwfl *dwfl, Dwarf_Addr addr, Dwarf_Word *result, void *arg) +@@ -167,6 +174,7 @@ sample_memory_read (Dwfl *dwfl, Dwarf_Addr addr, Dwarf_Word *result, void *arg) + return true; + } + ++#if defined(__linux__) + static bool + sample_set_initial_registers (Dwfl_Thread *thread, void *arg) + { +@@ -180,6 +188,7 @@ sample_set_initial_registers (Dwfl_Thread *thread, void *arg) + sample_arg->perf_regs_mask, sample_arg->abi, + __libdwfl_set_initial_registers_thread, thread); + } ++#endif + + static void + sample_detach (Dwfl *dwfl __attribute__ ((unused)), void *dwfl_arg) +@@ -194,7 +203,11 @@ static const Dwfl_Thread_Callbacks sample_thread_callbacks = + sample_next_thread, + sample_getthread, + sample_memory_read, ++#if defined(__linux__) + sample_set_initial_registers, ++#else ++ NULL, ++#endif + sample_detach, + NULL, /* sample_thread_detach */ + }; diff --git a/pkgs/by-name/el/elfutils/package.nix b/pkgs/by-name/el/elfutils/package.nix index 84c713cf7cfae..dfd9ed7fbcc6c 100644 --- a/pkgs/by-name/el/elfutils/package.nix +++ b/pkgs/by-name/el/elfutils/package.nix @@ -13,10 +13,12 @@ bison, flex, gettext, + libintl, xz, setupDebugInfoDirs, argp-standalone, - enableDebuginfod ? lib.meta.availableOn stdenv.hostPlatform libarchive, + enableDebuginfod ? + lib.meta.availableOn stdenv.hostPlatform libarchive && !stdenv.hostPlatform.isFreeBSD, sqlite, curl, json_c, @@ -38,6 +40,7 @@ stdenv.mkDerivation rec { patches = [ + ./nonlinux-perf.patch ./debug-info-from-env.patch (fetchpatch { name = "fix-aarch64_fregs.patch"; @@ -63,7 +66,34 @@ stdenv.mkDerivation rec { ++ lib.optionals stdenv.hostPlatform.isMusl [ ./musl-error_h.patch ] # Prevent headers and binaries from colliding which results in an error. # https://sourceware.org/pipermail/elfutils-devel/2024q3/007281.html - ++ lib.optional (stdenv.targetPlatform.useLLVM or false) ./cxx-header-collision.patch; + ++ lib.optional (stdenv.targetPlatform.useLLVM or false) ./cxx-header-collision.patch + ++ lib.optionals stdenv.hostPlatform.isFreeBSD [ + (fetchpatch { + url = "https://raw.githubusercontent.com/freebsd/freebsd-ports/ed3a65c936adead5ef586d5121aebed85585a75e/devel/elfutils/files/patch-configure.ac"; + hash = "sha256-tUdqqcB5m/oIphHBc9ubia7rOoN78eQmwGrbM+3L8GA="; + extraPrefix = ""; + }) + (fetchpatch { + url = "https://raw.githubusercontent.com/freebsd/freebsd-ports/412c9ba424c45d482bb7ca2740933cebcca5bacf/devel/elfutils/files/patch-lib_eu-config.h"; + hash = "sha256-yF37OBz/oBiH8okPts2GMGJaJbJ5X58AI7MsvO3SKuM="; + extraPrefix = ""; + }) + (fetchpatch { + url = "https://raw.githubusercontent.com/freebsd/freebsd-ports/adf6019c3c9053e617353dfb9f0843e4880ab4ae/devel/elfutils/files/patch-lib_stdio__ext.h"; + hash = "sha256-I11AX6mRkiOsqSHHb1ObP6Ft0E925nyyUWlolas9q5I="; + extraPrefix = ""; + }) + (fetchpatch { + url = "https://raw.githubusercontent.com/freebsd/freebsd-ports/2c1e4c5f2dda0912ede3a03515b54a99eea90997/devel/elfutils/files/patch-libelf_elf.h"; + hash = "sha256-UVj8dzMrS01YTyjl2xPOih/f6Kvs+QO4Fq+cwwln760="; + extraPrefix = ""; + }) + (fetchpatch { + url = "https://raw.githubusercontent.com/freebsd/freebsd-ports/2c1e4c5f2dda0912ede3a03515b54a99eea90997/devel/elfutils/files/patch-libelf_gelf.h"; + hash = "sha256-dNbX9um1dHCc8v7R3dl0xD4NIkLlhPPk49RG4uC7OZg="; + extraPrefix = ""; + }) + ]; postPatch = '' @@ -74,6 +104,23 @@ stdenv.mkDerivation rec { # # > dwfl_thread_getframes: No DWARF information found sed -i s/run-backtrace-dwarf.sh//g tests/Makefile.in + '' + + lib.optionalString stdenv.hostPlatform.isFreeBSD ( + # alloca is part of stdlib.h here + '' + sed -E -i -e "/alloca.h/d" lib/libeu.h + '' + # one of the ports patches targets an older version which interacts poorly with a #pragma poision directive + + '' + sed -E -i -e '/^#define.*basename.*eu_basename$/d' lib/eu-config.h + '' + # C compilers are strict + + '' + substituteInPlace lib/eu-config.h --replace-fail 'return (memchr(s, c, SSIZE_MAX))' 'return ((void*)memchr(s, c, SSIZE_MAX))' + '' + ) + + lib.optionalString (!enableDebuginfod) '' + sed -E -i -e '/size_t BUFFER_SIZE/d' src/srcfiles.cxx ''; outputs = [ @@ -93,7 +140,7 @@ stdenv.mkDerivation rec { gettext bzip2 ] - ++ lib.optional enableDebuginfod pkg-config + ++ lib.optional (enableDebuginfod || stdenv.targetPlatform.useLLVM or false) pkg-config ++ lib.optional (stdenv.targetPlatform.useLLVM or false) autoreconfHook; buildInputs = [ @@ -113,10 +160,20 @@ stdenv.mkDerivation rec { json_c libmicrohttpd libarchive + ] + ++ lib.optionals stdenv.hostPlatform.isFreeBSD [ + argp-standalone + libintl + musl-obstack ]; propagatedNativeBuildInputs = [ setupDebugInfoDirs ]; + env = lib.optionalAttrs stdenv.hostPlatform.isFreeBSD { + NIX_CFLAGS_COMPILE = "-Wno-error=format-nonliteral -DFREEBSD_HAS_MEMPCPY -D_GL_CONFIG_H_INCLUDED"; + NIX_LDFLAGS = "-lobstack"; + }; + hardeningDisable = [ "strictflexarrays3" ]; configureFlags = @@ -164,7 +221,7 @@ stdenv.mkDerivation rec { meta = with lib; { homepage = "https://sourceware.org/elfutils/"; description = "Set of utilities to handle ELF objects"; - platforms = platforms.linux; + platforms = platforms.linux ++ platforms.freebsd; # https://lists.fedorahosted.org/pipermail/elfutils-devel/2014-November/004223.html badPlatforms = [ lib.systems.inspect.platformPatterns.isStatic ]; # licenses are GPL2 or LGPL3+ for libraries, GPL3+ for bins,