[compiler-rt] r352604 - [libFuzzer] remove stale code, NFC

Kostya Serebryany via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 29 22:21:21 PST 2019


Author: kcc
Date: Tue Jan 29 22:21:20 2019
New Revision: 352604

URL: http://llvm.org/viewvc/llvm-project?rev=352604&view=rev
Log:
[libFuzzer] remove stale code, NFC

Removed:
    compiler-rt/trunk/lib/fuzzer/FuzzerShmem.h
    compiler-rt/trunk/lib/fuzzer/FuzzerShmemFuchsia.cpp
    compiler-rt/trunk/lib/fuzzer/FuzzerShmemPosix.cpp
    compiler-rt/trunk/lib/fuzzer/FuzzerShmemWindows.cpp
Modified:
    compiler-rt/trunk/lib/fuzzer/CMakeLists.txt
    compiler-rt/trunk/lib/fuzzer/FuzzerDriver.cpp
    compiler-rt/trunk/lib/fuzzer/FuzzerFlags.def
    compiler-rt/trunk/lib/fuzzer/FuzzerInternal.h
    compiler-rt/trunk/lib/fuzzer/FuzzerLoop.cpp

Modified: compiler-rt/trunk/lib/fuzzer/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/CMakeLists.txt?rev=352604&r1=352603&r2=352604&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/fuzzer/CMakeLists.txt Tue Jan 29 22:21:20 2019
@@ -13,9 +13,6 @@ set(LIBFUZZER_SOURCES
   FuzzerMerge.cpp
   FuzzerMutate.cpp
   FuzzerSHA1.cpp
-  FuzzerShmemFuchsia.cpp
-  FuzzerShmemPosix.cpp
-  FuzzerShmemWindows.cpp
   FuzzerTracePC.cpp
   FuzzerUtil.cpp
   FuzzerUtilDarwin.cpp
@@ -43,7 +40,6 @@ set(LIBFUZZER_HEADERS
   FuzzerOptions.h
   FuzzerRandom.h
   FuzzerSHA1.h
-  FuzzerShmem.h
   FuzzerTracePC.h
   FuzzerUtil.h
   FuzzerValueBitMap.h)

Modified: compiler-rt/trunk/lib/fuzzer/FuzzerDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerDriver.cpp?rev=352604&r1=352603&r2=352604&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerDriver.cpp (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerDriver.cpp Tue Jan 29 22:21:20 2019
@@ -15,7 +15,6 @@
 #include "FuzzerInternal.h"
 #include "FuzzerMutate.h"
 #include "FuzzerRandom.h"
-#include "FuzzerShmem.h"
 #include "FuzzerTracePC.h"
 #include <algorithm>
 #include <atomic>
@@ -672,34 +671,6 @@ int FuzzerDriver(int *argc, char ***argv
   if (Flags.cleanse_crash)
     return CleanseCrashInput(Args, Options);
 
-#if 0  // deprecated, to be removed.
-  if (auto Name = Flags.run_equivalence_server) {
-    SMR.Destroy(Name);
-    if (!SMR.Create(Name)) {
-       Printf("ERROR: can't create shared memory region\n");
-      return 1;
-    }
-    Printf("INFO: EQUIVALENCE SERVER UP\n");
-    while (true) {
-      SMR.WaitClient();
-      size_t Size = SMR.ReadByteArraySize();
-      SMR.WriteByteArray(nullptr, 0);
-      const Unit tmp(SMR.GetByteArray(), SMR.GetByteArray() + Size);
-      F->ExecuteCallback(tmp.data(), tmp.size());
-      SMR.PostServer();
-    }
-    return 0;
-  }
-
-  if (auto Name = Flags.use_equivalence_server) {
-    if (!SMR.Open(Name)) {
-      Printf("ERROR: can't open shared memory region\n");
-      return 1;
-    }
-    Printf("INFO: EQUIVALENCE CLIENT UP\n");
-  }
-#endif
-
   if (DoPlainRun) {
     Options.SaveArtifacts = false;
     int Runs = std::max(1, Flags.runs);

Modified: compiler-rt/trunk/lib/fuzzer/FuzzerFlags.def
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerFlags.def?rev=352604&r1=352603&r2=352604&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerFlags.def (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerFlags.def Tue Jan 29 22:21:20 2019
@@ -145,8 +145,6 @@ FUZZER_FLAG_INT(ignore_remaining_args, 0
 FUZZER_FLAG_STRING(focus_function, "Experimental. "
      "Fuzzing will focus on inputs that trigger calls to this function")
 
-FUZZER_DEPRECATED_FLAG(run_equivalence_server)
-FUZZER_DEPRECATED_FLAG(use_equivalence_server)
 FUZZER_FLAG_INT(analyze_dict, 0, "Experimental")
 FUZZER_DEPRECATED_FLAG(use_clang_coverage)
 FUZZER_FLAG_STRING(data_flow_trace, "Experimental: use the data flow trace")

Modified: compiler-rt/trunk/lib/fuzzer/FuzzerInternal.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerInternal.h?rev=352604&r1=352603&r2=352604&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerInternal.h (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerInternal.h Tue Jan 29 22:21:20 2019
@@ -89,7 +89,6 @@ public:
                                bool DuringInitialCorpusExecution);
 
   void HandleMalloc(size_t Size);
-  void AnnounceOutput(const uint8_t *Data, size_t Size);
 
 private:
   void AlarmCallback();

Modified: compiler-rt/trunk/lib/fuzzer/FuzzerLoop.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerLoop.cpp?rev=352604&r1=352603&r2=352604&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerLoop.cpp (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerLoop.cpp Tue Jan 29 22:21:20 2019
@@ -13,7 +13,6 @@
 #include "FuzzerInternal.h"
 #include "FuzzerMutate.h"
 #include "FuzzerRandom.h"
-#include "FuzzerShmem.h"
 #include "FuzzerTracePC.h"
 #include <algorithm>
 #include <cstring>
@@ -40,8 +39,6 @@ static const size_t kMaxUnitSizeToPrint
 
 thread_local bool Fuzzer::IsMyThread;
 
-SharedMemoryRegion SMR;
-
 bool RunningUserCallback = false;
 
 // Only one Fuzzer per process.
@@ -510,8 +507,6 @@ void Fuzzer::ExecuteCallback(const uint8
   TPC.RecordInitialStack();
   TotalNumberOfRuns++;
   assert(InFuzzingThread());
-  if (SMR.IsClient())
-    SMR.WriteByteArray(Data, Size);
   // We copy the contents of Unit into a separate heap buffer
   // so that we reliably find buffer overflows in it.
   uint8_t *DataCopy = new uint8_t[Size];
@@ -821,30 +816,6 @@ void Fuzzer::MinimizeCrashLoop(const Uni
   }
 }
 
-void Fuzzer::AnnounceOutput(const uint8_t *Data, size_t Size) {
-  if (SMR.IsServer()) {
-    SMR.WriteByteArray(Data, Size);
-  } else if (SMR.IsClient()) {
-    SMR.PostClient();
-    SMR.WaitServer();
-    size_t OtherSize = SMR.ReadByteArraySize();
-    uint8_t *OtherData = SMR.GetByteArray();
-    if (Size != OtherSize || memcmp(Data, OtherData, Size) != 0) {
-      size_t i = 0;
-      for (i = 0; i < Min(Size, OtherSize); i++)
-        if (Data[i] != OtherData[i])
-          break;
-      Printf("==%lu== ERROR: libFuzzer: equivalence-mismatch. Sizes: %zd %zd; "
-             "offset %zd\n",
-             GetPid(), Size, OtherSize, i);
-      DumpCurrentUnit("mismatch-");
-      Printf("SUMMARY: libFuzzer: equivalence-mismatch\n");
-      PrintFinalStats();
-      _Exit(Options.ErrorExitCode);
-    }
-  }
-}
-
 } // namespace fuzzer
 
 extern "C" {
@@ -855,10 +826,4 @@ LLVMFuzzerMutate(uint8_t *Data, size_t S
   return fuzzer::F->GetMD().DefaultMutate(Data, Size, MaxSize);
 }
 
-// Experimental
-ATTRIBUTE_INTERFACE void
-LLVMFuzzerAnnounceOutput(const uint8_t *Data, size_t Size) {
-  assert(fuzzer::F);
-  fuzzer::F->AnnounceOutput(Data, Size);
-}
 } // extern "C"

Removed: compiler-rt/trunk/lib/fuzzer/FuzzerShmem.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerShmem.h?rev=352603&view=auto
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerShmem.h (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerShmem.h (removed)
@@ -1,68 +0,0 @@
-//===- FuzzerShmem.h - shared memory interface ------------------*- C++ -* ===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-// SharedMemoryRegion
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_FUZZER_SHMEM_H
-#define LLVM_FUZZER_SHMEM_H
-
-#include <algorithm>
-#include <cstring>
-#include <string>
-
-#include "FuzzerDefs.h"
-
-namespace fuzzer {
-
-class SharedMemoryRegion {
- public:
-  bool Create(const char *Name);
-  bool Open(const char *Name);
-  bool Destroy(const char *Name);
-  uint8_t *GetData() { return Data; }
-  void PostServer() {Post(0);}
-  void WaitServer() {Wait(0);}
-  void PostClient() {Post(1);}
-  void WaitClient() {Wait(1);}
-
-  size_t WriteByteArray(const uint8_t *Bytes, size_t N) {
-    assert(N <= kShmemSize - sizeof(N));
-    memcpy(GetData(), &N, sizeof(N));
-    memcpy(GetData() + sizeof(N), Bytes, N);
-    assert(N == ReadByteArraySize());
-    return N;
-  }
-  size_t ReadByteArraySize() {
-    size_t Res;
-    memcpy(&Res, GetData(), sizeof(Res));
-    return Res;
-  }
-  uint8_t *GetByteArray() { return GetData() + sizeof(size_t); }
-
-  bool IsServer() const { return Data && IAmServer; }
-  bool IsClient() const { return Data && !IAmServer; }
-
-private:
-
-  static const size_t kShmemSize = 1 << 22;
-  bool IAmServer;
-  std::string Path(const char *Name);
-  std::string SemName(const char *Name, int Idx);
-  void Post(int Idx);
-  void Wait(int Idx);
-
-  bool Map(int fd);
-  uint8_t *Data = nullptr;
-  void *Semaphore[2];
-};
-
-extern SharedMemoryRegion SMR;
-
-}  // namespace fuzzer
-
-#endif  // LLVM_FUZZER_SHMEM_H

Removed: compiler-rt/trunk/lib/fuzzer/FuzzerShmemFuchsia.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerShmemFuchsia.cpp?rev=352603&view=auto
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerShmemFuchsia.cpp (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerShmemFuchsia.cpp (removed)
@@ -1,37 +0,0 @@
-//===- FuzzerShmemPosix.cpp - Posix shared memory ---------------*- C++ -* ===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-// SharedMemoryRegion.  For Fuchsia, this is just stubs as equivalence servers
-// are not currently supported.
-//===----------------------------------------------------------------------===//
-#include "FuzzerDefs.h"
-
-#if LIBFUZZER_FUCHSIA
-
-#include "FuzzerShmem.h"
-
-namespace fuzzer {
-
-bool SharedMemoryRegion::Create(const char *Name) {
-  return false;
-}
-
-bool SharedMemoryRegion::Open(const char *Name) {
-  return false;
-}
-
-bool SharedMemoryRegion::Destroy(const char *Name) {
-  return false;
-}
-
-void SharedMemoryRegion::Post(int Idx) {}
-
-void SharedMemoryRegion::Wait(int Idx) {}
-
-}  // namespace fuzzer
-
-#endif  // LIBFUZZER_FUCHSIA

Removed: compiler-rt/trunk/lib/fuzzer/FuzzerShmemPosix.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerShmemPosix.cpp?rev=352603&view=auto
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerShmemPosix.cpp (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerShmemPosix.cpp (removed)
@@ -1,107 +0,0 @@
-//===- FuzzerShmemPosix.cpp - Posix shared memory ---------------*- C++ -* ===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-// SharedMemoryRegion
-//===----------------------------------------------------------------------===//
-#include "FuzzerDefs.h"
-#if LIBFUZZER_POSIX
-
-#include "FuzzerIO.h"
-#include "FuzzerShmem.h"
-
-#include <errno.h>
-#include <fcntl.h>
-#include <semaphore.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-namespace fuzzer {
-
-std::string SharedMemoryRegion::Path(const char *Name) {
-  return DirPlusFile(TmpDir(), Name);
-}
-
-std::string SharedMemoryRegion::SemName(const char *Name, int Idx) {
-  std::string Res(Name);
-  // When passing a name without a leading <slash> character to
-  // sem_open, the behaviour is unspecified in POSIX. Add a leading
-  // <slash> character for the name if there is no such one.
-  if (!Res.empty() && Res[0] != '/')
-    Res.insert(Res.begin(), '/');
-  return Res + (char)('0' + Idx);
-}
-
-bool SharedMemoryRegion::Map(int fd) {
-  Data =
-      (uint8_t *)mmap(0, kShmemSize, PROT_WRITE | PROT_READ, MAP_SHARED, fd, 0);
-  if (Data == (uint8_t*)-1)
-    return false;
-  return true;
-}
-
-bool SharedMemoryRegion::Create(const char *Name) {
-  int fd = open(Path(Name).c_str(), O_CREAT | O_RDWR, 0777);
-  if (fd < 0) return false;
-  if (ftruncate(fd, kShmemSize) < 0) return false;
-  if (!Map(fd))
-    return false;
-  for (int i = 0; i < 2; i++) {
-    sem_unlink(SemName(Name, i).c_str());
-    Semaphore[i] = sem_open(SemName(Name, i).c_str(), O_CREAT, 0644, 0);
-    if (Semaphore[i] == SEM_FAILED)
-      return false;
-  }
-  IAmServer = true;
-  return true;
-}
-
-bool SharedMemoryRegion::Open(const char *Name) {
-  int fd = open(Path(Name).c_str(), O_RDWR);
-  if (fd < 0) return false;
-  struct stat stat_res;
-  if (0 != fstat(fd, &stat_res))
-    return false;
-  assert(stat_res.st_size == kShmemSize);
-  if (!Map(fd))
-    return false;
-  for (int i = 0; i < 2; i++) {
-    Semaphore[i] = sem_open(SemName(Name, i).c_str(), 0);
-    if (Semaphore[i] == SEM_FAILED)
-      return false;
-  }
-  IAmServer = false;
-  return true;
-}
-
-bool SharedMemoryRegion::Destroy(const char *Name) {
-  return 0 == unlink(Path(Name).c_str());
-}
-
-void SharedMemoryRegion::Post(int Idx) {
-  assert(Idx == 0 || Idx == 1);
-  sem_post((sem_t*)Semaphore[Idx]);
-}
-
-void SharedMemoryRegion::Wait(int Idx) {
-  assert(Idx == 0 || Idx == 1);
-  for (int i = 0; i < 10 && sem_wait((sem_t*)Semaphore[Idx]); i++) {
-    // sem_wait may fail if interrupted by a signal.
-    sleep(i);
-    if (i)
-      Printf("%s: sem_wait[%d] failed %s\n", i < 9 ? "WARNING" : "ERROR", i,
-             strerror(errno));
-    if (i == 9) abort();
-  }
-}
-
-}  // namespace fuzzer
-
-#endif  // LIBFUZZER_POSIX

Removed: compiler-rt/trunk/lib/fuzzer/FuzzerShmemWindows.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerShmemWindows.cpp?rev=352603&view=auto
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerShmemWindows.cpp (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerShmemWindows.cpp (removed)
@@ -1,63 +0,0 @@
-//===- FuzzerShmemWindows.cpp - Posix shared memory -------------*- C++ -* ===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-// SharedMemoryRegion
-//===----------------------------------------------------------------------===//
-#include "FuzzerDefs.h"
-#if LIBFUZZER_WINDOWS
-
-#include "FuzzerIO.h"
-#include "FuzzerShmem.h"
-
-#include <fcntl.h>
-#include <stdio.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-namespace fuzzer {
-
-std::string SharedMemoryRegion::Path(const char *Name) {
-  return DirPlusFile(TmpDir(), Name);
-}
-
-std::string SharedMemoryRegion::SemName(const char *Name, int Idx) {
-  std::string Res(Name);
-  return Res + (char)('0' + Idx);
-}
-
-bool SharedMemoryRegion::Map(int fd) {
-  assert(0 && "UNIMPLEMENTED");
-  return false;
-}
-
-bool SharedMemoryRegion::Create(const char *Name) {
-  assert(0 && "UNIMPLEMENTED");
-  return false;
-}
-
-bool SharedMemoryRegion::Open(const char *Name) {
-  assert(0 && "UNIMPLEMENTED");
-  return false;
-}
-
-bool SharedMemoryRegion::Destroy(const char *Name) {
-  assert(0 && "UNIMPLEMENTED");
-  return false;
-}
-
-void SharedMemoryRegion::Post(int Idx) {
-  assert(0 && "UNIMPLEMENTED");
-}
-
-void SharedMemoryRegion::Wait(int Idx) {
-  Semaphore[1] = nullptr;
-  assert(0 && "UNIMPLEMENTED");
-}
-
-}  // namespace fuzzer
-
-#endif  // LIBFUZZER_WINDOWS




More information about the llvm-commits mailing list