OSDN Git Service

bpf: print backward branch target properly
authorYonghong Song <yhs@fb.com>
Thu, 16 Nov 2017 19:15:36 +0000 (19:15 +0000)
committerYonghong Song <yhs@fb.com>
Thu, 16 Nov 2017 19:15:36 +0000 (19:15 +0000)
commit7a07b064e95d464a7192a4ea78ad902e232b9604
treebb07f3249798cfc99a32250bc67aafeb2ae4b700
parent4c98672343e4338ea7fc5f3a325f5fdc175314e5
bpf: print backward branch target properly

Currently, it prints the backward branch offset as unsigned value
like below:
       7:       7d 34 0b 00 00 00 00 00         if r4 s>= r3 goto 11 <LBB0_3>
       8:       b7 00 00 00 00 00 00 00         r0 = 0
LBB0_2:
       9:       07 00 00 00 01 00 00 00         r0 += 1
      ......
      17:       bf 31 00 00 00 00 00 00         r1 = r3
      18:       6d 32 f6 ff 00 00 00 00         if r2 s> r3 goto 65526 <LBB0_3+0x7FFB0>

The correct print insn 18 should be:
      18:       6d 32 f6 ff 00 00 00 00         if r2 s> r3 goto -10 <LBB0_2>

To provide better clarity and be consistent with kernel verifier output,
the insn 7 output is changed to the following with "+" added to
non-negative branch offset:
       7:       7d 34 0b 00 00 00 00 00         if r4 s>= r3 goto +11 <LBB0_3>

Signed-off-by: Yonghong Song <yhs@fb.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@318442 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/BPF/BPFInstrInfo.td
lib/Target/BPF/InstPrinter/BPFInstPrinter.cpp
lib/Target/BPF/InstPrinter/BPFInstPrinter.h
lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.cpp
test/CodeGen/BPF/objdump_cond_op.ll
test/CodeGen/BPF/objdump_cond_op_2.ll [new file with mode: 0644]
test/MC/BPF/insn-unit.s