]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
bpf: fix calculation when deciding to relax branch
authorDavid Faust <david.faust@oracle.com>
Thu, 25 Apr 2024 18:40:31 +0000 (11:40 -0700)
committerDavid Faust <david.faust@oracle.com>
Thu, 25 Apr 2024 20:16:34 +0000 (13:16 -0700)
commitdffb4a0784f401c2aa20446abb651a4e19f34a44
treeeee62fd09beed5d19910f2ee60ef213345edb382
parentd3c2603167baf9f6fea006f8b747b8186f89b177
bpf: fix calculation when deciding to relax branch

In certain cases we were calculating the jump displacement incorrectly
when deciding whether to relax a branch.  This meant for some branches,
such as a very long backwards conditional branch, relaxation was not
done when it should have been.  The result was to error later, because
the actual jump displacement was too large to fit in the original
instruction.

This patch fixes up the displacement calculation so that those branches
are correctly relaxed and no longer result in an error.  In addition, it
changes md_convert_frag to install fixups for the JAL instructions in
the resulting relaxations rather than encoding the displacement value
directly.

gas/
* config/tc-bpf.c (relaxed_branch_length): Correct displacement
calculation when relaxing.
(md_convert_frag): Likewise.  Install fixups for JAL
instructions resulting from relaxation.
* testsuite/gas/bpf/jump-relax-ja-be.d: Correct and expand test.
* testsuite/gas/bpf/jump-relax-ja.d: Likewise.
* testsuite/gas/bpf/jump-relax-ja.s: Likewise.
* testsuite/gas/bpf/jump-relax-jump-be.d: Likewise.
* testsuite/gas/bpf/jump-relax-jump.d: Likewise.
* testsuite/gas/bpf/jump-relax-jump.s: Likewise.
gas/config/tc-bpf.c
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