Revert "[libFuzzer] Port to Windows"

This reverts commit r340860 due to failing tests.

llvm-svn: 340867
GitOrigin-RevId: bab8556f01b36f519f3f7bd9f616cab17a5bf862
diff --git a/FuzzerDefs.h b/FuzzerDefs.h
index 31655d5..a35c7a1 100644
--- a/FuzzerDefs.h
+++ b/FuzzerDefs.h
@@ -129,15 +129,8 @@
 
 #if LIBFUZZER_WINDOWS
 #define ATTRIBUTE_INTERFACE __declspec(dllexport)
-// This is used for __sancov_lowest_stack which is needed for
-// -fsanitize-coverage=stack-depth. That feature is not yet available on
-// Windows, so make the symbol static to avoid linking errors.
-#define ATTRIBUTES_INTERFACE_TLS_INITIAL_EXEC \
-  __attribute__((tls_model("initial-exec"))) thread_local static
 #else
 #define ATTRIBUTE_INTERFACE __attribute__((visibility("default")))
-#define ATTRIBUTES_INTERFACE_TLS_INITIAL_EXEC \
-  ATTRIBUTE_INTERFACE __attribute__((tls_model("initial-exec"))) thread_local
 #endif
 
 namespace fuzzer {
diff --git a/FuzzerIO.cpp b/FuzzerIO.cpp
index dac5ec6..f3ead0e 100644
--- a/FuzzerIO.cpp
+++ b/FuzzerIO.cpp
@@ -100,6 +100,14 @@
   return DirPath + GetSeparator() + FileName;
 }
 
+std::string Basename(const std::string &Path, char Separator) {
+  size_t Pos = Path.rfind(Separator);
+  if (Pos == std::string::npos)
+    return Path;
+  assert(Pos < Path.size());
+  return Path.substr(Pos + 1);
+}
+
 void DupAndCloseStderr() {
   int OutputFd = DuplicateFile(2);
   if (OutputFd > 0) {
diff --git a/FuzzerIO.h b/FuzzerIO.h
index b4a6819..6d77574 100644
--- a/FuzzerIO.h
+++ b/FuzzerIO.h
@@ -68,7 +68,7 @@
 
 char GetSeparator();
 // Similar to the basename utility: returns the file name w/o the dir prefix.
-std::string Basename(const std::string &Path);
+std::string Basename(const std::string &Path, char Separator = GetSeparator());
 
 FILE* OpenFile(int Fd, const char *Mode);
 
diff --git a/FuzzerIOPosix.cpp b/FuzzerIOPosix.cpp
index 401b4cb..17e884d 100644
--- a/FuzzerIOPosix.cpp
+++ b/FuzzerIOPosix.cpp
@@ -46,13 +46,6 @@
   return St.st_size;
 }
 
-std::string Basename(const std::string &Path) {
-  size_t Pos = Path.rfind(GetSeparator());
-  if (Pos == std::string::npos) return Path;
-  assert(Pos < Path.size());
-  return Path.substr(Pos + 1);
-}
-
 void ListFilesInDirRecursive(const std::string &Dir, long *Epoch,
                              Vector<std::string> *V, bool TopDir) {
   auto E = GetEpoch(Dir);
diff --git a/FuzzerIOWindows.cpp b/FuzzerIOWindows.cpp
index 314b79d..7485364 100644
--- a/FuzzerIOWindows.cpp
+++ b/FuzzerIOWindows.cpp
@@ -72,26 +72,6 @@
   return IsFile(Path, Att);
 }
 
-std::string Basename(const std::string &Path) {
-  size_t Pos = Path.find_last_of("/\\");
-  if (Pos == std::string::npos) return Path;
-  assert(Pos < Path.size());
-  return Path.substr(Pos + 1);
-}
-
-size_t FileSize(const std::string &Path) {
-  WIN32_FILE_ATTRIBUTE_DATA attr;
-  if (!GetFileAttributesExA(Path.c_str(), GetFileExInfoStandard, &attr)) {
-    Printf("GetFileAttributesExA() failed for \"%s\" (Error code: %lu).\n",
-           Path.c_str(), GetLastError());
-    return 0;
-  }
-  ULARGE_INTEGER size;
-  size.HighPart = attr.nFileSizeHigh;
-  size.LowPart = attr.nFileSizeLow;
-  return size.QuadPart;
-}
-
 void ListFilesInDirRecursive(const std::string &Dir, long *Epoch,
                              Vector<std::string> *V, bool TopDir) {
   auto E = GetEpoch(Dir);
diff --git a/FuzzerTracePC.cpp b/FuzzerTracePC.cpp
index 7513084..1aba816 100644
--- a/FuzzerTracePC.cpp
+++ b/FuzzerTracePC.cpp
@@ -32,7 +32,8 @@
 uintptr_t __sancov_trace_pc_pcs[fuzzer::TracePC::kNumPCs];
 
 // Used by -fsanitize-coverage=stack-depth to track stack depth
-ATTRIBUTES_INTERFACE_TLS_INITIAL_EXEC uintptr_t __sancov_lowest_stack;
+ATTRIBUTE_INTERFACE __attribute__((tls_model("initial-exec")))
+thread_local uintptr_t __sancov_lowest_stack;
 
 namespace fuzzer {
 
diff --git a/FuzzerUtilWindows.cpp b/FuzzerUtilWindows.cpp
index 257723b..8227e77 100644
--- a/FuzzerUtilWindows.cpp
+++ b/FuzzerUtilWindows.cpp
@@ -179,9 +179,7 @@
 }
 
 std::string DisassembleCmd(const std::string &FileName) {
-  Vector<std::string> command_vector;
-  command_vector.push_back("dumpbin /summary > nul");
-  if (ExecuteCommand(Command(command_vector)) == 0)
+  if (ExecuteCommand("dumpbin /summary > nul") == 0)
     return "dumpbin /disasm " + FileName;
   Printf("libFuzzer: couldn't find tool to disassemble (dumpbin)\n");
   exit(1);
diff --git a/tests/FuzzerUnittest.cpp b/tests/FuzzerUnittest.cpp
index 7cdd445..e3b0670 100644
--- a/tests/FuzzerUnittest.cpp
+++ b/tests/FuzzerUnittest.cpp
@@ -34,13 +34,6 @@
   EXPECT_EQ(Basename("/bar"), "bar");
   EXPECT_EQ(Basename("foo/x"), "x");
   EXPECT_EQ(Basename("foo/"), "");
-#if LIBFUZZER_WINDOWS
-  EXPECT_EQ(Basename("foo\\bar"), "bar");
-  EXPECT_EQ(Basename("foo\\bar/baz"), "baz");
-  EXPECT_EQ(Basename("\\bar"), "bar");
-  EXPECT_EQ(Basename("foo\\x"), "x");
-  EXPECT_EQ(Basename("foo\\"), "");
-#endif
 }
 
 TEST(Fuzzer, CrossOver) {