diff options
author | Mark Wielaard <mark@klomp.org> | 2017-07-18 14:12:36 +0200 |
---|---|---|
committer | Mark Wielaard <mark@klomp.org> | 2017-07-24 12:06:14 +0200 |
commit | 1609679b1ef3611c71a08900c2f6b94bb97d454d (patch) | |
tree | 24b3f6dfa5308e4c3a1ddb37b5097694a263ac7f | |
parent | c8e16c12661d18e6ae724a6d89b81c0df9da365a (diff) | |
download | elfutils-1609679b1ef3611c71a08900c2f6b94bb97d454d.tar.gz |
backends: Don't depend on linux/bpf.h to compile bpf disassembler.
We only need a few constants and one structure definition from linux/bpf.
Just define those in a local lib/bpf.h file. This makes sure the bpf
disassembler is always build and included even when elfutils is build
on older GNU/Linux systems (and even on other platforms).
Signed-off-by: Mark Wielaard <mark@klomp.org>
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | backends/ChangeLog | 7 | ||||
-rw-r--r-- | backends/Makefile.am | 5 | ||||
-rw-r--r-- | backends/bpf_init.c | 2 | ||||
-rw-r--r-- | backends/bpf_regs.c | 6 | ||||
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | lib/ChangeLog | 5 | ||||
-rw-r--r-- | lib/Makefile.am | 2 | ||||
-rw-r--r-- | lib/bpf.h | 82 | ||||
-rw-r--r-- | libcpu/ChangeLog | 6 | ||||
-rw-r--r-- | libcpu/Makefile.am | 2 | ||||
-rw-r--r-- | libcpu/bpf_disasm.c | 7 | ||||
-rw-r--r-- | tests/ChangeLog | 4 | ||||
-rw-r--r-- | tests/Makefile.am | 5 |
15 files changed, 115 insertions, 29 deletions
@@ -1,3 +1,8 @@ +2017-07-18 Mark Wielaard <mark@klomp.org> + + * configure.ac: Don't check for linux/bpf.h. + * NEWS: Mention always build bpf backend. + 2017-07-14 Mark Wielaard <mark@klomp.org> * NEWS: Add 0.170 section and new strip options. @@ -2,6 +2,8 @@ Version 0.170 strip: Add -R, --remove-section=SECTION and --keep-section=SECTION. +backends: The bpf disassembler is now always build on all platforms. + Version 0.169 backends: Add support for EM_PPC64 GNU_ATTRIBUTES. diff --git a/backends/ChangeLog b/backends/ChangeLog index 784e6b03..eb7e25f1 100644 --- a/backends/ChangeLog +++ b/backends/ChangeLog @@ -1,3 +1,10 @@ +2017-07-18 Mark Wielaard <mark@klomp.org> + + * Makefile.am (cpu_bpf): Always define. + * bpf_init.c (disasm): Always hook. + * bpf_regs.c: Include bpf.h instead of linux/bpf.h. Don't define + MAX_BPF_REG. + 2017-02-17 Ulf Hermann <ulf.hermann@qt.io> * Makefile.am: Add libeu. diff --git a/backends/Makefile.am b/backends/Makefile.am index 996602f2..37dc2d20 100644 --- a/backends/Makefile.am +++ b/backends/Makefile.am @@ -120,12 +120,7 @@ libebl_m68k_pic_a_SOURCES = $(m68k_SRCS) am_libebl_m68k_pic_a_OBJECTS = $(m68k_SRCS:.c=.os) bpf_SRCS = bpf_init.c bpf_regs.c -# The disam hook depends on this if we have linux/bpf.h. -if HAVE_LINUX_BPF_H cpu_bpf = ../libcpu/libcpu_bpf.a -else -cpu_bpf = -endif libebl_bpf_pic_a_SOURCES = $(bpf_SRCS) am_libebl_bpf_pic_a_OBJECTS = $(bpf_SRCS:.c=.os) diff --git a/backends/bpf_init.c b/backends/bpf_init.c index 22842e26..8ea1bc1a 100644 --- a/backends/bpf_init.c +++ b/backends/bpf_init.c @@ -52,9 +52,7 @@ bpf_init (Elf *elf __attribute__ ((unused)), eh->name = "BPF"; bpf_init_reloc (eh); HOOK (eh, register_info); -#ifdef HAVE_LINUX_BPF_H HOOK (eh, disasm); -#endif return MODVERSION; } diff --git a/backends/bpf_regs.c b/backends/bpf_regs.c index 180af83b..1863a164 100644 --- a/backends/bpf_regs.c +++ b/backends/bpf_regs.c @@ -32,11 +32,7 @@ #include <stdio.h> #include <string.h> -#ifdef HAVE_LINUX_BPF_H -#include <linux/bpf.h> -#else -#define MAX_BPF_REG 10 -#endif +#include "bpf.h" #define BACKEND bpf_ #include "libebl_CPU.h" diff --git a/configure.ac b/configure.ac index c2c1d90b..bb58f4b8 100644 --- a/configure.ac +++ b/configure.ac @@ -385,10 +385,6 @@ else fi AC_SUBST([argp_LDADD]) -dnl Check if we have <linux/bpf.h> for EM_BPF disassembly. -AC_CHECK_HEADERS(linux/bpf.h) -AM_CONDITIONAL(HAVE_LINUX_BPF_H, [test "x$ac_cv_header_linux_bpf_h" = "xyes"]) - dnl The directories with content. dnl Documentation. diff --git a/lib/ChangeLog b/lib/ChangeLog index 1fc1a38c..1f162286 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,8 @@ +2017-07-18 Mark Wielaard <mark@klomp.org> + + * bpf.h: New file. + * Makefile.am (noinst_HEADERS): Add bpf.h + 2017-05-05 Mark Wielaard <mark@klomp.org> * printversion.c (print_version): Update copyright year. diff --git a/lib/Makefile.am b/lib/Makefile.am index 7a65eb91..ada2030d 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -38,7 +38,7 @@ libeu_a_SOURCES = xstrdup.c xstrndup.c xmalloc.c next_prime.c \ color.c printversion.c noinst_HEADERS = fixedsizehash.h libeu.h system.h dynamicsizehash.h list.h \ - md5.h sha1.h eu-config.h color.h printversion.h + md5.h sha1.h eu-config.h color.h printversion.h bpf.h EXTRA_DIST = dynamicsizehash.c if !GPROF diff --git a/lib/bpf.h b/lib/bpf.h new file mode 100644 index 00000000..db80a51e --- /dev/null +++ b/lib/bpf.h @@ -0,0 +1,82 @@ +/* Minimal extended BPF constants as alternative for linux/bpf.h. */ + +#ifndef _ELFUTILS_BPF_H +#define _ELFUTILS_BPF_H 1 + +#include <stdint.h> + +#define BPF_CLASS(code) ((code) & 0x07) + +#define BPF_LD 0x00 +#define BPF_LDX 0x01 +#define BPF_ST 0x02 +#define BPF_STX 0x03 +#define BPF_ALU 0x04 +#define BPF_JMP 0x05 +#define BPF_RET 0x06 +#define BPF_MISC 0x07 + +#define BPF_ALU64 0x07 + +#define BPF_JNE 0x50 +#define BPF_JSGT 0x60 +#define BPF_JSGE 0x70 +#define BPF_CALL 0x80 +#define BPF_EXIT 0x90 + +#define BPF_W 0x00 +#define BPF_H 0x08 +#define BPF_B 0x10 + +#define BPF_IMM 0x00 +#define BPF_ABS 0x20 +#define BPF_IND 0x40 +#define BPF_MEM 0x60 +#define BPF_LEN 0x80 +#define BPF_MSH 0xa0 + +#define BPF_DW 0x18 +#define BPF_XADD 0xc0 + +#define BPF_ADD 0x00 +#define BPF_SUB 0x10 +#define BPF_MUL 0x20 +#define BPF_DIV 0x30 +#define BPF_OR 0x40 +#define BPF_AND 0x50 +#define BPF_LSH 0x60 +#define BPF_RSH 0x70 +#define BPF_NEG 0x80 +#define BPF_MOD 0x90 +#define BPF_XOR 0xa0 + +#define BPF_MOV 0xb0 +#define BPF_ARSH 0xc0 + +#define BPF_JA 0x00 +#define BPF_JEQ 0x10 +#define BPF_JGT 0x20 +#define BPF_JGE 0x30 +#define BPF_JSET 0x40 + +#define BPF_K 0x00 +#define BPF_X 0x08 + +#define BPF_END 0xd0 +#define BPF_TO_LE 0x00 +#define BPF_TO_BE 0x08 + +#define BPF_PSEUDO_MAP_FD 1 + +#define MAX_BPF_REG 10 + +struct bpf_insn +{ + uint8_t code; + uint8_t dst_reg:4; + uint8_t src_reg:4; + int16_t off; + int32_t imm; +}; + +#endif diff --git a/libcpu/ChangeLog b/libcpu/ChangeLog index 22bec9b3..28b220fc 100644 --- a/libcpu/ChangeLog +++ b/libcpu/ChangeLog @@ -1,3 +1,9 @@ +2017-07-18 Mark Wielaard <mark@klomp.org> + + * Makefile.am: Don't check HAVE_LINUX_BPF_H, just define libcpu_bpf. + * bpf_disasm.c: Include bpf.h instead of linux/bpf.h. Don't define + BPF_PSEUDO_MAP_FD. + 2017-04-20 Ulf Hermann <ulf.hermann@qt.io> * Makefile.am: Add EXEEXT to gendis. diff --git a/libcpu/Makefile.am b/libcpu/Makefile.am index 31fc906b..94de56ef 100644 --- a/libcpu/Makefile.am +++ b/libcpu/Makefile.am @@ -45,11 +45,9 @@ i386_gendis_SOURCES = i386_gendis.c i386_lex.l i386_parse.y i386_disasm.o: i386.mnemonics $(srcdir)/i386_dis.h x86_64_disasm.o: x86_64.mnemonics $(srcdir)/x86_64_dis.h -if HAVE_LINUX_BPF_H noinst_LIBRARIES += libcpu_bpf.a libcpu_bpf_a_SOURCES = bpf_disasm.c libcpu_bpf_a_CFLAGS = $(AM_CFLAGS) -Wno-format-nonliteral -endif %_defs: $(srcdir)/defs/i386 $(AM_V_GEN)m4 -D$* -DDISASSEMBLER $< > $@T diff --git a/libcpu/bpf_disasm.c b/libcpu/bpf_disasm.c index e4bbae4a..054aba2b 100644 --- a/libcpu/bpf_disasm.c +++ b/libcpu/bpf_disasm.c @@ -35,16 +35,11 @@ #include <stdio.h> #include <gelf.h> #include <inttypes.h> -#include <linux/bpf.h> +#include "bpf.h" #include "../libelf/common.h" #include "../libebl/libeblP.h" -/* BPF_PSEUDO_MAP_FD was only introduced in linux 3.20. */ -#ifndef BPF_PSEUDO_MAP_FD - #define BPF_PSEUDO_MAP_FD 1 -#endif - static const char class_string[8][8] = { [BPF_LD] = "ld", [BPF_LDX] = "ldx", diff --git a/tests/ChangeLog b/tests/ChangeLog index a4404e42..194d019f 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,7 @@ +2017-07-18 Mark Wielaard <mark@klomp.org> + + * Makefile.am (TESTS): Always add run-disasm-bpf.sh if HAVE_LIBASM. + 2017-05-04 Ulf Hermann <ulf.hermann@qt.io> * elfshphehdr.c: For writing, use /dev/null rather than /dev/zero. diff --git a/tests/Makefile.am b/tests/Makefile.am index 7fd4b211..368e9263 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -156,10 +156,7 @@ endif if HAVE_LIBASM check_PROGRAMS += $(asm_TESTS) -TESTS += $(asm_TESTS) -if HAVE_LINUX_BPF_H -TESTS += run-disasm-bpf.sh -endif +TESTS += $(asm_TESTS) run-disasm-bpf.sh endif EXTRA_DIST = run-arextract.sh run-arsymtest.sh \ |