Skip to content

Commit

Permalink
Merge branch 'master' into 2405-monero
Browse files Browse the repository at this point in the history
  • Loading branch information
maflcko committed Jun 25, 2024
2 parents dadb2cb + 3b9936f commit be9c94d
Show file tree
Hide file tree
Showing 107 changed files with 1,887 additions and 702 deletions.
4 changes: 4 additions & 0 deletions docs/getting-started/continuous_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ and the `Run Fuzzers` sanitizer field needs to be the same. To specify a list of
a [matrix](https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix)
can be used. To use a sanitizer add it to the list of sanitizers in the matrix field below:

`report-timeouts`: Determines whether to report fails due to timeouts.

`report-ooms`: Determines whether to report fails due to OOM.

```yaml
{% raw %}
name: CIFuzz
Expand Down
11 changes: 11 additions & 0 deletions infra/base-images/base-builder-rust/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,15 @@ ENV PATH=$PATH:/rust/bin
# Set up custom environment variable for source code copy for coverage reports
ENV OSSFUZZ_RUSTPATH /rust

# Force rustup to ignore `rust-toolchain` and `rust-toolchain.toml` files by
# manually specifying what toolchain to use. Note that this environment variable
# is additionally used by `install_rust.sh` as the toolchain to install.
# cf https://rust-lang.github.io/rustup/overrides.html
ENV RUSTUP_TOOLCHAIN nightly-2024-02-12

# Configure the linker used by default for x86_64 linux to be `clang` instead of
# rustc's default of `cc` which is able to find custom-built libraries like
# `libc++` by default more easily.
ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER clang

RUN install_rust.sh
6 changes: 4 additions & 2 deletions infra/base-images/base-builder/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,10 @@ COPY bazel_build_fuzz_tests \

# TODO: Build this as part of a multi-stage build.
ADD https://commondatastorage.googleapis.com/clusterfuzz-builds/jcc/clang-jcc /usr/local/bin/
ADD https://commondatastorage.googleapis.com/clusterfuzz-builds/jcc/clang++-jcc /usr/local/bin/
RUN chmod +x /usr/local/bin/clang-jcc && chmod +x /usr/local/bin/clang++-jcc
ADD https://commondatastorage.googleapis.com/clusterfuzz-builds/jcc/clang++-jcc /usr/local/bin
ADD https://commondatastorage.googleapis.com/clusterfuzz-builds/jcc/clang-jcc2 /usr/local/bin/
ADD https://commondatastorage.googleapis.com/clusterfuzz-builds/jcc/clang++-jcc2 /usr/local/bin
RUN chmod +x /usr/local/bin/clang-jcc /usr/local/bin/clang++-jcc /usr/local/bin/clang-jcc2 /usr/local/bin/clang++-jcc2

COPY llvmsymbol.diff $SRC
COPY detect_repo.py /opt/cifuzz/
Expand Down
4 changes: 2 additions & 2 deletions infra/base-images/base-builder/install_rust.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#
################################################################################

curl https://sh.rustup.rs | sh -s -- -y --default-toolchain=nightly-2023-12-28 --profile=minimal
curl https://sh.rustup.rs | sh -s -- -y --default-toolchain=$RUSTUP_TOOLCHAIN --profile=minimal
cargo install cargo-fuzz && rm -rf /rust/registry
# Needed to recompile rust std library for MSAN
rustup component add rust-src --toolchain nightly-2023-12-28
rustup component add rust-src
cp -r /usr/local/lib/x86_64-unknown-linux-gnu/* /usr/local/lib/
6 changes: 4 additions & 2 deletions infra/base-images/base-builder/jcc/build_jcc.bash
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
################################################################################

go build jcc.go
cp jcc clang
cp jcc clang++
go build jcc2.go
gsutil cp jcc gs://clusterfuzz-builds/jcc/clang++-jcc
gsutil cp jcc gs://clusterfuzz-builds/jcc/clang-jcc

gsutil cp jcc2 gs://clusterfuzz-builds/jcc/clang++-jcc2
gsutil cp jcc2 gs://clusterfuzz-builds/jcc/clang-jcc2
64 changes: 1 addition & 63 deletions infra/base-images/base-builder/jcc/jcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"os/exec"
"path/filepath"
"regexp"
"slices"
"strings"
)

Expand Down Expand Up @@ -169,63 +168,6 @@ func CorrectMissingHeaders(bin string, cmd []string) ([]string, bool, error) {
return cmd, false, nil
}

func EnsureDir(dirPath string) {
// Checks if a path is an existing directory, otherwise create one.
if pathInfo, err := os.Stat(dirPath); err == nil {
if isDir := pathInfo.IsDir(); !isDir {
panic(dirPath + " exists but is not a directory.")
}
} else if errors.Is(err, fs.ErrNotExist) {
if err := os.MkdirAll(dirPath, 0755); err != nil {
panic("Failed to create directory: " + dirPath + ".")
}
fmt.Println("Created directory: " + dirPath + ".")
} else {
panic("An error occurred in os.Stat(" + dirPath + "): " + err.Error())
}
}

func GenerateAST(bin string, args []string, filePath string) {
// Generates AST.
outFile, err := os.Create(filePath)
if err != nil {
fmt.Println(err)
}
defer outFile.Close()

cmd := exec.Command(bin, args...)
cmd.Stdout = outFile
cmd.Run()
}

func GenerateASTs(bin string, args []string, astDir string) {
// Generates an AST for each C/CPP file in the command.
// Cannot save AST when astDir is not available.
EnsureDir(astDir)

// Target file suffixes.
suffixes := []string{".cpp", ".cc", ".cxx", ".c++", ".c", ".h", ".hpp"}
// C/CPP targets in the command.
targetFiles := []string{}
// Flags to generate AST.
flags := []string{"-Xclang", "-ast-dump=json", "-fsyntax-only"}
for _, arg := range args {
targetFileExt := strings.ToLower(filepath.Ext(arg))
if slices.Contains(suffixes, targetFileExt) {
targetFiles = append(targetFiles, arg)
continue
}
flags = append(flags, arg)
}

// Generate an AST for each target file. Skips AST generation when a
// command has no target file (e.g., during linking).
for _, targetFile := range targetFiles {
filePath := filepath.Join(astDir, fmt.Sprintf("%s.ast", filepath.Base(targetFile)))
GenerateAST(bin, append(flags, targetFile), filePath)
}
}

func ExecBuildCommand(bin string, args []string) (int, string, string) {
// Executes the original command.
cmd := exec.Command(bin, args...)
Expand All @@ -238,10 +180,6 @@ func ExecBuildCommand(bin string, args []string) (int, string, string) {
}

func Compile(bin string, args []string) (int, string, string) {
// Generate ASTs f we define this ENV var.
if astDir := os.Getenv("JCC_GENERATE_AST_DIR"); astDir != "" {
GenerateASTs(bin, args, astDir)
}
// Run the actual command.
return ExecBuildCommand(bin, args)
}
Expand Down Expand Up @@ -360,7 +298,7 @@ func WriteStdErrOut(args []string, outstr string, errstr string) {
fmt.Print(outstr)
fmt.Fprint(os.Stderr, errstr)
// Record what compile args produced the error and the error itself in log file.
AppendStringToFile("/workspace/err.log", fmt.Sprintf("%s\n", args) + errstr)
AppendStringToFile("/workspace/err.log", fmt.Sprintf("%s\n", args)+errstr)
}

func main() {
Expand Down
Loading

0 comments on commit be9c94d

Please sign in to comment.