Skip to content

Commit b7d0c47

Browse files
committed
fuzz: Check in relevant files rather than creating
Move some of the embedded bash script to a directory structure that we can pass to Clang directly rather than recreating.
1 parent b23edbf commit b7d0c47

8 files changed

Lines changed: 29 additions & 16 deletions

File tree

fuzz/build.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ fn main() -> io::Result<ExitCode> {
3333

3434
let manifest_dir =
3535
PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR unset"));
36+
let fake_include_dir = manifest_dir.join("cxx/include");
3637
let target_dir = env::var_os("CARGO_TARGET_DIR")
3738
.map(PathBuf::from)
3839
.unwrap_or_else(|| manifest_dir.parent().unwrap().join("target"));
@@ -61,6 +62,7 @@ fn main() -> io::Result<ExitCode> {
6162
let sh_script_exit_status = Command::new("bash")
6263
.args(["-c", SH_SCRIPT])
6364
.env("llvm", &llvm_dir.join("llvm"))
65+
.env("manifest_dir", &manifest_dir)
6466
.envs([
6567
("llvm_project_git_hash", llvm_commit_hash),
6668
("cxx_apf_fuzz_exports", &cxx_exported_symbols.join(",")),
@@ -81,20 +83,6 @@ fn main() -> io::Result<ExitCode> {
8183
const SH_SCRIPT: &str = r#"
8284
set -eux
8385
84-
mkdir -p "$OUT_DIR"/fake-config/llvm/Config
85-
touch "$OUT_DIR"/fake-config/llvm/Config/{abi-breaking,config,llvm-config}.h
86-
87-
# HACK(eddyb) we want standard `assert`s to work, but `NDEBUG` also controls
88-
# unrelated LLVM facilities that are spread all over the place and it's harder
89-
# to compile all of them, than do this workaround where we shadow `assert.h`.
90-
echo -e '#undef NDEBUG\n#include_next <assert.h>\n#define NDEBUG' \
91-
> "$OUT_DIR"/fake-config/assert.h
92-
93-
# HACK(eddyb) bypass `$llvm/include/llvm/Support/DataTypes.h.cmake`.
94-
mkdir -p "$OUT_DIR"/fake-config/llvm/Support
95-
echo -e '#include <'{math,inttypes,stdint,sys/types}'.h>\n' \
96-
> "$OUT_DIR"/fake-config/llvm/Support/DataTypes.h
97-
9886
# FIXME(eddyb) maybe split `$clang_codegen_flags` into front-end vs back-end.
9987
clang_codegen_flags="-g -fPIC -fno-exceptions -O3 -march=native"
10088
@@ -104,9 +92,10 @@ clang_codegen_flags="-g -fPIC -fno-exceptions -O3 -march=native"
10492
echo | clang++ -x c++ - -std=c++17 \
10593
$clang_codegen_flags \
10694
-I "$llvm"/include \
107-
-I "$OUT_DIR"/fake-config \
95+
-I "$llvm"/lib/Support \
96+
-I "$manifest_dir/cxx/include" \
10897
-DNDEBUG -DHAVE_UNISTD_H -DLLVM_ON_UNIX -DLLVM_ENABLE_THREADS=0 \
109-
--include="$llvm"/lib/Support/{APInt,APFloat,SmallVector,ErrorHandling}.cpp \
98+
--include="$manifest_dir/cxx/fuzz_unity_build.cpp" \
11099
--include="$OUT_DIR"/cxx_apf_fuzz.cpp \
111100
-c -emit-llvm -o "$OUT_DIR"/cxx_apf_fuzz.bc
112101

fuzz/cxx/fuzz_unity_build.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* "unity build" file which builds all needed source files as a single
2+
translation unit to simplify the compilation process (specifically dead
3+
code removal and to some degree, optimization) */
4+
5+
#include "APInt.cpp"
6+
#include "APFloat.cpp"
7+
#include "SmallVector.cpp"
8+
#include "ErrorHandling.cpp"

fuzz/cxx/include/README.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This directory has overrides needed to make it possible to compiler LLVM's
2+
`APFloat.cpp` and related files without the rest of LLVM. Some files are
3+
stubs since they are included in LLVM but not used for our purposes.

fuzz/cxx/include/assert.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* HACK(eddyb) we want standard `assert`s to work, but `NDEBUG` also controls
2+
unrelated LLVM facilities that are spread all over the place and it's harder
3+
to compile all of them, than do this workaround where we shadow `assert.h`. */
4+
5+
#undef NDEBUG
6+
#include_next <assert.h>
7+
#define NDEBUG

fuzz/cxx/include/llvm/Config/abi-breaking.h

Whitespace-only changes.

fuzz/cxx/include/llvm/Config/config.h

Whitespace-only changes.

fuzz/cxx/include/llvm/Config/llvm-config.h

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* Bypass `/include/llvm/Support/DataTypes.h.cmake` */
2+
3+
#include <math.h>
4+
#include <inttypes.h>
5+
#include <stdint.h>
6+
#include <sys/types.h>

0 commit comments

Comments
 (0)