1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 11:42:57 +01:00
llvm-mirror/test/CodeGen/BPF/objdump_dis_all.ll
Yonghong Song 7968749f42 [BPF] Return fail if disassembled insn registers out of range
Daniel reported a llvm-objdump segfault like below:
  $ llvm-objdump -D bpf_xdp.o
  ...
  0000000000000000 <.strtab>:
       0:       00 63 69 6c 69 75 6d 5f <unknown>
       1:       6c 62 36 5f 61 66 66 69 w2 <<= w6
  ...
  (llvm-objdump: lib/Target/BPF/BPFGenAsmWriter.inc:1087: static const char*
   llvm::BPFInstPrinter::getRegisterName(unsigned int): Assertion
   `RegNo && RegNo < 25 && "Invalid register number!"' failed.
   Stack dump:
   0.      Program arguments: llvm-objdump -D bpf_xdp.o
    ...
    abort
    ...
    llvm::BPFInstPrinter::getRegisterName(unsigned int)
    llvm::BPFInstPrinter::printMemOperand(llvm::MCInst const*,
                          int, llvm::raw_ostream&, char const*)
    llvm::BPFInstPrinter::printInstruction(llvm::MCInst const*,
                          unsigned long, llvm::raw_ostream&)
    llvm::BPFInstPrinter::printInst(llvm::MCInst const*,
                          unsigned long, llvm::StringRef, llvm::MCSubtargetInfo const&,
                          llvm::raw_ostream&)
   ...

Basically, since -D enables disassembly for all sections, .strtab is also disassembled,
but some strings are decoded as legal instructions but with illegal register numbers.
When llvm-objdump tries to print register name for these illegal register numbers,
assertion and segfault happens.

The patch fixed the issue by returning fail for a disassembled insn if
that insn contains a reg operand with illegal reg number.
The insn will be printed as "<unknown>" instead of causing an assertion.
2020-05-18 18:53:23 -07:00

27 lines
739 B
LLVM

; RUN: llc -march=bpfel -filetype=obj -o - %s | llvm-objdump -D - | FileCheck %s
;
; Source:
; /* *(u64 *)(r10 - 16) = r1 */
; unsigned long long g = 0x00000000fff01a7bULL;
; /* *(u64 *)(r15 - 16) = r1 */
; unsigned long long h = 0x00000000fff01f7bULL;
; int test() {
; return 0;
; }
; Compilation flag:
; clang -target bpf -O2 -S -emit-llvm t.c
@g = dso_local local_unnamed_addr global i64 4293925499, align 8
@h = dso_local local_unnamed_addr global i64 4293926779, align 8
; Function Attrs: norecurse nounwind readnone
define dso_local i32 @test() local_unnamed_addr {
entry:
ret i32 0
}
; CHECK-LABEL: section .data
; CHECK-LABEL: g
; CHECK: *(u64 *)(r10 - 16) = r1
; CHECK-LABEL: h
; CHECK: <unknown>