-
Notifications
You must be signed in to change notification settings - Fork 6
Description
Hi,
I have been trying to use LLpatch for creating live patches. However, I am having some issues making it work, probably because my setup/understanding is not correct. Therefore, I was wondering if you could kindly help me clarify a few of my confusions listed below.
Which compiler to use for building LLpatch?
The README states that LLpatch is implemented in C++ and Bash scripts and that the prerequisite for C++ is clang++. However, the Makefile indicates that if the compiler is not specified, CC = gcc and CXX = g++. Does this mean it is supposed to work with g++ as well?
Which compiler to use for building Linux?
I find it a bit unclear. The README mentions that as long as 'clang' is available for the architecture and the Linux kernel can be compiled with 'clang', LLpatch should work. It also says that LLpatch assumes the Linux kernel is already built. Does this essentially mean that the kernel should be built with clang first, and not gcc? This thread says that in principle, this should work with gcc-built kernels, but it's not recommended. Anyway, I tried building Linux v6.4 with gcc v8.3.0 and LLpatch with LLVM v17.0.6, and got the following error.
llpatch[ OK |12/05 02:40]:: Aligning is done
llpatch[INFO|12/05 02:40]:: Building LLVM IR files for the 'original'
/tmp/livepatch.OXuw6hP07K/block/bdev.c
cc1: error: output filename specified twice
Does both compilers need to be the same?
The answers to the previous two questions might already cover this, but I wanted to ask for clarification: Is it necessary to use the same compiler for building both Linux and LLpatch?
What should be the compiler version/s?
If I need to use the same compiler for both Linux and LLpatch, which versions of it can I use? Do I need to use the same version of the compiler for both Linux and LLpatch?
What versions of Linux kernels are required?
Are there any version restrictions on the Linux kernel that we intend to patch and the kernel for the host OS? Do they need to be the same, i.e., does LLpatch require the target kernel to be running to generate a live patch for it?
I tried to create a live patch for the kernel v5.15 and got the following error, where both LLpatch and kernel was built with LLVM v17.0.6.
llpatch[ OK |12/05 02:26]:: Livepatch is ready to be packaged.
llpatch[INFO|12/05 02:26]:: Building kernel livepatch
llpatch[INFO|12/05 02:26]:: Build livepatch.o and resolve LLPatch symbols
make: Entering directory '/data00/mehrab/livepatch/linux'
CC [M] /tmp/livepatch.Fg34H9yfZY/vmlinux/livepatch.o
make: Leaving directory '/data00/mehrab/livepatch/linux'
cat: '*.thin': No such file or directory
However, for kernel v6.4, I get a different error. Is it because v6.4 generates vmlinux.a, whereas v5.15 does not?
llpatch[ OK |12/04 23:35]:: Computing diffs is done
llpatch[INFO|12/04 23:35]:: Building LLVM IR diff files
/tmp/livepatch.aOF8WokHWD/block/bdev.c__klp_diff.ll
clang-17: error: argument unused during compilation: '-MMD' [-Werror,-Wunused-command-line-argument]
clang-17: error: argument unused during compilation: '-MF block/.bdev.o.d' [-Werror,-Wunused-command-line-argument]
clang-17: error: argument unused during compilation: '-I ./arch/x86/include' [-Werror,-Wunused-command-line-argument]
clang-17: error: argument unused during compilation: '-I ./arch/x86/include/generated' [-Werror,-Wunused-command-line-argument]
clang-17: error: argument unused during compilation: '-I ./include' [-Werror,-Wunused-command-line-argument]
clang-17: error: argument unused during compilation: '-I ./arch/x86/include/uapi' [-Werror,-Wunused-command-line-argument]
clang-17: error: argument unused during compilation: '-I ./arch/x86/include/generated/uapi' [-Werror,-Wunused-command-line-argument]
clang-17: error: argument unused during compilation: '-I ./include/uapi' [-Werror,-Wunused-command-line-argument]
clang-17: error: argument unused during compilation: '-I ./include/generated/uapi' [-Werror,-Wunused-command-line-argument]
clang-17: error: argument unused during compilation: '-include ./include/linux/compiler-version.h' [-Werror,-Wunused-command-line-argument]
clang-17: error: argument unused during compilation: '-include ./include/linux/kconfig.h' [-Werror,-Wunused-command-line-argument]
clang-17: error: argument unused during compilation: '-include ./include/linux/compiler_types.h' [-Werror,-Wunused-command-line-argument]
clang-17: error: argument unused during compilation: '-fmacro-prefix-map=./=' [-Werror,-Wunused-command-line-argument]
clang-17: error: argument unused during compilation: '-I block' [-Werror,-Wunused-command-line-argument]
livepatch-compile[ERR |12/04 23:35]:: trap at line: 218, with error:1.
livepatch-compile[ERR |12/04 23:35]:: trap at line: 1, with error:1.
llpatch[ERR |12/04 23:35]:: trap at line: 154, with error:1.
llpatch[ERR |12/04 23:35]:: trap at line: 1, with error:1.
I used the following command to run llpatch.
LLpatch/llpatch --kdir=path_to_linux_source block.patch
The block.patch file looks like the following.
diff --git a/block/bdev.c b/block/bdev.c
index 21c63bfef323..495da805eb3e 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -86,6 +86,7 @@ void invalidate_bdev(struct block_device *bdev)
lru_add_drain_all(); /* make sure all lru add caches are flushed */
invalidate_mapping_pages(mapping, 0, -1);
}
+ printk("Patched function: invalidate_bdev\n");
}
EXPORT_SYMBOL(invalidate_bdev);
Specifications
- LLpatch version: Commit 262113a
- Host OS: Debian GNU/Linux 10 (buster)
The answers to these questions are probably straightforward and obvious. However, since I failed to make it work, I started asking myself these simple questions. I would greatly appreciate it if you could kindly help me with some clarifications to clear my confusions.
Thanks,
Mehrab