summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllen Webb <allenwebb@google.com>2018-08-20 10:50:49 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-09-07 18:36:35 -0700
commita8e3f2388c0a950ec431e6fffc916b42ea6c816d (patch)
tree0f8554e770469a1515321aca1bdaab4cef59b198
parent269ff3569799531fa2b7f7a5def012ea254ceb57 (diff)
downloadchrome-ec-a8e3f2388c0a950ec431e6fffc916b42ea6c816d.tar.gz
makefule.rules: Add cxx_to_o rule for building c++ files.
This adds a rule for building c++ object files to make it possible to use libprotobuf-mutator in fuzzing targets. BRANCH=none BUG=chromium:876582 TEST=make -j buildfuzztargets && ./build/host/cr50_fuzz/cr50_fuzz.exe Change-Id: I1355c313e47a1a83a599eb0f0b9142fefdf6de8b Signed-off-by: Allen Webb <allenwebb@google.com> Reviewed-on: https://chromium-review.googlesource.com/1183535 Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--Makefile.rules7
-rw-r--r--fuzz/cr50_fuzz.cc (renamed from fuzz/cr50_fuzz.c)17
2 files changed, 17 insertions, 7 deletions
diff --git a/Makefile.rules b/Makefile.rules
index d44db81ba5..d6150a5c47 100644
--- a/Makefile.rules
+++ b/Makefile.rules
@@ -77,6 +77,8 @@ cmd_elf = $(CC) $(objs) $(libsharedobjs_elf-y) $(LDFLAGS) \
cmd_fuzz_exe = $(CXX) $^ $(HOST_TEST_LDFLAGS) $(LDFLAGS_EXTRA) -o $@
cmd_exe = $(CC) $(ro-objs) $(HOST_TEST_LDFLAGS) -o $@
cmd_c_to_o = $(CC) $(CFLAGS) -MMD -MP -MF $@.d -c $< -o $(@D)/$(@F)
+cmd_cxx_to_o = $(CXX) -std=c++11 $(CFLAGS) $(CXXFLAGS) -MMD -MP -MF $@.d -c $< \
+ -o $(@D)/$(@F)
cmd_c_to_build = $(BUILDCC) $(BUILD_CFLAGS) \
$(sort $(foreach c,$($(*F)-objs),util/$(c:%.o=%.c)) $(wildcard $*.c)) \
$(BUILD_LDFLAGS) \
@@ -444,6 +446,11 @@ $(out)/RO/%.o:%.c
$(out)/RW/%.o:%.c
$(call quiet,c_to_o,CC )
+$(out)/RO/%.o:%.cc
+ $(call quiet,cxx_to_o,CXX )
+$(out)/RW/%.o:%.cc
+ $(call quiet,cxx_to_o,CXX )
+
$(out)/$(SHOBJLIB)/%.o: override LATE_CFLAGS_DEFINE:=-DSHAREDLIB_IMAGE
$(out)/$(SHOBJLIB)/%.o:%.c
$(call quiet,c_to_o,CC )
diff --git a/fuzz/cr50_fuzz.c b/fuzz/cr50_fuzz.cc
index ccf99172d6..dc4220afb8 100644
--- a/fuzz/cr50_fuzz.c
+++ b/fuzz/cr50_fuzz.cc
@@ -5,25 +5,28 @@
* Fuzzer for the TPM2 and vendor specific Cr50 commands.
*/
-#include <stdint.h>
-#include <stdlib.h>
#include <unistd.h>
+#include <cstdint>
+#include <cstdlib>
+
+extern "C" {
#include "fuzz_config.h"
#include "nvmem.h"
#include "nvmem_vars.h"
#include "persistence.h"
#include "pinweaver.h"
+}
#define NVMEM_TPM_SIZE ((sizeof((struct nvmem_partition *)0)->buffer) \
- NVMEM_CR50_SIZE)
-uint32_t nvmem_user_sizes[NVMEM_NUM_USERS] = {
+extern "C" uint32_t nvmem_user_sizes[NVMEM_NUM_USERS] = {
NVMEM_TPM_SIZE,
NVMEM_CR50_SIZE
};
-void rand_bytes(void *buffer, size_t len)
+extern "C" void rand_bytes(void *buffer, size_t len)
{
size_t x = 0;
@@ -31,12 +34,12 @@ void rand_bytes(void *buffer, size_t len)
((uint8_t *)buffer)[x] = rand();
}
-void get_storage_seed(void *buf, size_t *len)
+extern "C" void get_storage_seed(void *buf, size_t *len)
{
memset(buf, 0x77, *len);
}
-void run_test(void)
+extern "C" void run_test(void)
{
}
@@ -54,7 +57,7 @@ static void assign_pw_field_from_bytes(const uint8_t *data, unsigned int size,
/* Prevent this from being stack allocated. */
static uint8_t tpm_io_buffer[PW_MAX_MESSAGE_SIZE];
-int test_fuzz_one_input(const uint8_t *data, unsigned int size)
+extern "C" int test_fuzz_one_input(const uint8_t *data, unsigned int size)
{
struct merkle_tree_t merkle_tree = {};
struct pw_request_t *request = (struct pw_request_t *)tpm_io_buffer;