[llvm] [Tools] add symbol prof parsing fuzzer (PR #77752)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 11 03:02:41 PST 2024


https://github.com/DavidKorczynski created https://github.com/llvm/llvm-project/pull/77752

The goal is to have this fuzzer running as part of the LLVM OSS-Fuzz integration (https://github.com/google/oss-fuzz/tree/master/projects/llvm)

>From 2b98f6452aa21fcdd314a9cf304436978ce86e93 Mon Sep 17 00:00:00 2001
From: David Korczynski <david at adalogics.com>
Date: Thu, 11 Jan 2024 03:03:29 -0800
Subject: [PATCH] [Tools] add symbol prof parsing fuzzer

Signed-off-by: David Korczynski <david at adalogics.com>
---
 .../llvm-symbol-reader-fuzzer/CMakeLists.txt  |  6 ++++
 .../llvm-symbol-reader-fuzzer.cpp             | 30 +++++++++++++++++++
 2 files changed, 36 insertions(+)
 create mode 100644 llvm/tools/llvm-symbol-reader-fuzzer/CMakeLists.txt
 create mode 100644 llvm/tools/llvm-symbol-reader-fuzzer/llvm-symbol-reader-fuzzer.cpp

diff --git a/llvm/tools/llvm-symbol-reader-fuzzer/CMakeLists.txt b/llvm/tools/llvm-symbol-reader-fuzzer/CMakeLists.txt
new file mode 100644
index 00000000000000..0d77d26c5bbbad
--- /dev/null
+++ b/llvm/tools/llvm-symbol-reader-fuzzer/CMakeLists.txt
@@ -0,0 +1,6 @@
+set(LLVM_LINK_COMPONENTS
+  ProfileData
+)
+add_llvm_fuzzer(llvm-symbol-reader-fuzzer
+  llvm-symbol-reader-fuzzer.cpp
+)
diff --git a/llvm/tools/llvm-symbol-reader-fuzzer/llvm-symbol-reader-fuzzer.cpp b/llvm/tools/llvm-symbol-reader-fuzzer/llvm-symbol-reader-fuzzer.cpp
new file mode 100644
index 00000000000000..0973596fd3edfa
--- /dev/null
+++ b/llvm/tools/llvm-symbol-reader-fuzzer/llvm-symbol-reader-fuzzer.cpp
@@ -0,0 +1,30 @@
+//===-- llvm-smybol-reader-fuzzer.cpp - Fuzzer for symbol prof parsing ---====//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ProfileData/SymbolRemappingReader.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/MemoryBuffer.h"
+
+using namespace llvm;
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+  std::string ErrMsg;
+  raw_string_ostream OS(ErrMsg);
+
+  std::string Payload(reinterpret_cast<const char *>(Data), Size);
+  std::unique_ptr<llvm::MemoryBuffer> Buf =
+      llvm::MemoryBuffer::getMemBuffer(Payload);
+
+  SymbolRemappingReader Reader;
+  Error E = Reader.read(*Buf);
+  if ((bool)E) {
+    logAllUnhandledErrors(std::move(E), OS);
+  }
+
+  return 0;
+}



More information about the llvm-commits mailing list