Skip to content

Commit c380abc

Browse files
committed
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)
1 parent 5a46c0d commit c380abc

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ endif
114114
check_copyright check_language check_whitespace check_links check_diff check_commits check_shebang check_html \
115115
presubmit presubmit_aux presubmit_build presubmit_arch_linux presubmit_arch_freebsd \
116116
presubmit_arch_netbsd presubmit_arch_openbsd presubmit_arch_darwin presubmit_arch_windows \
117-
presubmit_arch_executor presubmit_dashboard presubmit_race presubmit_race_dashboard presubmit_old
117+
presubmit_arch_executor presubmit_dashboard presubmit_race presubmit_race_dashboard presubmit_old codesearch
118118

119119
all: host target
120120
host: manager repro mutate prog2c db upgrade
@@ -240,6 +240,15 @@ extract: bin/syz-extract
240240
bin/syz-extract:
241241
GOOS=$(HOSTOS) GOARCH=$(HOSTARCH) $(HOSTGO) build $(GOHOSTFLAGS) -o $@ ./sys/syz-extract
242242

243+
codesearch: bin/syz-codesearch
244+
245+
bin/syz-codesearch: tools/clang/codesearch/codesearch.cpp
246+
$(CXX) -Itools/clang $(shell llvm-config --cxxflags) -o $@ $< \
247+
-lclangTooling -lclangFrontend -lclangSerialization -lclangDriver \
248+
-lclangToolingCore -lclangParse -lclangSema -lclangAPINotes -lclangAnalysis \
249+
-lclangASTMatchers -lclangRewrite -lclangEdit -lclangAST -lclangLex -lclangBasic -lclangSupport \
250+
$(shell llvm-config --ldflags --libs --system-libs)
251+
243252
# `generate` does *not* depend on any kernel sources, and generates everything
244253
# in one pass, for all arches. It can be run on a bare syzkaller checkout.
245254
generate:

tools/clang/codesearch/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ Clang-based tool that indexes kernel source code to power
55
agentic tool.
66

77
The tool can be built following the procedure described for
8-
[syz-declextract tool](/tools/syz-declextract/README.md).
8+
[syz-declextract tool](/tools/syz-declextract/README.md) or with `make
9+
codesearch`.

0 commit comments

Comments
 (0)