Bug 1618958

Summary: clang -target bpf generates unknown opcode 8d
Product: [Fedora] Fedora Reporter: Stanislav Kozina <skozina>
Component: clangAssignee: Tom Stellard <tstellar>
Status: CLOSED RAWHIDE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: rawhideCC: airlied, davejohansen, ravnzon, sbergman, siddharth.kde, tstellar
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: llvm-7.0.0-0.13.rc3.fc30 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-09-26 17:09:39 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Testing source code file none

Description Stanislav Kozina 2018-08-18 20:00:17 UTC
Created attachment 1476812 [details]
Testing source code file

Description of problem:

clang -target bpf generates unknown opcode 8d.
It doesn't generate this opcode when run with -O2.

Version-Release number of selected component (if applicable):

clang-6.0.1-1.fc28.x86_64
kernel-4.16.12-300.fc28.x86_64

How reproducible: 100%

Steps to reproduce:

Compile attached C source code file using:
$ clang -target bpf -c -o kprobes_kern.o kprobes_kern.c

Then use bpf_load.c from Linux source code tree to load it. BPF in-kernel verifier declines to load this file with following error:

# ./kprobes 
bpf_load_program() err=Invalid argument
unknown opcode 8d
unknown opcode 8d

This problem goes away when the same code is compiled with -O2.

Comment 1 Tom Stellard 2018-08-28 18:12:48 UTC
Upstream has fixed this by emitting an error message rather than producing illegal code.  The backend can't always handle the LLVM IR produced at -O0, so don't expect -O0 to work and use -O2 instead.

Comment 2 Tom Stellard 2018-09-26 17:09:39 UTC
Fixed in rawhide by llvm-7.0.0-0.13.rc3.fc30.