bpf: gas: consolidate handling of immediate overflows
authorJose E. Marchesi <jose.marchesi@oracle.com>
Thu, 17 Aug 2023 07:38:37 +0000 (09:38 +0200)
committerJose E. Marchesi <jose.marchesi@oracle.com>
Thu, 17 Aug 2023 07:41:43 +0000 (09:41 +0200)
commit5be1b787276d2adbe85ae7febc709ca517b62f08
tree78eee9ce0af69c9ac2d98af1204dd771b46893f6
parent646657284f6b62a71a6869826e951b3def4d73a6
bpf: gas: consolidate handling of immediate overflows

This commit changes the BPF GAS port in order to handle immediate
overflows the same way than the clang BPF assembler:

- For an immediate field of N bits, any written number (positive or
  negative) whose two's complement encoding fit in N its is accepted.
  This means that -2 is the same than 0xffffffe.  It is up to the
  instructions to decide how to interpret the encoded value.

- Immediate fields in jump instructions are no longer relaxed.
  Relaxing to jump instructions with wider range is only performed
  when expressions are involved.

- The manual is updated to document this, and testsuite adapted
  accordingly.

Tested in x86_64-linux-gnu host, bpf-unknown-none target.

gas/ChangeLog:

2023-08-17  Jose E. Marchesi  <jose.marchesi@oracle.com>

* config/tc-bpf.c (check_immediate_overflow): New function.
(encode_insn): Use check_immediate_overflow.
(md_assemble): Do not relax instructions with
constant disp16 fields.
* doc/c-bpf.texi (BPF Instructions): Add note about how numerical
literal values are interpreted for instruction immediate operands.
* testsuite/gas/bpf/disp16-overflow.s: Adapt accordingly.
* testsuite/gas/bpf/jump-relax-jump.s: Likewise.
* testsuite/gas/bpf/jump-relax-jump.d: Likewise.
* testsuite/gas/bpf/jump-relax-jump-be.d: Likewise.
* testsuite/gas/bpf/jump-relax-ja.s: Likewise.
* testsuite/gas/bpf/jump-relax-ja.d: Likewise.
* testsuite/gas/bpf/jump-relax-ja-be.d: Likewise.
* testsuite/gas/bpf/disp16-overflow-relax.l: Likewise.
* testsuite/gas/bpf/imm32-overflow.s: Likewise.
* testsuite/gas/bpf/disp32-overflow.s: Likewise.
* testsuite/gas/bpf/disp16-overflow.l: Likewise.
* testsuite/gas/bpf/disp32-overflow.l: Likewise.
* testsuite/gas/bpf/imm32-overflow.l: Likewise.
* testsuite/gas/bpf/offset16-overflow.l: Likewise.
20 files changed:
gas/ChangeLog
gas/config/tc-bpf.c
gas/config/tc-sparc.c
gas/doc/c-bpf.texi
gas/testsuite/gas/bpf/disp16-overflow-relax.l
gas/testsuite/gas/bpf/disp16-overflow-relax.s
gas/testsuite/gas/bpf/disp16-overflow.l
gas/testsuite/gas/bpf/disp16-overflow.s
gas/testsuite/gas/bpf/disp32-overflow.l
gas/testsuite/gas/bpf/disp32-overflow.s
gas/testsuite/gas/bpf/imm32-overflow.l
gas/testsuite/gas/bpf/imm32-overflow.s
gas/testsuite/gas/bpf/jump-relax-ja-be.d
gas/testsuite/gas/bpf/jump-relax-ja.d
gas/testsuite/gas/bpf/jump-relax-ja.s
gas/testsuite/gas/bpf/jump-relax-jump-be.d
gas/testsuite/gas/bpf/jump-relax-jump.d
gas/testsuite/gas/bpf/jump-relax-jump.s
gas/testsuite/gas/bpf/offset16-overflow.l
gas/testsuite/gas/bpf/offset16-overflow.s