New user self-registration is disabled due to spam. For an account please email bugs-admin@lists.llvm.org with your e-mail address and full name.

Bug 38643 - BPF: Assertion faliure at BPFAsmBackend.cpp:73: Assertion `Value == 0' failed
Summary: BPF: Assertion faliure at BPFAsmBackend.cpp:73: Assertion `Value == 0' failed
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Core LLVM classes (show other bugs)
Version: 6.0
Hardware: PC Linux
: P enhancement
Assignee: Yonghong Song
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-08-20 11:04 PDT by Tom Stellard
Modified: 2018-08-28 11:08 PDT (History)
3 users (show)

See Also:
Fixed By Commit(s): r340455


Attachments
C test case (2.74 KB, text/plain)
2018-08-20 11:04 PDT, Tom Stellard
Details
LLVM IR test case (1.08 KB, text/plain)
2018-08-20 11:05 PDT, Tom Stellard
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Stellard 2018-08-20 11:04:38 PDT
Created attachment 20745 [details]
C test case

The attached test cases trigger assertion failures in BPFAsmBackend::applyFixup() with llvm/clang 6.0.1.  I've provided the original C test case as well as a reduced LLVM IR To reproduce:

clang -target bpf kprobes_kern.c

or 

./llc -march=bpf bpf-fixup-crash.ll -filetype=obj
Comment 1 Tom Stellard 2018-08-20 11:05:08 PDT
Created attachment 20746 [details]
LLVM IR test case
Comment 2 Yonghong Song 2018-08-20 17:01:36 PDT
llvm 7.0.0 seems working fine.

-bash-4.2$ llc -version
LLVM (http://llvm.org/):
  LLVM version 7.0.0
  Optimized build.
  Default target: x86_64-unknown-linux-gnu
  Host CPU: broadwell

  Registered Targets:
    bpf    - BPF (host endian)
    bpfeb  - BPF (big endian)
    bpfel  - BPF (little endian)
    x86    - 32-bit X86: Pentium-Pro and above
    x86-64 - 64-bit X86: EM64T and AMD64
-bash-4.2$ cat fixup.ll
; ModuleID = 'bugpoint-reduced-simplified.bc'
source_filename = "bugpoint-output-9102428.bc"
target datalayout = "e-m:e-p:64:64-i64:64-n32:64-S128"
target triple = "bpf"

%struct.bpf_map_def.0.4.8.10.12.16.20.22.24.26 = type { i32, i32, i32, i32, i32, i32, i32 }
%struct.pt_regs.1.5.9.11.13.17.21.23.25.27 = type { i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64 }

@my_map = external global %struct.bpf_map_def.0.4.8.10.12.16.20.22.24.26, section "maps", align 4
@bpf_map_lookup_elem = internal global i8* (i8*, i8*)* inttoptr (i64 1 to i8* (i8*, i8*)*), align 8
@bpf_map_update_elem = internal global i32 (i8*, i8*, i8*, i64)* inttoptr (i64 2 to i32 (i8*, i8*, i8*, i64)*), align 8

; Function Attrs: noinline nounwind optnone
define i32 @bpf_prog1(%struct.pt_regs.1.5.9.11.13.17.21.23.25.27* %ctx) {
entry:
  %0 = load i32 (i8*, i8*, i8*, i64)*, i32 (i8*, i8*, i8*, i64)** @bpf_map_update_elem, align 8
  %call2 = call i32 %0(i8* bitcast (%struct.bpf_map_def.0.4.8.10.12.16.20.22.24.26* @my_map to i8*), i8* undef, i8* undef, i64 0)
  ret i32 %call2
}

-bash-4.2$ llc -march=bpf -filetype=obj fixup.ll 
-bash-4.2$ 

and latest trunk 8.0.0 works as well.

-bash-4.2$ llc -version
LLVM (http://llvm.org/):
  LLVM version 8.0.0svn
  Optimized build.
  Default target: x86_64-unknown-linux-gnu
  Host CPU: broadwell

  Registered Targets:
    bpf    - BPF (host endian)
    bpfeb  - BPF (big endian)
    bpfel  - BPF (little endian)
    x86    - 32-bit X86: Pentium-Pro and above
    x86-64 - 64-bit X86: EM64T and AMD64
-bash-4.2$ llc -march=bpf -filetype=obj fixup.ll 
-bash-4.2$
Comment 3 Yonghong Song 2018-08-20 17:12:01 PDT
Some how I cannot reproduce the issue with manually built 6.0.1.
The following is how I built llvm:
  # release_60 branch of llvm and clang
  cd llvm/build
cmake -G "Unix Makefiles" -DLLVM_TARGETS_TO_BUILD="BPF;X86" \
    -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PWD/install ..
make -j120
make install

-bash-4.2$ llc -version
LLVM (http://llvm.org/):
  LLVM version 6.0.1
  Optimized build.
  Default target: x86_64-unknown-linux-gnu
  Host CPU: broadwell

  Registered Targets:
    bpf    - BPF (host endian)
    bpfeb  - BPF (big endian)
    bpfel  - BPF (little endian)
    x86    - 32-bit X86: Pentium-Pro and above
    x86-64 - 64-bit X86: EM64T and AMD64
-bash-4.2$ llc -march=bpf -filetype=obj fixup.ll 
-bash-4.2$

Did I miss anything in order to reproduce the failure?
Comment 4 Tom Stellard 2018-08-20 17:15:26 PDT
You need to build with -DLLVM_ENABLE_ASSERTIONS=ON
Comment 5 Yonghong Song 2018-08-20 17:49:22 PDT
Okay, I can reproduce the problem now with latest trunk. will take a look soon.
Comment 6 Yonghong Song 2018-08-22 14:24:25 PDT
Fixed with better error messages.
https://reviews.llvm.org/rL340455