;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2015 Eric Bavier ;;; Copyright © 2016 Jan Nieuwenhuizen ;;; Copyright © 2016, 2017 Mathieu Lirzin ;;; Copyright © 2017, 2020, 2021 Mathieu Othacehe ;;; Copyright © 2017, 2019, 2020 Ricardo Wurmus ;;; Copyright © 2018 Clément Lassieur ;;; Copyright © 2022, 2024 Arun Isaac ;;; Copyright © 2023 David Pflug ;;; ;;; This file is part of GNU Guix. ;;; ;;; GNU Guix is free software; you can redistribute it and/or modify it ;;; under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 3 of the License, or (at ;;; your option) any later version. ;;; ;;; GNU Guix is distributed in the hope that it will be useful, but ;;; WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY o
aboutsummaryrefslogtreecommitdiff
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2014, 2015 Mark H Weaver <mhw@netris.org>
;;; Copyright © 2015 Andreas Enge <andreas@enge.fr>
;;; Copyright © 2017-2024 Efraim Flashner <efraim@flashner.co.il>
;;; Copyright © 2017 Leo Famulari <leo@famulari.name>
;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
;;; Copyright © 2018, 2020 Marius Bakke <mbakke@fastmail.com>
;;; Copyright © 2020 Mark Wielaard <mark@klomp.org>
;;; Copyright © 2020 Michael Rohleder <mike@rohleder.de>
;;; Copyright © 2021 Leo Le Bouter <lle-bout@zaclys.net>
;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
;;; Copyright © 2022 Daniel Maksymow <daniel.maksymow@tuta.io>
;;; Copyright © 2023, 2024 Janneke Nieuwenhuizen <janneke@gnu.org>
;;; Copyright © 2024 Zheng Junjie <873216071@qq.com>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu packages elf)
  #:use-module (guix gexp)
  #:use-module (guix utils)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module (guix build-system gnu)
  #:use-module ((guix licenses) #:select (gpl2+ gpl3+ lgpl3+ lgpl2.0+ lgpl2.1 gpl2 bsd-2))
  #:use-module (gnu packages)
  #:use-module (gnu packages autotools)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages documentation)
  #:use-module (gnu packages gcc)
  #:use-module (gnu packages m4)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages python)
  #:use-module (gnu packages sphinx)
  #:use-module (gnu packages texinfo)
  #:use-module (gnu packages xml)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-26))

(define-public chrpath
  (package
    (name "chrpath")
    (version "0.18")
    (source (origin
              (method git-fetch)
              (uri (git-reference
                    (url "https://codeberg.org/pere/chrpath")
                    (commit (string-append "release_" version))))
              (file-name (git-file-name name version))
              (sha256
               (base32
                "0n7fp6xm660m8inaadlblh7zr8izyc3x39bfdqi6rj1kn0vmzra6"))))
    (build-system gnu-build-system)
    (native-inputs (list automake autoconf))
    (home-page "https://codeberg.org/pere/chrpath")
    (synopsis "Utility for editing the RPATH or RUNPATH of ELF binaries")
    (description "@code{chrpath} allows listing, changing or removing the
dynamic library load path (RPATH and RUNPATH) of compiled programs and
libraries.")
    (license gpl2+)))

(define-public elfutils
  (package
    (name "elfutils")
    (version "0.187")
    (source (origin
              (method url-fetch)
              (uri (string-append "https://sourceware.org/elfutils/ftp/"
                                  version "/elfutils-" version ".tar.bz2"))
              (sha256
               (base32
                "1j2lsicm3dkj5n6spszr9qy5rqm48bqimmz03x6hry8hwvxhs2z7"))
              (patches (search-patches "elfutils-tests-ptrace.patch"))))
    (build-system gnu-build-system)

    ;; Separate programs because that's usually not what elfutils users want,
    ;; and because they duplicate what Binutils provides (but are named
    ;; differently, using the eu- prefix and can be installed in parallel).
    (outputs '("out"                           ; libelf.so, elfutils/*.h, etc.
               "bin"))                         ; eu-nm, eu-objdump, etc.

    (arguments
     ;; Programs don't have libelf.so in their RUNPATH and libraries don't
     ;; know where to find each other.
     `(#:configure-flags (list (string-append "LDFLAGS=-Wl,-rpath="
                                              (assoc-ref %outputs "out")
                                              "/lib")
                               "--disable-static"
                               ;; TODO: Enable the debuginfo server.  It
                               ;; increases the closure size significantly
                               ;; and presents bootstrapping problems, so
                               ;; we disable it for now.  See
                               ;; https://issues.guix.gnu.org/38803 and
                               ;; https://sourceware.org/bugzilla/show_bug.cgi?id=25509
                               ;; for more information.
                               "--disable-libdebuginfod"
                               "--disable-debuginfod")

       ,@(if (target-hurd64?)
             '(#:make-flags '("core-file_no_Werror=yes"))
             '())

       ;; Disable tests on MIPS and PowerPC (without changing
       ;; the arguments list on other systems).
       ,@(if (any (cute string-prefix? <> (or (%current-target-system)
                                              (%current-system)))
                  '("mips" "powerpc"))
             '(#:tests? #f)
             '())

       #:phases
       ,#~(modify-phases %standard-phases
            ;; No reason has been found for this test to reliably fail on aarch64-linux.
            (add-after 'unpack 'disable-failing-aarch64-tests
              (lambda _
                (substitute* "tests/Makefile.in"
                  (("run-backtrace-native.sh") ""))
                #t))
            #$@(if (target-riscv64?)
                   #~((add-after 'unpack 'disable-failing-riscv64-test
                        (lambda _
                          (substitute* "tests/Makefile.in"
                            ;; dwfl_thread_getframes: No DWARF information found
                            (("run-backtrace-dwarf.sh") "")
                            ;; These tests have several errors:
                            ;; unknown program header entry type 0x70000003
                            ;; '.riscv.attributes' has unsupported type 1879048195
                            (("run-reverse-sections-self.sh") "")
                            (("run-strip-strmerge.sh") "")
                            (("run-elflint-self.sh") "")))))
                   #~())
            #$@(if (target-loongarch64?)
                   `((add-after 'unpack 'update-config-scripts
                       (lambda* (#:key inputs native-inputs #:allow-other-keys)
                         ;; Replace outdated config.guess and config.sub.
                         (for-each (lambda (file)
                                     (install-file
                                      (search-input-file
                                       (or native-inputs inputs)
                                       (string-append "/bin/" file)) "./config"))
                                   '("config.guess" "config.sub")))))
                   '())
            #$@(if (system-hurd?)
                   #~((add-after 'unpack 'skip-tests
                        (lambda _
                          (substitute* '("tests/elfstrtab.c"
                                         "tests/emptyfile.c")
                            (("elf_version \\(EV_CURRENT\\);" all)
                             "exit (77);"))
                          (substitute* '("tests/run-all-dwarf-ranges.sh"
                                         "tests/run-allfcts-multi.sh"
                                         "tests/run-attr-integrate-skel.sh"
                                         "tests/run-bug1-test.sh"
                                         "tests/run-copyadd-sections.sh"
                                         "tests/run-deleted.sh"
                                         "tests/run-get-units-split.sh"
                                         "tests/run-native-test.sh"
                                         "tests/run-readelf-loc.sh"
                                         "tests/run-readelf-ranges.sh"
                                         "tests/run-unit-info.sh"
                                         "tests/run-varlocs.sh")
                            (("^#!.*" all)
                             (string-append all "exit 77;\n"))))))
                   #~())
            #$@(if (%current-target-system)
                   #~((add-after 'unpack 'patch
                        (lambda* (#:key native-inputs #:allow-other-keys)
                          (invoke
                           "patch" "-p1" "--force" "-i"
                           #$(local-file
                              (search-patch
                               "elfutils-libdwfl-string-overflow.patch"))))))
                   #~()))))
    (native-inputs (append (if (target-loongarch64?)
                               (list config)
                               (list))
                           (list m4)))
    (inputs (list xz zlib))
    (home-page "https://sourceware.org/elfutils/")
    (synopsis "Collection of utilities and libraries to handle ELF files and
DWARF data")
    (description
     "Elfutils is a collection of utilities and libraries to read, create and
modify Executable and Linkable Format (@dfn{ELF}) binary files, find and
handle Debugging With Arbitrary Record Formats (@dfn{DWARF}) debug data,
symbols, thread state and stacktraces for processes and core files on
GNU/Linux.  Elfutils includes @file{libelf} for