Skip to content

Commit 6a13d74

Browse files
committed
libdrgn: build with bundled elfutils
Now that we have the bundled version of elfutils, build it from libdrgn and link to it. We can also get rid of the elfutils version checks from the libdrgn code.
1 parent 1cedca8 commit 6a13d74

14 files changed

+453
-94
lines changed

.travis.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@ script: python setup.py test
1010
env:
1111
global:
1212
- OMP_NUM_THREADS=4
13-
matrix:
14-
- CC=gcc
15-
- CC=clang
1613

1714
addons:
1815
apt:
1916
packages:
20-
- libelf-dev
21-
- libdw-dev
22-
- libomp-dev
17+
- libbz2-dev
18+
- liblzma-dev
19+
- zlib1g-dev

README.rst

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,33 @@ Documentation can be found at `drgn.readthedocs.io
4242
Installation
4343
------------
4444

45-
Install the following dependencies:
45+
.. start-install-dependencies
4646
47-
* Python 3.6 or newer
48-
* elfutils development libraries (libelf and libdw)
49-
* GNU autotools (autoconf, automake, and libtool) and pkgconf
47+
Install dependencies:
48+
49+
Arch Linux::
50+
51+
$ sudo pacman -S --needed autoconf automake bison bzip2 flex gawk gcc libtool make pkgconf python python-setuptools xz zlib
52+
53+
Debian/Ubuntu::
54+
55+
$ sudo apt-get install autoconf automake bison flex gawk gcc libbz2-dev liblzma-dev libtool make pkgconf python3 python3-dev python3-setuptools zlib1g-dev
56+
57+
Note that Debian Stretch, Ubuntu Trusty, and Ubuntu Xenial (and older) ship
58+
Python versions which are too old. Python 3.6 or newer must be installed
59+
manually.
60+
61+
Fedora::
62+
63+
$ sudo dnf install autoconf automake bison bzip2-devel flex gawk gcc libtool make pkgconf python3 python3-devel python3-setuptools xz-devel zlib-devel
5064

5165
Optionally, install:
5266

5367
* `libkdumpfile <https://github.com/ptesarik/libkdumpfile>`_ if you want
5468
support for kdump-compressed kernel core dumps
5569

70+
.. end-install-dependencies
71+
5672
Then, run:
5773

5874
.. code-block:: console

docs/installation.rst

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,32 @@ Installation
33

44
.. highlight:: console
55

6-
drgn depends on `Python <https://www.python.org/>`_ 3.6 or newer as well as
7-
`elfutils <https://sourceware.org/elfutils/>`_. The build requires `GCC
8-
<https://gcc.gnu.org/>`_ or `Clang <https://clang.llvm.org/>`_, `GNU Make
9-
<https://www.gnu.org/software/make/>`_, `pkgconf <http://pkgconf.org/>`_, and
10-
`setuptools <https://pypi.org/project/setuptools/>`_. A build from a Git
11-
checkout also requires the GNU Autotools (`autoconf
12-
<https://www.gnu.org/software/autoconf/>`_, `automake
13-
<https://www.gnu.org/software/automake/automake.html>`_, and `libtool
14-
<https://www.gnu.org/software/libtool/libtool.html>`_). Install those
15-
dependencies:
16-
17-
Arch Linux::
18-
19-
$ sudo pacman -S --needed autoconf automake libtool make gcc pkgconf libelf python python-setuptools
20-
21-
Debian/Ubuntu::
22-
23-
$ sudo apt-get install autoconf automake libtool make gcc pkgconf libelf-dev libdw-dev python3 python3-dev python3-setuptools
24-
25-
Note that Debian, Ubuntu Trusty, and Ubuntu Xenial ship Python versions which
26-
are too old, so a newer version must be installed manually.
27-
28-
Due to a packaging `bug
29-
<https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=885071>`_, the following may
30-
also be required::
31-
32-
$ sudo apt-get install liblzma-dev zlib1g-dev
33-
34-
Fedora::
35-
36-
$ sudo dnf install autoconf automake libtool make gcc pkgconf elfutils-devel python3 python3-devel python3-setuptools
6+
drgn depends on:
7+
8+
- `Python <https://www.python.org/>`_ 3.6 or newer
9+
- `zlib <https://www.zlib.net>`_
10+
- `xz <https://tukaani.org/xz/>`_
11+
- `bzip2 <http://www.bzip.org>`_
12+
13+
A version of `elfutils <https://sourceware.org/elfutils/>`_ is bundled with
14+
drgn.
15+
16+
The build requires:
17+
18+
- `GCC <https://gcc.gnu.org/>`_
19+
- `GNU Make <https://www.gnu.org/software/make/>`_
20+
- `pkgconf <http://pkgconf.org/>`_
21+
- `setuptools <https://pypi.org/project/setuptools/>`_
22+
- `autoconf <https://www.gnu.org/software/autoconf/>`_
23+
- `automake <https://www.gnu.org/software/automake/>`_
24+
- `libtool <https://www.gnu.org/software/libtool/>`_
25+
- `flex <https://github.com/westes/flex>`_
26+
- `GNU bison <https://www.gnu.org/software/bison/>`_
27+
- `GNU awk <https://www.gnu.org/software/gawk/>`_
28+
29+
.. include:: ../README.rst
30+
:start-after: start-install-dependencies
31+
:end-before: end-install-dependencies
3732

3833
Then, drgn can be built and installed::
3934

libdrgn/Makefile.am

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
ACLOCAL_AMFLAGS = -I m4
22

3+
SUBDIRS = elfutils include
4+
5+
AM_CPPFLAGS = -Iinclude -D_GNU_SOURCE
6+
37
include_HEADERS = drgn.h
48

59
noinst_LTLIBRARIES = libdrgnimpl.la
@@ -51,22 +55,21 @@ libdrgnimpl_la_SOURCES = arch_x86_64.c \
5155
vector.c \
5256
vector.h
5357

54-
libdrgnimpl_la_CFLAGS = -fvisibility=hidden -fopenmp $(libelf_CFLAGS) \
55-
$(libdw_CFLAGS)
56-
libdrgnimpl_la_CPPFLAGS = -D_GNU_SOURCE
57-
libdrgnimpl_la_LIBADD = $(libelf_LIBS) $(libdw_LIBS)
58+
libdrgnimpl_la_CFLAGS = -fvisibility=hidden -fopenmp
5859

5960
if WITH_LIBKDUMPFILE
6061
libdrgnimpl_la_SOURCES += kdump.c
6162
libdrgnimpl_la_CFLAGS += $(libkdumpfile_CFLAGS)
62-
libdrgnimpl_la_LIBADD += $(libkdumpfile_LIBS)
63+
libdrgnimpl_la_LIBADD = $(libkdumpfile_LIBS)
6364
endif
6465

66+
elfutils_LIBS = elfutils/libdw/libdw.a elfutils/libelf/libelf.a -lz -llzma -lbz2
67+
6568
lib_LTLIBRARIES = libdrgn.la
6669

6770
libdrgn_la_SOURCES =
6871
libdrgn_la_LDFLAGS = -version-info 0:0:0
69-
libdrgn_la_LIBADD = libdrgnimpl.la
72+
libdrgn_la_LIBADD = libdrgnimpl.la $(elfutils_LIBS)
7073

7174
if WITH_PYTHON
7275
noinst_LTLIBRARIES += _drgn.la
@@ -90,10 +93,10 @@ _drgn_la_SOURCES = python/docstrings.h \
9093
nodist__drgn_la_SOURCES = python/constants.c python/docstrings.c
9194

9295
_drgn_la_CFLAGS = -fvisibility=hidden
93-
_drgn_la_CPPFLAGS = $(PYTHON_CPPFLAGS) -D_GNU_SOURCE
96+
_drgn_la_CPPFLAGS = $(AM_CPPFLAGS) $(PYTHON_CPPFLAGS)
9497
_drgn_la_LDFLAGS = -Wl,--exclude-libs,ALL -avoid-version -module -shared \
9598
-rpath $(pkgpyexecdir)
96-
_drgn_la_LIBADD = libdrgnimpl.la
99+
_drgn_la_LIBADD = libdrgnimpl.la $(elfutils_LIBS)
97100

98101
if WITH_LIBKDUMPFILE
99102
_drgn_la_CFLAGS += $(libkdumpfile_CFLAGS)

libdrgn/configure.ac

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ python3-devel or python3-dev) or specify the location of the Python development
4848
headers by setting the PYTHON_CPPFLAGS environment variable.])])
4949
CPPFLAGS="$save_CPPFLAGS"])
5050

51+
PKG_PROG_PKG_CONFIG
5152
AC_ARG_WITH([libkdumpfile],
5253
[AS_HELP_STRING([--with-libkdumpfile],
5354
[build with support for the makedumpfile kernel
@@ -62,14 +63,13 @@ AS_CASE(["x$with_libkdumpfile"],
6263
AM_CONDITIONAL([WITH_LIBKDUMPFILE], [test "x$with_libkdumpfile" = xyes])
6364
AM_COND_IF([WITH_LIBKDUMPFILE], [AC_DEFINE(WITH_LIBKDUMPFILE)])
6465

65-
PKG_PROG_PKG_CONFIG
66-
PKG_CHECK_MODULES(libelf, [libelf])
67-
AC_SUBST([libelf_CFLAGS])
68-
AC_SUBST([libelf_LIBS])
69-
dnl We need dwarf_cu_getdwarf() which was added in elfutils 0.160.
70-
PKG_CHECK_MODULES(libdw, [libdw >= 0.160])
71-
AC_SUBST([libdw_CFLAGS])
72-
AC_SUBST([libdw_LIBS])
66+
AX_SUBDIRS_CONFIGURE([elfutils],
67+
[[--enable-maintainer-mode],
68+
[--disable-nls],
69+
[--disable-programs],
70+
[--disable-shared]],
71+
[CFLAGS=-fPIC -Wno-error], [],
72+
[--disable-static])
7373

74-
AC_CONFIG_FILES([Makefile])
74+
AC_CONFIG_FILES([Makefile include/Makefile])
7575
AC_OUTPUT

libdrgn/dwarf_index.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,20 +1825,9 @@ static int drgn_dwfl_module_removed(Dwfl_Module *module, void *userdatap,
18251825

18261826
static void drgn_remove_dwfl_modules(Dwfl *dwfl, bool unindexed)
18271827
{
1828-
int fd;
1829-
1830-
/*
1831-
* Work around a libdwfl bug that causes it to close stdin when it frees
1832-
* some modules which are reported by dwfl_core_file_report().
1833-
*/
1834-
fd = dup(0);
18351828
dwfl_report_begin(dwfl);
18361829
dwfl_report_end(dwfl, drgn_dwfl_module_removed,
18371830
unindexed ? dwfl : NULL);
1838-
if (fd != -1) {
1839-
dup2(fd, 0);
1840-
close(fd);
1841-
}
18421831
}
18431832

18441833
void drgn_remove_unindexed_dwfl_modules(Dwfl *dwfl)

libdrgn/dwarf_info_cache.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@
1414
#include "type_index.h"
1515
#include "vector.h"
1616

17-
#if !_ELFUTILS_PREREQ(0, 162)
18-
#define DW_TAG_atomic_type 0x47
19-
#endif
20-
#if !_ELFUTILS_PREREQ(0, 171)
21-
#define DW_FORM_implicit_const 0x21
22-
#endif
23-
2417
DEFINE_HASH_TABLE_FUNCTIONS(dwarf_type_map, hash_pair_ptr_type,
2518
hash_table_scalar_eq)
2619

libdrgn/include/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*
2+
!/.gitignore
3+
!/Makefile.am

libdrgn/include/Makefile.am

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# "Install" the elfutils headers to the build directory.
2+
3+
BUILT_SOURCES = dwarf.h \
4+
elf.h \
5+
elfutils/elf-knowledge.h \
6+
elfutils/known-dwarf.h \
7+
elfutils/libasm.h \
8+
elfutils/libdw.h \
9+
elfutils/libdwelf.h \
10+
elfutils/libdwfl.h \
11+
elfutils/version.h \
12+
gelf.h \
13+
libelf.h \
14+
nlist.h
15+
16+
dwarf.h: ../elfutils/libdw/dwarf.h
17+
elf.h: ../elfutils/libelf/elf.h
18+
elfutils/elf-knowledge.h: ../elfutils/libelf/elf-knowledge.h
19+
elfutils/known-dwarf.h: ../elfutils/libdw/known-dwarf.h
20+
elfutils/libasm.h: ../elfutils/libasm/libasm.h
21+
elfutils/libdw.h: ../elfutils/libdw/libdw.h
22+
elfutils/libdwelf.h: ../elfutils/libdwelf/libdwelf.h
23+
elfutils/libdwfl.h: ../elfutils/libdwfl/libdwfl.h
24+
elfutils/version.h: ../elfutils/version.h
25+
gelf.h: ../elfutils/libelf/gelf.h
26+
libelf.h: ../elfutils/libelf/libelf.h
27+
nlist.h: ../elfutils/libelf/nlist.h
28+
29+
$(BUILT_SOURCES):
30+
mkdir -p $$(dirname $@)
31+
cp $< $@

libdrgn/internal.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,8 @@ struct drgn_error *read_elf_section(Elf_Scn *scn, Elf_Data **ret)
4343
if (!shdr)
4444
return drgn_error_libelf();
4545
if (shdr->sh_flags & SHF_COMPRESSED) {
46-
#if _ELFUTILS_PREREQ(0, 165)
4746
if (elf_compress(scn, 0, 0) < 0)
4847
return drgn_error_libelf();
49-
#else
50-
return drgn_error_create(DRGN_ERROR_ELF_FORMAT,
51-
"section is compressed but libelf does not support decompression");
52-
#endif
5348
}
5449
data = elf_getdata(scn, NULL);
5550
if (!data)

libdrgn/m4/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*
22
!/.gitignore
3+
!/ax_subdirs_configure.m4

0 commit comments

Comments
 (0)