Skip to content

Commit 249d471

Browse files
committed
bpf: gas: support relaxation of V4 jump instructions
The BPF jump-always instruction (JA), like all other jump instructions in the ISA, get a signed 16-bit displacement target argument denoted in number of 64-bit words minus one. This can sometimes be overflown. The BPF V4 ISA thus introduced support for a jump-always instruction (JAL) that gets a signed 32-bit displacement instead. This patch makes the BPF assembler to perform the following relaxations when the disp16 field gets overflown, unless the option -mno-relax is specified: JA disp16 -> JAL disp32 Jxx disp16 -> Jxx +1; JA +1; JAL disp32 Documentation and tests added. Tested in bpf-unknown-none. gas/ChangeLog: 2023-07-28 Jose E. Marchesi <[email protected]> PR gas/30690 * config/tc-bpf.c (struct bpf_insn): Add fields is_relaxable and relaxed_exp. (enum options): Add OPTION_NO_RELAX. (md_longopts): Likewise for -mno-relax. (do_relax): New global. (md_parse_option): Handle OPTION_NO_RELAX. (RELAX_BRANCH_ENCODE): Define. (RELAX_BRANCH_P): Likewise. (RELAX_BRANCH_LENGTH): Likewise. (RELAX_BRANCH_CONST): Likewise. (RELAX_BRANCH_UNCOND): Likewise. (relaxed_branch_length): New function. (md_estimate_size_before_relax): Likewise. (read_insn_word): Likewise. (encode_int16): Likewise. (encode_int32): Likewise. (write_insn_bytes): Likewise. (md_convert_frag): Likewise. (encode_insn): Likewise. (install_insn_fixups): Likewise. (add_fixed_insn): Likewise. (add_relaxed_insn): Likewise. (md_assemble): Move instruction encoding logic to the above new functions. * testsuite/gas/bpf/jump-relax-ja.d: New test. * testsuite/gas/bpf/jump-relax-ja-be.d: Likewise. * testsuite/gas/bpf/jump-relax-ja.s: And corresponding source. * testsuite/gas/bpf/jump-relax-jump.d: New test. * testsuite/gas/bpf/jump-relax-jump-be.d: Likewise. * testsuite/gas/bpf/jump-relax-jump.s: And corresponding source. * testsuite/gas/bpf/bpf.exp: Run new tests. * doc/c-bpf.texi (BPF Options): Document -mno-relax.
1 parent 07d8d4b commit 249d471

File tree

9 files changed

+858
-308
lines changed

9 files changed

+858
-308
lines changed

gas/ChangeLog

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
1+
2023-07-28 Jose E. Marchesi <[email protected]>
2+
3+
PR gas/30690
4+
* config/tc-bpf.c (struct bpf_insn): Add fields is_relaxable and
5+
relaxed_exp.
6+
(enum options): Add OPTION_NO_RELAX.
7+
(md_longopts): Likewise for -mno-relax.
8+
(do_relax): New global.
9+
(md_parse_option): Handle OPTION_NO_RELAX.
10+
(RELAX_BRANCH_ENCODE): Define.
11+
(RELAX_BRANCH_P): Likewise.
12+
(RELAX_BRANCH_LENGTH): Likewise.
13+
(RELAX_BRANCH_CONST): Likewise.
14+
(RELAX_BRANCH_UNCOND): Likewise.
15+
(relaxed_branch_length): New function.
16+
(md_estimate_size_before_relax): Likewise.
17+
(read_insn_word): Likewise.
18+
(encode_int16): Likewise.
19+
(encode_int32): Likewise.
20+
(write_insn_bytes): Likewise.
21+
(md_convert_frag): Likewise.
22+
(encode_insn): Likewise.
23+
(install_insn_fixups): Likewise.
24+
(add_fixed_insn): Likewise.
25+
(add_relaxed_insn): Likewise.
26+
(md_assemble): Move instruction encoding logic to the above
27+
new functions.
28+
* testsuite/gas/bpf/jump-relax-ja.d: New test.
29+
* testsuite/gas/bpf/jump-relax-ja-be.d: Likewise.
30+
* testsuite/gas/bpf/jump-relax-ja.s: And corresponding source.
31+
* testsuite/gas/bpf/jump-relax-jump.d: New test.
32+
* testsuite/gas/bpf/jump-relax-jump-be.d: Likewise.
33+
* testsuite/gas/bpf/jump-relax-jump.s: And corresponding source.
34+
* testsuite/gas/bpf/bpf.exp: Run new tests.
35+
* doc/c-bpf.texi (BPF Options): Document -mno-relax.
36+
137
2023-07-26 Jose E. Marchesi <[email protected]>
238

339
* testsuite/gas/bpf/alu.s: Add test for NEGI and NEG32I.

0 commit comments

Comments
 (0)