Rbbcc試したメモ
試した日: 2020/01/05
試した人: hanachin.icon
これをやってみる
Arch Linux、新しいbccしかなくてこんなエラーがでる
code:plaintext
% sudo bundle exec ruby foo.rb
Traceback (most recent call last):
16: from foo.rb:1:in `<main>'
15: from foo.rb:1:in `require'
14: from /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc.rb:2:in `<top (required)>'
13: from /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc.rb:2:in `require'
12: from /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/bcc.rb:2:in `<top (required)>'
11: from /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/bcc.rb:2:in `require'
10: from /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/table.rb:1:in `<top (required)>'
9: from /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/table.rb:1:in `require'
8: from /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/clib.rb:3:in `<top (required)>'
7: from /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/clib.rb:4:in `<module:RbBCC>'
6: from /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/clib.rb:16:in `<module:Clib>'
5: from /home/sei/.rbenv/versions/master/lib/ruby/2.8.0/fiddle/import.rb:77:in `dlload'
4: from /home/sei/.rbenv/versions/master/lib/ruby/2.8.0/fiddle/import.rb:77:in `collect'
3: from /home/sei/.rbenv/versions/master/lib/ruby/2.8.0/fiddle/import.rb:87:in `block in dlload'
2: from /home/sei/.rbenv/versions/master/lib/ruby/2.8.0/fiddle.rb:47:in `dlopen'
1: from /home/sei/.rbenv/versions/master/lib/ruby/2.8.0/fiddle.rb:47:in `new'
/home/sei/.rbenv/versions/master/lib/ruby/2.8.0/fiddle.rb:47:in `initialize': libbcc.so.0.10.0: cannot open shared object file: No such file or directory (Fiddle::DLError)
14: from foo.rb:1:in `<main>'
13: from foo.rb:1:in `require'
12: from /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc.rb:2:in `<top (required)>'
11: from /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc.rb:2:in `require'
10: from /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/bcc.rb:2:in `<top (required)>'
9: from /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/bcc.rb:2:in `require'
8: from /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/table.rb:1:in `<top (required)>'
7: from /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/table.rb:1:in `require'
6: from /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/clib.rb:3:in `<top (required)>'
5: from /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/clib.rb:4:in `<module:RbBCC>'
4: from /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/clib.rb:16:in `<module:Clib>'
3: from /home/sei/.rbenv/versions/master/lib/ruby/2.8.0/fiddle/import.rb:77:in `dlload'
2: from /home/sei/.rbenv/versions/master/lib/ruby/2.8.0/fiddle/import.rb:77:in `collect'
1: from /home/sei/.rbenv/versions/master/lib/ruby/2.8.0/fiddle/import.rb:86:in `block in dlload'
/home/sei/.rbenv/versions/master/lib/ruby/2.8.0/fiddle/import.rb:89:in `rescue in block in dlload': can't load libbcc.so.0.10.0 (Fiddle::DLError)
この記述は見なかったものとする
RbBCC requires libbcc.so version 0.10.0(we plan to support newer version of libbcc, but it may be done after rbbcc 1.0...).
とりあえずこう書き換えてみる
code:diff
diff --git a/lib/rbbcc/clib.rb b/lib/rbbcc/clib.rb
index ec98fdc..981d41c 100644
--- a/lib/rbbcc/clib.rb
+++ b/lib/rbbcc/clib.rb
@@ -13,7 +13,7 @@ def self.__extract_char(ptr)
end
extend Fiddle::Importer
- dlload "libbcc.so.0.10.0"
+ dlload "libbcc.so.0.12.0"
typealias "size_t", "int"
extern 'void * bpf_module_create_c_from_string(char *, unsigned int, char **, int, long)'
clangないとfiddleうごかないのかな
code:plaintext
/home/sei/.rbenv/versions/master/lib/ruby/2.8.0/fiddle.rb:47:in `initialize': libclangFrontend.so.9: cannot open shared object file: No such file or directory (Fiddle::DLError)
14: from foo.rb:1:in `<main>'
13: from foo.rb:1:in `require'
12: from /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc.rb:2:in `<top (required)>'
11: from /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc.rb:2:in `require'
10: from /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/bcc.rb:2:in `<top (required)>'
9: from /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/bcc.rb:2:in `require'
8: from /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/table.rb:1:in `<top (required)>'
7: from /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/table.rb:1:in `require'
6: from /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/clib.rb:3:in `<top (required)>'
5: from /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/clib.rb:4:in `<module:RbBCC>'
4: from /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/clib.rb:16:in `<module:Clib>'
3: from /home/sei/.rbenv/versions/master/lib/ruby/2.8.0/fiddle/import.rb:77:in `dlload'
2: from /home/sei/.rbenv/versions/master/lib/ruby/2.8.0/fiddle/import.rb:77:in `collect'
1: from /home/sei/.rbenv/versions/master/lib/ruby/2.8.0/fiddle/import.rb:86:in `block in dlload'
/home/sei/.rbenv/versions/master/lib/ruby/2.8.0/fiddle/import.rb:89:in `rescue in block in dlload': can't load libbcc.so.0.12.0 (Fiddle::DLError)
入れてなかった、 pacman -S clang する。
code:plaintext
% pacman -Ss clang
extra/clang 9.0.0-3
C language family frontend for LLVM
extra/clazy 1.6-1
Qt oriented code checker based on clang framework
extra/compiler-rt 9.0.0-2
Compiler runtime libraries for clang
community/intel-opencl-clang 9.0.0-3
A wrapper library around clang that can compile OpenCL C kernels to SPIR-V modules
community/zapcc 7.0.325000-3
C++ compiler based on Clang, but significantly faster
とりあえずこうなった
code:plaintext
% sudo bundle exec ruby foo.rb
modprobe: FATAL: Module kheaders not found in directory /lib/modules/5.4.6-arch1-1
Unable to find kernel headers. Try rebuilding kernel with CONFIG_IKHEADERS=m (module)
chdir(/lib/modules/5.4.6-arch1-1/build): No such file or directory
TIME(s) COMM PID value
pacman -S linux-headers する
code:plaintext
% sudo bundle exec ruby foo.rb
Found fnc: kprobe__sys_clone
/home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/clib.rb:25: BUG Segmentation fault at 0x000000000000000a ruby 2.8.0dev (2020-01-03T05:53:25Z master 170f4dbb9b) x86_64-linux -- Control frame information -----------------------------------------------
c:0010 p:---- s:0069 e:000068 CFUNC :call
c:0009 p:0016 s:0055 e:000054 METHOD /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/clib.rb:25
c:0008 p:0104 s:0049 e:000048 METHOD /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/bcc.rb:208
c:0007 p:0133 s:0040 e:000039 BLOCK /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/bcc.rb:413 FINISH c:0006 p:---- s:0032 e:000031 CFUNC :each
c:0005 p:0020 s:0028 e:000027 METHOD /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/bcc.rb:398
c:0004 p:0108 s:0024 e:000023 METHOD /home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/bcc.rb:175 FINISH c:0003 p:---- s:0013 e:000012 CFUNC :new
c:0002 p:0036 s:0008 E:001060 EVAL foo.rb:12 FINISH c:0001 p:0000 s:0003 E:000d40 (none) FINISH -- Ruby level backtrace information ----------------------------------------
foo.rb:12:in `<main>'
foo.rb:12:in `new'
/home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/bcc.rb:175:in `initialize'
/home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/bcc.rb:398:in `trace_autoload!'
/home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/bcc.rb:398:in `each'
/home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/bcc.rb:413:in `block in trace_autoload!'
/home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/bcc.rb:208:in `load_func'
/home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/clib.rb:25:in `bcc_func_load'
/home/sei/src/github.com/udzura/rbbcc/lib/rbbcc/clib.rb:25:in `call'
まあそうですね