-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move distro hack to tools/vmlinux-distro-hack
- Loading branch information
Showing
5 changed files
with
74 additions
and
49 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
dkms-use-debian-hack.patch | ||
dkms-use-distro-hack.patch |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,52 @@ | ||
obj-m += mimic.o | ||
ccflags-y := -D_MIMIC_KMOD | ||
|
||
KERNEL_UNAME ?= $(shell uname -r) | ||
|
||
SYSTEM_BUILD_DIR := /lib/modules/$(KERNEL_UNAME)/build | ||
PWD := $(CURDIR) | ||
|
||
ccflags-y := -D_MIMIC_KMOD | ||
|
||
# Notes on Debian hack: | ||
# Notes on distro hack: | ||
# | ||
# Debian does not ship vmlinux nor resolve_btfids in | ||
# linux-headers like Arch Linux does, so we need to refer to externally | ||
# built one in order to build kernel module BTF successfully. | ||
# - Debian does not ship vmlinux nor resolve_btfids in | ||
# linux-headers like Arch Linux does, so we need to refer to externally | ||
# built one in order to build kernel module BTF successfully. | ||
# | ||
# Ubuntu does not ship vmlinux, but provides resolve_btfid, and there | ||
# might be dead symlinks (e.g. rust/) inside. This needs to work around as | ||
# well. | ||
# - Ubuntu does not ship vmlinux, but provides resolve_btfids, and there | ||
# might be dead symlinks (e.g. rust/) inside. This needs to work around as | ||
# well. | ||
# | ||
# - Fedora does not provide resolve_btfids. However they ship the source code | ||
# of it inside /lib/modules/*. | ||
# | ||
# Other distributions lacking components necessary to build kernel module BTF | ||
# can also use the hack in packaging. | ||
|
||
ifdef DISTRO_HACK | ||
|
||
build_dir := build | ||
|
||
VMLINUX_DISTRO_HACK ?= /usr/lib/mimic/vmlinux-distro-hack | ||
RESOLVE_BTFIDS ?= /usr/lib/mimic/resolve_btfids | ||
|
||
export EXTRACT_VMLINUX ?= /usr/lib/mimic/extract-vmlinux | ||
export EXTRACT_BTF ?= /usr/lib/mimic/extract-btf | ||
export VMLINUX_SUFFIX ?= -$(KERNEL_UNAME) | ||
|
||
ifdef DEBIAN_HACK | ||
BUILD := build | ||
else | ||
BUILD := $(SYSTEM_BUILD_DIR) | ||
build_dir := $(SYSTEM_BUILD_DIR) | ||
endif | ||
|
||
all: | ||
ifdef DEBIAN_HACK | ||
cp -rL $(SYSTEM_BUILD_DIR) $(BUILD) || true | ||
|
||
if [ ! -f $(BUILD)/vmlinux ]; then \ | ||
if [ -f /boot/vmlinuz-$(KERNEL_UNAME) ]; then \ | ||
/usr/lib/mimic/extract-vmlinux /boot/vmlinuz-$(KERNEL_UNAME) > $(BUILD)/vmlinux; \ | ||
[ $? -eq 0 ] || /usr/lib/mimic/extract-btf /boot/vmlinuz-$(KERNEL_UNAME) > $(BUILD)/vmlinux; \ | ||
if [ $? -ne 0 ]; then \ | ||
echo ERROR: cannot extract BTF from boot image; \ | ||
exit 1; \ | ||
fi \ | ||
elif [ -f /boot/vmlinux-$(KERNEL_UNAME) ]; then \ | ||
if readelf -h /boot/vmlinux-$(KERNEL_UNAME) >/dev/null 2>/dev/null; then \ | ||
cp /boot/vmlinux-$(KERNEL_UNAME) $(BUILD)/vmlinux; \ | ||
else \ | ||
/usr/lib/mimic/extract-btf /boot/vmlinux-$(KERNEL_UNAME) > $(BUILD)/vmlinux; \ | ||
if [ $? -ne 0 ]; then \ | ||
echo ERROR: cannot extract BTF from boot image; \ | ||
exit 1; \ | ||
fi \ | ||
fi \ | ||
else \ | ||
echo ERROR: no boot image found; \ | ||
exit 1; \ | ||
fi \ | ||
fi | ||
|
||
if [ ! -f $(BUILD)/tools/bpf/resolve_btfids/resolve_btfids ]; then \ | ||
install -Dm755 /usr/lib/mimic/resolve_btfids $(BUILD)/tools/bpf/resolve_btfids/resolve_btfids; \ | ||
ifdef DISTRO_HACK | ||
cp -rL $(SYSTEM_BUILD_DIR) $(build_dir) || true | ||
$(VMLINUX_DISTRO_HACK) $(build_dir) | ||
if [ ! -f $(build_dir)/tools/bpf/resolve_btfids/resolve_btfids ]; then \ | ||
install -Dm755 $(RESOLVE_BTFIDS) $(build_dir)/tools/bpf/resolve_btfids/resolve_btfids; \ | ||
fi | ||
endif | ||
$(MAKE) -C $(BUILD) M=$(PWD) modules | ||
$(MAKE) -C $(build_dir) M=$(CURDIR) modules | ||
|
||
clean: | ||
rm -rf build | ||
[ ! -d $(SYSTEM_BUILD_DIR) ] || $(MAKE) -C $(SYSTEM_BUILD_DIR) M=$(PWD) clean | ||
ifdef DISTRO_HACK | ||
rm -rf $(build_dir) | ||
endif | ||
[ ! -d $(SYSTEM_BUILD_DIR) ] || $(MAKE) -C $(SYSTEM_BUILD_DIR) M=$(CURDIR) clean |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/sh | ||
# | ||
# Extract vmlinux (either ELF with .BTF section or entirely BTF blob) when | ||
# distributions do not provide it in its module path. | ||
# | ||
# See kmod/Makefile for usage with automatic kernel building tool e.g. DKMS. | ||
|
||
module_dir="$1" | ||
: "${VMLINUX_SUFFIX:=-$(uname -r)}" | ||
: "${EXTRACT_VMLINUX:="$module_dir/scripts/extract-vmlinux"}" | ||
: "${EXTRACT_BTF:="out/extract-btf"}" | ||
|
||
if [ ! -f "$module_dir/vmlinux" ]; then | ||
if [ -f "/boot/vmlinuz$VMLINUX_SUFFIX" ]; then | ||
"$EXTRACT_VMLINUX" "/boot/vmlinuz$VMLINUX_SUFFIX" >"$module_dir/vmlinux" | ||
[ $? -eq 0 ] || "$EXTRACT_BTF" "/boot/vmlinuz$VMLINUX_SUFFIX" >"$module_dir/vmlinux" | ||
if [ $? -ne 0 ]; then | ||
>&2 echo "ERROR: cannot extract BTF from '/boot/vmlinuz$VMLINUX_SUFFIX'" | ||
exit 1 | ||
fi | ||
elif [ -f "/boot/vmlinux$VMLINUX_SUFFIX" ]; then | ||
if readelf -h "/boot/vmlinux$VMLINUX_SUFFIX" >/dev/null 2>/dev/null; then | ||
cp "/boot/vmlinux$VMLINUX_SUFFIX" "$module_dir/vmlinux" | ||
else | ||
"$EXTRACT_BTF" "/boot/vmlinux$VMLINUX_SUFFIX" >"$module_dir/vmlinux" | ||
if [ $? -ne 0 ]; then | ||
>&2 echo "ERROR: cannot extract BTF from '/boot/vmlinux$VMLINUX_SUFFIX'" | ||
exit 1 | ||
fi | ||
fi | ||
else | ||
>&2 echo "ERROR: no boot image found" | ||
exit 1 | ||
fi | ||
fi |