Created
January 30, 2024 14:16
-
-
Save shunghsiyu/f9319c0c5d5025c8f98162a970be73ef to your computer and use it in GitHub Desktop.
Reproducer for iovisor/bcc#4890
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eEuxo pipefail | |
export PATH="$HOME/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" | |
export LD_LIBRARY_PATH="$HOME/.local/lib64" | |
trap 'exit -1' ERR | |
pushd "$HOME/llvm-project" | |
rm -r ./build || true | |
if ! grep -e 'include <cstdint>' 'llvm/include/llvm/Support/Signals.h'; then | |
git cherry-pick \ | |
--no-commit \ | |
--keep-redundant-commits \ | |
ff1681ddb303223973653f7f5f3f3435b48a1983 | |
fi | |
if ! grep -e 'include <limits>' 'llvm/utils/benchmark/src/benchmark_register.h'; then | |
git cherry-pick \ | |
--no-commit \ | |
--keep-redundant-commits \ | |
b498303066a63a203d24f739b2d2e0e56dca70d1 | |
fi | |
if ! grep -e 'include <cstdint>' 'llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h'; then | |
git cherry-pick \ | |
--no-commit \ | |
--keep-redundant-commits \ | |
b288d90b39f4b905c02092a9bfcfd6d78f99b191 | |
fi | |
cmake -S llvm -B build -G Ninja -Wno-dev \ | |
-DCMAKE_BUILD_TYPE=Release \ | |
-DLLVM_ENABLE_ASSERTIONS=OFF \ | |
-DLLVM_OPTIMIZED_TABLEGEN=ON \ | |
-DCMAKE_INSTALL_PREFIX="$HOME/.local" \ | |
-DLLVM_LIBDIR_SUFFIX=64 \ | |
-DLLVM_CCACHE_BUILD=ON \ | |
-DLLVM_CCACHE_MAXSIZE=60G \ | |
-DLLVM_BUILD_LLVM_DYLIB=ON \ | |
-DLLVM_LINK_LLVM_DYLIB=ON \ | |
-DBUILD_SHARED_LIBS=OFF \ | |
-DLLVM_ENABLE_PROJECTS=clang \ | |
-DLLVM_TARGETS_TO_BUILD='BPF' \ | |
-DLLVM_PARALLEL_LINK_JOBS=2 | |
time ninja -C build | |
rm -r \ | |
~/.local/lib64/libLLVM* \ | |
~/.local/lib64/libclang* \ | |
~/.local/lib64/clang \ | |
~/.local/lib64/libLTO* || true | |
ninja -C build install | |
git reset --hard HEAD | |
popd | |
pushd "$HOME/bcc" | |
rm -r ./build || true | |
git submodule update | |
if ! grep -e 'collections.abc' 'src/python/bcc/table.py'; then | |
git cherry-pick \ | |
--no-commit \ | |
--keep-redundant-commits \ | |
--rerere-autoupdate \ | |
48946d2f31afbfb7b4bc7c62a9d3d6f1d2ffc330 | |
fi | |
LLVM_ROOT='/home/user/.local/bin/llvm-' cmake -B build -Wno-dev \ | |
-DCMAKE_MODULE_PATH='/home/user/.local/lib64/cmake' \ | |
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ | |
-DCMAKE_C_COMPILER_LAUNCHER=ccache \ | |
-DLLVM_LIBRARY_DIRS='/home/user/.local/lib64' \ | |
-DREVISION="$(git describe --tags HEAD | sed 's/^v//' | sed 's/-.*$//')" \ | |
-DPYTHON_CMD=python3 \ | |
-DCMAKE_INSTALL_PREFIX="$HOME/.local" \ | |
-DENABLE_LLVM_SHARED=1 \ | |
-DLUAJIT_INCLUDE_DIR=`pkg-config --variable=includedir luajit` \ | |
-DLUAJIT_LIBRARY=/usr/lib64/lib`pkg-config --variable=libname luajit`.so \ | |
-DENABLE_NO_PIE=OFF \ | |
-DRUN_LUA_TESTS=OFF \ | |
-DENABLE_TESTS=OFF \ | |
-DENABLE_USDT=ON | |
time make -C build -j$(nproc) | |
rm -r \ | |
~/.local/lib64/libbcc* \ | |
~/.local/lib/python3.11/site-packages/bcc* || true | |
make -C build install | |
git reset --hard HEAD | |
popd | |
pushd "$HOME" | |
if (~/bitfield_test.py 2>&1 || true) | grep -e ' = 32'; then | |
echo "Has bug" | |
exit 1 | |
else | |
echo "NO bug" | |
exit 0 | |
fi | |
popd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import bcc | |
from bcc import BPF | |
import sys | |
bpf_text = """ | |
#include <uapi/linux/ptrace.h> | |
struct event_t { | |
long offset1; | |
long offset2; | |
}; | |
BPF_PERF_OUTPUT(events); | |
struct sk_buff; | |
struct my_struct | |
{ | |
long: 64; | |
long: 64; | |
long: 64; | |
void* ptr; | |
}; | |
int kprobe__netif_rx(struct pt_regs *ctx) | |
{ | |
struct event_t event = {}; | |
void* p1 = (void*)ctx->di; | |
void* p2 = NULL; | |
event.offset1 = ((long)&((struct my_struct*)p1)->ptr) - (long)p1; | |
event.offset2 = ((long)&((struct my_struct*)p2)->ptr) - (long)p2; | |
events.perf_submit(ctx, &event, sizeof(event)); | |
return 0; | |
} | |
""" | |
def print_event(cpu, data, size): | |
event = b["events"].event(data) | |
print(f"offset1: {event.offset1}") | |
print(f"offset2: {event.offset2}") | |
sys.exit(0) | |
b = BPF(text=bpf_text, debug=bcc.DEBUG_SOURCE | bcc.DEBUG_LLVM_IR | bcc.DEBUG_BTF | bcc.DEBUG_PREPROCESSOR) | |
b["events"].open_perf_buffer(print_event) | |
while 1: | |
try: | |
b.perf_buffer_poll() | |
except KeyboardInterrupt: | |
exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment