[lld] r316178 - [COFF] Move MinGW specific functions/classes to a separate file. NFC.

Martin Storsjo via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 19 12:49:38 PDT 2017


Author: mstorsjo
Date: Thu Oct 19 12:49:38 2017
New Revision: 316178

URL: http://llvm.org/viewvc/llvm-project?rev=316178&view=rev
Log:
[COFF] Move MinGW specific functions/classes to a separate file. NFC.

Differential Revision: https://reviews.llvm.org/D39067

Added:
    lld/trunk/COFF/MinGW.cpp
    lld/trunk/COFF/MinGW.h
Modified:
    lld/trunk/COFF/CMakeLists.txt
    lld/trunk/COFF/Driver.cpp
    lld/trunk/include/lld/Common/LLVM.h

Modified: lld/trunk/COFF/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/CMakeLists.txt?rev=316178&r1=316177&r2=316178&view=diff
==============================================================================
--- lld/trunk/COFF/CMakeLists.txt (original)
+++ lld/trunk/COFF/CMakeLists.txt Thu Oct 19 12:49:38 2017
@@ -17,6 +17,7 @@ add_lld_library(lldCOFF
   LTO.cpp
   MapFile.cpp
   MarkLive.cpp
+  MinGW.cpp
   PDB.cpp
   Strings.cpp
   SymbolTable.cpp

Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=316178&r1=316177&r2=316178&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Thu Oct 19 12:49:38 2017
@@ -12,6 +12,7 @@
 #include "Error.h"
 #include "InputFiles.h"
 #include "Memory.h"
+#include "MinGW.h"
 #include "SymbolTable.h"
 #include "Symbols.h"
 #include "Writer.h"
@@ -548,113 +549,6 @@ static void parseModuleDefs(StringRef Pa
   }
 }
 
-// Logic for deciding what symbols to export, when exporting all
-// symbols for MinGW.
-class AutoExporter {
-public:
-  AutoExporter() {
-    if (Config->Machine == I386)
-      ExcludeSymbols = {
-          "__NULL_IMPORT_DESCRIPTOR",
-          "__pei386_runtime_relocator",
-          "_do_pseudo_reloc",
-          "_impure_ptr",
-          "__impure_ptr",
-          "__fmode",
-          "_environ",
-          "___dso_handle",
-          // These are the MinGW names that differ from the standard
-          // ones (lacking an extra underscore).
-          "_DllMain at 12",
-          "_DllEntryPoint at 12",
-          "_DllMainCRTStartup at 12",
-      };
-    else
-      ExcludeSymbols = {
-          "_NULL_IMPORT_DESCRIPTOR",
-          "_pei386_runtime_relocator",
-          "do_pseudo_reloc",
-          "impure_ptr",
-          "_impure_ptr",
-          "_fmode",
-          "environ",
-          "__dso_handle",
-          // These are the MinGW names that differ from the standard
-          // ones (lacking an extra underscore).
-          "DllMain",
-          "DllEntryPoint",
-          "DllMainCRTStartup",
-      };
-  }
-
-  StringSet<> ExcludeSymbols;
-  StringSet<> ExcludeLibs = {
-      "libgcc",
-      "libgcc_s",
-      "libstdc++",
-      "libmingw32",
-      "libmingwex",
-      "libg2c",
-      "libsupc++",
-      "libobjc",
-      "libgcj",
-      "libclang_rt.builtins-aarch64",
-      "libclang_rt.builtins-arm",
-      "libclang_rt.builtins-i386",
-      "libclang_rt.builtins-x86_64",
-  };
-  StringSet<> ExcludeObjects = {
-      "crt0.o",
-      "crt1.o",
-      "crt1u.o",
-      "crt2.o",
-      "crt2u.o",
-      "dllcrt1.o",
-      "dllcrt2.o",
-      "gcrt0.o",
-      "gcrt1.o",
-      "gcrt2.o",
-      "crtbegin.o",
-      "crtend.o",
-  };
-
-  bool shouldExport(Defined *Sym) const {
-    if (!Sym || !Sym->isLive() || !Sym->getChunk())
-      return false;
-    if (ExcludeSymbols.count(Sym->getName()))
-      return false;
-    StringRef LibName = sys::path::filename(Sym->getFile()->ParentName);
-    // Drop the file extension.
-    LibName = LibName.substr(0, LibName.rfind('.'));
-    if (ExcludeLibs.count(LibName))
-      return false;
-    StringRef FileName = sys::path::filename(Sym->getFile()->getName());
-    if (LibName.empty() && ExcludeObjects.count(FileName))
-      return false;
-    return true;
-  }
-};
-
-// This is MinGW specific.
-static void writeDefFile(StringRef Name) {
-  std::error_code EC;
-  raw_fd_ostream OS(Name, EC, sys::fs::F_None);
-  if (EC)
-    fatal("cannot open " + Name + ": " + EC.message());
-
-  OS << "EXPORTS\n";
-  for (Export &E : Config->Exports) {
-    OS << "    " << E.ExportName << " "
-       << "@" << E.Ordinal;
-    if (auto *Def = dyn_cast_or_null<Defined>(E.Sym)) {
-      if (Def && Def->getChunk() &&
-          !(Def->getChunk()->getPermissions() & IMAGE_SCN_MEM_EXECUTE))
-        OS << " DATA";
-    }
-    OS << "\n";
-  }
-}
-
 // A helper function for filterBitcodeFiles.
 static bool needsRebuilding(MemoryBufferRef MB) {
   // The MSVC linker doesn't support thin archives, so if it's a thin

Added: lld/trunk/COFF/MinGW.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/MinGW.cpp?rev=316178&view=auto
==============================================================================
--- lld/trunk/COFF/MinGW.cpp (added)
+++ lld/trunk/COFF/MinGW.cpp Thu Oct 19 12:49:38 2017
@@ -0,0 +1,119 @@
+//===- MinGW.cpp ----------------------------------------------------------===//
+//
+//                             The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "MinGW.h"
+#include "Error.h"
+#include "llvm/Object/COFF.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace lld;
+using namespace lld::coff;
+using namespace llvm;
+using namespace llvm::COFF;
+
+AutoExporter::AutoExporter() {
+  if (Config->Machine == I386)
+    ExcludeSymbols = {
+        "__NULL_IMPORT_DESCRIPTOR",
+        "__pei386_runtime_relocator",
+        "_do_pseudo_reloc",
+        "_impure_ptr",
+        "__impure_ptr",
+        "__fmode",
+        "_environ",
+        "___dso_handle",
+        // These are the MinGW names that differ from the standard
+        // ones (lacking an extra underscore).
+        "_DllMain at 12",
+        "_DllEntryPoint at 12",
+        "_DllMainCRTStartup at 12",
+    };
+  else
+    ExcludeSymbols = {
+        "_NULL_IMPORT_DESCRIPTOR",
+        "_pei386_runtime_relocator",
+        "do_pseudo_reloc",
+        "impure_ptr",
+        "_impure_ptr",
+        "_fmode",
+        "environ",
+        "__dso_handle",
+        // These are the MinGW names that differ from the standard
+        // ones (lacking an extra underscore).
+        "DllMain",
+        "DllEntryPoint",
+        "DllMainCRTStartup",
+    };
+
+  ExcludeLibs = {
+      "libgcc",
+      "libgcc_s",
+      "libstdc++",
+      "libmingw32",
+      "libmingwex",
+      "libg2c",
+      "libsupc++",
+      "libobjc",
+      "libgcj",
+      "libclang_rt.builtins-aarch64",
+      "libclang_rt.builtins-arm",
+      "libclang_rt.builtins-i386",
+      "libclang_rt.builtins-x86_64",
+  };
+  ExcludeObjects = {
+      "crt0.o",
+      "crt1.o",
+      "crt1u.o",
+      "crt2.o",
+      "crt2u.o",
+      "dllcrt1.o",
+      "dllcrt2.o",
+      "gcrt0.o",
+      "gcrt1.o",
+      "gcrt2.o",
+      "crtbegin.o",
+      "crtend.o",
+  };
+}
+
+bool AutoExporter::shouldExport(Defined *Sym) const {
+  if (!Sym || !Sym->isLive() || !Sym->getChunk())
+    return false;
+  if (ExcludeSymbols.count(Sym->getName()))
+    return false;
+  StringRef LibName = sys::path::filename(Sym->getFile()->ParentName);
+  // Drop the file extension.
+  LibName = LibName.substr(0, LibName.rfind('.'));
+  if (ExcludeLibs.count(LibName))
+    return false;
+  StringRef FileName = sys::path::filename(Sym->getFile()->getName());
+  if (LibName.empty() && ExcludeObjects.count(FileName))
+    return false;
+  return true;
+}
+
+void coff::writeDefFile(StringRef Name) {
+  std::error_code EC;
+  raw_fd_ostream OS(Name, EC, sys::fs::F_None);
+  if (EC)
+    fatal("cannot open " + Name + ": " + EC.message());
+
+  OS << "EXPORTS\n";
+  for (Export &E : Config->Exports) {
+    OS << "    " << E.ExportName << " "
+       << "@" << E.Ordinal;
+    if (auto *Def = dyn_cast_or_null<Defined>(E.Sym)) {
+      if (Def && Def->getChunk() &&
+          !(Def->getChunk()->getPermissions() & IMAGE_SCN_MEM_EXECUTE))
+        OS << " DATA";
+    }
+    OS << "\n";
+  }
+}

Added: lld/trunk/COFF/MinGW.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/MinGW.h?rev=316178&view=auto
==============================================================================
--- lld/trunk/COFF/MinGW.h (added)
+++ lld/trunk/COFF/MinGW.h Thu Oct 19 12:49:38 2017
@@ -0,0 +1,38 @@
+//===- MinGW.h --------------------------------------------------*- C++ -*-===//
+//
+//                             The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLD_COFF_MINGW_H
+#define LLD_COFF_MINGW_H
+
+#include "Config.h"
+#include "Symbols.h"
+#include "lld/Common/LLVM.h"
+
+namespace lld {
+namespace coff {
+
+// Logic for deciding what symbols to export, when exporting all
+// symbols for MinGW.
+class AutoExporter {
+public:
+  AutoExporter();
+
+  StringSet<> ExcludeSymbols;
+  StringSet<> ExcludeLibs;
+  StringSet<> ExcludeObjects;
+
+  bool shouldExport(Defined *Sym) const;
+};
+
+void writeDefFile(StringRef Name);
+
+} // namespace coff
+} // namespace lld
+
+#endif

Modified: lld/trunk/include/lld/Common/LLVM.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Common/LLVM.h?rev=316178&r1=316177&r2=316178&view=diff
==============================================================================
--- lld/trunk/include/lld/Common/LLVM.h (original)
+++ lld/trunk/include/lld/Common/LLVM.h Thu Oct 19 12:49:38 2017
@@ -25,6 +25,7 @@ namespace llvm {
   // ADT's.
   class Error;
   class StringRef;
+  template<typename T> class StringSet;
   class Twine;
   class MemoryBuffer;
   class MemoryBufferRef;
@@ -57,6 +58,7 @@ namespace lld {
   // ADT's.
   using llvm::Error;
   using llvm::StringRef;
+  using llvm::StringSet;
   using llvm::Twine;
   using llvm::MemoryBuffer;
   using llvm::MemoryBufferRef;




More information about the llvm-commits mailing list