aboutsummaryrefslogtreecommitdiff
path: root/opcodes
diff options
context:
space:
mode:
authorJose E. Marchesi <jose.marchesi@oracle.com>2023-07-30 22:39:30 +0200
committerJose E. Marchesi <jose.marchesi@oracle.com>2023-07-30 22:39:30 +0200
commit1e18ffc9915bb9d3bbcd934d8b3e57ae9fe82f60 (patch)
tree92abdac23f41629b636c939591747e6fe5571ad9 /opcodes
parent0346042938539324a5052cc09023c1fe426e8b31 (diff)
downloadgdb-1e18ffc9915bb9d3bbcd934d8b3e57ae9fe82f60.zip
gdb-1e18ffc9915bb9d3bbcd934d8b3e57ae9fe82f60.tar.gz
gdb-1e18ffc9915bb9d3bbcd934d8b3e57ae9fe82f60.tar.bz2
bpf: include, bfd, opcodes: add EF_BPF_CPUVER ELF header flags
This patch adds support for EF_BPF_CPUVER bits in the ELF machine-dependent header flags. These bits encode the BPF CPU version for which the object file has been compiled for. The BPF assembler is updated so it annotates the object files it generates with these bits. The BPF disassembler is updated so it honors EF_BPF_CPUVER to use the appropriate ISA version if the user didn't specify an explicit ISA version in the command line. Note that a value of zero in EF_BPF_CPUVER is interpreted by the disassembler as "use the later supported version" (the BPF CPU versions start with v1.) The readelf utility is updated to pretty print EF_BPF_CPUVER when it prints out the ELF header: $ readelf -h a.out ELF Header: ... Flags: 0x4, CPU Version: 4 Tested in bpf-unknown-none. include/ChangeLog: 2023-07-30 Jose E. Marchesi <jose.marchesi@oracle.com> * elf/bpf.h (EF_BPF_CPUVER): Define. * opcode/bpf.h (BPF_XBPF): Change from 0xf to 0xff so it fits in EF_BPF_CPUVER. binutils/ChangeLog: 2023-07-30 Jose E. Marchesi <jose.marchesi@oracle.com> * readelf.c (get_machine_flags): Recognize and pretty print BPF machine flags. opcodes/ChangeLog: 2023-07-30 Jose E. Marchesi <jose.marchesi@oracle.com> * bpf-dis.c: Initialize asm_bpf_version to -1. (print_insn_bpf): Set BPF ISA version from the cpu version ELF header flags if no explicit version set in the command line. * disassemble.c (disassemble_init_for_target): Remove unused code. gas/ChangeLog: 2023-07-30 Jose E. Marchesi <jose.marchesi@oracle.com> * config/tc-bpf.h (elf_tc_final_processing): Define. * config/tc-bpf.c (bpf_elf_final_processing): New function.
Diffstat (limited to 'opcodes')
-rw-r--r--opcodes/ChangeLog7
-rw-r--r--opcodes/bpf-dis.c30
-rw-r--r--opcodes/disassemble.c20
3 files changed, 36 insertions, 21 deletions
diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog
index f611ec5..9d33da2 100644
--- a/opcodes/ChangeLog
+++ b/opcodes/ChangeLog
@@ -1,3 +1,10 @@
+2023-07-30 Jose E. Marchesi <jose.marchesi@oracle.com>
+
+ * bpf-dis.c: Initialize asm_bpf_version to -1.
+ (print_insn_bpf): Set BPF ISA version from the cpu version ELF
+ header flags if no explicit version set in the command line.
+ * disassemble.c (disassemble_init_for_target): Remove unused code.
+
2023-07-26 Jose E. Marchesi <jose.marchesi@oracle.com>
* bpf-opc.c (bpf_opcodes): Fix BPF_INSN_NEGR to not use a src
diff --git a/opcodes/bpf-dis.c b/opcodes/bpf-dis.c
index 4fe0efc..a8cb9e8 100644
--- a/opcodes/bpf-dis.c
+++ b/opcodes/bpf-dis.c
@@ -24,6 +24,8 @@
#include "libiberty.h"
#include "opintl.h"
#include "opcode/bpf.h"
+#include "elf-bfd.h"
+#include "elf/bpf.h"
#include <string.h>
#include <inttypes.h>
@@ -42,7 +44,7 @@ enum bpf_dialect
/* Global configuration for the disassembler. */
static enum bpf_dialect asm_dialect = BPF_DIALECT_NORMAL;
-static int asm_bpf_version = BPF_V4;
+static int asm_bpf_version = -1;
static int asm_obase = 10;
/* Print BPF specific command-line options. */
@@ -141,6 +143,32 @@ print_insn_bpf (bfd_vma pc, disassemble_info *info)
info->disassembler_options = NULL;
}
+ /* Determine what version of the BPF ISA to use when disassembling.
+ If the user didn't explicitly specify an ISA version, then derive
+ it from the CPU Version flag in the ELF header. A CPU version of
+ 0 in the header means "latest version". */
+ if (asm_bpf_version == -1)
+ {
+ struct bfd *abfd = info->section->owner;
+ Elf_Internal_Ehdr *header = elf_elfheader (abfd);
+ int cpu_version = header->e_flags & EF_BPF_CPUVER;
+
+ switch (cpu_version)
+ {
+ case 0: asm_bpf_version = BPF_V4; break;
+ case 1: asm_bpf_version = BPF_V1; break;
+ case 2: asm_bpf_version = BPF_V2; break;
+ case 3: asm_bpf_version = BPF_V3; break;
+ case 4: asm_bpf_version = BPF_V4; break;
+ case 0xf: asm_bpf_version = BPF_XBPF; break;
+ default:
+ /* xgettext:c-format */
+ opcodes_error_handler (_("unknown BPF CPU version %u\n"),
+ cpu_version);
+ break;
+ }
+ }
+
/* Print eight bytes per line. */
info->bytes_per_chunk = 1;
info->bytes_per_line = 8;
diff --git a/opcodes/disassemble.c b/opcodes/disassemble.c
index a5cb396..8aac42e 100644
--- a/opcodes/disassemble.c
+++ b/opcodes/disassemble.c
@@ -680,27 +680,7 @@ disassemble_init_for_target (struct disassemble_info * info)
#endif
#ifdef ARCH_bpf
case bfd_arch_bpf:
- /* XXX option for dialect */
info->created_styled_output = true;
-#if 0
- info->endian_code = BFD_ENDIAN_LITTLE;
- if (!info->private_data)
- {
- info->private_data = cgen_bitset_create (ISA_MAX);
- if (info->endian == BFD_ENDIAN_BIG)
- {
- cgen_bitset_set (info->private_data, ISA_EBPFBE);
- if (info->mach == bfd_mach_xbpf)
- cgen_bitset_set (info->private_data, ISA_XBPFBE);
- }
- else
- {
- cgen_bitset_set (info->private_data, ISA_EBPFLE);
- if (info->mach == bfd_mach_xbpf)
- cgen_bitset_set (info->private_data, ISA_XBPFLE);
- }
- }
-#endif
break;
#endif
#ifdef ARCH_pru