From cf20fe98a57b940f293234cb22c3cd51a1c9fa9d Mon Sep 17 00:00:00 2001 From: Florent Revest Date: Mon, 12 Jan 2026 18:58:23 +0100 Subject: tools/clang/codesearch: support building with make Currently, clang tools are built by copying their code into a llvm-project repository and adding build rule to LLVM's CMake. This allows pinning a specific LLVM hash which is convenient but it's also a bit painful to copy code across repositories. This adds a rule to make that can build syz-codesearch with a simple g++ invocation that uses llvm-config to get the LLVM compiler and linker flags and hardcodes some clang libraries to link against since I could not find a better way. (llvm-config does not have "components" for clang) --- Makefile | 11 ++++++++++- tools/clang/codesearch/README.md | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 8495f6c5e..f67a4227f 100644 --- a/Makefile +++ b/Makefile @@ -114,7 +114,7 @@ endif check_copyright check_language check_whitespace check_links check_diff check_commits check_shebang check_html \ presubmit presubmit_aux presubmit_build presubmit_arch_linux presubmit_arch_freebsd \ presubmit_arch_netbsd presubmit_arch_openbsd presubmit_arch_darwin presubmit_arch_windows \ - presubmit_arch_executor presubmit_dashboard presubmit_race presubmit_race_dashboard presubmit_old + presubmit_arch_executor presubmit_dashboard presubmit_race presubmit_race_dashboard presubmit_old codesearch all: host target host: manager repro mutate prog2c db upgrade @@ -240,6 +240,15 @@ extract: bin/syz-extract bin/syz-extract: GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) $(HOSTGO) build $(GOHOSTFLAGS) -o $@ ./sys/syz-extract +codesearch: bin/syz-codesearch + +bin/syz-codesearch: tools/clang/codesearch/codesearch.cpp + $(CXX) -Itools/clang $(shell llvm-config --cxxflags) -o $@ $< \ + -lclangTooling -lclangFrontend -lclangSerialization -lclangDriver \ + -lclangToolingCore -lclangParse -lclangSema -lclangAPINotes -lclangAnalysis \ + -lclangASTMatchers -lclangRewrite -lclangEdit -lclangAST -lclangLex -lclangBasic -lclangSupport \ + $(shell llvm-config --ldflags --libs --system-libs) + # `generate` does *not* depend on any kernel sources, and generates everything # in one pass, for all arches. It can be run on a bare syzkaller checkout. generate: diff --git a/tools/clang/codesearch/README.md b/tools/clang/codesearch/README.md index 3f444f61d..6d876c78e 100644 --- a/tools/clang/codesearch/README.md +++ b/tools/clang/codesearch/README.md @@ -5,4 +5,5 @@ Clang-based tool that indexes kernel source code to power agentic tool. The tool can be built following the procedure described for -[syz-declextract tool](/tools/syz-declextract/README.md). +[syz-declextract tool](/tools/syz-declextract/README.md) or with `make +codesearch`. -- cgit mrf-deployment