DesCGENization of the BPF binutils port
authorJose E. Marchesi <jose.marchesi@oracle.com>
Fri, 14 Jul 2023 22:50:14 +0000 (00:50 +0200)
committerJose E. Marchesi <jose.marchesi@oracle.com>
Fri, 21 Jul 2023 10:20:40 +0000 (12:20 +0200)
commitd218e7fedc74d67837d2134120917f4ac877454c
treedf890450897d7540385d9d7b5926ab35cbafb120
parent1c850ca80dc53ffa2bfadabbacda231c941dee76
DesCGENization of the BPF binutils port

CGEN is cool, but the BPF architecture is simply too bizarre for it.

The weird way of BPF to handle endianness in instruction encoding, the
weird C-like alternative assembly syntax, the weird abuse of
multi-byte (or infra-byte) instruction fields as opcodes, the unusual
presence of opcodes beyond the first 32-bits of some instructions, are
all examples of what makes it a PITA to continue using CGEN for this
port.  The bpf.cpu file is becoming so complex and so nested with
p-macros that it is very difficult to read, and quite challenging to
update.  Also, every time we are forced to change something in CGEN to
accommodate BPF requirements (which is often) we have to do extensive
testing to make sure we do not break any other target using CGEN.

This is getting un-maintenable.

So I have decided to bite the bullet and revamp/rewrite the port so it
no longer uses CGEN.  Overall, this involved:

* To remove the cpu/bpf.{cpu,opc} descriptions.

* To remove the CGEN generated files.

* To replace the CGEN generated opcodes table with a new hand-written
  opcodes table for BPF.

* To replace the CGEN generated disassembler wih a new disassembler
  that uses the new opcodes.

* To replace the CGEN generated assembler with a new assembler that uses the
  new opcodes.

* To replace the CGEN generated simulator with a new simulator that uses the
  new opcodes. [This is pushed in GDB in another patch.]

* To adapt the build systems to the new situation.

Additionally, this patch introduces some extensions and improvements:

* A new BPF relocation BPF_RELOC_BPF_DISP16 plus corresponding ELF
  relocation R_BPF_GNU_64_16 are added to the BPF BFD port.  These
  relocations are used for section-relative 16-bit offsets used in
  load/store instructions.

* The disassembler now has support for the "pseudo-c" assembly syntax of
  BPF.  What dialect to use when disassembling is controlled by a command
  line option.

* The disassembler now has support for dumping instruction immediates in
  either octal, hexadecimal or decimal.  The used output base is controlled
  by a new command-line option.

* The GAS BPF test suite has been re-structured and expanded in order to
  test the disassembler pseudoc syntax support.  Minor bugs have been also
  fixed there.  The assembler generic tests that were disabled for bpf-*-*
  targets due to the previous implementation of pseudoc syntax are now
  re-enabled.  Additional tests have been added to test the new features of
  the assembler.  .dump files are no longer used.

* The linker BPF test suite has been adapted to the command line options
  used by the new disassembler.

The result is very satisfactory.  This patchs adds 3448 lines of code
and removes 10542 lines of code.

Tested in:

* Target bpf-unknown-none with 64-bit little-endian host and 32-bit
  little-endian host.

* Target x86-64-linux-gnu with --enable-targets=all

Note that I have not tested in a big-endian host yet.  I will do so
once this lands upstream so I can use the GCC compiler farm.

I have not included ChangeLog entries in this patch: these would be
massive and not very useful, considering this is pretty much a rewrite
of the port.  I beg the indulgence of the global maintainers.
101 files changed:
bfd/bfd-in2.h
bfd/bpf-reloc.def
bfd/elf64-bpf.c
bfd/libbfd.h
bfd/reloc.c
cpu/bpf.cpu [deleted file]
cpu/bpf.opc [deleted file]
gas/config/tc-bpf.c
gas/config/tc-bpf.h
gas/configure
gas/configure.ac
gas/doc/c-bpf.texi
gas/testsuite/gas/all/assign-bad-recursive.d
gas/testsuite/gas/all/eqv-dot.d
gas/testsuite/gas/all/gas.exp
gas/testsuite/gas/bpf/alu-be-pseudoc.d
gas/testsuite/gas/bpf/alu-be.d
gas/testsuite/gas/bpf/alu-be.dump [deleted file]
gas/testsuite/gas/bpf/alu-pseudoc.d
gas/testsuite/gas/bpf/alu-pseudoc.s
gas/testsuite/gas/bpf/alu-xbpf.d [deleted file]
gas/testsuite/gas/bpf/alu-xbpf.s [deleted file]
gas/testsuite/gas/bpf/alu.d
gas/testsuite/gas/bpf/alu.dump [deleted file]
gas/testsuite/gas/bpf/alu.s
gas/testsuite/gas/bpf/alu32-be-pseudoc.d
gas/testsuite/gas/bpf/alu32-be.d
gas/testsuite/gas/bpf/alu32-be.dump [deleted file]
gas/testsuite/gas/bpf/alu32-pseudoc.d
gas/testsuite/gas/bpf/alu32-pseudoc.s
gas/testsuite/gas/bpf/alu32-xbpf.d [deleted file]
gas/testsuite/gas/bpf/alu32-xbpf.s [deleted file]
gas/testsuite/gas/bpf/alu32.d
gas/testsuite/gas/bpf/alu32.dump [deleted file]
gas/testsuite/gas/bpf/alu32.s
gas/testsuite/gas/bpf/atomic-be-pseudoc.d [new file with mode: 0644]
gas/testsuite/gas/bpf/atomic-be.d
gas/testsuite/gas/bpf/atomic-pseudoc.d
gas/testsuite/gas/bpf/atomic-pseudoc.s
gas/testsuite/gas/bpf/atomic.d
gas/testsuite/gas/bpf/atomic.dump [deleted file]
gas/testsuite/gas/bpf/atomic.s
gas/testsuite/gas/bpf/bpf.exp
gas/testsuite/gas/bpf/call-be.d
gas/testsuite/gas/bpf/call.d
gas/testsuite/gas/bpf/data-be.d
gas/testsuite/gas/bpf/data.d
gas/testsuite/gas/bpf/exit-be.d
gas/testsuite/gas/bpf/exit.d
gas/testsuite/gas/bpf/indcall-1-pseudoc.d
gas/testsuite/gas/bpf/indcall-1.d
gas/testsuite/gas/bpf/indcall-1.dump [deleted file]
gas/testsuite/gas/bpf/indcall-bad-1.l [deleted file]
gas/testsuite/gas/bpf/indcall-bad-1.s [deleted file]
gas/testsuite/gas/bpf/jump-be-pseudoc.d [new file with mode: 0644]
gas/testsuite/gas/bpf/jump-be.d
gas/testsuite/gas/bpf/jump-pseudoc.d
gas/testsuite/gas/bpf/jump.d
gas/testsuite/gas/bpf/jump.dump [deleted file]
gas/testsuite/gas/bpf/jump32-be-pseudoc.d [new file with mode: 0644]
gas/testsuite/gas/bpf/jump32-be.d [new file with mode: 0644]
gas/testsuite/gas/bpf/jump32-pseudoc.d
gas/testsuite/gas/bpf/jump32.d
gas/testsuite/gas/bpf/jump32.dump [deleted file]
gas/testsuite/gas/bpf/lddw-be-pseudoc.d
gas/testsuite/gas/bpf/lddw-be.d
gas/testsuite/gas/bpf/lddw-be.dump [deleted file]
gas/testsuite/gas/bpf/lddw-pseudoc.d
gas/testsuite/gas/bpf/lddw.d
gas/testsuite/gas/bpf/lddw.dump [deleted file]
gas/testsuite/gas/bpf/mem-be-pseudoc.d [new file with mode: 0644]
gas/testsuite/gas/bpf/mem-be.d
gas/testsuite/gas/bpf/mem-pseudoc.d
gas/testsuite/gas/bpf/mem-pseudoc.s
gas/testsuite/gas/bpf/mem.d
gas/testsuite/gas/bpf/mem.dump [deleted file]
gas/testsuite/gas/bpf/mem.s
gas/testsuite/gas/bpf/pseudoc-normal-be.d [deleted file]
gas/testsuite/gas/bpf/pseudoc-normal.d [deleted file]
gas/testsuite/gas/bpf/pseudoc-normal.s [deleted file]
gas/testsuite/gas/bpf/spacing-pseudoc.d [new file with mode: 0644]
gas/testsuite/gas/bpf/spacing-pseudoc.s [new file with mode: 0644]
include/dis-asm.h
include/elf/bpf.h
include/opcode/bpf.h [new file with mode: 0644]
ld/testsuite/ld-bpf/call-1.d
ld/testsuite/ld-bpf/call-2.d
ld/testsuite/ld-bpf/reloc-insn-external-be.d
ld/testsuite/ld-bpf/reloc-insn-external-le.d
opcodes/Makefile.am
opcodes/Makefile.in
opcodes/bpf-asm.c [deleted file]
opcodes/bpf-desc.c [deleted file]
opcodes/bpf-desc.h [deleted file]
opcodes/bpf-dis.c
opcodes/bpf-ibld.c [deleted file]
opcodes/bpf-opc.c
opcodes/bpf-opc.h [deleted file]
opcodes/configure
opcodes/configure.ac
opcodes/disassemble.c