1# Copyright (c) 2011-present, Facebook, Inc. All rights reserved. 2# This source code is licensed under both the GPLv2 (found in the 3# COPYING file in the root directory) and Apache 2.0 License 4# (found in the LICENSE.Apache file in the root directory). 5 6ROOT_DIR = $(abspath $(shell pwd)/../) 7 8include $(ROOT_DIR)/make_config.mk 9 10PROTOBUF_CFLAGS = `pkg-config --cflags protobuf` 11PROTOBUF_LDFLAGS = `pkg-config --libs protobuf` 12 13PROTOBUF_MUTATOR_CFLAGS = `pkg-config --cflags libprotobuf-mutator` 14PROTOBUF_MUTATOR_LDFLAGS = `pkg-config --libs libprotobuf-mutator` 15 16ROCKSDB_INCLUDE_DIR = $(ROOT_DIR)/include 17ROCKSDB_LIB_DIR = $(ROOT_DIR) 18 19PROTO_IN = $(ROOT_DIR)/fuzz/proto 20PROTO_OUT = $(ROOT_DIR)/fuzz/proto/gen 21 22ifneq ($(FUZZ_ENV), ossfuzz) 23CC = clang++ 24CCFLAGS += -Wall -fsanitize=address,fuzzer 25CFLAGS += $(PLATFORM_CXXFLAGS) $(PROTOBUF_CFLAGS) $(PROTOBUF_MUTATOR_CFLAGS) -I$(PROTO_OUT) -I$(ROCKSDB_INCLUDE_DIR) -I$(ROCKSDB_LIB_DIR) 26LDFLAGS += $(PLATFORM_LDFLAGS) $(PROTOBUF_LDFLAGS) $(PROTOBUF_MUTATOR_LDFLAGS) -L$(ROCKSDB_LIB_DIR) -lrocksdb 27else 28# OSS-Fuzz sets various environment flags that are used for compilation. 29# These environment flags depend on which type of sanitizer build is being 30# used, however, an ASan build would set the environment flags as follows: 31# CFLAGS="-O1 -fno-omit-frame-pointer -gline-tables-only \ 32 -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address \ 33 -fsanitize-address-use-after-scope -fsanitize=fuzzer-no-link" 34# CXXFLAGS="-O1 -fno-omit-frame-pointer -gline-tables-only \ 35 -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address \ 36 -fsanitize-address-use-after-scope -fsanitize=fuzzer-no-link \ 37 -stdlib=libc++" 38# LIB_FUZZING_ENGINE="-fsanitize=fuzzer" 39CC = $(CXX) 40CCFLAGS = $(CXXFLAGS) 41CFLAGS += $(PROTOBUF_CFLAGS) $(PROTOBUF_MUTATOR_CFLAGS) -I$(PROTO_OUT) -I$(ROCKSDB_INCLUDE_DIR) -I$(ROCKSDB_LIB_DIR) 42LDFLAGS += $(PLATFORM_LDFLAGS) $(LIB_FUZZING_ENGINE) $(PROTOBUF_MUTATOR_LDFLAGS) $(PROTOBUF_LDFLAGS) -L$(ROCKSDB_LIB_DIR) -lrocksdb 43endif 44 45.PHONY: gen_proto 46 47gen_proto: 48 mkdir -p $(PROTO_OUT) 49 protoc \ 50 --proto_path=$(PROTO_IN) \ 51 --cpp_out=$(PROTO_OUT) \ 52 $(PROTO_IN)/*.proto 53 54db_fuzzer: db_fuzzer.cc 55 $(CC) $(CCFLAGS) -o db_fuzzer db_fuzzer.cc $(CFLAGS) $(LDFLAGS) 56 57db_map_fuzzer: gen_proto db_map_fuzzer.cc proto/gen/db_operation.pb.cc 58 $(CC) $(CCFLAGS) -o db_map_fuzzer db_map_fuzzer.cc proto/gen/db_operation.pb.cc $(CFLAGS) $(LDFLAGS) 59 60sst_file_writer_fuzzer: gen_proto sst_file_writer_fuzzer.cc proto/gen/db_operation.pb.cc 61 $(CC) $(CCFLAGS) -o sst_file_writer_fuzzer sst_file_writer_fuzzer.cc proto/gen/db_operation.pb.cc $(CFLAGS) $(LDFLAGS) 62