elf.scm 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2014, 2015 Mark H Weaver <mhw@netris.org>
  4. ;;; Copyright © 2015 Andreas Enge <andreas@enge.fr>
  5. ;;; Copyright © 2017, 2018, 2019, 2020 Efraim Flashner <efraim@flashner.co.il>
  6. ;;; Copyright © 2017 Leo Famulari <leo@famulari.name>
  7. ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
  8. ;;; Copyright © 2018, 2020 Marius Bakke <mbakke@fastmail.com>
  9. ;;; Copyright © 2020 Mark Wielaard <mark@klomp.org>
  10. ;;; Copyright © 2020 Michael Rohleder <mike@rohleder.de>
  11. ;;; Copyright © 2021 Leo Le Bouter <lle-bout@zaclys.net>
  12. ;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
  13. ;;;
  14. ;;; This file is part of GNU Guix.
  15. ;;;
  16. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  17. ;;; under the terms of the GNU General Public License as published by
  18. ;;; the Free Software Foundation; either version 3 of the License, or (at
  19. ;;; your option) any later version.
  20. ;;;
  21. ;;; GNU Guix is distributed in the hope that it will be useful, but
  22. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  23. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. ;;; GNU General Public License for more details.
  25. ;;;
  26. ;;; You should have received a copy of the GNU General Public License
  27. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  28. (define-module (gnu packages elf)
  29. #:use-module (guix utils)
  30. #:use-module (guix packages)
  31. #:use-module (guix download)
  32. #:use-module (guix build-system gnu)
  33. #:use-module ((guix licenses) #:select (gpl3+ lgpl3+ lgpl2.0+))
  34. #:use-module (gnu packages)
  35. #:use-module (gnu packages autotools)
  36. #:use-module (gnu packages compression)
  37. #:use-module (gnu packages documentation)
  38. #:use-module (gnu packages gcc)
  39. #:use-module (gnu packages m4)
  40. #:use-module (gnu packages pkg-config)
  41. #:use-module (gnu packages python)
  42. #:use-module (gnu packages sphinx)
  43. #:use-module (gnu packages texinfo)
  44. #:use-module (gnu packages xml)
  45. #:use-module (srfi srfi-1)
  46. #:use-module (srfi srfi-26))
  47. (define-public elfutils
  48. (package
  49. (name "elfutils")
  50. (version "0.183")
  51. (source (origin
  52. (method url-fetch)
  53. (uri (string-append "https://sourceware.org/elfutils/ftp/"
  54. version "/elfutils-" version ".tar.bz2"))
  55. (sha256
  56. (base32
  57. "1igjfia9x8h6fmh9nbl8mpz0i24my5iixrji99qmi79hilh7qqy3"))
  58. (patches (search-patches "elfutils-tests-ptrace.patch"))))
  59. (build-system gnu-build-system)
  60. ;; Separate programs because that's usually not what elfutils users want,
  61. ;; and because they duplicate what Binutils provides (but are named
  62. ;; differently, using the eu- prefix and can be installed in parallel).
  63. (outputs '("out" ; libelf.so, elfutils/*.h, etc.
  64. "bin")) ; eu-nm, eu-objdump, etc.
  65. (arguments
  66. ;; Programs don't have libelf.so in their RUNPATH and libraries don't
  67. ;; know where to find each other.
  68. `(#:configure-flags (list (string-append "LDFLAGS=-Wl,-rpath="
  69. (assoc-ref %outputs "out")
  70. "/lib")
  71. "--disable-static"
  72. ;; TODO: Enable the debuginfo server. It
  73. ;; increases the closure size significantly
  74. ;; and presents bootstrapping problems, so
  75. ;; we disable it for now. See
  76. ;; https://issues.guix.gnu.org/38803 and
  77. ;; https://sourceware.org/bugzilla/show_bug.cgi?id=25509
  78. ;; for more information.
  79. "--disable-libdebuginfod"
  80. "--disable-debuginfod")
  81. ;; Disable tests on MIPS and PowerPC (without changing
  82. ;; the arguments list on other systems).
  83. ,@(if (any (cute string-prefix? <> (or (%current-target-system)
  84. (%current-system)))
  85. '("mips" "powerpc"))
  86. '(#:tests? #f)
  87. '())
  88. #:phases
  89. (modify-phases %standard-phases
  90. ;; No reason has been found for this test to reliably fail on aarch64-linux.
  91. (add-after 'unpack 'disable-failing-aarch64-tests
  92. (lambda _
  93. (substitute* "tests/Makefile.in"
  94. (("run-backtrace-native.sh") ""))
  95. #t)))))
  96. (native-inputs `(("m4" ,m4)))
  97. (inputs `(("zlib" ,zlib)))
  98. (home-page "https://sourceware.org/elfutils/")
  99. (synopsis "Collection of utilities and libraries to handle ELF files and
  100. DWARF data")
  101. (description
  102. "Elfutils is a collection of utilities and libraries to read, create and
  103. modify Executable and Linkable Format (@dfn{ELF}) binary files, find and
  104. handle Debugging With Arbitrary Record Formats (@dfn{DWARF}) debug data,
  105. symbols, thread state and stacktraces for processes and core files on
  106. GNU/Linux. Elfutils includes @file{libelf} for manipulating ELF files,
  107. @file{libdw} for inspecting DWARF data and process state and utilities like
  108. @command{eu-stack} (to show backtraces), @command{eu-nm} (for listing symbols
  109. from object files), @command{eu-size} (for listing the section sizes of an
  110. object or archive file), @command{eu-strip} (for discarding symbols),
  111. @command{eu-readelf} (to see the raw ELF file structures),
  112. @command{eu-elflint} (to check for well-formed ELF files),
  113. @command{eu-elfcompress} (to compress or decompress ELF sections), and more.")
  114. ;; Libraries are dual-licensed LGPLv3.0+ | GPLv2, and programs are GPLv3+.
  115. (license lgpl3+)))
  116. (define-public libabigail
  117. (package
  118. (name "libabigail")
  119. (home-page "https://sourceware.org/libabigail/")
  120. (version "1.8")
  121. (source (origin
  122. (method url-fetch)
  123. (uri (string-append "https://sourceware.org/pub/libabigail/"
  124. "libabigail-" version ".tar.gz"))
  125. (sha256
  126. (base32
  127. "0p363mkgypcklgf8iylxpbdnfgqc086a6fv7n9hzrjjci45jdgqw"))))
  128. (build-system gnu-build-system)
  129. (arguments
  130. `(#:configure-flags '("--disable-static"
  131. "--enable-bash-completion"
  132. "--enable-manual")
  133. #:make-flags '("V=1")
  134. #:phases (modify-phases %standard-phases
  135. (add-after 'unpack 'patch-source
  136. (lambda _
  137. (substitute* "build-aux/ltmain.sh"
  138. ;; Don't add -specs=/usr/lib/rpm/redhat/redhat-hardened-ld
  139. ;; to the GCC command line.
  140. (("compiler_flags=\"-specs=.*")
  141. "compiler_flags=\n"))
  142. #t))
  143. (add-after 'build 'build-documentation
  144. (lambda _
  145. (invoke "make" "-C" "doc/manuals" "html-doc" "man" "info")))
  146. (add-before 'check 'set-test-environment
  147. (lambda _
  148. (setenv "XDG_CACHE_HOME" "/tmp")
  149. #t))
  150. (add-after 'install 'install-documentation
  151. (lambda _
  152. (invoke "make" "-C" "doc/manuals"
  153. "install-man-and-info-doc")))
  154. (add-after 'install-documentation 'install-bash-completion
  155. (lambda* (#:key outputs #:allow-other-keys)
  156. (for-each (lambda (file)
  157. (install-file
  158. file (string-append (assoc-ref outputs "out")
  159. "/share/bash-completion"
  160. "/completions")))
  161. (find-files "bash-completion" ".*abi.*"))
  162. #t)))))
  163. (native-inputs
  164. `(("pkg-config" ,pkg-config)
  165. ("makeinfo" ,texinfo)
  166. ("python-sphinx" ,python-sphinx)
  167. ("python" ,python))) ;for tests
  168. (propagated-inputs
  169. `(("elfutils" ,elfutils) ;libabigail.la says -lelf
  170. ("libxml2" ,libxml2))) ;in Requires.private of libabigail.pc
  171. (synopsis "Analyze application binary interfaces (ABIs)")
  172. (description
  173. "@dfn{ABIGAIL} stands for the Application Binary Interface Generic
  174. Analysis and Instrumentation Library. It is a framework which aims at
  175. helping developers and software distributors to spot ABI-related issues
  176. like interface incompatibility in ELF shared libraries by performing a
  177. static analysis of the ELF binaries at hand.")
  178. (license lgpl3+)))
  179. (define-public libelf
  180. (package
  181. (name "libelf")
  182. (version "0.8.13")
  183. (source
  184. (origin
  185. (method url-fetch)
  186. (uri (list
  187. ;; As of May 2019, the original URL at mr511.de redirects to a
  188. ;; domain that doesn't resolve. Use these two mirrors instead.
  189. (string-append "https://fossies.org/linux/misc/old/"
  190. "libelf-" version ".tar.gz")
  191. (string-append "https://ftp.osuosl.org/pub/blfs/conglomeration/"
  192. "libelf/libelf-" version ".tar.gz")))
  193. (sha256
  194. (base32
  195. "0vf7s9dwk2xkmhb79aigqm0x0yfbw1j0b9ksm51207qwr179n6jr"))))
  196. (build-system gnu-build-system)
  197. (arguments
  198. `(#:phases
  199. (modify-phases %standard-phases
  200. ;; This old 'configure' script doesn't support cross-compilation
  201. ;; well. I.e., it fails to find the cross-compiler. Also,
  202. ;; the old `configure' script doesn't support variables passed as
  203. ;; arguments. A third problem is that config.sub is too old to
  204. ;; recognise aarch64 and powerpc64le.
  205. ;;
  206. ;; Solve this by regenerating the configure script and letting
  207. ;; autoreconf update 'config.sub'. While 'config.sub' is updated
  208. ;; anyway, update 'config.guess' as well.
  209. (add-before 'bootstrap 'delete-configure
  210. (lambda* (#:key native-inputs inputs #:allow-other-keys)
  211. (delete-file "configure")
  212. (delete-file "config.sub")
  213. (delete-file "config.guess")
  214. (for-each (lambda (file)
  215. (install-file
  216. (string-append
  217. (assoc-ref (or native-inputs inputs) "automake")
  218. "/share/automake-"
  219. ,(version-major+minor (package-version automake))
  220. "/" file) "."))
  221. '("config.sub" "config.guess")))))))
  222. (native-inputs
  223. `(("autoconf" ,autoconf)
  224. ;; For up-to-date 'config.guess' and 'config.sub'
  225. ("automake" ,automake)))
  226. (home-page (string-append "https://web.archive.org/web/20181111033959/"
  227. "http://www.mr511.de/software/english.html"))
  228. (synopsis "ELF object file access library")
  229. (description "Libelf is a C library to access ELF object files.")
  230. (license lgpl2.0+)))
  231. (define-public patchelf
  232. (package
  233. (name "patchelf")
  234. (version "0.11")
  235. (source (origin
  236. (method url-fetch)
  237. (uri (string-append
  238. "https://nixos.org/releases/patchelf/patchelf-"
  239. version
  240. "/patchelf-" version ".tar.bz2"))
  241. (sha256
  242. (base32
  243. "16ms3ijcihb88j3x6cl8cbvhia72afmfcphczb9cfwr0gbc22chx"))))
  244. (build-system gnu-build-system)
  245. (arguments
  246. '(#:phases
  247. (modify-phases %standard-phases
  248. (add-after 'unpack 'fix-tests
  249. ;; Our GCC code ensures that RUNPATH is never empty, it includes
  250. ;; at least glibc/lib and gcc:lib/lib.
  251. (lambda* (#:key inputs #:allow-other-keys)
  252. (substitute* "tests/no-rpath.sh"
  253. ;; Disable checking for an empty runpath:
  254. (("^if test.*") "")
  255. ;; Find libgcc_s.so, which is necessary for the test:
  256. (("/xxxxxxxxxxxxxxx") (string-append (assoc-ref inputs "gcc:lib")
  257. "/lib")))
  258. #t)))))
  259. (native-inputs
  260. `(("gcc:lib" ,gcc "lib")))
  261. (home-page "https://nixos.org/patchelf.html")
  262. (synopsis "Modify the dynamic linker and RPATH of ELF executables")
  263. (description
  264. "PatchELF allows the ELF \"interpreter\" and RPATH of an ELF binary to be
  265. changed.")
  266. (license gpl3+)))