From 5cbc0add24760165f557fd00bd9d915279ea4611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Fri, 15 Sep 2017 19:06:16 +0200 Subject: [PATCH] clang: update to 5.0.0 (#2890) Signed-off-by: Mateusz Mikula --- .../0001-genlib-named-as-llvm-dlltool.patch | 1447 ----------------- ...gw-w64-use-MSVC-style-ByteAlignment.patch} | 20 +- ...GetHostTriple-for-mingw-w64-in-msys.patch} | 6 +- ...y-provide-DESTDIR-for-all-platforms.patch} | 6 +- ...for-unversioned-shared-lib-on-win32.patch} | 12 +- ...add-pthread-as-system-lib-for-mingw.patch} | 9 +- .../0005-not-install-msvc-files.patch | 22 - ...06-fix-bugpoint-multiple-definition.patch} | 6 +- ...uild-static-clang-library-for-mingw.patch} | 6 +- ...ble-support-for-__declspec-selectany.patch | 28 - ...=> 0102-fix-libclang-name-for-mingw.patch} | 6 +- ...x86-arch-name-to-i686-for-mingw-w64.patch} | 10 +- .../0104-don-t-use-GCC-headers.patch | 32 - .../0104-link-pthread-with-mingw.patch | 25 + .../0105-use-emulated-tls-with-mingw.patch | 26 + .../0106-link-pthread-with-mingw.patch | 26 - ...0107-enable-__float128-for-X86-MinGW.patch | 35 - ...Don-t-create-cl-executable-for-mingw.patch | 25 - .../0109-use-emulated-tls-with-mingw.patch | 26 - ...0201-mingw-w64-__udivdi3-mangle-hack.patch | 11 +- .../0202-compiler-rt-fix-mingw-build.patch | 7 +- .../0301-COFF-gnu-driver-support.patch | 230 --- ...-add-install-target-for-the-lld-tool.patch | 125 -- ...gw-w64-hack-and-slash-fixes-for-libc.patch | 258 +-- .../0501-fixes-to-get-lldb-building.patch | 172 ++ ...501-minor-fixes-to-get-lldb-building.patch | 130 -- ...02-hack-to-use-64-bit-time-for-mingw.patch | 24 +- ...-libunwind-add-support-for-mingw-w64.patch | 127 +- ...fix-visibility-for-libc-abi-on-win32.patch | 36 - .../0801-Don-t-build-LLVMPolly-on-WIN32.patch | 39 + mingw-w64-clang/PKGBUILD | 174 +- 31 files changed, 472 insertions(+), 2634 deletions(-) delete mode 100644 mingw-w64-clang/0001-genlib-named-as-llvm-dlltool.patch rename mingw-w64-clang/{0002-mingw-w64-use-MSVC-style-ByteAlignment.patch => 0001-mingw-w64-use-MSVC-style-ByteAlignment.patch} (66%) rename mingw-w64-clang/{0003-Fix-GetHostTriple-for-mingw-w64-in-msys.patch => 0002-Fix-GetHostTriple-for-mingw-w64-in-msys.patch} (85%) rename mingw-w64-clang/{0004-Globally-provide-DESTDIR-for-all-platforms.patch => 0003-Globally-provide-DESTDIR-for-all-platforms.patch} (81%) rename mingw-w64-clang/{0006-llvm-config-look-for-unversioned-shared-lib-on-win32.patch => 0004-llvm-config-look-for-unversioned-shared-lib-on-win32.patch} (79%) rename mingw-w64-clang/{0007-add-pthread-as-system-lib-for-mingw.patch => 0005-add-pthread-as-system-lib-for-mingw.patch} (79%) delete mode 100644 mingw-w64-clang/0005-not-install-msvc-files.patch rename mingw-w64-clang/{0008-fix-bugpoint-multiple-definition.patch => 0006-fix-bugpoint-multiple-definition.patch} (54%) rename mingw-w64-clang/{0102-Allow-build-static-clang-library-for-mingw.patch => 0101-Allow-build-static-clang-library-for-mingw.patch} (82%) delete mode 100644 mingw-w64-clang/0101-mingw-w64-enable-support-for-__declspec-selectany.patch rename mingw-w64-clang/{0103-fix-libclang-name-for-mingw.patch => 0102-fix-libclang-name-for-mingw.patch} (82%) rename mingw-w64-clang/{0105-Set-the-x86-arch-name-to-i686-for-mingw-w64.patch => 0103-Set-the-x86-arch-name-to-i686-for-mingw-w64.patch} (74%) delete mode 100644 mingw-w64-clang/0104-don-t-use-GCC-headers.patch create mode 100644 mingw-w64-clang/0104-link-pthread-with-mingw.patch create mode 100644 mingw-w64-clang/0105-use-emulated-tls-with-mingw.patch delete mode 100644 mingw-w64-clang/0106-link-pthread-with-mingw.patch delete mode 100644 mingw-w64-clang/0107-enable-__float128-for-X86-MinGW.patch delete mode 100644 mingw-w64-clang/0108-Don-t-create-cl-executable-for-mingw.patch delete mode 100644 mingw-w64-clang/0109-use-emulated-tls-with-mingw.patch delete mode 100644 mingw-w64-clang/0301-COFF-gnu-driver-support.patch delete mode 100644 mingw-w64-clang/0302-add-install-target-for-the-lld-tool.patch create mode 100644 mingw-w64-clang/0501-fixes-to-get-lldb-building.patch delete mode 100644 mingw-w64-clang/0501-minor-fixes-to-get-lldb-building.patch delete mode 100644 mingw-w64-clang/0701-fix-visibility-for-libc-abi-on-win32.patch create mode 100644 mingw-w64-clang/0801-Don-t-build-LLVMPolly-on-WIN32.patch diff --git a/mingw-w64-clang/0001-genlib-named-as-llvm-dlltool.patch b/mingw-w64-clang/0001-genlib-named-as-llvm-dlltool.patch deleted file mode 100644 index 57204eab81..0000000000 --- a/mingw-w64-clang/0001-genlib-named-as-llvm-dlltool.patch +++ /dev/null @@ -1,1447 +0,0 @@ -From 462496b4bc03a0243f4c43f7e40ac70cedd1dcec Mon Sep 17 00:00:00 2001 -From: Martell Malone -Date: Tue, 9 Aug 2016 17:52:46 -0700 -Subject: [PATCH 1/6] genlib: named as llvm-dlltool - -A PE COFF spec compliant import library generator. -Intended to be used with mingw-w64. - -Supports: -PE COFF spec (section 8, Import Library Format) -PE COFF spec (Aux Format 3: Weak Externals) ---- - include/llvm/DllDriver/DllDriver.h | 24 ++ - lib/CMakeLists.txt | 1 + - lib/DLLDriver/CMakeLists.txt | 11 + - lib/DLLDriver/Config.h | 119 ++++++++ - lib/DLLDriver/DllDriver.cpp | 185 ++++++++++++ - lib/DLLDriver/LLVMBuild.txt | 22 ++ - lib/DLLDriver/Librarian.cpp | 603 +++++++++++++++++++++++++++++++++++++ - lib/DLLDriver/ModuleDef.cpp | 321 ++++++++++++++++++++ - lib/DLLDriver/Options.td | 5 + - lib/Object/ArchiveWriter.cpp | 3 +- - tools/llvm-ar/CMakeLists.txt | 2 + - tools/llvm-ar/llvm-ar.cpp | 6 +- - 12 files changed, 1300 insertions(+), 2 deletions(-) - create mode 100644 include/llvm/DllDriver/DllDriver.h - create mode 100644 lib/DLLDriver/CMakeLists.txt - create mode 100644 lib/DLLDriver/Config.h - create mode 100644 lib/DLLDriver/DllDriver.cpp - create mode 100644 lib/DLLDriver/LLVMBuild.txt - create mode 100644 lib/DLLDriver/Librarian.cpp - create mode 100644 lib/DLLDriver/ModuleDef.cpp - create mode 100644 lib/DLLDriver/Options.td - -diff --git a/include/llvm/DllDriver/DllDriver.h b/include/llvm/DllDriver/DllDriver.h -new file mode 100644 -index 00000000000..79fb7b76deb ---- /dev/null -+++ b/include/llvm/DllDriver/DllDriver.h -@@ -0,0 +1,24 @@ -+//===- llvm/DLLDriver/DLLDriver.h - dlltool.exe-compatible driver ---*- C++ -*-===// -+// -+// The LLVM Compiler Infrastructure -+// -+// This file is distributed under the University of Illinois Open Source -+// License. See LICENSE.TXT for details. -+// -+//===----------------------------------------------------------------------===// -+// -+// Defines an interface to a dlltool.exe-compatible driver that also understands -+// bitcode files. Used by llvm-dlltool and lld. -+// -+//===----------------------------------------------------------------------===// -+ -+#ifndef LLVM_DLLDRIVER_DLLDRIVER_H -+#define LLVM_DLLDRIVER_DLLDRIVER_H -+ -+namespace llvm { -+template class ArrayRef; -+ -+int dllToolDriverMain(ArrayRef ARgs); -+} -+ -+#endif -diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt -index 76549540ce0..bebb628e06d 100644 ---- a/lib/CMakeLists.txt -+++ b/lib/CMakeLists.txt -@@ -21,5 +21,6 @@ add_subdirectory(LineEditor) - add_subdirectory(ProfileData) - add_subdirectory(Fuzzer) - add_subdirectory(Passes) -+add_subdirectory(DLLDriver) - add_subdirectory(LibDriver) - add_subdirectory(XRay) -diff --git a/lib/DLLDriver/CMakeLists.txt b/lib/DLLDriver/CMakeLists.txt -new file mode 100644 -index 00000000000..91fb2f08de0 ---- /dev/null -+++ b/lib/DLLDriver/CMakeLists.txt -@@ -0,0 +1,11 @@ -+set(LLVM_TARGET_DEFINITIONS Options.td) -+tablegen(LLVM Options.inc -gen-opt-parser-defs) -+add_public_tablegen_target(DllOptionsTableGen) -+ -+add_llvm_library(LLVMDllDriver -+ DllDriver.cpp -+ ModuleDef.cpp -+ Librarian.cpp -+ ) -+ -+add_dependencies(LLVMDllDriver DllOptionsTableGen) -diff --git a/lib/DLLDriver/Config.h b/lib/DLLDriver/Config.h -new file mode 100644 -index 00000000000..d5a3d261de0 ---- /dev/null -+++ b/lib/DLLDriver/Config.h -@@ -0,0 +1,119 @@ -+#ifndef LLVM_COFF_CONFIG_H -+#define LLVM_COFF_CONFIG_H -+ -+#include "llvm/ADT/StringRef.h" -+#include "llvm/Object/COFF.h" -+#include -+#include -+#include -+#include -+ -+namespace llvm { -+ -+using llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN; -+using llvm::COFF::WindowsSubsystem; -+using llvm::StringRef; -+ -+// Short aliases. -+static const auto AMD64 = llvm::COFF::IMAGE_FILE_MACHINE_AMD64; -+static const auto ARMNT = llvm::COFF::IMAGE_FILE_MACHINE_ARMNT; -+static const auto I386 = llvm::COFF::IMAGE_FILE_MACHINE_I386; -+ -+struct Export { -+ StringRef Name; // N in N or E=N -+ StringRef ExtName; // E in E=N -+ -+ uint16_t Ordinal = 0; -+ bool Noname = false; -+ bool Data = false; -+ bool Private = false; -+ -+ // True if this /export option was in .drectves section. -+ bool Directives = false; -+ StringRef SymbolName; -+ StringRef ExportName; // Name in DLL -+ -+ bool isWeak() { -+ if(ExtName.size() && Name != ExtName) -+ return true; -+ return false; -+ } -+}; -+ -+// Global configuration. -+struct Configuration { -+ enum ManifestKind { SideBySide, Embed, No }; -+ bool is64() { return Machine == AMD64; } -+ std::vector Exports; -+ -+ llvm::COFF::MachineTypes Machine = IMAGE_FILE_MACHINE_UNKNOWN; -+ bool Verbose = false; -+ WindowsSubsystem Subsystem = llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN; -+ bool NoEntry = false; -+ std::string OutputFile; -+ bool DoGC = true; -+ bool DoICF = true; -+ bool Relocatable = true; -+ bool Force = false; -+ bool Debug = false; -+ bool WriteSymtab = true; -+ -+ std::set NoDefaultLibs; -+ bool NoDefaultLibAll = false; -+ -+ // True if we are creating a DLL. -+ bool DLL = false; -+ StringRef Implib; -+ std::set DelayLoads; -+ std::map DLLOrder; -+ -+ // Used for /opt:lldlto=N -+ unsigned LTOOptLevel = 2; -+ -+ // Used for /opt:lldltojobs=N -+ unsigned LTOJobs = 1; -+ -+ // Used for /merge:from=to (e.g. /merge:.rdata=.text) -+ std::map Merge; -+ -+ // Used for /section=.name,{DEKPRSW} to set section attributes. -+ std::map Section; -+ -+ // Options for manifest files. -+ ManifestKind Manifest = SideBySide; -+ int ManifestID = 1; -+ StringRef ManifestDependency; -+ bool ManifestUAC = true; -+ std::vector ManifestInput; -+ StringRef ManifestLevel = "'asInvoker'"; -+ StringRef ManifestUIAccess = "'false'"; -+ StringRef ManifestFile; -+ -+ // Used for /failifmismatch. -+ std::map MustMatch; -+ -+ // Used for /alternatename. -+ std::map AlternateNames; -+ -+ uint64_t ImageBase = -1; -+ uint64_t StackReserve = 1024 * 1024; -+ uint64_t StackCommit = 4096; -+ uint64_t HeapReserve = 1024 * 1024; -+ uint64_t HeapCommit = 4096; -+ uint32_t MajorImageVersion = 0; -+ uint32_t MinorImageVersion = 0; -+ uint32_t MajorOSVersion = 6; -+ uint32_t MinorOSVersion = 0; -+ bool DynamicBase = true; -+ bool AllowBind = true; -+ bool NxCompat = true; -+ bool AllowIsolation = true; -+ bool TerminalServerAware = true; -+ bool LargeAddressAware = false; -+ bool HighEntropyVA = false; -+}; -+ -+extern Configuration *Config; -+} // namespace llvm -+ -+#endif -\ No newline at end of file -diff --git a/lib/DLLDriver/DllDriver.cpp b/lib/DLLDriver/DllDriver.cpp -new file mode 100644 -index 00000000000..aa9adc84688 ---- /dev/null -+++ b/lib/DLLDriver/DllDriver.cpp -@@ -0,0 +1,185 @@ -+//===- DllDriver.cpp - dlltool.exe-compatible driver --------------------------===// -+// -+// The LLVM Compiler Infrastructure -+// -+// This file is distributed under the University of Illinois Open Source -+// License. See LICENSE.TXT for details. -+// -+//===----------------------------------------------------------------------===// -+// -+// Defines an interface to a dlltool.exe-compatible driver that also understands -+// bitcode files. -+// -+//===----------------------------------------------------------------------===// -+ -+#include "llvm/DllDriver/DllDriver.h" -+#include "llvm/ADT/STLExtras.h" -+#include "llvm/Object/ArchiveWriter.h" -+#include "llvm/Option/Arg.h" -+#include "llvm/Option/ArgList.h" -+#include "llvm/Object/COFF.h" -+#include "llvm/Option/Option.h" -+#include "llvm/Support/CommandLine.h" -+#include "llvm/Support/StringSaver.h" -+#include "llvm/Support/Path.h" -+#include "llvm/Support/Process.h" -+#include "llvm/Support/raw_ostream.h" -+ -+#include -+#include -+#include -+#include -+#include -+ -+#include "Config.h" -+ -+using namespace llvm; -+ -+namespace llvm{ -+Configuration *Config; -+void parseModuleDefs(MemoryBufferRef MB, StringSaver *Alloc); -+} -+ -+namespace { -+ -+enum { -+ OPT_INVALID = 0, -+#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11) OPT_##ID, -+#include "Options.inc" -+#undef OPTION -+}; -+ -+#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE; -+#include "Options.inc" -+#undef PREFIX -+ -+static const llvm::opt::OptTable::Info infoTable[] = { -+#define OPTION(X1, X2, ID, KIND, GROUP, ALIAS, X6, X7, X8, X9, X10) \ -+ { \ -+ X1, X2, X9, X10, OPT_##ID, llvm::opt::Option::KIND##Class, X8, X7, \ -+ OPT_##GROUP, OPT_##ALIAS, X6 \ -+ }, -+#include "Options.inc" -+#undef OPTION -+}; -+ -+class DllOptTable : public llvm::opt::OptTable { -+public: -+ DllOptTable() : OptTable(infoTable, false) {} -+}; -+ -+} -+ -+std::vector> OwningMBs; -+ -+// Opens a file. Path has to be resolved already. -+// Newly created memory buffers are owned by this driver. -+MemoryBufferRef openFile(StringRef Path) { -+ llvm::ErrorOr> MB = -+ MemoryBuffer::getFile(Path); -+ -+ if (std::error_code EC = MB.getError()) -+ llvm::errs() << "fail openFile: " << EC.message() << "\n"; -+ -+ MemoryBufferRef MBRef = MB.get()->getMemBufferRef(); -+ OwningMBs.push_back(std::move(MB.get())); // take ownership -+ return MBRef; -+} -+ -+#include "llvm/Support/raw_ostream.h" -+ -+#include "llvm/ADT/StringSwitch.h" -+#include "llvm/Option/Arg.h" -+#include "llvm/Option/ArgList.h" -+#include "llvm/Support/StringSaver.h" -+ -+static llvm::COFF::MachineTypes getEmulation(StringRef S) { -+ return StringSwitch(S) -+ .Case("x86", llvm::COFF::IMAGE_FILE_MACHINE_I386) -+ .Case("x86_64", llvm::COFF::IMAGE_FILE_MACHINE_AMD64) -+ .Case("arm", llvm::COFF::IMAGE_FILE_MACHINE_ARMNT) -+ .Default(llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN); -+} -+ -+static std::string getImplibPath() { -+ if (!Config->Implib.empty()) -+ return Config->Implib; -+ SmallString<128> Out = StringRef(Config->OutputFile); -+ sys::path::replace_extension(Out, ".lib"); -+ return Out.str(); -+} -+ -+int writeImportLibrary(std::string &Path); -+ -+int llvm::dllToolDriverMain(llvm::ArrayRef ArgsArr) { -+ SmallVector NewArgs(ArgsArr.begin(), ArgsArr.end()); -+ BumpPtrAllocator Alloc; -+ StringSaver Saver(Alloc); -+ cl::ExpandResponseFiles(Saver, cl::TokenizeWindowsCommandLine, NewArgs); -+ ArgsArr = NewArgs; -+ -+ Configuration C; -+ Config = &C; -+ -+ DllOptTable Table; -+ unsigned MissingIndex; -+ unsigned MissingCount; -+ llvm::opt::InputArgList Args = -+ Table.ParseArgs(ArgsArr.slice(1), MissingIndex, MissingCount); -+ if (MissingCount) { -+ llvm::errs() << "missing arg value for \"" -+ << Args.getArgString(MissingIndex) << "\", expected " -+ << MissingCount -+ << (MissingCount == 1 ? " argument.\n" : " arguments.\n"); -+ return 1; -+ } -+ for (auto *Arg : Args.filtered(OPT_UNKNOWN)) -+ llvm::errs() << "ignoring unknown argument: " << Arg->getSpelling() << "\n"; -+ -+ if (Args.filtered_begin(OPT_INPUT) == Args.filtered_end()) { -+ llvm::outs() << "NO ARGS" << "\n"; -+ return 0; -+ } -+ -+ if (Args.filtered_begin(OPT_emu) == Args.filtered_end()) { -+ llvm::outs() << "Need to set an emulation mode" << "\n"; -+ return -1; -+ } -+ -+ std::string Path; -+ MemoryBufferRef MB; -+ int i=0; -+ for (auto *Arg : Args.filtered(OPT_INPUT)) { -+ if(i==0) -+ MB = openFile(Arg->getValue()); -+ if(i==1) -+ Path = Arg->getValue(); -+ i++; -+ } -+ -+ if (auto *Arg = Args.getLastArg(OPT_out)) -+ Path = Arg->getValue(); -+ -+ if(!Path.length()) -+ Path = getImplibPath(); -+ -+ llvm::outs() << Path << "\n"; -+ -+ Config->Machine = IMAGE_FILE_MACHINE_UNKNOWN; -+ if (auto *Arg = Args.getLastArg(OPT_emu)) -+ Config->Machine = getEmulation(Arg->getValue()); -+ -+ if(Config->Machine == IMAGE_FILE_MACHINE_UNKNOWN) { -+ llvm::outs() << "Need to set a valid emulation mode" << "\n"; -+ return -2; -+ } -+ -+ llvm::parseModuleDefs(MB, &Saver); -+ -+ // has to happen after the parser -+ if (auto *Arg = Args.getLastArg(OPT_dll)) -+ Config->OutputFile = Arg->getValue(); -+ -+ return writeImportLibrary(Path); -+ -+} -diff --git a/lib/DLLDriver/LLVMBuild.txt b/lib/DLLDriver/LLVMBuild.txt -new file mode 100644 -index 00000000000..8e2b1d651f2 ---- /dev/null -+++ b/lib/DLLDriver/LLVMBuild.txt -@@ -0,0 +1,22 @@ -+;===- ./lib/LibDriver/LLVMBuild.txt ----------------------------*- Conf -*--===; -+; -+; The LLVM Compiler Infrastructure -+; -+; This file is distributed under the University of Illinois Open Source -+; License. See LICENSE.TXT for details. -+; -+;===------------------------------------------------------------------------===; -+; -+; This is an LLVMBuild description file for the components in this subdirectory. -+; -+; For more information on the LLVMBuild system, please see: -+; -+; http://llvm.org/docs/LLVMBuild.html -+; -+;===------------------------------------------------------------------------===; -+ -+[component_0] -+type = Library -+name = DllDriver -+parent = Libraries -+required_libraries = Object Option Support -diff --git a/lib/DLLDriver/Librarian.cpp b/lib/DLLDriver/Librarian.cpp -new file mode 100644 -index 00000000000..486733e6c5c ---- /dev/null -+++ b/lib/DLLDriver/Librarian.cpp -@@ -0,0 +1,603 @@ -+//===- Librarian.cpp ------------------------------------------------------===// -+// -+// The LLVM Linker -+// -+// This file is distributed under the University of Illinois Open Source -+// License. See LICENSE.TXT for details. -+// -+//===----------------------------------------------------------------------===// -+// -+// This file contains functions for the Librarian. The librarian creates and -+// manages libraries of the Common Object File Format (COFF) object files. It -+// primarily is used for creating static libraries and import libraries. -+// -+//===----------------------------------------------------------------------===// -+ -+#include "llvm/Object/Archive.h" -+#include "llvm/Object/ArchiveWriter.h" -+#include "llvm/Object/COFF.h" -+#include "llvm/Support/Error.h" -+#include "llvm/Support/Path.h" -+ -+#include -+#include -+#include -+#include -+#include -+ -+#include "Config.h" -+ -+using namespace llvm; -+using namespace llvm::COFF; -+using namespace llvm::object; -+ -+static bool is32bit() { -+ switch (Config->Machine) { -+ default: -+ llvm_unreachable("unsupported machine"); -+ case IMAGE_FILE_MACHINE_AMD64: -+ return false; -+ case IMAGE_FILE_MACHINE_ARMNT: -+ case IMAGE_FILE_MACHINE_I386: -+ return true; -+ } -+} -+ -+static uint16_t getImgRelRelocation() { -+ switch (Config->Machine) { -+ default: -+ llvm_unreachable("unsupported machine"); -+ case IMAGE_FILE_MACHINE_AMD64: -+ return IMAGE_REL_AMD64_ADDR32NB; -+ case IMAGE_FILE_MACHINE_ARMNT: -+ return IMAGE_REL_ARM_ADDR32NB; -+ case IMAGE_FILE_MACHINE_I386: -+ return IMAGE_REL_I386_DIR32NB; -+ } -+} -+ -+template static void append(std::vector &B, const T &Data) { -+ size_t S = B.size(); -+ B.resize(S + sizeof(T)); -+ memcpy(&B[S], &Data, sizeof(T)); -+} -+ -+static void writeStringTable(std::vector &B, -+ ArrayRef Strings) { -+ // The COFF string table consists of a 4-byte value which is the size of the -+ // table, including the length field itself. This value is followed by the -+ // string content itself, which is an array of null-terminated C-style -+ // strings. The termination is important as they are referenced to by offset -+ // by the symbol entity in the file format. -+ -+ std::vector::size_type Pos = B.size(); -+ std::vector::size_type Offset = B.size(); -+ -+ // Skip over the length field, we will fill it in later as we will have -+ // computed the length while emitting the string content itself. -+ Pos += sizeof(uint32_t); -+ -+ for (const auto &S : Strings) { -+ B.resize(Pos + S.length() + 1); -+ strcpy(reinterpret_cast(&B[Pos]), S.c_str()); -+ Pos += S.length() + 1; -+ } -+ -+ // Backfill the length of the table now that it has been computed. -+ support::ulittle32_t Length(B.size() - Offset); -+ memcpy(&B[Offset], &Length, sizeof(Length)); -+} -+ -+static ImportNameType getNameType(StringRef Sym, StringRef ExtName) { -+ if (Sym != ExtName) -+ return IMPORT_NAME_UNDECORATE; -+ if (Config->Machine == I386 && Sym.startswith("_")) -+ return IMPORT_NAME_NOPREFIX; -+ return IMPORT_NAME; -+} -+ -+static const std::string NullImportDescriptorSymbolName = -+ "__NULL_IMPORT_DESCRIPTOR"; -+ -+namespace { -+// This class constructs various small object files necessary to support linking -+// symbols imported from a DLL. The contents are pretty strictly defined and -+// nearly entirely static. The details of the structures files are defined in -+// WINNT.h and the PE/COFF specification. -+class ObjectFactory { -+ using u16 = support::ulittle16_t; -+ using u32 = support::ulittle32_t; -+ -+ BumpPtrAllocator Alloc; -+ StringRef DLLName; -+ StringRef Library; -+ std::string ImportDescriptorSymbolName; -+ std::string NullThunkSymbolName; -+ -+public: -+ ObjectFactory(StringRef S) -+ : DLLName(S), Library(S.drop_back(4)), -+ ImportDescriptorSymbolName(("__IMPORT_DESCRIPTOR_" + Library).str()), -+ NullThunkSymbolName(("\x7f" + Library + "_NULL_THUNK_DATA").str()) {} -+ -+ // Creates an Import Descriptor. This is a small object file which contains a -+ // reference to the terminators and contains the library name (entry) for the -+ // import name table. It will force the linker to construct the necessary -+ // structure to import symbols from the DLL. -+ NewArchiveMember createImportDescriptor(std::vector &Buffer); -+ -+ // Creates a NULL import descriptor. This is a small object file whcih -+ // contains a NULL import descriptor. It is used to terminate the imports -+ // from a specific DLL. -+ NewArchiveMember createNullImportDescriptor(std::vector &Buffer); -+ -+ // Create a NULL Thunk Entry. This is a small object file which contains a -+ // NULL Import Address Table entry and a NULL Import Lookup Table Entry. It -+ // is used to terminate the IAT and ILT. -+ NewArchiveMember createNullThunk(std::vector &Buffer); -+ -+ // Create a short import file which is described in PE/COFF spec 7. Import -+ // Library Format. -+ NewArchiveMember createShortImport(StringRef Sym, uint16_t Ordinal, -+ ImportNameType NameType, bool isData); -+ -+ // Create a weak external file which is described in PE/COFF Aux Format 3. -+ NewArchiveMember createWeakExternal(std::vector &Buffer, StringRef Sym, StringRef Weak, bool imp); -+}; -+} -+ -+NewArchiveMember -+ObjectFactory::createImportDescriptor(std::vector &Buffer) { -+ static const uint32_t NumberOfSections = 2; -+ static const uint32_t NumberOfSymbols = 8; -+ static const uint32_t NumberOfRelocations = 3; -+ -+ // COFF Header -+ coff_file_header Header{ -+ u16(Config->Machine), u16(NumberOfSections), u32(0), -+ u32(sizeof(Header) + (NumberOfSections * sizeof(coff_section)) + -+ // .idata$2 -+ sizeof(coff_import_directory_table_entry) + -+ NumberOfRelocations * sizeof(coff_relocation) + -+ // .idata$6 -+ (DLLName.size() + 1)), -+ u32(NumberOfSymbols), u16(0), -+ u16(is32bit() ? IMAGE_FILE_32BIT_MACHINE : 0), -+ }; -+ append(Buffer, Header); -+ -+ // Section Header Table -+ static const coff_section SectionTable[NumberOfSections] = { -+ {{'.', 'i', 'd', 'a', 't', 'a', '$', '2'}, -+ u32(0), -+ u32(0), -+ u32(sizeof(coff_import_directory_table_entry)), -+ u32(sizeof(coff_file_header) + NumberOfSections * sizeof(coff_section)), -+ u32(sizeof(coff_file_header) + NumberOfSections * sizeof(coff_section) + -+ sizeof(coff_import_directory_table_entry)), -+ u32(0), -+ u16(NumberOfRelocations), -+ u16(0), -+ u32(IMAGE_SCN_ALIGN_4BYTES | IMAGE_SCN_CNT_INITIALIZED_DATA | -+ IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE)}, -+ {{'.', 'i', 'd', 'a', 't', 'a', '$', '6'}, -+ u32(0), -+ u32(0), -+ u32(DLLName.size() + 1), -+ u32(sizeof(coff_file_header) + NumberOfSections * sizeof(coff_section) + -+ sizeof(coff_import_directory_table_entry) + -+ NumberOfRelocations * sizeof(coff_relocation)), -+ u32(sizeof(coff_file_header) + NumberOfSections * sizeof(coff_section) + -+ sizeof(coff_import_directory_table_entry)), -+ u32(0), -+ u16(0), -+ u16(0), -+ u32(IMAGE_SCN_ALIGN_2BYTES | IMAGE_SCN_CNT_INITIALIZED_DATA | -+ IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE)}, -+ }; -+ append(Buffer, SectionTable); -+ -+ // .idata$2 -+ static const coff_import_directory_table_entry ImportDescriptor{ -+ u32(0), u32(0), u32(0), u32(0), u32(0), -+ }; -+ append(Buffer, ImportDescriptor); -+ -+ static const coff_relocation RelocationTable[NumberOfRelocations] = { -+ {u32(offsetof(coff_import_directory_table_entry, NameRVA)), u32(3), -+ u16(getImgRelRelocation())}, -+ {u32(offsetof(coff_import_directory_table_entry, ImportLookupTableRVA)), -+ u32(4), u16(getImgRelRelocation())}, -+ {u32(offsetof(coff_import_directory_table_entry, ImportAddressTableRVA)), -+ u32(5), u16(getImgRelRelocation())}, -+ }; -+ append(Buffer, RelocationTable); -+ -+ // .idata$6 -+ auto S = Buffer.size(); -+ Buffer.resize(S + DLLName.size() + 1); -+ memcpy(&Buffer[S], DLLName.data(), DLLName.size()); -+ Buffer[S + DLLName.size()] = '\0'; -+ -+ // Symbol Table -+ coff_symbol16 SymbolTable[NumberOfSymbols] = { -+ {{{'@', 'c', 'o', 'm', 'p', '.', 'i', 'd'}}, -+ u32(0), -+ u16(0xFFFF), -+ u16(0), -+ IMAGE_SYM_CLASS_STATIC, -+ 0}, -+ {{{0, 0, 0, 0, 0, 0, 0, 0}}, -+ u32(0), -+ u16(2), -+ u16(0), -+ IMAGE_SYM_CLASS_EXTERNAL, -+ 0}, -+ {{{'.', 'i', 'd', 'a', 't', 'a', '$', '2'}}, -+ u32(0), -+ u16(2), -+ u16(0), -+ IMAGE_SYM_CLASS_SECTION, -+ 0}, -+ {{{'.', 'i', 'd', 'a', 't', 'a', '$', '6'}}, -+ u32(0), -+ u16(3), -+ u16(0), -+ IMAGE_SYM_CLASS_STATIC, -+ 0}, -+ {{{'.', 'i', 'd', 'a', 't', 'a', '$', '4'}}, -+ u32(0), -+ u16(0), -+ u16(0), -+ IMAGE_SYM_CLASS_SECTION, -+ 0}, -+ {{{'.', 'i', 'd', 'a', 't', 'a', '$', '5'}}, -+ u32(0), -+ u16(0), -+ u16(0), -+ IMAGE_SYM_CLASS_SECTION, -+ 0}, -+ {{{0, 0, 0, 0, 0, 0, 0, 0}}, -+ u32(0), -+ u16(2), -+ u16(0), -+ IMAGE_SYM_CLASS_NULL, -+ 0}, -+ {{{0, 0, 0, 0, 0, 0, 0, 0}}, -+ u32(0), -+ u16(2), -+ u16(0), -+ IMAGE_SYM_CLASS_NULL, -+ 0}, -+ }; -+ reinterpret_cast(SymbolTable[1].Name).Offset = -+ sizeof(uint32_t); -+ reinterpret_cast(SymbolTable[6].Name).Offset = -+ sizeof(uint32_t) + ImportDescriptorSymbolName.length() + 1; -+ reinterpret_cast(SymbolTable[7].Name).Offset = -+ sizeof(uint32_t) + ImportDescriptorSymbolName.length() + 1 + -+ NullImportDescriptorSymbolName.length() + 1; -+ append(Buffer, SymbolTable); -+ -+ // String Table -+ writeStringTable(Buffer, -+ {ImportDescriptorSymbolName, NullImportDescriptorSymbolName, -+ NullThunkSymbolName}); -+ -+ StringRef F{reinterpret_cast(Buffer.data()), Buffer.size()}; -+ return {MemoryBufferRef(F, DLLName)}; -+} -+ -+NewArchiveMember -+ObjectFactory::createNullImportDescriptor(std::vector &Buffer) { -+ static const uint32_t NumberOfSections = 1; -+ static const uint32_t NumberOfSymbols = 2; -+ -+ // COFF Header -+ coff_file_header Header{ -+ u16(Config->Machine), u16(NumberOfSections), u32(0), -+ u32(sizeof(Header) + (NumberOfSections * sizeof(coff_section)) + -+ // .idata$3 -+ sizeof(coff_import_directory_table_entry)), -+ u32(NumberOfSymbols), u16(0), -+ u16(is32bit() ? IMAGE_FILE_32BIT_MACHINE : 0), -+ }; -+ append(Buffer, Header); -+ -+ // Section Header Table -+ static const coff_section SectionTable[NumberOfSections] = { -+ {{'.', 'i', 'd', 'a', 't', 'a', '$', '3'}, -+ u32(0), -+ u32(0), -+ u32(sizeof(coff_import_directory_table_entry)), -+ u32(sizeof(coff_file_header) + -+ (NumberOfSections * sizeof(coff_section))), -+ u32(0), -+ u32(0), -+ u16(0), -+ u16(0), -+ u32(IMAGE_SCN_ALIGN_4BYTES | IMAGE_SCN_CNT_INITIALIZED_DATA | -+ IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE)}, -+ }; -+ append(Buffer, SectionTable); -+ -+ // .idata$3 -+ static const coff_import_directory_table_entry ImportDescriptor{ -+ u32(0), u32(0), u32(0), u32(0), u32(0), -+ }; -+ append(Buffer, ImportDescriptor); -+ -+ // Symbol Table -+ coff_symbol16 SymbolTable[NumberOfSymbols] = { -+ {{{'@', 'c', 'o', 'm', 'p', '.', 'i', 'd'}}, -+ u32(0), -+ u16(0xFFFF), -+ u16(0), -+ IMAGE_SYM_CLASS_STATIC, -+ 0}, -+ {{{0, 0, 0, 0, 0, 0, 0, 0}}, -+ u32(0), -+ u16(2), -+ u16(0), -+ IMAGE_SYM_CLASS_EXTERNAL, -+ 0}, -+ }; -+ reinterpret_cast(SymbolTable[1].Name).Offset = -+ sizeof(uint32_t); -+ append(Buffer, SymbolTable); -+ -+ // String Table -+ writeStringTable(Buffer, {NullImportDescriptorSymbolName}); -+ -+ StringRef F{reinterpret_cast(Buffer.data()), Buffer.size()}; -+ return {MemoryBufferRef(F, DLLName)}; -+} -+ -+NewArchiveMember ObjectFactory::createNullThunk(std::vector &Buffer) { -+ static const uint32_t NumberOfSections = 2; -+ static const uint32_t NumberOfSymbols = 2; -+ -+ // COFF Header -+ coff_file_header Header{ -+ u16(Config->Machine), u16(NumberOfSections), u32(0), -+ u32(sizeof(Header) + (NumberOfSections * sizeof(coff_section)) + -+ // .idata$5 -+ sizeof(export_address_table_entry) + -+ // .idata$4 -+ sizeof(export_address_table_entry)), -+ u32(NumberOfSymbols), u16(0), -+ u16(is32bit() ? IMAGE_FILE_32BIT_MACHINE : 0), -+ }; -+ append(Buffer, Header); -+ -+ // Section Header Table -+ static const coff_section SectionTable[NumberOfSections] = { -+ {{'.', 'i', 'd', 'a', 't', 'a', '$', '5'}, -+ u32(0), -+ u32(0), -+ u32(sizeof(export_address_table_entry)), -+ u32(sizeof(coff_file_header) + NumberOfSections * sizeof(coff_section)), -+ u32(0), -+ u32(0), -+ u16(0), -+ u16(0), -+ u32(IMAGE_SCN_ALIGN_4BYTES | IMAGE_SCN_CNT_INITIALIZED_DATA | -+ IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE)}, -+ {{'.', 'i', 'd', 'a', 't', 'a', '$', '4'}, -+ u32(0), -+ u32(0), -+ u32(sizeof(export_address_table_entry)), -+ u32(sizeof(coff_file_header) + NumberOfSections * sizeof(coff_section) + -+ sizeof(export_address_table_entry)), -+ u32(0), -+ u32(0), -+ u16(0), -+ u16(0), -+ u32(IMAGE_SCN_ALIGN_4BYTES | IMAGE_SCN_CNT_INITIALIZED_DATA | -+ IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE)}, -+ }; -+ append(Buffer, SectionTable); -+ -+ // .idata$5 -+ static const export_address_table_entry ILT{u32(0)}; -+ append(Buffer, ILT); -+ -+ // .idata$4 -+ static const export_address_table_entry IAT{u32(0)}; -+ append(Buffer, IAT); -+ -+ // Symbol Table -+ coff_symbol16 SymbolTable[NumberOfSymbols] = { -+ {{{'@', 'c', 'o', 'm', 'p', '.', 'i', 'd'}}, -+ u32(0), -+ u16(0xFFFF), -+ u16(0), -+ IMAGE_SYM_CLASS_STATIC, -+ 0}, -+ {{{0, 0, 0, 0, 0, 0, 0, 0}}, -+ u32(0), -+ u16(2), -+ u16(0), -+ IMAGE_SYM_CLASS_EXTERNAL, -+ 0}, -+ }; -+ reinterpret_cast(SymbolTable[1].Name).Offset = -+ sizeof(uint32_t); -+ append(Buffer, SymbolTable); -+ -+ // String Table -+ writeStringTable(Buffer, {NullThunkSymbolName}); -+ -+ StringRef F{reinterpret_cast(Buffer.data()), Buffer.size()}; -+ return {MemoryBufferRef{F, DLLName}}; -+} -+ -+NewArchiveMember ObjectFactory::createShortImport(StringRef Sym, -+ uint16_t Ordinal, -+ ImportNameType NameType, -+ bool isData) { -+ size_t ImpSize = DLLName.size() + Sym.size() + 2; // +2 for NULs -+ size_t Size = sizeof(coff_import_header) + ImpSize; -+ char *Buf = Alloc.Allocate(Size); -+ memset(Buf, 0, Size); -+ char *P = Buf; -+ -+ // Write short import library. -+ auto *Imp = reinterpret_cast(P); -+ P += sizeof(*Imp); -+ Imp->Sig2 = 0xFFFF; -+ Imp->Machine = Config->Machine; -+ Imp->SizeOfData = ImpSize; -+ if (Ordinal > 0) -+ Imp->OrdinalHint = Ordinal; -+ Imp->TypeInfo = (isData ? IMPORT_DATA : IMPORT_CODE); -+ -+ if(Config->Machine == IMAGE_FILE_MACHINE_I386) { -+ if(Sym.find('@') != StringRef::npos) -+ Imp->TypeInfo |= IMPORT_NAME_UNDECORATE << 2; -+ else -+ Imp->TypeInfo |= IMPORT_NAME_NOPREFIX << 2; -+ } -+ else -+ Imp->TypeInfo |= IMPORT_NAME << 2; -+ -+ // Write symbol name and DLL name. -+ memcpy(P, Sym.data(), Sym.size()); -+ P += Sym.size() + 1; -+ memcpy(P, DLLName.data(), DLLName.size()); -+ -+ return {MemoryBufferRef(StringRef(Buf, Size), DLLName)}; -+} -+ -+NewArchiveMember ObjectFactory::createWeakExternal(std::vector &Buffer, -+ StringRef Sym, StringRef Weak, bool imp) { -+ static const uint32_t NumberOfSections = 1; -+ static const uint32_t NumberOfSymbols = 5; -+ -+ // COFF Header -+ coff_file_header Header{ -+ u16(0), u16(NumberOfSections), u32(0), -+ u32(sizeof(Header) + (NumberOfSections * sizeof(coff_section))), -+ u32(NumberOfSymbols), u16(0), -+ u16(0), -+ }; -+ append(Buffer, Header); -+ -+ // Section Header Table -+ static const coff_section SectionTable[NumberOfSections] = { -+ {{'.', 'd', 'r', 'e', 'c', 't', 'v', 'e'}, -+ u32(0), -+ u32(0), -+ u32(0), -+ u32(0), -+ u32(0), -+ u32(0), -+ u16(0), -+ u16(0), -+ u32(IMAGE_SCN_LNK_INFO | IMAGE_SCN_LNK_REMOVE)} -+ }; -+ append(Buffer, SectionTable); -+ -+ // Symbol Table -+ coff_symbol16 SymbolTable[NumberOfSymbols] = { -+ {{{'@', 'c', 'o', 'm', 'p', '.', 'i', 'd'}}, -+ u32(0), -+ u16(0xFFFF), -+ u16(0), -+ IMAGE_SYM_CLASS_STATIC, -+ 0}, -+ {{{'@', 'f', 'e', 'a', 't', '.', '0', '0'}}, -+ u32(0), -+ u16(0xFFFF), -+ u16(0), -+ IMAGE_SYM_CLASS_STATIC, -+ 0}, -+ {{{0, 0, 0, 0, 0, 0, 0, 0}}, -+ u32(0), -+ u16(0), -+ u16(0), -+ IMAGE_SYM_CLASS_EXTERNAL, -+ 0}, -+ {{{0, 0, 0, 0, 0, 0, 0, 0}}, -+ u32(0), -+ u16(0), -+ u16(0), -+ IMAGE_SYM_CLASS_WEAK_EXTERNAL, -+ 1}, -+ {{{2, 0, 0, 0, 3, 0, 0, 0}}, -+ u32(0), -+ u16(0), -+ u16(0), -+ uint8_t(0), -+ 0}, -+ }; -+ reinterpret_cast(SymbolTable[2].Name).Offset = -+ sizeof(uint32_t); -+ -+ if(imp) -+ reinterpret_cast(SymbolTable[3].Name).Offset = -+ sizeof(uint32_t) + Sym.size() + 1 + 6; //__imp_ -+ else -+ reinterpret_cast(SymbolTable[3].Name).Offset = -+ sizeof(uint32_t) + Sym.size() + 1;// + 6; //__imp_ -+ -+ append(Buffer, SymbolTable); -+ -+ // String Table -+ if(imp) -+ writeStringTable(Buffer, {std::string("__imp_").append(Sym), std::string("__imp_").append(Weak)}); -+ else -+ writeStringTable(Buffer, {Sym, Weak}); -+ -+ StringRef F{reinterpret_cast(Buffer.data()), Buffer.size()}; -+ return {MemoryBufferRef{F, DLLName}}; -+ -+} -+ -+// Creates an import library for a DLL. In this function, we first -+// create an empty import library using lib.exe and then adds short -+// import files to that file. -+int writeImportLibrary(std::string &Path) { -+ -+ std::vector Members; -+ -+ ObjectFactory OF(llvm::sys::path::filename(Config->OutputFile)); -+ -+ std::vector ImportDescriptor; -+ Members.push_back(OF.createImportDescriptor(ImportDescriptor)); -+ -+ std::vector NullImportDescriptor; -+ Members.push_back(OF.createNullImportDescriptor(NullImportDescriptor)); -+ -+ std::vector NullThunk; -+ Members.push_back(OF.createNullThunk(NullThunk)); -+ -+ for (Export &E : Config->Exports) { -+ if (E.Private) -+ continue; -+ -+ if (E.isWeak()) { -+ std::vector *WeakBuffer1 = new std::vector(); -+ std::vector *WeakBuffer2 = new std::vector(); -+ Members.push_back(OF.createWeakExternal(*WeakBuffer1, E.Name, E.ExtName, false)); -+ Members.push_back(OF.createWeakExternal(*WeakBuffer2, E.Name, E.ExtName, true)); -+ continue; -+ } -+ -+ if(E.ExtName.size() == 0) { -+ E.ExtName = E.Name; -+ } -+ -+ ImportNameType Type = getNameType(E.SymbolName, E.Name); -+ Members.push_back(OF.createShortImport(E.Name, E.Ordinal, Type, E.Data)); -+ } -+ -+ std::pair Result = -+ writeArchive(Path, Members, /*WriteSymtab*/ true, object::Archive::K_GNU, -+ /*Deterministic*/ true, /*Thin*/ false); -+ -+ if (Result.second) -+ return -1; -+ -+ return 0; -+} -diff --git a/lib/DLLDriver/ModuleDef.cpp b/lib/DLLDriver/ModuleDef.cpp -new file mode 100644 -index 00000000000..428049abc5d ---- /dev/null -+++ b/lib/DLLDriver/ModuleDef.cpp -@@ -0,0 +1,321 @@ -+//===- COFF/ModuleDef.cpp -------------------------------------------------===// -+// -+// The LLVM Linker -+// -+// This file is distributed under the University of Illinois Open Source -+// License. See LICENSE.TXT for details. -+// -+//===----------------------------------------------------------------------===// -+// -+// Windows-specific. -+// A parser for the module-definition file (.def file). -+// Parsed results are directly written to Config global variable. -+// -+// The format of module-definition files are described in this document: -+// https://msdn.microsoft.com/en-us/library/28d6s79h.aspx -+// -+//===----------------------------------------------------------------------===// -+ -+#include "Config.h" -+//#include "Error.h" -+#include "llvm/ADT/StringRef.h" -+#include "llvm/ADT/StringSwitch.h" -+#include "llvm/Object/COFF.h" -+#include "llvm/Support/StringSaver.h" -+#include "llvm/Support/raw_ostream.h" -+ -+#include -+#include -+#include -+#include -+#include -+#include -+ -+using llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN; -+using llvm::COFF::WindowsSubsystem; -+using llvm::StringRef; -+ -+using namespace llvm::COFF; -+using namespace llvm::object; -+using namespace llvm; -+ -+#include "llvm/Support/Error.h" -+ -+void fatal(const Twine &Msg) { -+ llvm::errs() << Msg << "\n"; -+ exit(1); -+} -+ -+void fatal(std::error_code EC, const Twine &Msg) { -+ fatal(Msg + ": " + EC.message()); -+} -+ -+void fatal(llvm::Error &Err, const Twine &Msg) { -+ fatal(errorToErrorCode(std::move(Err)), Msg); -+} -+ -+namespace llvm { -+namespace { -+ -+enum Kind { -+ Unknown, -+ Eof, -+ Identifier, -+ Comma, -+ Equal, -+ KwBase, -+ KwData, -+ KwExports, -+ KwHeapsize, -+ KwLibrary, -+ KwName, -+ KwNoname, -+ KwPrivate, -+ KwStacksize, -+ KwVersion, -+}; -+ -+struct Token { -+ explicit Token(Kind T = Unknown, StringRef S = "") : K(T), Value(S) {} -+ Kind K; -+ StringRef Value; -+}; -+ -+static bool isDecorated(StringRef Sym) { -+ // Disable Sym.startswith("_") because mingw-w64 is weird about this -+ return Sym.startswith("@") || Sym.startswith("?"); -+} -+ -+class Lexer { -+public: -+ explicit Lexer(StringRef S) : Buf(S) {} -+ -+ Token lex() { -+ Buf = Buf.trim(); -+ if (Buf.empty()) -+ return Token(Eof); -+ -+ switch (Buf[0]) { -+ case '\0': -+ return Token(Eof); -+ case ';': { -+ size_t End = Buf.find('\n'); -+ Buf = (End == Buf.npos) ? "" : Buf.drop_front(End); -+ return lex(); -+ } -+ case '=': -+ // TODO: Fix HACK TO WORK AROUND "==" in mingw-w64 -+ if(Buf[1] == '=') -+ Buf = Buf.drop_front(); -+ Buf = Buf.drop_front(); -+ return Token(Equal, "="); -+ case ',': -+ Buf = Buf.drop_front(); -+ return Token(Comma, ","); -+ case '"': { -+ StringRef S; -+ std::tie(S, Buf) = Buf.substr(1).split('"'); -+ return Token(Identifier, S); -+ } -+ default: { -+ size_t End = Buf.find_first_of("=,\r\n \t\v"); -+ StringRef Word = Buf.substr(0, End); -+ Kind K = llvm::StringSwitch(Word) -+ .Case("BASE", KwBase) -+ .Case("DATA", KwData) -+ .Case("EXPORTS", KwExports) -+ .Case("HEAPSIZE", KwHeapsize) -+ .Case("LIBRARY", KwLibrary) -+ .Case("NAME", KwName) -+ .Case("NONAME", KwNoname) -+ .Case("PRIVATE", KwPrivate) -+ .Case("STACKSIZE", KwStacksize) -+ .Case("VERSION", KwVersion) -+ .Default(Identifier); -+ Buf = (End == Buf.npos) ? "" : Buf.drop_front(End); -+ return Token(K, Word); -+ } -+ } -+ } -+ -+private: -+ StringRef Buf; -+}; -+ -+class Parser { -+public: -+ explicit Parser(StringRef S, StringSaver *A) : Lex(S), Alloc(A) {} -+ -+ void parse() { -+ do { -+ parseOne(); -+ } while (Tok.K != Eof); -+ } -+ -+private: -+ void read() { -+ if (Stack.empty()) { -+ Tok = Lex.lex(); -+ return; -+ } -+ Tok = Stack.back(); -+ Stack.pop_back(); -+ } -+ -+ void readAsInt(uint64_t *I) { -+ read(); -+ if (Tok.K != Identifier || Tok.Value.getAsInteger(10, *I)) -+ fatal("integer expected"); -+ } -+ -+ void expect(Kind Expected, StringRef Msg) { -+ read(); -+ if (Tok.K != Expected) -+ fatal(Msg); -+ } -+ -+ void unget() { Stack.push_back(Tok); } -+ -+ void parseOne() { -+ read(); -+ switch (Tok.K) { -+ case Eof: -+ return; -+ case KwExports: -+ for (;;) { -+ read(); -+ if (Tok.K != Identifier) { -+ unget(); -+ return; -+ } -+ parseExport(); -+ } -+ case KwHeapsize: -+ parseNumbers(&Config->HeapReserve, &Config->HeapCommit); -+ return; -+ case KwLibrary: -+ parseName(&Config->OutputFile, &Config->ImageBase); -+ if (!StringRef(Config->OutputFile).endswith_lower(".dll")) -+ Config->OutputFile += ".dll"; -+ return; -+ case KwStacksize: -+ parseNumbers(&Config->StackReserve, &Config->StackCommit); -+ return; -+ case KwName: -+ parseName(&Config->OutputFile, &Config->ImageBase); -+ return; -+ case KwVersion: -+ parseVersion(&Config->MajorImageVersion, &Config->MinorImageVersion); -+ return; -+ default: -+ fatal("unknown directive: " + Tok.Value); -+ } -+ } -+ -+ void parseExport() { -+ Export E; -+ E.Name = Tok.Value; -+ read(); -+ if (Tok.K == Equal) { -+ read(); -+ if (Tok.K != Identifier) -+ fatal("identifier expected, but got " + Tok.Value); -+ E.ExtName = E.Name; -+ E.Name = Tok.Value; -+ } else { -+ unget(); -+ } -+ -+ if (Config->Machine == I386) { -+ if (!isDecorated(E.Name)) -+ E.Name = Alloc->save("_" + E.Name); -+ if (!E.ExtName.empty() && !isDecorated(E.ExtName)) -+ E.ExtName = Alloc->save("_" + E.ExtName); -+ } -+ -+ for (;;) { -+ read(); -+ if (Tok.K == Identifier && Tok.Value[0] == '@') { -+ Tok.Value.drop_front().getAsInteger(10, E.Ordinal); -+ read(); -+ if (Tok.K == KwNoname) { -+ E.Noname = true; -+ } else { -+ unget(); -+ } -+ continue; -+ } -+ if (Tok.K == KwData) { -+ E.Data = true; -+ continue; -+ } -+ if (Tok.K == KwPrivate) { -+ E.Private = true; -+ continue; -+ } -+ unget(); -+ Config->Exports.push_back(E); -+ return; -+ } -+ } -+ -+ // HEAPSIZE/STACKSIZE reserve[,commit] -+ void parseNumbers(uint64_t *Reserve, uint64_t *Commit) { -+ readAsInt(Reserve); -+ read(); -+ if (Tok.K != Comma) { -+ unget(); -+ Commit = nullptr; -+ return; -+ } -+ readAsInt(Commit); -+ } -+ -+ // NAME outputPath [BASE=address] -+ void parseName(std::string *Out, uint64_t *Baseaddr) { -+ read(); -+ if (Tok.K == Identifier) { -+ *Out = Tok.Value; -+ } else { -+ *Out = ""; -+ unget(); -+ return; -+ } -+ read(); -+ if (Tok.K == KwBase) { -+ expect(Equal, "'=' expected"); -+ readAsInt(Baseaddr); -+ } else { -+ unget(); -+ *Baseaddr = 0; -+ } -+ } -+ -+ // VERSION major[.minor] -+ void parseVersion(uint32_t *Major, uint32_t *Minor) { -+ read(); -+ if (Tok.K != Identifier) -+ fatal("identifier expected, but got " + Tok.Value); -+ StringRef V1, V2; -+ std::tie(V1, V2) = Tok.Value.split('.'); -+ if (V1.getAsInteger(10, *Major)) -+ fatal("integer expected, but got " + Tok.Value); -+ if (V2.empty()) -+ *Minor = 0; -+ else if (V2.getAsInteger(10, *Minor)) -+ fatal("integer expected, but got " + Tok.Value); -+ } -+ -+ Lexer Lex; -+ Token Tok; -+ std::vector Stack; -+ StringSaver *Alloc; -+}; -+ -+} // anonymous namespace -+ -+void parseModuleDefs(MemoryBufferRef MB, StringSaver *Alloc) { -+ Parser(MB.getBuffer(), Alloc).parse(); -+} -+ -+} // namespace llvm -diff --git a/lib/DLLDriver/Options.td b/lib/DLLDriver/Options.td -new file mode 100644 -index 00000000000..62f33f386e8 ---- /dev/null -+++ b/lib/DLLDriver/Options.td -@@ -0,0 +1,5 @@ -+include "llvm/Option/OptParser.td" -+ -+def emu: JoinedOrSeparate<["-"], "a">, HelpText<"Set target arch">; -+def out: JoinedOrSeparate<["-"], "o">, HelpText<"Set output file">; -+def dll: JoinedOrSeparate<["-"], "d">, HelpText<"Set dll name">; -diff --git a/lib/Object/ArchiveWriter.cpp b/lib/Object/ArchiveWriter.cpp -index f8e3c5a0a03..d5f067ed675 100644 ---- a/lib/Object/ArchiveWriter.cpp -+++ b/lib/Object/ArchiveWriter.cpp -@@ -299,7 +299,8 @@ writeSymbolTable(raw_fd_ostream &Out, object::Archive::Kind Kind, - continue; - if (!(Symflags & object::SymbolRef::SF_Global)) - continue; -- if (Symflags & object::SymbolRef::SF_Undefined) -+ if (Symflags & object::SymbolRef::SF_Undefined && -+ !(Symflags & object::SymbolRef::SF_Weak)) - continue; - - unsigned NameOffset = NameOS.tell(); -diff --git a/tools/llvm-ar/CMakeLists.txt b/tools/llvm-ar/CMakeLists.txt -index 3bb0c8f7b7c..14732b47b93 100644 ---- a/tools/llvm-ar/CMakeLists.txt -+++ b/tools/llvm-ar/CMakeLists.txt -@@ -1,6 +1,7 @@ - set(LLVM_LINK_COMPONENTS - ${LLVM_TARGETS_TO_BUILD} - Core -+ DllDriver - LibDriver - Object - Support -@@ -15,3 +16,4 @@ add_llvm_tool(llvm-ar - - add_llvm_tool_symlink(llvm-ranlib llvm-ar) - add_llvm_tool_symlink(llvm-lib llvm-ar) -+add_llvm_tool_symlink(llvm-dlltool llvm-ar) -diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp -index b99a396da62..23e323c8082 100644 ---- a/tools/llvm-ar/llvm-ar.cpp -+++ b/tools/llvm-ar/llvm-ar.cpp -@@ -16,6 +16,7 @@ - #include "llvm/ADT/Triple.h" - #include "llvm/IR/LLVMContext.h" - #include "llvm/IR/Module.h" -+#include "llvm/DllDriver/DllDriver.h" - #include "llvm/LibDriver/LibDriver.h" - #include "llvm/Object/Archive.h" - #include "llvm/Object/ArchiveWriter.h" -@@ -850,6 +851,9 @@ int main(int argc, char **argv) { - llvm::InitializeAllAsmParsers(); - - StringRef Stem = sys::path::stem(ToolName); -+ if (Stem.find("dlltool") != StringRef::npos) -+ return dllToolDriverMain(makeArrayRef(argv, argc)); -+ - if (Stem.find("ranlib") == StringRef::npos && - Stem.find("lib") != StringRef::npos) - return libDriverMain(makeArrayRef(argv, argc)); -@@ -865,5 +869,5 @@ int main(int argc, char **argv) { - return ranlib_main(); - if (Stem.find("ar") != StringRef::npos) - return ar_main(); -- fail("Not ranlib, ar or lib!"); -+ fail("Not ranlib, ar, lib or dlltool!"); - } --- -2.11.0.windows.3 - diff --git a/mingw-w64-clang/0002-mingw-w64-use-MSVC-style-ByteAlignment.patch b/mingw-w64-clang/0001-mingw-w64-use-MSVC-style-ByteAlignment.patch similarity index 66% rename from mingw-w64-clang/0002-mingw-w64-use-MSVC-style-ByteAlignment.patch rename to mingw-w64-clang/0001-mingw-w64-use-MSVC-style-ByteAlignment.patch index 65bcd766bb..058faba144 100644 --- a/mingw-w64-clang/0002-mingw-w64-use-MSVC-style-ByteAlignment.patch +++ b/mingw-w64-clang/0001-mingw-w64-use-MSVC-style-ByteAlignment.patch @@ -1,19 +1,19 @@ -From da82422a5f9c9709ba3ac15b52891b8b310278ad Mon Sep 17 00:00:00 2001 +From 6832b520f918211609cb0b6ee427e922720d4803 Mon Sep 17 00:00:00 2001 From: Martell Malone Date: Tue, 16 Aug 2016 12:55:01 -0700 -Subject: [PATCH 2/6] mingw-w64: use MSVC style ByteAlignment +Subject: [PATCH 1/5] mingw-w64: use MSVC style ByteAlignment We can do alignment without -aligncomm derectives in PE COFF Until we support GNU style in lld we should use this --- - lib/MC/WinCOFFStreamer.cpp | 4 ++-- + lib/MC/MCWinCOFFStreamer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -diff --git a/lib/MC/WinCOFFStreamer.cpp b/lib/MC/WinCOFFStreamer.cpp -index 6383d879403..06a5aef0e3b 100644 ---- a/lib/MC/WinCOFFStreamer.cpp -+++ b/lib/MC/WinCOFFStreamer.cpp -@@ -217,7 +217,7 @@ void MCWinCOFFStreamer::EmitCommonSymbol(MCSymbol *S, uint64_t Size, +diff --git a/lib/MC/MCWinCOFFStreamer.cpp b/lib/MC/MCWinCOFFStreamer.cpp +index bf341bb1f45..3b3fecfc1d7 100644 +--- a/lib/MC/MCWinCOFFStreamer.cpp ++++ b/lib/MC/MCWinCOFFStreamer.cpp +@@ -222,7 +222,7 @@ void MCWinCOFFStreamer::EmitCommonSymbol(MCSymbol *S, uint64_t Size, auto *Symbol = cast(S); const Triple &T = getContext().getObjectFileInfo()->getTargetTriple(); @@ -22,7 +22,7 @@ index 6383d879403..06a5aef0e3b 100644 if (ByteAlignment > 32) report_fatal_error("alignment is limited to 32-bytes"); -@@ -229,7 +229,7 @@ void MCWinCOFFStreamer::EmitCommonSymbol(MCSymbol *S, uint64_t Size, +@@ -234,7 +234,7 @@ void MCWinCOFFStreamer::EmitCommonSymbol(MCSymbol *S, uint64_t Size, Symbol->setExternal(true); Symbol->setCommon(Size, ByteAlignment); @@ -32,5 +32,5 @@ index 6383d879403..06a5aef0e3b 100644 raw_svector_ostream OS(Directive); const MCObjectFileInfo *MFI = getContext().getObjectFileInfo(); -- -2.11.0.windows.3 +2.13.3 diff --git a/mingw-w64-clang/0003-Fix-GetHostTriple-for-mingw-w64-in-msys.patch b/mingw-w64-clang/0002-Fix-GetHostTriple-for-mingw-w64-in-msys.patch similarity index 85% rename from mingw-w64-clang/0003-Fix-GetHostTriple-for-mingw-w64-in-msys.patch rename to mingw-w64-clang/0002-Fix-GetHostTriple-for-mingw-w64-in-msys.patch index 207da58a5b..90da3552db 100644 --- a/mingw-w64-clang/0003-Fix-GetHostTriple-for-mingw-w64-in-msys.patch +++ b/mingw-w64-clang/0002-Fix-GetHostTriple-for-mingw-w64-in-msys.patch @@ -1,7 +1,7 @@ -From fffcfe99dab9c1ef714067d337159fbefbd5d139 Mon Sep 17 00:00:00 2001 +From b47a00af69f3c662e54dc54e482fc9b0d4ba6480 Mon Sep 17 00:00:00 2001 From: Martell Malone Date: Sun, 28 Jun 2015 20:14:51 +0100 -Subject: [PATCH 3/6] Fix GetHostTriple for mingw-w64 in msys +Subject: [PATCH 2/5] Fix GetHostTriple for mingw-w64 in msys --- cmake/modules/GetHostTriple.cmake | 4 ++-- @@ -26,5 +26,5 @@ index 0cad1db4eff..47e9f986e15 100644 else( MSVC ) set(config_guess ${LLVM_MAIN_SRC_DIR}/cmake/config.guess) -- -2.11.0.windows.3 +2.13.3 diff --git a/mingw-w64-clang/0004-Globally-provide-DESTDIR-for-all-platforms.patch b/mingw-w64-clang/0003-Globally-provide-DESTDIR-for-all-platforms.patch similarity index 81% rename from mingw-w64-clang/0004-Globally-provide-DESTDIR-for-all-platforms.patch rename to mingw-w64-clang/0003-Globally-provide-DESTDIR-for-all-platforms.patch index 57e548871b..71be66a3fb 100644 --- a/mingw-w64-clang/0004-Globally-provide-DESTDIR-for-all-platforms.patch +++ b/mingw-w64-clang/0003-Globally-provide-DESTDIR-for-all-platforms.patch @@ -1,7 +1,7 @@ -From 44b291e8ebb6d4a80843cf9b46b4804b0f0d6515 Mon Sep 17 00:00:00 2001 +From f4cea343d6e61f388de78241e89b1032ff11b0c7 Mon Sep 17 00:00:00 2001 From: Alexey Pavlov Date: Fri, 25 Dec 2015 20:14:51 +0100 -Subject: [PATCH 4/6] Globally provide DESTDIR for all platforms +Subject: [PATCH 3/5] Globally provide DESTDIR for all platforms --- cmake/modules/LLVMInstallSymlink.cmake | 2 +- @@ -23,5 +23,5 @@ index 482697b06ba..61c4b9dea80 100644 set(LINK_OR_COPY copy) endif() -- -2.11.0.windows.3 +2.13.3 diff --git a/mingw-w64-clang/0006-llvm-config-look-for-unversioned-shared-lib-on-win32.patch b/mingw-w64-clang/0004-llvm-config-look-for-unversioned-shared-lib-on-win32.patch similarity index 79% rename from mingw-w64-clang/0006-llvm-config-look-for-unversioned-shared-lib-on-win32.patch rename to mingw-w64-clang/0004-llvm-config-look-for-unversioned-shared-lib-on-win32.patch index 36408ab415..3edd842032 100644 --- a/mingw-w64-clang/0006-llvm-config-look-for-unversioned-shared-lib-on-win32.patch +++ b/mingw-w64-clang/0004-llvm-config-look-for-unversioned-shared-lib-on-win32.patch @@ -1,17 +1,17 @@ -From cccec8226592a0a635a4f00d5bf6f72803616e38 Mon Sep 17 00:00:00 2001 +From 56c0371a3cbc98ef5dc039324ad43c153ff601c4 Mon Sep 17 00:00:00 2001 From: Mateusz Mikula Date: Thu, 2 Feb 2017 11:48:25 +0100 -Subject: [PATCH 6/6] llvm-config: look for unversioned shared lib on win32 +Subject: [PATCH 4/5] llvm-config: look for unversioned shared lib on win32 --- tools/llvm-config/llvm-config.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp -index 25344e4cd01..24aeba7cb0f 100644 +index 08b096afb05..e388d9e5d3f 100644 --- a/tools/llvm-config/llvm-config.cpp +++ b/tools/llvm-config/llvm-config.cpp -@@ -351,7 +351,7 @@ int main(int argc, char **argv) { +@@ -353,7 +353,7 @@ int main(int argc, char **argv) { const Triple HostTriple(Triple::normalize(LLVM_HOST_TRIPLE)); if (HostTriple.isOSWindows()) { SharedExt = "dll"; @@ -20,7 +20,7 @@ index 25344e4cd01..24aeba7cb0f 100644 if (HostTriple.isOSCygMing()) { StaticExt = "a"; StaticPrefix = "lib"; -@@ -389,8 +389,10 @@ int main(int argc, char **argv) { +@@ -391,8 +391,10 @@ int main(int argc, char **argv) { const bool BuiltSharedLibs = !!LLVM_ENABLE_SHARED; bool DyLibExists = false; @@ -34,5 +34,5 @@ index 25344e4cd01..24aeba7cb0f 100644 // If LLVM_LINK_DYLIB is ON, the single shared library will be returned // for "--libs", etc, if they exist. This behaviour can be overridden with -- -2.11.0.windows.3 +2.13.3 diff --git a/mingw-w64-clang/0007-add-pthread-as-system-lib-for-mingw.patch b/mingw-w64-clang/0005-add-pthread-as-system-lib-for-mingw.patch similarity index 79% rename from mingw-w64-clang/0007-add-pthread-as-system-lib-for-mingw.patch rename to mingw-w64-clang/0005-add-pthread-as-system-lib-for-mingw.patch index b99298c5b9..33bb94a050 100644 --- a/mingw-w64-clang/0007-add-pthread-as-system-lib-for-mingw.patch +++ b/mingw-w64-clang/0005-add-pthread-as-system-lib-for-mingw.patch @@ -1,14 +1,14 @@ -From 6caf7048b2a66fa2beb198e52e5c62fa08b786e8 Mon Sep 17 00:00:00 2001 +From 9102055df75457e1194008ce6152221112a785ad Mon Sep 17 00:00:00 2001 From: Mateusz Mikula Date: Tue, 14 Mar 2017 17:50:29 +0100 -Subject: [PATCH] add pthread as system lib for mingw +Subject: [PATCH 5/5] add pthread as system lib for mingw --- lib/Support/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Support/CMakeLists.txt b/lib/Support/CMakeLists.txt -index 15418ad2fd0..c69f75b7e48 100644 +index 0a8e3897cce..de9cda5dda3 100644 --- a/lib/Support/CMakeLists.txt +++ b/lib/Support/CMakeLists.txt @@ -2,6 +2,9 @@ set(system_libs) @@ -22,4 +22,5 @@ index 15418ad2fd0..c69f75b7e48 100644 if( HAVE_LIBRT ) set(system_libs ${system_libs} rt) -- -2.12.0 +2.13.3 + diff --git a/mingw-w64-clang/0005-not-install-msvc-files.patch b/mingw-w64-clang/0005-not-install-msvc-files.patch deleted file mode 100644 index 4b967bfe6b..0000000000 --- a/mingw-w64-clang/0005-not-install-msvc-files.patch +++ /dev/null @@ -1,22 +0,0 @@ -From 1d467138106facb26fd780ada69314ee2ba865a2 Mon Sep 17 00:00:00 2001 -From: Alexey Pavlov -Date: Thu, 2 Feb 2017 11:43:35 +0100 -Subject: [PATCH 5/6] not install msvc files - ---- - tools/msbuild/CMakeLists.txt | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/tools/msbuild/CMakeLists.txt b/tools/msbuild/CMakeLists.txt -index 4f471e5408b..9d132ea58d5 100644 ---- a/tools/msbuild/CMakeLists.txt -+++ b/tools/msbuild/CMakeLists.txt -@@ -1,4 +1,4 @@ --if (WIN32) -+if (MSVC) - # CPack will install a registry key in this format that we wish to reference. - set(REG_KEY "${CPACK_PACKAGE_INSTALL_REGISTRY_KEY}") - set(LIB_PATH_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}") --- -2.11.0.windows.3 - diff --git a/mingw-w64-clang/0008-fix-bugpoint-multiple-definition.patch b/mingw-w64-clang/0006-fix-bugpoint-multiple-definition.patch similarity index 54% rename from mingw-w64-clang/0008-fix-bugpoint-multiple-definition.patch rename to mingw-w64-clang/0006-fix-bugpoint-multiple-definition.patch index 879684eee6..677179585b 100644 --- a/mingw-w64-clang/0008-fix-bugpoint-multiple-definition.patch +++ b/mingw-w64-clang/0006-fix-bugpoint-multiple-definition.patch @@ -1,6 +1,6 @@ ---- llvm-4.0.0.src/tools/bugpoint/CMakeLists.txt -+++ llvm-4.0.0.src/tools/bugpoint/CMakeLists.txt -@@ -37,6 +37,4 @@ +--- llvm-5.0.0.src/tools/bugpoint/CMakeLists.txt.orig 2017-09-08 22:16:39.035644100 +0200 ++++ llvm-5.0.0.src/tools/bugpoint/CMakeLists.txt 2017-09-14 13:26:53.811311200 +0200 +@@ -38,6 +38,4 @@ if(WITH_POLLY AND LINK_POLLY_INTO_TOOLS) target_link_libraries(bugpoint Polly) diff --git a/mingw-w64-clang/0102-Allow-build-static-clang-library-for-mingw.patch b/mingw-w64-clang/0101-Allow-build-static-clang-library-for-mingw.patch similarity index 82% rename from mingw-w64-clang/0102-Allow-build-static-clang-library-for-mingw.patch rename to mingw-w64-clang/0101-Allow-build-static-clang-library-for-mingw.patch index 9ee441c427..d8f543e810 100644 --- a/mingw-w64-clang/0102-Allow-build-static-clang-library-for-mingw.patch +++ b/mingw-w64-clang/0101-Allow-build-static-clang-library-for-mingw.patch @@ -1,7 +1,7 @@ -From c1c93aaa9b8a903ce3f761ae2dabb20daf521f5c Mon Sep 17 00:00:00 2001 +From ded1b370c6ccbb427406edc6ab39656144d61818 Mon Sep 17 00:00:00 2001 From: Alexey Pavlov Date: Fri, 25 Dec 2015 20:14:51 +0100 -Subject: [PATCH 2/9] Allow build static clang library for mingw +Subject: [PATCH 1/5] Allow build static clang library for mingw --- tools/libclang/CMakeLists.txt | 2 +- @@ -21,5 +21,5 @@ index 2dd6703076..477e53dd15 100644 endif() -- -2.12.0 +2.13.3 diff --git a/mingw-w64-clang/0101-mingw-w64-enable-support-for-__declspec-selectany.patch b/mingw-w64-clang/0101-mingw-w64-enable-support-for-__declspec-selectany.patch deleted file mode 100644 index 7805b1a743..0000000000 --- a/mingw-w64-clang/0101-mingw-w64-enable-support-for-__declspec-selectany.patch +++ /dev/null @@ -1,28 +0,0 @@ -From 43803cddf8b2f53203cacb575e1e53db4b8191ed Mon Sep 17 00:00:00 2001 -From: Martell Malone -Date: Mon, 15 Aug 2016 20:57:27 -0700 -Subject: [PATCH 1/9] mingw-w64: enable support for __declspec(selectany) - ---- - include/clang/Basic/Attr.td | 5 ++--- - 1 file changed, 2 insertions(+), 3 deletions(-) - -diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td -index d7db7186b3..ddb41c0eb8 100644 ---- a/include/clang/Basic/Attr.td -+++ b/include/clang/Basic/Attr.td -@@ -2194,9 +2194,8 @@ def DLLImport : InheritableAttr, TargetSpecificAttr { - let Documentation = [DLLImportDocs]; - } - --def SelectAny : InheritableAttr { -- let Spellings = [Declspec<"selectany">]; -- let LangOpts = [MicrosoftExt]; -+def SelectAny : InheritableAttr, TargetSpecificAttr { -+ let Spellings = [Declspec<"selectany">, GCC<"selectany">]; - let Documentation = [Undocumented]; - } - --- -2.12.0 - diff --git a/mingw-w64-clang/0103-fix-libclang-name-for-mingw.patch b/mingw-w64-clang/0102-fix-libclang-name-for-mingw.patch similarity index 82% rename from mingw-w64-clang/0103-fix-libclang-name-for-mingw.patch rename to mingw-w64-clang/0102-fix-libclang-name-for-mingw.patch index f6ef6e606c..7bad047bbe 100644 --- a/mingw-w64-clang/0103-fix-libclang-name-for-mingw.patch +++ b/mingw-w64-clang/0102-fix-libclang-name-for-mingw.patch @@ -1,7 +1,7 @@ -From 180bffbe07c0c43e7f103debc8d8d777cb027096 Mon Sep 17 00:00:00 2001 +From 4fea4f3cc0f23cc4aacc727cff812303a63a83b5 Mon Sep 17 00:00:00 2001 From: Mateusz Mikula Date: Thu, 2 Feb 2017 12:21:45 +0100 -Subject: [PATCH 3/9] fix libclang name for mingw +Subject: [PATCH 2/5] fix libclang name for mingw --- tools/libclang/CMakeLists.txt | 2 +- @@ -21,5 +21,5 @@ index 477e53dd15..dc2e3538fa 100644 else() set(output_name "clang") -- -2.12.0 +2.13.3 diff --git a/mingw-w64-clang/0105-Set-the-x86-arch-name-to-i686-for-mingw-w64.patch b/mingw-w64-clang/0103-Set-the-x86-arch-name-to-i686-for-mingw-w64.patch similarity index 74% rename from mingw-w64-clang/0105-Set-the-x86-arch-name-to-i686-for-mingw-w64.patch rename to mingw-w64-clang/0103-Set-the-x86-arch-name-to-i686-for-mingw-w64.patch index c74654c408..798d9cbbaf 100644 --- a/mingw-w64-clang/0105-Set-the-x86-arch-name-to-i686-for-mingw-w64.patch +++ b/mingw-w64-clang/0103-Set-the-x86-arch-name-to-i686-for-mingw-w64.patch @@ -1,17 +1,17 @@ -From 0e31fbf4e602f857cd33c1b5b446da354b64df11 Mon Sep 17 00:00:00 2001 +From 5042e15216190f11cfb12f0c81c187c7353fb1d5 Mon Sep 17 00:00:00 2001 From: Martell Malone Date: Sun, 28 Jun 2015 19:12:19 +0100 -Subject: [PATCH 5/9] Set the x86 arch name to i686 for mingw-w64 +Subject: [PATCH 3/5] Set the x86 arch name to i686 for mingw-w64 --- lib/Driver/Driver.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp -index b8ae7e4c31..a76ef16c8a 100644 +index ba4d0e836b..9f8c850b22 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp -@@ -381,6 +381,11 @@ static llvm::Triple computeTargetTriple(const Driver &D, +@@ -429,6 +429,11 @@ static llvm::Triple computeTargetTriple(const Driver &D, if (AT != llvm::Triple::UnknownArch && AT != Target.getArch()) Target.setArch(AT); @@ -24,5 +24,5 @@ index b8ae7e4c31..a76ef16c8a 100644 // Handle -miamcu flag. -- -2.12.0 +2.13.3 diff --git a/mingw-w64-clang/0104-don-t-use-GCC-headers.patch b/mingw-w64-clang/0104-don-t-use-GCC-headers.patch deleted file mode 100644 index 2e6fc1cda1..0000000000 --- a/mingw-w64-clang/0104-don-t-use-GCC-headers.patch +++ /dev/null @@ -1,32 +0,0 @@ -From b1025201e074846b13132a7c417fa776312816fc Mon Sep 17 00:00:00 2001 -From: Mateusz Mikula -Date: Thu, 2 Feb 2017 12:26:19 +0100 -Subject: [PATCH 4/9] don't use GCC headers - ---- - lib/Driver/MinGWToolChain.cpp | 2 ++ - 1 file changed, 2 insertions(+) - -diff --git a/lib/Driver/MinGWToolChain.cpp b/lib/Driver/MinGWToolChain.cpp -index e971869fb5..252c5e818f 100644 ---- a/lib/Driver/MinGWToolChain.cpp -+++ b/lib/Driver/MinGWToolChain.cpp -@@ -208,6 +208,7 @@ void MinGW::AddClangSystemIncludeArgs(const ArgList &DriverArgs, - if (DriverArgs.hasArg(options::OPT_nostdlibinc)) - return; - -+#ifndef LLVM_ON_WIN32 - if (GetRuntimeLibType(DriverArgs) == ToolChain::RLT_Libgcc) { - llvm::SmallString<1024> IncludeDir(GccLibDir); - llvm::sys::path::append(IncludeDir, "include"); -@@ -218,6 +219,7 @@ void MinGW::AddClangSystemIncludeArgs(const ArgList &DriverArgs, - Base + Arch + "/sys-root/mingw/include"); - addSystemInclude(DriverArgs, CC1Args, IncludeDir.c_str()); - } -+#endif - addSystemInclude(DriverArgs, CC1Args, - Base + Arch + llvm::sys::path::get_separator() + "include"); - addSystemInclude(DriverArgs, CC1Args, Base + "include"); --- -2.12.0 - diff --git a/mingw-w64-clang/0104-link-pthread-with-mingw.patch b/mingw-w64-clang/0104-link-pthread-with-mingw.patch new file mode 100644 index 0000000000..4c26c4c692 --- /dev/null +++ b/mingw-w64-clang/0104-link-pthread-with-mingw.patch @@ -0,0 +1,25 @@ +From 9498118b65fa150f074efb52b4507b53434a90ad Mon Sep 17 00:00:00 2001 +From: Mateusz Mikula +Date: Thu, 2 Feb 2017 12:33:51 +0100 +Subject: [PATCH 4/5] link pthread with mingw + +--- + lib/Driver/ToolChains/MinGW.cpp | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/lib/Driver/ToolChains/MinGW.cpp b/lib/Driver/ToolChains/MinGW.cpp +index 632b76d92b..23da2d6376 100644 +--- a/lib/Driver/ToolChains/MinGW.cpp ++++ b/lib/Driver/ToolChains/MinGW.cpp +@@ -215,7 +215,7 @@ void tools::MinGW::Linker::ConstructJob(Compilation &C, const JobAction &JA, + if (Args.hasArg(options::OPT_pg)) + CmdArgs.push_back("-lgmon"); + +- if (Args.hasArg(options::OPT_pthread)) ++ if (!Args.hasArg(options::OPT_no_pthread)) + CmdArgs.push_back("-lpthread"); + + // add system libraries +-- +2.13.3 + diff --git a/mingw-w64-clang/0105-use-emulated-tls-with-mingw.patch b/mingw-w64-clang/0105-use-emulated-tls-with-mingw.patch new file mode 100644 index 0000000000..2c744df0ad --- /dev/null +++ b/mingw-w64-clang/0105-use-emulated-tls-with-mingw.patch @@ -0,0 +1,26 @@ +From 89e43bd7141cc12f6b4eca71b549d6b2eb6030c0 Mon Sep 17 00:00:00 2001 +From: Mateusz Mikula +Date: Wed, 1 Mar 2017 19:56:37 +0100 +Subject: [PATCH 5/5] use emulated tls with mingw + +--- + lib/Driver/ToolChains/Clang.cpp | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp +index 6a6b90f868..f7967fe79b 100644 +--- a/lib/Driver/ToolChains/Clang.cpp ++++ b/lib/Driver/ToolChains/Clang.cpp +@@ -3207,7 +3207,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, + // Emulated TLS is enabled by default on Android and OpenBSD, and can be enabled + // manually with -femulated-tls. + bool EmulatedTLSDefault = Triple.isAndroid() || Triple.isOSOpenBSD() || +- Triple.isWindowsCygwinEnvironment(); ++ Triple.isWindowsCygwinEnvironment() || ++ Triple.isWindowsGNUEnvironment(); + if (Args.hasFlag(options::OPT_femulated_tls, options::OPT_fno_emulated_tls, + EmulatedTLSDefault)) + CmdArgs.push_back("-femulated-tls"); +-- +2.13.3 + diff --git a/mingw-w64-clang/0106-link-pthread-with-mingw.patch b/mingw-w64-clang/0106-link-pthread-with-mingw.patch deleted file mode 100644 index 0200f96ce9..0000000000 --- a/mingw-w64-clang/0106-link-pthread-with-mingw.patch +++ /dev/null @@ -1,26 +0,0 @@ -From 2156ae73b265c3c77803b5ee1e46af45b52fccc3 Mon Sep 17 00:00:00 2001 -From: Mateusz Mikula -Date: Thu, 2 Feb 2017 12:33:51 +0100 -Subject: [PATCH 6/9] link pthread with mingw - ---- - lib/Driver/Tools.cpp | 3 ++- - 1 file changed, 2 insertions(+), 1 deletion(-) - -diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp -index 339f6976cd..7a6e1f6f36 100644 ---- a/lib/Driver/Tools.cpp -+++ b/lib/Driver/Tools.cpp -@@ -11428,7 +11428,8 @@ void MinGW::Linker::ConstructJob(Compilation &C, const JobAction &JA, - if (Args.hasArg(options::OPT_pg)) - CmdArgs.push_back("-lgmon"); - -- if (Args.hasArg(options::OPT_pthread)) -+ // it might break libc++ -+ if (!Args.hasArg(options::OPT_no_pthread)) - CmdArgs.push_back("-lpthread"); - - // add system libraries --- -2.12.0 - diff --git a/mingw-w64-clang/0107-enable-__float128-for-X86-MinGW.patch b/mingw-w64-clang/0107-enable-__float128-for-X86-MinGW.patch deleted file mode 100644 index 8ee9d391ae..0000000000 --- a/mingw-w64-clang/0107-enable-__float128-for-X86-MinGW.patch +++ /dev/null @@ -1,35 +0,0 @@ -From 2243dd85c1e5c27edf76cc7b5e2c836518ab2a6b Mon Sep 17 00:00:00 2001 -From: Mateusz Mikula -Date: Fri, 3 Feb 2017 11:04:25 +0100 -Subject: [PATCH 7/9] enable __float128 for X86 MinGW - ---- - lib/Basic/Targets.cpp | 5 ++++- - 1 file changed, 4 insertions(+), 1 deletion(-) - -diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp -index d69a0ff4ab..9fe6c51be2 100644 ---- a/lib/Basic/Targets.cpp -+++ b/lib/Basic/Targets.cpp -@@ -4443,7 +4443,9 @@ static void addMinGWDefines(const LangOptions &Opts, MacroBuilder &Builder) { - class MinGWX86_32TargetInfo : public WindowsX86_32TargetInfo { - public: - MinGWX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) -- : WindowsX86_32TargetInfo(Triple, Opts) {} -+ : WindowsX86_32TargetInfo(Triple, Opts) { -+ this->HasFloat128 = true; -+ } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override { - WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder); -@@ -4735,6 +4737,7 @@ public: - // with x86 FP ops. Weird. - LongDoubleWidth = LongDoubleAlign = 128; - LongDoubleFormat = &llvm::APFloat::x87DoubleExtended(); -+ this->HasFloat128 = true; - } - - void getTargetDefines(const LangOptions &Opts, --- -2.12.0 - diff --git a/mingw-w64-clang/0108-Don-t-create-cl-executable-for-mingw.patch b/mingw-w64-clang/0108-Don-t-create-cl-executable-for-mingw.patch deleted file mode 100644 index c4487d5e73..0000000000 --- a/mingw-w64-clang/0108-Don-t-create-cl-executable-for-mingw.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 28f3e2bd27cb8e3f7a182a17d45af72303a47862 Mon Sep 17 00:00:00 2001 -From: Alexey Pavlov -Date: Fri, 25 Dec 2015 20:14:51 +0100 -Subject: [PATCH 8/9] Don't create cl executable for mingw - ---- - tools/driver/CMakeLists.txt | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/tools/driver/CMakeLists.txt b/tools/driver/CMakeLists.txt -index f6e26fa11f..901b6d62e4 100644 ---- a/tools/driver/CMakeLists.txt -+++ b/tools/driver/CMakeLists.txt -@@ -61,7 +61,7 @@ add_dependencies(clang clang-headers) - if(NOT CLANG_LINKS_TO_CREATE) - set(CLANG_LINKS_TO_CREATE clang++ clang-cl clang-cpp) - -- if (WIN32) -+ if (MSVC) - list(APPEND CLANG_LINKS_TO_CREATE ../msbuild-bin/cl) - endif() - endif() --- -2.12.0 - diff --git a/mingw-w64-clang/0109-use-emulated-tls-with-mingw.patch b/mingw-w64-clang/0109-use-emulated-tls-with-mingw.patch deleted file mode 100644 index 09d9ffee3f..0000000000 --- a/mingw-w64-clang/0109-use-emulated-tls-with-mingw.patch +++ /dev/null @@ -1,26 +0,0 @@ -From 7b80268c2f6475fcb932b961680ba6acdd33758d Mon Sep 17 00:00:00 2001 -From: Mateusz Mikula -Date: Wed, 1 Mar 2017 19:56:37 +0100 -Subject: [PATCH 9/9] use emulated tls with mingw - ---- - lib/Driver/Tools.cpp | 3 ++- - 1 file changed, 2 insertions(+), 1 deletion(-) - -diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp -index 7a6e1f6f36..4c7d40a549 100644 ---- a/lib/Driver/Tools.cpp -+++ b/lib/Driver/Tools.cpp -@@ -5423,7 +5423,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, - Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names); - // Emulated TLS is enabled by default on Android, and can be enabled manually - // with -femulated-tls. -- bool EmulatedTLSDefault = Triple.isAndroid() || Triple.isWindowsCygwinEnvironment(); -+ bool EmulatedTLSDefault = Triple.isAndroid() || Triple.isWindowsCygwinEnvironment() -+ || Triple.isWindowsGNUEnvironment(); - if (Args.hasFlag(options::OPT_femulated_tls, options::OPT_fno_emulated_tls, - EmulatedTLSDefault)) - CmdArgs.push_back("-femulated-tls"); --- -2.12.0 - diff --git a/mingw-w64-clang/0201-mingw-w64-__udivdi3-mangle-hack.patch b/mingw-w64-clang/0201-mingw-w64-__udivdi3-mangle-hack.patch index e69bc0eecf..450308d242 100644 --- a/mingw-w64-clang/0201-mingw-w64-__udivdi3-mangle-hack.patch +++ b/mingw-w64-clang/0201-mingw-w64-__udivdi3-mangle-hack.patch @@ -1,11 +1,14 @@ -From 67f899a1294d8ad56ea60b02a6ed5b111e2c2d24 Mon Sep 17 00:00:00 2001 +From 9a4406ce9d21da7042974c049f3715e1a1e606fb Mon Sep 17 00:00:00 2001 From: Martell Malone Date: Tue, 16 Aug 2016 16:00:52 -0700 -Subject: [PATCH 2/2] mingw-w64: __udivdi3 mangle hack +Subject: [PATCH 1/2] mingw-w64: __udivdi3 mangle hack +--- + lib/builtins/udivdi3.c | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/builtins/udivdi3.c b/lib/builtins/udivdi3.c -index dc68e15..4c616fd 100644 +index dc68e154b..4c616fde2 100644 --- a/lib/builtins/udivdi3.c +++ b/lib/builtins/udivdi3.c @@ -17,7 +17,12 @@ @@ -23,5 +26,5 @@ index dc68e15..4c616fd 100644 return __udivmoddi4(a, b, 0); } -- -2.8.3 +2.14.1.windows.1 diff --git a/mingw-w64-clang/0202-compiler-rt-fix-mingw-build.patch b/mingw-w64-clang/0202-compiler-rt-fix-mingw-build.patch index 78b6d16a2f..547600a0d2 100644 --- a/mingw-w64-clang/0202-compiler-rt-fix-mingw-build.patch +++ b/mingw-w64-clang/0202-compiler-rt-fix-mingw-build.patch @@ -1,7 +1,7 @@ -From b65c6b61099d87369d756a4137ea731a3a45f192 Mon Sep 17 00:00:00 2001 +From 056e6d2e8010dbf7777fa6d5d88496c1f9a49100 Mon Sep 17 00:00:00 2001 From: Mateusz Mikula Date: Wed, 15 Feb 2017 19:21:48 +0100 -Subject: [PATCH] compiler-rt: fix mingw build +Subject: [PATCH 2/2] compiler-rt: fix mingw build --- lib/profile/InstrProfilingPort.h | 2 +- @@ -21,4 +21,5 @@ index 578935195..3bda151ad 100644 #endif #endif -- -2.11.1 +2.14.1.windows.1 + diff --git a/mingw-w64-clang/0301-COFF-gnu-driver-support.patch b/mingw-w64-clang/0301-COFF-gnu-driver-support.patch deleted file mode 100644 index 67a041dcab..0000000000 --- a/mingw-w64-clang/0301-COFF-gnu-driver-support.patch +++ /dev/null @@ -1,230 +0,0 @@ -From 5bd9ff32fea92a763d99186619946764793bec87 Mon Sep 17 00:00:00 2001 -From: Martell Malone -Date: Sat, 6 Aug 2016 02:33:13 -0700 -Subject: [PATCH] COFF: gnu driver support - -Notes: --aligncomm is not needed anymore -we should patch mingw-w64 to use _ImageBase -A new seperate driver should be made. -Now that this works we should be able to revisit -this with Rui - -diff --git a/COFF/Driver.cpp b/COFF/Driver.cpp -index ffd6936..c927355 100644 ---- a/COFF/Driver.cpp -+++ b/COFF/Driver.cpp -@@ -130,6 +130,7 @@ void LinkerDriver::parseDirectives(StringRef S) { - case OPT_fastfail: - case OPT_guardsym: - case OPT_throwingnew: -+ case OPT_aligncomm: - break; - default: - fatal(Arg->getSpelling() + " is not allowed in .drectve"); -@@ -158,6 +159,31 @@ StringRef LinkerDriver::doFindFile(StringRef Filename) { - return Filename; - } - -+// Searches a given library from input search paths, which are filled -+// from -L command line switches. Returns a path to an existent library file. -+StringRef LinkerDriver::searchLibrary(StringRef Filename) { -+ -+ std::vector Names; -+ if (Filename[0] == ':') { -+ Names.push_back(Filename.drop_front()); -+ } else { -+ //TODO: Link with static only -+ //if (!Config->Static) -+ Names.push_back(("lib" + Filename + ".dll.a").str()); -+ Names.push_back(("lib" + Filename + ".a").str()); -+ } -+ -+ for (const std::string &Name : Names) { -+ for (StringRef Dir : SearchPaths) { -+ SmallString<128> Path = Dir; -+ llvm::sys::path::append(Path, Name.c_str()); -+ if (llvm::sys::fs::exists(Path.str())) -+ return Alloc.save(Path.str()); -+ } -+ } -+ fatal("Unable to find library -l" + Filename); -+} -+ - // Resolves a file path. This never returns the same path - // (in that case, it returns None). - Optional LinkerDriver::findFile(StringRef Filename) { -@@ -526,6 +552,9 @@ void LinkerDriver::link(llvm::ArrayRef ArgsArr) { - // for /defaultlib option. - std::vector Paths; - std::vector MBs; -+ for (auto *Arg : Args.filtered(OPT_l)) -+ if (Optional Path = searchLibrary(Arg->getValue())) -+ Paths.push_back(*Path); - for (auto *Arg : Args.filtered(OPT_INPUT)) - if (Optional Path = findFile(Arg->getValue())) - Paths.push_back(*Path); -@@ -655,6 +684,8 @@ void LinkerDriver::link(llvm::ArrayRef ArgsArr) { - Config->ImageBase = getDefaultImageBase(); - - Symtab.addRelative(mangle("__ImageBase"), 0); -+ // no mangle because mingw has defines to stop it for i686 -+ Symtab.addRelative("__image_base__", 0); - if (Config->Machine == I386) { - Config->SEHTable = Symtab.addRelative("___safe_se_handler_table", 0); - Config->SEHCount = Symtab.addAbsolute("___safe_se_handler_count", 0); -diff --git a/COFF/Driver.h b/COFF/Driver.h -index 0afde18..530baff 100644 ---- a/COFF/Driver.h -+++ b/COFF/Driver.h -@@ -87,6 +87,9 @@ private: - StringRef doFindFile(StringRef Filename); - StringRef doFindLib(StringRef Filename); - -+ // Searches for a gnu library -+ StringRef searchLibrary(StringRef Path); -+ - // Parses LIB environment which contains a list of search paths. - void addLibSearchPaths(); - -diff --git a/COFF/DriverUtils.cpp b/COFF/DriverUtils.cpp -index 5d7dc2b..571761c 100644 ---- a/COFF/DriverUtils.cpp -+++ b/COFF/DriverUtils.cpp -@@ -86,6 +86,19 @@ MachineTypes getMachineType(StringRef S) { - fatal("unknown /machine argument: " + S); - } - -+StringRef GNUMachineToStr(MachineTypes MT) { -+ switch (MT) { -+ case ARMNT: -+ return "arm"; -+ case AMD64: -+ return "x86_64"; -+ case I386: -+ return "x86"; -+ default: -+ llvm_unreachable("unknown machine type"); -+ } -+} -+ - StringRef machineToStr(MachineTypes MT) { - switch (MT) { - case ARMNT: -@@ -591,7 +604,7 @@ static const llvm::opt::OptTable::Info infoTable[] = { - - class COFFOptTable : public llvm::opt::OptTable { - public: -- COFFOptTable() : OptTable(infoTable, true) {} -+ COFFOptTable() : OptTable(infoTable) {} - }; - - // Parses a given list of options. -diff --git a/COFF/Options.td b/COFF/Options.td -index 3866993..a097325 100644 ---- a/COFF/Options.td -+++ b/COFF/Options.td -@@ -94,7 +94,41 @@ def help_q : Flag<["/?", "-?"], "">, Alias; - def nosymtab : F<"nosymtab">; - - // Flags for debugging --def lldmap : Joined<["/", "-"], "lldmap:">; -+def lldmap : Joined<["/", "-"], "debugmap:">; -+ -+def output : Separate<["-"], "o">, Alias; -+def L : Joined<["-"], "L">, Alias; -+def e : Separate<["-"], "e">, Alias; -+def subs : Separate<["--"], "subsystem">, Alias; -+ -+def outlib : Separate<["--"], "out-implib">, Alias; -+ -+def l : JoinedOrSeparate<["-"], "l">, MetaVarName<"">; -+ -+def enable_auto_image_base: Flag<["--"], "enable-auto-image-base">; -+ -+def unexported_symbols_list : Separate<["-"], "unexported_symbols_list">; -+def reexported_symbols_list : Separate<["-"], "reexported_symbols_list">; -+def force_symbols_not_weak_list : Separate<["-"], "force_symbols_not_weak_list">; -+def force_symbols_weak_list : Separate<["-"], "force_symbols_weak_list">; -+ -+def major_image_version : Separate<["--"], "major-image-version">; -+def minor_image_version : Separate<["--"], "minor-image-version">; -+ -+ -+def shared: Flag<["--"], "shared">, Alias; -+ -+// Used to silence some gnu warnings -+def aligncomm : P<"aligncomm", "Comm Alignment">; -+def Bdynamic: Flag<["-"], "Bdynamic">; -+ -+// Used to override gnu pe targets -+def m : Separate<["-"], "m">, MetaVarName<"">, -+ HelpText<"Select target emulation">; -+ -+// Select an optional flavor -+def flavor: Separate<["-"], "flavor">, -+ HelpText<"Flavor for linking, options are gnu/darwin/link">; - - //============================================================================== - // The flags below do nothing. They are defined only for link.exe compatibility. -diff --git a/COFF/SymbolTable.cpp b/COFF/SymbolTable.cpp -index df9da4c..1f5552d 100644 ---- a/COFF/SymbolTable.cpp -+++ b/COFF/SymbolTable.cpp -@@ -210,9 +210,10 @@ void SymbolTable::addSymbol(SymbolBody *New) { - // compare() returns -1, 0, or 1 if the lhs symbol is less preferable, - // equivalent (conflicting), or more preferable, respectively. - int Comp = Existing->compare(New); -- if (Comp == 0) -- fatal("duplicate symbol: " + Existing->getDebugName() + " and " + -- New->getDebugName()); -+ // disable for now because of _free_locale in libc++ with mingw -+ //if (Comp == 0) -+ // fatal("duplicate symbol: " + Existing->getDebugName() + " and " + -+ // New->getDebugName()); - if (Comp < 0) - Sym->Body = New; - } -diff --git a/tools/lld/lld.cpp b/tools/lld/lld.cpp -index 8805e02..d6baefd 100644 ---- a/tools/lld/lld.cpp -+++ b/tools/lld/lld.cpp -@@ -51,6 +51,24 @@ static Flavor getFlavor(StringRef S) { - .Default(Invalid); - } - -+static bool isPETarget(const std::vector &V) { -+ for (auto It = V.begin(); It != V.end(); It++) { -+ if (*It == StringRef("-m")) { -+ It++; -+ if (It == V.end()) -+ return false; -+ if (*It == StringRef("i386pe")) -+ return true; -+ if (*It == StringRef("i386pep")) -+ return true; -+ if (*It == StringRef("thumb2pe")) -+ return true; -+ return false; -+ } -+ } -+ return false; -+} -+ - static Flavor parseProgname(StringRef Progname) { - #if __APPLE__ - // Use Darwin driver for "ld" on Darwin. -@@ -101,6 +119,10 @@ int main(int Argc, const char **Argv) { - llvm_shutdown_obj Shutdown; - - std::vector Args(Argv, Argv + Argc); -+ -+ if (isPETarget(Args)) -+ return !coff::link(Args); -+ - switch (parseFlavor(Args)) { - case Gnu: - return !elf::link(Args); --- -2.8.3 - diff --git a/mingw-w64-clang/0302-add-install-target-for-the-lld-tool.patch b/mingw-w64-clang/0302-add-install-target-for-the-lld-tool.patch deleted file mode 100644 index b0043462a6..0000000000 --- a/mingw-w64-clang/0302-add-install-target-for-the-lld-tool.patch +++ /dev/null @@ -1,125 +0,0 @@ -From 1abddce89f69fee1d7352d8019638ca954fcd3a9 Mon Sep 17 00:00:00 2001 -From: Petr Hosek -Date: Fri, 23 Dec 2016 00:22:47 +0000 -Subject: [PATCH] [CMake] Add install target for the lld tool - -This is necessary for the distribution targets which assume that -each component has an install target. This also moves the CMake -macros into a separate file akin to other LLVM projects. - -Differential Revision: https://reviews.llvm.org/D27876 - -git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@290391 91177308-0d34-0410-b5e6-96231b3b80d8 ---- - CMakeLists.txt | 10 ++++------ - cmake/modules/AddLLD.cmake | 45 +++++++++++++++++++++++++++++++++++++++++++++ - tools/lld/CMakeLists.txt | 7 ++----- - 3 files changed, 51 insertions(+), 11 deletions(-) - create mode 100644 cmake/modules/AddLLD.cmake - -diff --git a/CMakeLists.txt b/CMakeLists.txt -index 58101e1..23cef2e 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -106,6 +106,8 @@ endif() - - list (APPEND CMAKE_MODULE_PATH "${LLD_SOURCE_DIR}/cmake/modules") - -+include(AddLLD) -+ - option(LLD_USE_VTUNE - "Enable VTune user task tracking." - OFF) -@@ -118,6 +120,8 @@ if (LLD_USE_VTUNE) - endif() - endif() - -+option(LLD_BUILD_TOOLS -+ "Build the lld tools. If OFF, just generate build targets." ON) - - if (MSVC) - add_definitions(-wd4530) # Suppress 'warning C4530: C++ exception handler used, but unwind semantics are not enabled.' -@@ -138,12 +142,6 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) - ) - endif() - --macro(add_lld_library name) -- add_llvm_library(${name} ${ARGN}) -- set_target_properties(${name} PROPERTIES FOLDER "lld libraries") --endmacro(add_lld_library) -- -- - add_subdirectory(lib) - add_subdirectory(tools/lld) - -diff --git a/cmake/modules/AddLLD.cmake b/cmake/modules/AddLLD.cmake -new file mode 100644 -index 0000000..752ca7f ---- /dev/null -+++ b/cmake/modules/AddLLD.cmake -@@ -0,0 +1,45 @@ -+macro(add_lld_library name) -+ add_llvm_library(${name} ${ARGN}) -+ set_target_properties(${name} PROPERTIES FOLDER "lld libraries") -+endmacro(add_lld_library) -+ -+macro(add_lld_executable name) -+ add_llvm_executable(${name} ${ARGN}) -+ set_target_properties(${name} PROPERTIES FOLDER "lld executables") -+endmacro(add_lld_executable) -+ -+macro(add_lld_tool name) -+ if (NOT LLD_BUILD_TOOLS) -+ set(EXCLUDE_FROM_ALL ON) -+ endif() -+ -+ add_lld_executable(${name} ${ARGN}) -+ -+ if (LLD_BUILD_TOOLS) -+ if(${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR -+ NOT LLVM_DISTRIBUTION_COMPONENTS) -+ set(export_to_lldtargets EXPORT lldTargets) -+ set_property(GLOBAL PROPERTY LLD_HAS_EXPORTS True) -+ endif() -+ -+ install(TARGETS ${name} -+ ${export_to_lldtargets} -+ RUNTIME DESTINATION bin -+ COMPONENT ${name}) -+ -+ if(NOT CMAKE_CONFIGURATION_TYPES) -+ add_custom_target(install-${name} -+ DEPENDS ${name} -+ COMMAND "${CMAKE_COMMAND}" -+ -DCMAKE_INSTALL_COMPONENT=${name} -+ -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") -+ endif() -+ set_property(GLOBAL APPEND PROPERTY LLD_EXPORTS ${name}) -+ endif() -+endmacro() -+ -+macro(add_lld_symlink name dest) -+ add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE) -+ # Always generate install targets -+ llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE) -+endmacro() -diff --git a/tools/lld/CMakeLists.txt b/tools/lld/CMakeLists.txt -index 5951da6..0c946a3 100644 ---- a/tools/lld/CMakeLists.txt -+++ b/tools/lld/CMakeLists.txt -@@ -1,4 +1,4 @@ --add_llvm_executable(lld -+add_lld_tool(lld - lld.cpp - ) - -@@ -17,8 +17,5 @@ if(NOT LLD_SYMLINKS_TO_CREATE) - endif() - - foreach(link ${LLD_SYMLINKS_TO_CREATE}) -- add_llvm_tool_symlink(${link} lld ALWAYS_GENERATE) -- # Always generate install targets -- llvm_install_symlink(${link} lld ALWAYS_GENERATE) -+ add_lld_symlink(${link} lld) - endforeach() -- diff --git a/mingw-w64-clang/0401-mingw-w64-hack-and-slash-fixes-for-libc.patch b/mingw-w64-clang/0401-mingw-w64-hack-and-slash-fixes-for-libc.patch index e8c339a2ac..5afce7be74 100644 --- a/mingw-w64-clang/0401-mingw-w64-hack-and-slash-fixes-for-libc.patch +++ b/mingw-w64-clang/0401-mingw-w64-hack-and-slash-fixes-for-libc.patch @@ -1,243 +1,27 @@ -From b45cafc920b84ea40f9760266473c0da2260c58e Mon Sep 17 00:00:00 2001 +From 5ad3d8c960e46a85e6fa3ec457dafdd53394ef77 Mon Sep 17 00:00:00 2001 From: Mateusz Mikula Date: Mon, 20 Mar 2017 18:33:53 +0100 Subject: [PATCH] workarounds to build libc++ with MinGW Based on Martell's patches --- - cmake/Modules/CheckLibcxxAtomic.cmake | 2 +- - cmake/config-ix.cmake | 6 +++++- - include/__config | 5 +++-- - include/locale | 8 ++++++++ - include/support/win32/locale_win32.h | 26 ++++++++++++++++++++------ - include/support/win32/support.h | 5 +++-- - lib/CMakeLists.txt | 2 +- - src/locale.cpp | 2 +- - src/new.cpp | 2 +- - src/support/win32/locale_win32.cpp | 4 ++++ - src/support/win32/support.cpp | 2 ++ - src/system_error.cpp | 2 +- - 12 files changed, 56 insertions(+), 17 deletions(-) + src/support/win32/support.cpp | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) -diff --git a/cmake/Modules/CheckLibcxxAtomic.cmake b/cmake/Modules/CheckLibcxxAtomic.cmake -index a7ae667..4f9de3e 100644 ---- a/cmake/Modules/CheckLibcxxAtomic.cmake -+++ b/cmake/Modules/CheckLibcxxAtomic.cmake -@@ -9,7 +9,7 @@ INCLUDE(CheckCXXSourceCompiles) - - function(check_cxx_atomics varname) - set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) -- set(CMAKE_REQUIRED_FLAGS "-nodefaultlibs -std=c++11 -nostdinc++ -isystem ${LIBCXX_SOURCE_DIR}/include") -+ set(CMAKE_REQUIRED_FLAGS "-std=c++11 -nostdinc++ -isystem ${LIBCXX_SOURCE_DIR}/include") - if (${LIBCXX_GCC_TOOLCHAIN}) - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} --gcc-toolchain=${LIBCXX_GCC_TOOLCHAIN}") - endif() -diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake -index 4f13b78..1590399 100644 ---- a/cmake/config-ix.cmake -+++ b/cmake/config-ix.cmake -@@ -24,7 +24,11 @@ endif() - # required during compilation (which has the -nodefaultlibs). libc is - # required for the link to go through. We remove sanitizers from the - # configuration checks to avoid spurious link errors. --check_cxx_compiler_flag(-nodefaultlibs LIBCXX_SUPPORTS_NODEFAULTLIBS_FLAG) -+if (MINGW) -+ SET(LIBCXX_SUPPORTS_NODEFAULTLIBS_FLAG NO) -+else() -+ check_cxx_compiler_flag(-nodefaultlibs LIBCXX_SUPPORTS_NODEFAULTLIBS_FLAG) -+endif() - if (LIBCXX_SUPPORTS_NODEFAULTLIBS_FLAG) - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs") - if (LIBCXX_HAS_C_LIB) -diff --git a/include/__config b/include/__config -index 340c573..db9b74a 100644 ---- a/include/__config -+++ b/include/__config -@@ -222,7 +222,7 @@ - // including accesses to the special files under /dev. C++11's - // std::random_device is instead exposed through a NaCl syscall. - # define _LIBCPP_USING_NACL_RANDOM --#elif defined(_LIBCPP_WIN32API) -+#elif defined(_MSC_VER) - # define _LIBCPP_USING_WIN32_RANDOM - #else - # define _LIBCPP_USING_DEV_RANDOM -@@ -930,7 +935,8 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container( - defined(__linux__) || \ - defined(__APPLE__) || \ - defined(__CloudABI__) || \ -- defined(__sun__) -+ defined(__sun__) || \ -+ defined(__MINGW32__) - # define _LIBCPP_HAS_THREAD_API_PTHREAD - # elif defined(_LIBCPP_WIN32API) - # define _LIBCPP_HAS_THREAD_API_WIN32 -diff --git a/include/locale b/include/locale -index 9cef429..ad3586a 100644 ---- a/include/locale -+++ b/include/locale -@@ -695,7 +695,11 @@ __num_get_signed_integral(const char* __a, const char* __a_end, - typename remove_reference::type __save_errno = errno; - errno = 0; - char *__p2; -+#ifdef __MINGW32__ -+ long long __ll = strtoll(__a, &__p2, __base); -+#else - long long __ll = strtoll_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE); -+#endif - typename remove_reference::type __current_errno = errno; - if (__current_errno == 0) - errno = __save_errno; -@@ -735,7 +739,11 @@ __num_get_unsigned_integral(const char* __a, const char* __a_end, - typename remove_reference::type __save_errno = errno; - errno = 0; - char *__p2; -+#ifdef __MINGW32__ -+ unsigned long long __ll = strtoull(__a, &__p2, __base); -+#else - unsigned long long __ll = strtoull_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE); -+#endif - typename remove_reference::type __current_errno = errno; - if (__current_errno == 0) - errno = __save_errno; -diff --git a/include/support/win32/locale_win32.h b/include/support/win32/locale_win32.h -index ebf5bda..525cfc7 100644 ---- a/include/support/win32/locale_win32.h -+++ b/include/support/win32/locale_win32.h -@@ -11,7 +11,11 @@ - #ifndef _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H - #define _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H - -+#ifdef __MINGW32__ -+#define _VC_CRT_MAJOR_VERSION 6 -+#else - #include -+#endif - - #if _VC_CRT_MAJOR_VERSION < 14 - // ctype mask table defined in msvcrt.dll -@@ -40,16 +44,26 @@ int wctob_l( wint_t c, locale_t loc ); - inline _LIBCPP_ALWAYS_INLINE - decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l ) - { -+#ifdef __MINGW32__ -+ return MB_CUR_MAX; -+#else - return ___mb_cur_max_l_func(__l); -+#endif - } - -+#ifdef __MINGW32__ -+# define strtod_l _strtod_l -+# define strtof_l _strtod_l -+# define strtold_l _strtod_l -+#else - // the *_l functions are prefixed on Windows, only available for msvcr80+, VS2005+ --#define mbtowc_l _mbtowc_l --#define strtoll_l _strtoi64_l --#define strtoull_l _strtoui64_l --#define strtof_l _strtof_l --#define strtod_l _strtod_l --#define strtold_l _strtold_l -+# define mbtowc_l _mbtowc_l -+# define strtoll_l _strtoi64_l -+# define strtoull_l _strtoui64_l -+# define strtof_l _strtof_l -+# define strtod_l _strtod_l -+# define strtold_l _strtold_l -+#endif - - inline _LIBCPP_INLINE_VISIBILITY - int -diff --git a/include/support/win32/support.h b/include/support/win32/support.h -index f961344..501cd06 100644 ---- a/include/support/win32/support.h -+++ b/include/support/win32/support.h -@@ -37,12 +37,13 @@ extern "C" { - - int vasprintf(char **sptr, const char *__restrict fmt, va_list ap); - int asprintf(char **sptr, const char *__restrict fmt, ...); -+} -+#endif -+ - size_t mbsnrtowcs(wchar_t *__restrict dst, const char **__restrict src, - size_t nmc, size_t len, mbstate_t *__restrict ps); - size_t wcsnrtombs(char *__restrict dst, const wchar_t **__restrict src, - size_t nwc, size_t len, mbstate_t *__restrict ps); --} --#endif // __MINGW32__ - - #if defined(_VC_CRT_MAJOR_VERSION) && _VC_CRT_MAJOR_VERSION < 14 - #define snprintf _snprintf -diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt -index cc3ed16..3c2716f 100644 ---- a/lib/CMakeLists.txt -+++ b/lib/CMakeLists.txt -@@ -101,8 +101,8 @@ endif() - # Setup flags. - if (NOT WIN32) - add_flags_if_supported(-fPIC) -+ add_link_flags_if_supported(-nodefaultlibs) - endif() --add_link_flags_if_supported(-nodefaultlibs) - - if (LIBCXX_OSX_REEXPORT_SYSTEM_ABI_LIBRARY) - if (NOT DEFINED LIBCXX_LIBCPPABI_VERSION) -diff --git a/src/locale.cpp b/src/locale.cpp -index 338ffde..5c44346 100644 ---- a/src/locale.cpp -+++ b/src/locale.cpp -@@ -1114,7 +1114,7 @@ ctype::classic_table() _NOEXCEPT - #if _VC_CRT_MAJOR_VERSION < 14 - // This is assumed to be safe, which is a nonsense assumption because we're - // going to end up dereferencing it later... -- return _ctype+1; // internal ctype mask table defined in msvcrt.dll -+ return (const long unsigned int*)(_ctype + 1); // internal ctype mask table defined in msvcrt.dll - #else - return __pctype_func(); - #endif -diff --git a/src/new.cpp b/src/new.cpp -index b1e8ee3..e57b773 100644 ---- a/src/new.cpp -+++ b/src/new.cpp -@@ -162,7 +162,7 @@ operator new(std::size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC - if (static_cast(alignment) < sizeof(void*)) - alignment = std::align_val_t(sizeof(void*)); - void* p; --#if defined(_LIBCPP_MSVCRT) -+#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__) - while ((p = _aligned_malloc(size, static_cast(alignment))) == nullptr) - #else - while (::posix_memalign(&p, static_cast(alignment), size) != 0) -diff --git a/src/support/win32/locale_win32.cpp b/src/support/win32/locale_win32.cpp -index ee13811..f6ac5ed 100644 ---- a/src/support/win32/locale_win32.cpp -+++ b/src/support/win32/locale_win32.cpp -@@ -13,7 +13,11 @@ - #include - #include - -+#ifdef __MINGW32__ -+#define _VC_CRT_MAJOR_VERSION 6 -+#else - #include -+#endif - - typedef _VSTD::remove_pointer::type __locale_struct; - typedef _VSTD::unique_ptr<__locale_struct, decltype(&uselocale)> __locale_raii; diff --git a/src/support/win32/support.cpp b/src/support/win32/support.cpp -index e989681..0628767 100644 +index dbd1c4c41..fa8cabd65 100644 --- a/src/support/win32/support.cpp +++ b/src/support/win32/support.cpp -@@ -17,6 +17,7 @@ +@@ -15,7 +15,7 @@ + #include // strcpy, wcsncpy + #include // mbstate_t - // Some of these functions aren't standard or if they conform, the name does not. - -+#ifndef __MINGW32__ - int asprintf(char **sptr, const char *__restrict format, ...) - { - va_list ap; -@@ -51,6 +52,7 @@ int vasprintf( char **sptr, const char *__restrict format, va_list ap ) +- ++#ifndef __MINGW64_VERSION_MAJOR + // Like sprintf, but when return value >= 0 it returns + // a pointer to a malloc'd string in *sptr. + // If return >= 0, use free to delete *sptr. +@@ -40,6 +40,7 @@ int vasprintf( char **sptr, const char *__restrict format, va_list ap ) *sptr = p; return count; } @@ -245,18 +29,6 @@ index e989681..0628767 100644 // Returns >= 0: the number of wide characters found in the // multi byte sequence src (of src_size_bytes), that fit in the buffer dst -diff --git a/src/system_error.cpp b/src/system_error.cpp -index c547124..42171ef 100644 ---- a/src/system_error.cpp -+++ b/src/system_error.cpp -@@ -65,7 +65,7 @@ constexpr size_t strerror_buff_size = 1024; - - string do_strerror_r(int ev); - --#if defined(_LIBCPP_MSVCRT) -+#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__) - string do_strerror_r(int ev) { - char buffer[strerror_buff_size]; - if (::strerror_s(buffer, strerror_buff_size, ev) == 0) -- -2.12.0 +2.14.1.windows.1 + diff --git a/mingw-w64-clang/0501-fixes-to-get-lldb-building.patch b/mingw-w64-clang/0501-fixes-to-get-lldb-building.patch new file mode 100644 index 0000000000..42dce581e2 --- /dev/null +++ b/mingw-w64-clang/0501-fixes-to-get-lldb-building.patch @@ -0,0 +1,172 @@ +From b8a3387eee86d609b18ac880e7897252de62a0c5 Mon Sep 17 00:00:00 2001 +From: Mateusz Mikula +Date: Fri, 15 Sep 2017 15:03:12 +0200 +Subject: [PATCH] fixes to get lldb building + +--- + cmake/LLDBDependencies.cmake | 6 ++++++ + include/lldb/Host/windows/PosixApi.h | 14 ++++++++++---- + include/lldb/Host/windows/windows.h | 4 ++++ + source/Host/common/MainLoop.cpp | 1 + + source/Host/windows/Windows.cpp | 3 +++ + .../gdb-remote/GDBRemoteCommunicationServerPlatform.cpp | 1 + + source/Plugins/Process/gdb-remote/ProcessGDBRemote.h | 1 + + tools/lldb-mi/MIDataTypes.h | 2 ++ + tools/lldb-mi/Platform.h | 4 ++++ + 9 files changed, 32 insertions(+), 4 deletions(-) + +diff --git a/cmake/LLDBDependencies.cmake b/cmake/LLDBDependencies.cmake +index 55ce379..ae65ebe 100644 +--- a/cmake/LLDBDependencies.cmake ++++ b/cmake/LLDBDependencies.cmake +@@ -6,6 +6,12 @@ if ( CMAKE_SYSTEM_NAME MATCHES "Windows" ) + ws2_32 + rpcrt4 + ) ++ if (MINGW) ++ list(APPEND LLDB_SYSTEM_LIBS ++ dbghelp ++ psapi ++ ) ++ endif () + endif () + + if (NOT LLDB_DISABLE_LIBEDIT) +diff --git a/include/lldb/Host/windows/PosixApi.h b/include/lldb/Host/windows/PosixApi.h +index de70266..51fba95 100644 +--- a/include/lldb/Host/windows/PosixApi.h ++++ b/include/lldb/Host/windows/PosixApi.h +@@ -73,13 +73,9 @@ typedef uint32_t pid_t; + #define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR) + #endif + +-#endif // _MSC_VER +- + // Various useful posix functions that are not present in Windows. We provide + // custom implementations. + int vasprintf(char **ret, const char *fmt, va_list ap); +-char *strcasestr(const char *s, const char *find); +-char *realpath(const char *name, char *resolved); + + int usleep(uint32_t useconds); + char *basename(char *path); +@@ -88,6 +84,16 @@ char *dirname(char *path); + int strcasecmp(const char *s1, const char *s2); + int strncasecmp(const char *s1, const char *s2, size_t n); + ++#elif __MINGW64_VERSION_MAJOR ++ ++// pid_t definition ++#include ++ ++#endif ++ ++char *strcasestr(const char *s, const char *find); ++char *realpath(const char *name, char *resolved); ++ + // empty functions + inline int posix_openpt(int flag) { LLVM_BUILTIN_UNREACHABLE; } + +diff --git a/include/lldb/Host/windows/windows.h b/include/lldb/Host/windows/windows.h +index 3dc9f77..ca138c1 100644 +--- a/include/lldb/Host/windows/windows.h ++++ b/include/lldb/Host/windows/windows.h +@@ -28,4 +28,8 @@ + #define FAR + #define NEAR + ++#ifndef _MSC_VER ++#include ++#endif ++ + #endif // LLDB_lldb_windows_h_ +diff --git a/source/Host/common/MainLoop.cpp b/source/Host/common/MainLoop.cpp +index d0e0d00..cd1d4a8 100644 +--- a/source/Host/common/MainLoop.cpp ++++ b/source/Host/common/MainLoop.cpp +@@ -27,6 +27,7 @@ + #if HAVE_SYS_EVENT_H + #include + #elif defined(LLVM_ON_WIN32) ++#include "lldb/Host/windows/windows.h" + #include + #else + #include +diff --git a/source/Host/windows/Windows.cpp b/source/Host/windows/Windows.cpp +index 9d0e70e..aaf06b0 100644 +--- a/source/Host/windows/Windows.cpp ++++ b/source/Host/windows/Windows.cpp +@@ -43,6 +43,8 @@ bool wideToUtf8(const wchar_t *wide, char *buf, size_t bufSize) { + } + } + ++#ifdef _MSC_VER ++ + int vasprintf(char **ret, const char *fmt, va_list ap) { + char *buf; + int len; +@@ -69,6 +71,7 @@ int vasprintf(char **ret, const char *fmt, va_list ap) { + va_end(ap2); + return len; + } ++#endif + + char *strcasestr(const char *s, const char *find) { + char c, sc; +diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp +index 977c34c..9bec1d8 100644 +--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp ++++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp +@@ -12,6 +12,7 @@ + #include + + // C Includes ++#include + // C++ Includes + #include + #include +diff --git a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h +index 54a472d..196e012 100644 +--- a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h ++++ b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h +@@ -11,6 +11,7 @@ + #define liblldb_ProcessGDBRemote_h_ + + // C Includes ++#include + // C++ Includes + #include + #include +diff --git a/tools/lldb-mi/MIDataTypes.h b/tools/lldb-mi/MIDataTypes.h +index 34fe457..8372e8c 100644 +--- a/tools/lldb-mi/MIDataTypes.h ++++ b/tools/lldb-mi/MIDataTypes.h +@@ -19,6 +19,8 @@ + // Windows headers: + #ifdef _WIN32 + ++#include ++ + // Debugging: + #ifdef _DEBUG + #include // C-runtime debugging library (defines _ASSERT). +diff --git a/tools/lldb-mi/Platform.h b/tools/lldb-mi/Platform.h +index ce2de1b..d334d75 100644 +--- a/tools/lldb-mi/Platform.h ++++ b/tools/lldb-mi/Platform.h +@@ -78,8 +78,12 @@ typedef void (*sighandler_t)(int); + + #include + #include ++ ++#ifndef __MINGW64_VERSION_MAJOR + #include + #include ++#endif ++ + #include + + #include +-- +2.14.1.windows.1 + diff --git a/mingw-w64-clang/0501-minor-fixes-to-get-lldb-building.patch b/mingw-w64-clang/0501-minor-fixes-to-get-lldb-building.patch deleted file mode 100644 index 59262d9939..0000000000 --- a/mingw-w64-clang/0501-minor-fixes-to-get-lldb-building.patch +++ /dev/null @@ -1,130 +0,0 @@ -From 273fab668205311f4850fc025f7735f1019392a1 Mon Sep 17 00:00:00 2001 -From: Mateusz Mikula -Date: Thu, 16 Feb 2017 00:37:27 +0100 -Subject: [PATCH] hacky changes to get lldb building - ---- - cmake/LLDBDependencies.cmake | 6 ++++++ - include/lldb/Host/windows/PosixApi.h | 18 +++++++++++------- - source/Host/windows/Windows.cpp | 2 ++ - tools/lldb-mi/MIDataTypes.h | 7 +++++++ - tools/lldb-mi/Platform.h | 4 ++++ - 5 files changed, 30 insertions(+), 7 deletions(-) - -diff --git a/cmake/LLDBDependencies.cmake b/cmake/LLDBDependencies.cmake -index e12a52268..53b348caa 100644 ---- a/cmake/LLDBDependencies.cmake -+++ b/cmake/LLDBDependencies.cmake -@@ -94,6 +94,12 @@ if ( CMAKE_SYSTEM_NAME MATCHES "Windows" ) - ws2_32 - rpcrt4 - ) -+ if (MINGW) -+ list(APPEND LLDB_USED_LIBS -+ dbghelp -+ psapi -+ ) -+ endif () - endif () - - # Linux-only libraries -diff --git a/include/lldb/Host/windows/PosixApi.h b/include/lldb/Host/windows/PosixApi.h -index 4f2573781..519038296 100644 ---- a/include/lldb/Host/windows/PosixApi.h -+++ b/include/lldb/Host/windows/PosixApi.h -@@ -73,23 +73,27 @@ typedef uint32_t pid_t; - #define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR) - #endif - --#endif // _MSC_VER -+#elif __MINGW64_VERSION_MAJOR -+#include -+#endif - - // Various useful posix functions that are not present in Windows. We provide - // custom implementations. -+#ifndef __MINGW64_VERSION_MAJOR -+int chdir(const char *path); -+char *getcwd(char *path, int max); - int vasprintf(char **ret, const char *fmt, va_list ap); -+int usleep(uint32_t useconds); -+int strcasecmp(const char *s1, const char *s2); -+int strncasecmp(const char *s1, const char *s2, size_t n); -+#endif -+ - char *strcasestr(const char *s, const char *find); - char *realpath(const char *name, char *resolved); - --int usleep(uint32_t useconds); --char *getcwd(char *path, int max); --int chdir(const char *path); - char *basename(char *path); - char *dirname(char *path); - --int strcasecmp(const char *s1, const char *s2); --int strncasecmp(const char *s1, const char *s2, size_t n); -- - // empty functions - inline int posix_openpt(int flag) { LLVM_BUILTIN_UNREACHABLE; } - -diff --git a/source/Host/windows/Windows.cpp b/source/Host/windows/Windows.cpp -index 21afc6d85..4f75442e1 100644 ---- a/source/Host/windows/Windows.cpp -+++ b/source/Host/windows/Windows.cpp -@@ -50,6 +50,7 @@ bool wideToUtf8(const wchar_t *wide, char *buf, size_t bufSize) { - } - } - -+#ifndef __MINGW64_VERSION_MAJOR - int vasprintf(char **ret, const char *fmt, va_list ap) { - char *buf; - int len; -@@ -76,6 +77,7 @@ int vasprintf(char **ret, const char *fmt, va_list ap) { - va_end(ap2); - return len; - } -+#endif - - char *strcasestr(const char *s, const char *find) { - char c, sc; -diff --git a/tools/lldb-mi/MIDataTypes.h b/tools/lldb-mi/MIDataTypes.h -index 34fe45751..5522201d6 100644 ---- a/tools/lldb-mi/MIDataTypes.h -+++ b/tools/lldb-mi/MIDataTypes.h -@@ -40,9 +40,16 @@ const bool failure = false; - - // Portability issues - #ifdef _WIN64 -+# ifdef _MSC_VER - typedef unsigned __int64 size_t; - typedef __int64 MIint; - typedef unsigned __int64 MIuint; -+# else -+# include -+typedef uint64_t size_t; -+typedef int64_t MIint; -+typedef uint64_t MIuint; -+# endif - #else - #ifdef _WIN32 - typedef unsigned int size_t; -diff --git a/tools/lldb-mi/Platform.h b/tools/lldb-mi/Platform.h -index 1b6ff5549..147bb57a4 100644 ---- a/tools/lldb-mi/Platform.h -+++ b/tools/lldb-mi/Platform.h -@@ -79,8 +79,12 @@ typedef void (*sighandler_t)(int); - - #include - #include -+ -+#ifndef __MINGW64_VERSION_MAJOR - #include - #include -+#endif -+ - #include - - #include --- -2.12.0 - diff --git a/mingw-w64-clang/0502-hack-to-use-64-bit-time-for-mingw.patch b/mingw-w64-clang/0502-hack-to-use-64-bit-time-for-mingw.patch index e72daf21cb..3c161a65ce 100644 --- a/mingw-w64-clang/0502-hack-to-use-64-bit-time-for-mingw.patch +++ b/mingw-w64-clang/0502-hack-to-use-64-bit-time-for-mingw.patch @@ -1,12 +1,12 @@ -diff -urN lldb-3.9.0.src.orig/source/Host/windows/FileSystem.cpp lldb-3.9.0.src/source/Host/windows/FileSystem.cpp ---- lldb-3.9.0.src.orig/source/Host/windows/FileSystem.cpp 2016-03-22 18:58:09.000000000 +0100 -+++ lldb-3.9.0.src/source/Host/windows/FileSystem.cpp 2016-11-10 01:55:34.663530600 +0100 -@@ -276,7 +276,7 @@ - return -EINVAL; - } - int stat_result; --#ifdef _USE_32BIT_TIME_T -+#if defined(_USE_32BIT_TIME_T) && !defined(__MINGW64_VERSION_MAJOR) - struct _stat32 file_stats; - stat_result = ::_wstat32(wpath.c_str(), &file_stats); - #else +diff -urN lldb-3.9.0.src.orig/source/Host/windows/FileSystem.cpp lldb-3.9.0.src/source/Host/windows/FileSystem.cpp +--- lldb-3.9.0.src.orig/source/Host/windows/FileSystem.cpp 2016-03-22 18:58:09.000000000 +0100 ++++ lldb-3.9.0.src/source/Host/windows/FileSystem.cpp 2016-11-10 01:55:34.663530600 +0100 +@@ -276,7 +276,7 @@ + return -EINVAL; + } + int stat_result; +-#ifdef _USE_32BIT_TIME_T ++#if defined(_USE_32BIT_TIME_T) && !defined(__MINGW64_VERSION_MAJOR) + struct _stat32 file_stats; + stat_result = ::_wstat32(wpath.c_str(), &file_stats); + #else \ No newline at end of file diff --git a/mingw-w64-clang/0601-libunwind-add-support-for-mingw-w64.patch b/mingw-w64-clang/0601-libunwind-add-support-for-mingw-w64.patch index eca72b9974..0a89339ccb 100644 --- a/mingw-w64-clang/0601-libunwind-add-support-for-mingw-w64.patch +++ b/mingw-w64-clang/0601-libunwind-add-support-for-mingw-w64.patch @@ -1,17 +1,42 @@ -From dfe4f4533d720f2e057f35b104b3fd50cf9d0f32 Mon Sep 17 00:00:00 2001 +From 8d0335a3e369eca60ff53c5a6a0936aafcaaf13b Mon Sep 17 00:00:00 2001 From: Mateusz Mikula Date: Fri, 17 Mar 2017 21:20:49 +0100 Subject: [PATCH] libunwind add support for mingw-w64 --- - include/unwind.h | 2 +- - src/AddressSpace.hpp | 15 ++++++++------- - src/assembly.h | 2 ++ - src/config.h | 16 +++++++++++++++- - 4 files changed, 26 insertions(+), 9 deletions(-) + cmake/config-ix.cmake | 13 +++++++++++++ + include/unwind.h | 2 +- + src/AddressSpace.hpp | 10 ++++++---- + src/assembly.h | 2 ++ + src/config.h | 10 ++++++++-- + 5 files changed, 30 insertions(+), 7 deletions(-) +diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake +index 40a5dd1..e2041af 100644 +--- a/cmake/config-ix.cmake ++++ b/cmake/config-ix.cmake +@@ -29,6 +29,19 @@ if (LIBUNWIND_HAS_NODEFAULTLIBS_FLAG) + elseif (LIBUNWIND_HAS_GCC_S_LIB) + list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s) + endif () ++ if (MINGW) ++ # Mingw64 requires quite a few "C" runtime libraries in order for basic ++ # programs to link successfully with -nodefaultlibs. ++ if (LIBUNWIND_USE_COMPILER_RT) ++ set(MINGW_RUNTIME ${LIBUNWIND_BUILTINS_LIBRARY}) ++ else () ++ set(MINGW_RUNTIME gcc_s gcc) ++ endif() ++ set(MINGW_LIBRARIES mingw32 ${MINGW_RUNTIME} moldname mingwex msvcrt advapi32 ++ shell32 user32 kernel32 mingw32 ${MINGW_RUNTIME} ++ moldname mingwex msvcrt) ++ list(APPEND CMAKE_REQUIRED_LIBRARIES ${MINGW_LIBRARIES}) ++ endif() + if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all") + endif () diff --git a/include/unwind.h b/include/unwind.h -index 1d163ca..e54f39d 100644 +index fc7d122..db10654 100644 --- a/include/unwind.h +++ b/include/unwind.h @@ -122,7 +122,7 @@ struct _Unwind_Exception { @@ -24,7 +49,7 @@ index 1d163ca..e54f39d 100644 // above fields which has the side effect of causing this whole struct to // round up to 32 bytes in size. To be more explicit, we add pad fields diff --git a/src/AddressSpace.hpp b/src/AddressSpace.hpp -index 67aa664..f61e620 100644 +index 2ed52a5..b18851f 100644 --- a/src/AddressSpace.hpp +++ b/src/AddressSpace.hpp @@ -18,7 +18,7 @@ @@ -36,7 +61,7 @@ index 67aa664..f61e620 100644 #include #endif -@@ -109,7 +109,7 @@ struct UnwindInfoSections { +@@ -68,7 +68,7 @@ struct UnwindInfoSections { /// making local unwinds fast. class __attribute__((visibility("hidden"))) LocalAddressSpace { public: @@ -45,32 +70,7 @@ index 67aa664..f61e620 100644 typedef uint64_t pint_t; typedef int64_t sint_t; #else -@@ -161,7 +161,7 @@ public: - }; - - inline uintptr_t LocalAddressSpace::getP(pint_t addr) { --#ifdef __LP64__ -+#if defined(__LP64__) || defined(_WIN64) - return get64(addr); - #else - return get32(addr); -@@ -306,7 +306,7 @@ LocalAddressSpace::getEncodedP(pint_t &addr, pint_t end, uint8_t encoding, - return result; - } - --#ifdef __APPLE__ -+#ifdef __APPLE__ - struct dyld_unwind_sections - { - const struct mach_header* mh; -@@ -324,13 +324,13 @@ LocalAddressSpace::getEncodedP(pint_t &addr, pint_t end, uint8_t encoding, - // In 10.6.x and earlier, we need to implement this functionality. Note - // that this requires a newer version of libmacho (from cctools) than is - // present in libSystem on 10.6.x (for getsectiondata). -- static inline bool _dyld_find_unwind_sections(void* addr, -+ static inline bool _dyld_find_unwind_sections(void* addr, - dyld_unwind_sections* info) { - // Find mach-o image containing address. +@@ -290,7 +290,7 @@ LocalAddressSpace::getEncodedP(pint_t &addr, pint_t end, uint8_t encoding, Dl_info dlinfo; if (!dladdr(addr, &dlinfo)) return false; @@ -79,15 +79,17 @@ index 67aa664..f61e620 100644 const struct mach_header_64 *mh = (const struct mach_header_64 *)dlinfo.dli_fbase; #else const struct mach_header *mh = (const struct mach_header *)dlinfo.dli_fbase; -@@ -445,6 +445,7 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr, - }, - &cb_data); - return static_cast(found); -+#elif defined(_WIN32) - #else - #error "_LIBUNWIND_SUPPORT_DWARF_UNWIND requires _LIBUNWIND_SUPPORT_DWARF_INDEX on this platform." +@@ -327,7 +327,9 @@ extern char __exidx_end; + // independent ELF header traversal is not provided by on some + // systems (e.g., FreeBSD). On these systems the data structures are + // just called Elf_XXX. Define ElfW() locally. ++#ifndef _WIN32 + #include ++#endif + #if !defined(ElfW) + #define ElfW(type) Elf_##type #endif -@@ -468,7 +469,7 @@ inline bool LocalAddressSpace::findOtherFDE(pint_t targetAddr, pint_t &fde) { +@@ -478,7 +480,7 @@ inline bool LocalAddressSpace::findOtherFDE(pint_t targetAddr, pint_t &fde) { inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf, size_t bufLen, unw_word_t *offset) { @@ -97,7 +99,7 @@ index 67aa664..f61e620 100644 if (dladdr((void *)addr, &dyldInfo)) { if (dyldInfo.dli_sname != NULL) { diff --git a/src/assembly.h b/src/assembly.h -index 9fb9905..6391f22 100644 +index d28cbc9..df55679 100644 --- a/src/assembly.h +++ b/src/assembly.h @@ -26,6 +26,8 @@ @@ -110,41 +112,36 @@ index 9fb9905..6391f22 100644 #define HIDDEN_DIRECTIVE .hidden #endif diff --git a/src/config.h b/src/config.h -index 4e4dd99..f6002af 100644 +index ac8d7d9..07e7c1a 100644 --- a/src/config.h +++ b/src/config.h -@@ -40,6 +40,16 @@ +@@ -37,6 +37,13 @@ + #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 - #define _LIBUNWIND_SUPPORT_DWARF_INDEX 0 #endif +#elif defined(_WIN32) + // #define _LIBUNWIND_BUILD_SJLJ_APIS + // #define _LIBUNWIND_SUPPORT_FRAME_APIS + #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 1 -+ #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 ++ // #define _LIBUNWIND_SUPPORT_DWARF_UNWIND + // #define _LIBUNWIND_SUPPORT_DWARF_INDEX + #define bzero(s,n) memset(s,0,n) -+ // libcxx may have defined __USE_MINGW_ANSI_STDIO. -+ // Here we would like to get the regular versions, not the _mingw ones. -+ #undef __USE_MINGW_ANSI_STDIO #else #if defined(__ARM_DWARF_EH__) || !defined(__arm__) - #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 0 -@@ -52,9 +62,13 @@ + #define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1 +@@ -44,11 +51,10 @@ #endif #endif --// FIXME: these macros are not correct for COFF targets -+#if defined(_WIN32) -+#define _LIBUNWIND_EXPORT -+#define _LIBUNWIND_HIDDEN -+#else - #define _LIBUNWIND_EXPORT __attribute__((visibility("default"))) - #define _LIBUNWIND_HIDDEN __attribute__((visibility("hidden"))) -+#endif - - #if (defined(__APPLE__) && defined(__arm__)) || defined(__USING_SJLJ_EXCEPTIONS__) - #define _LIBUNWIND_BUILD_SJLJ_APIS 1 +-#if defined(_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS) ++#if defined(_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS) || defined(_WIN32) + #define _LIBUNWIND_EXPORT + #define _LIBUNWIND_HIDDEN + #else +- // FIXME: these macros are not correct for COFF targets + #define _LIBUNWIND_EXPORT __attribute__((visibility("default"))) + #define _LIBUNWIND_HIDDEN __attribute__((visibility("hidden"))) + #endif -- -2.12.0 +2.14.1 diff --git a/mingw-w64-clang/0701-fix-visibility-for-libc-abi-on-win32.patch b/mingw-w64-clang/0701-fix-visibility-for-libc-abi-on-win32.patch deleted file mode 100644 index 693f5f154c..0000000000 --- a/mingw-w64-clang/0701-fix-visibility-for-libc-abi-on-win32.patch +++ /dev/null @@ -1,36 +0,0 @@ -From a5908c964e8d40c084a912ec1ecfd45127c732d0 Mon Sep 17 00:00:00 2001 -From: Mateusz Mikula -Date: Mon, 20 Mar 2017 18:44:00 +0100 -Subject: [PATCH] fix visibility for libc++abi on win32 - ---- - src/private_typeinfo.h | 4 ++++ - 1 file changed, 4 insertions(+) - -diff --git a/src/private_typeinfo.h b/src/private_typeinfo.h -index f3d3e1d..99651a7 100644 ---- a/src/private_typeinfo.h -+++ b/src/private_typeinfo.h -@@ -16,7 +16,9 @@ - #include - - namespace __cxxabiv1 { -+#ifndef _WIN32 - #pragma GCC visibility push(hidden) -+#endif - - class _LIBCXXABI_TYPE_VIS __shim_type_info : public std::type_info { - public: -@@ -248,7 +250,9 @@ public: - _LIBCXXABI_HIDDEN bool can_catch_nested(const __shim_type_info *) const; - }; - -+#ifndef _WIN32 - #pragma GCC visibility pop -+#endif - - } // __cxxabiv1 - --- -2.12.0 - diff --git a/mingw-w64-clang/0801-Don-t-build-LLVMPolly-on-WIN32.patch b/mingw-w64-clang/0801-Don-t-build-LLVMPolly-on-WIN32.patch new file mode 100644 index 0000000000..de4568e041 --- /dev/null +++ b/mingw-w64-clang/0801-Don-t-build-LLVMPolly-on-WIN32.patch @@ -0,0 +1,39 @@ +From fbb0c64cb855fbc25c0420aea712ed1390a6ecba Mon Sep 17 00:00:00 2001 +From: Mateusz Mikula +Date: Fri, 15 Sep 2017 14:25:27 +0200 +Subject: [PATCH] Don't build LLVMPolly on WIN32 + +--- + cmake/CMakeLists.txt | 2 +- + lib/CMakeLists.txt | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt +index 969292c..2c7d81a 100644 +--- a/cmake/CMakeLists.txt ++++ b/cmake/CMakeLists.txt +@@ -10,7 +10,7 @@ else() + endif() + + set(POLLY_CONFIG_EXPORTED_TARGETS Polly ${ISL_TARGET}) +-if (NOT MSVC) ++if (NOT WIN32) + # LLVMPolly is a dummy target on Win + list(APPEND POLLY_CONFIG_EXPORTED_TARGETS LLVMPolly) + endif() +diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt +index 1141de5..3e0a8bc 100644 +--- a/lib/CMakeLists.txt ++++ b/lib/CMakeLists.txt +@@ -119,7 +119,7 @@ endif () + + # Create a loadable module Polly.so that can be loaded using + # LLVM's/clang's "-load" option. +-if (MSVC) ++if (WIN32) + # Add dummy target, because loadable modules are not supported on Windows + add_custom_target(LLVMPolly) + set_target_properties(LLVMPolly PROPERTIES FOLDER "Polly") +-- +2.14.1.windows.1 + diff --git a/mingw-w64-clang/PKGBUILD b/mingw-w64-clang/PKGBUILD index d23d8244cd..595ed1ec0b 100644 --- a/mingw-w64-clang/PKGBUILD +++ b/mingw-w64-clang/PKGBUILD @@ -4,9 +4,8 @@ # Contributor: Mateusz MikuĊ‚a # Contributor: wirx6 -# choose the compiler that will be used to build clang -# clang is fine but there are problems with libcxxabi -_compiler=gcc # clang, gcc +# We can switch to clang when it fully works with mingw-w64 +#_compiler=clang _realname=clang pkgbase=mingw-w64-${_realname} @@ -21,7 +20,7 @@ pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}" "${MINGW_PACKAGE_PREFIX}-llvm" "${MINGW_PACKAGE_PREFIX}-lldb" "${MINGW_PACKAGE_PREFIX}-polly") -pkgver=4.0.0 +pkgver=5.0.0 pkgrel=1 pkgdesc="C language family frontend for LLVM (mingw-w64)" arch=('any') @@ -49,32 +48,24 @@ source=(https://llvm.org/releases/${pkgver}/llvm-${pkgver}.src.tar.xz{,.sig} https://llvm.org/releases/${pkgver}/lldb-${pkgver}.src.tar.xz{,.sig} https://llvm.org/releases/${pkgver}/libunwind-${pkgver}.src.tar.xz{,.sig} https://llvm.org/releases/${pkgver}/polly-${pkgver}.src.tar.xz{,.sig} - "0001-genlib-named-as-llvm-dlltool.patch" - "0002-mingw-w64-use-MSVC-style-ByteAlignment.patch" - "0003-Fix-GetHostTriple-for-mingw-w64-in-msys.patch" - "0004-Globally-provide-DESTDIR-for-all-platforms.patch" - "0005-not-install-msvc-files.patch" - "0006-llvm-config-look-for-unversioned-shared-lib-on-win32.patch" - "0007-add-pthread-as-system-lib-for-mingw.patch" - "0008-fix-bugpoint-multiple-definition.patch" - "0101-mingw-w64-enable-support-for-__declspec-selectany.patch" - "0102-Allow-build-static-clang-library-for-mingw.patch" - "0103-fix-libclang-name-for-mingw.patch" - "0104-don-t-use-GCC-headers.patch" - "0105-Set-the-x86-arch-name-to-i686-for-mingw-w64.patch" - "0106-link-pthread-with-mingw.patch" - "0107-enable-__float128-for-X86-MinGW.patch" - "0108-Don-t-create-cl-executable-for-mingw.patch" - "0109-use-emulated-tls-with-mingw.patch" + "0001-mingw-w64-use-MSVC-style-ByteAlignment.patch" + "0002-Fix-GetHostTriple-for-mingw-w64-in-msys.patch" + "0003-Globally-provide-DESTDIR-for-all-platforms.patch" + "0004-llvm-config-look-for-unversioned-shared-lib-on-win32.patch" + "0005-add-pthread-as-system-lib-for-mingw.patch" + "0006-fix-bugpoint-multiple-definition.patch" + "0101-Allow-build-static-clang-library-for-mingw.patch" + "0102-fix-libclang-name-for-mingw.patch" + "0103-Set-the-x86-arch-name-to-i686-for-mingw-w64.patch" + "0104-link-pthread-with-mingw.patch" + "0105-use-emulated-tls-with-mingw.patch" "0201-mingw-w64-__udivdi3-mangle-hack.patch" "0202-compiler-rt-fix-mingw-build.patch" - "0301-COFF-gnu-driver-support.patch" - "0302-add-install-target-for-the-lld-tool.patch" "0401-mingw-w64-hack-and-slash-fixes-for-libc.patch" - "0501-minor-fixes-to-get-lldb-building.patch" + "0501-fixes-to-get-lldb-building.patch" "0502-hack-to-use-64-bit-time-for-mingw.patch" "0601-libunwind-add-support-for-mingw-w64.patch" - "0701-fix-visibility-for-libc-abi-on-win32.patch") + "0801-Don-t-build-LLVMPolly-on-WIN32.patch") # Some patch notes :) #0001-0099 -> llvm #0101-0199 -> clang @@ -84,54 +75,47 @@ source=(https://llvm.org/releases/${pkgver}/llvm-${pkgver}.src.tar.xz{,.sig} #0501-0599 -> lldb #0601-0699 -> libunwind #0701-0799 -> libc++abi -sha256sums=('8d10511df96e73b8ff9e7abbfb4d4d432edbdbe965f1f4f07afaf370b8a533be' +#0801-0899 -> polly +sha256sums=('e35dcbae6084adcf4abb32514127c5eabd7d63b733852ccdb31e06f1373136da' 'SKIP' - 'cea5f88ebddb30e296ca89130c83b9d46c2d833685e2912303c828054c4dc98a' + '019f23c2192df793ac746595e94a403908749f8e0c484b403476d2611dd20970' 'SKIP' - 'd3f25b23bef24c305137e6b44f7e81c51bbec764c119e01512a9bd2330be3115' + 'd5ad5266462134a482b381f1f8115b6cad3473741b3bb7d1acc7f69fd0f0c0b3' 'SKIP' - '31544baafbee0d6c652637f6dfa19ca91afe5ca577e07752f4b2c23656bc6304' + 'e96c8a6150b3538be43279a44f8a3e7b74e4bd324255537ba3017ce74304cdad' 'SKIP' - '4f4d33c4ad69bf9e360eebe6b29b7b19486948b1a41decf89d4adec12473cf96' + 'eae5981e9a21ef0decfcac80a1af584ddb064a32805f95a57c7c83a5eb28c9b1' 'SKIP' - 'dca9cb619662ad2d3a0d685c4366078345247218c3702dd35bcaaa23f63481d8' + '176918c7eb22245c3a5c56ef055e4d69f5345b4a98833e0e8cb1a19cab6b8911' 'SKIP' - '41b7d37eb128fd362ab3431be5244cf50325bb3bb153895735c5bacede647c99' + '87d078b959c4a6e5ff9fd137c2f477cadb1245f93812512996f73986a6d973c6' 'SKIP' - '33e06457b9ce0563c89b11ccc7ccabf9cff71b83571985a5bf8684c9150e7502' + '399a7920a5278d42c46a7bf7e4191820ec2301457a7d0d4fcc9a4ac05dd53897' 'SKIP' - '2dbd8f05c662c1c9f11270fc9d0c63b419ddc988095e0ad107ed911cf882033d' + 'c0a0ca32105e9881d86b7ca886220147e686edc97fdb9f3657c6659dc6568b7d' 'SKIP' - '0755efa9f969373d4d543123bbed4b3f9a835f6302875c1379c5745857725973' + '9a70e2333d54f97760623d89512c4831d6af29e78b77a33d824413ce98587f6f' 'SKIP' - '27a5dbf95e8aa9e0bbe3d6c5d1e83c92414d734357aa0d6c16020a65dc4dcd97' + '44694254a2b105cec13ce0560f207e8552e6116c181b8d21bda728559cf67042' 'SKIP' - '3f55d2114805110e370fab6630763c359d83b07c356f61b86afc32feb7cf7514' - '78b6951956360a8e05fdc7020bc7e1996da75b499022f9213465070fc238529c' - 'aceffb61d57c7c01bc2d9d5461f961df26cffdffaaabb8dda9f219acfe59c77a' - 'bccdb99553424121927b3f82086efb2adeee230f18944504ddd93d2d72371d5c' - 'c840f4e2286385c4ab3503c02976fd2459516fdc05e44f702d648afaaaebd97f' - 'f06f57af203811f6a4c62ac3f1e4545628db13185f5e7d3225d4b1104ca69be1' - 'c57d5f2904158b992378906bcddbae79d0566cdb07cc74fbd9b2d76d52661a12' - '5d1fbbe39221af57ae078e5387f43fec602541838b3608cd3f6517bb2364ae54' - 'afdd708e2431874da4e03d9f51848840ec30ef64b4d440c8dfd50446b2f5ce1a' - '8ba3968939f9a7c6a51849aaf1ab6126f85aa612349570b3644f855929d496fc' - '1740ffa1d23fdee2b147a46cfed4d186bf7d3dc626bb3a1d3ca925147895a2d4' - 'e8c8ebbcc7353548974e640b76bfe13d6b89afc832066e0d7156fe242b561a93' - '066e61c097fcad202b3b4f26dbe667719a9f5ae872837250629d69fe06bd1af1' - 'cae561cb643daeb68e9ec2716928ba79b459ec2064829e54ecd1edcc378d293b' - '8a636174bff1a05872777b935e27c15c3b87683b57c4277de0d1e9ecc1ca5548' - 'f2931ac1ebcc33faa1fa320ebe76143baf9d7635f4819e0f9e37924e70f30d39' - '9f9a12749869bb6c5817d6d5231417195c2e3bd80c10059b3f3e70b010159c26' - 'fb1ef06b26e88d37d52c3e0b3b261089e92bb7c08231ec8fa234465fdbdab308' - '29e61097ca4f9b1df304e1e7a8f65e6d8ed452e9eb88d9d8cc6ff78b64d84aa8' - '852d55907b469739fca96b043e41c596824ad9d933268ce65a82100b975e91fb' - '0f2cf89298303911a20e9cee7208ed418d91cf700af611a142dc735c708e1435' - '84e929fd0f59a90f8c46cf831f420a36e5e4dff359f2ae9338c42ea20f1243d7' - '5782b351170ab747c046efb79244a36de2c531014d5b719e7398f1597a10b948' - 'fbb5f936a0c23529a7ec43d458ea22c033a6c84c2017178ad3645b03d8584bcf' - '1ebe995823d427177bf79c4c73e205f708c58e25616b4183d5981a1b4c8130e0' - 'eecb723ed6fa59d9debd84a11bcede607020beadfdd0988778392dd7a1820963') + 'd5b11097084f8a03dd3002c2adb27b4fec99cf290404049f1a4e1185274bde67' + '5081a1a9d8074b275f3087d4d80a13ce5d1c20bc1962819953790e54275930c8' + '46e10ce71525836d67466af954542c7133b646d7cc81dc30388f42dc27c7a6d6' + 'ef273f4b3abb2e0ee5c452362fe82195c3f1787bd6788ed24234aaf8180a015e' + '5303e8a2d64a4c08a2088a3610d74cfda3adbf5fdf172c4ca1f0ddc8701e3cf2' + 'f6e04b5e2a65e1eaa4ab6d14427cf17b1e79625a428430dd16a441578b31df55' + '8599e0ca38c96cff811a17f0cffd9ff970632a0357ae8e6076b4dff03a18182c' + '1e602bc8d51e77942e0ea7bb6174f8c2256817887dca8d941bba063c06d6845d' + '1bbc52f951eb1a1162b8c01a3a951b1da8612572d346d603272229bd84c4d2e3' + '47621da0a866702525429fbe4b584eb5d719a93b249a90c0e7dbdfc2cf33ab44' + '4260da29db788e478503bcf3e3b1522991be3545828776cf7bc94df48f484328' + 'bafaf7d06bec3ed7fba58e8a926e7b472b5e16442b6ee9dd8c7ee6c0cce9792a' + 'a9e1c001701508c6ffd808cf530e0f6a756253a5cdb72d166e7987fa5ab64960' + 'da44cca549bc7fb9e04f0f038a1ed68ba99cdfec834fc241ab13880bd0aa3b0f' + 'df0fcd73d46207d23b4f6952de75ab626084560e9d9c698c3eb8d5ec071b308c' + 'a2bbb4d75d2d02b08a44a9f767b7f4ff11a546ae1ed79d06c3fc254218ac54e0' + '79d811b916b2ff718fd3b68b4211dd7548a7b51badc510d9e83eeac4229338a3' + 'bc394e597f8939b6f6630bd88c990f951738aaadacded2f3be71c658e9608fe7') validpgpkeys=('B6C8F98282B944E3B0D5C2530FC3042E345AD05D' # Hans Wennborg, Google. '11E521D646982372EB577A1F8F0871F202119294') # Tom Stellard noextract=(cfe-${pkgver}.src.tar.xz @@ -153,58 +137,43 @@ prepare() { [[ -d ${srcdir}/lldb-${pkgver} ]] || tar -xJvf ${srcdir}/lldb-${pkgver}.src.tar.xz -C ${srcdir} || true cd "${srcdir}/llvm-${pkgver}.src" - # cleanup files created by patch - rm -rf lib/DLLDriver/CMakeLists.txt \ - lib/DLLDriver/Config.h \ - lib/DLLDriver/DllDriver.cpp \ - lib/DLLDriver/LLVMBuild.txt \ - lib/DLLDriver/Librarian.cpp \ - lib/DLLDriver/ModuleDef.cpp \ - lib/DLLDriver/Options.td \ - include/llvm/DllDriver/DllDriver.h || true - patch -p1 -i "${srcdir}/0001-genlib-named-as-llvm-dlltool.patch" - patch -p1 -i "${srcdir}/0002-mingw-w64-use-MSVC-style-ByteAlignment.patch" - patch -p1 -i "${srcdir}/0003-Fix-GetHostTriple-for-mingw-w64-in-msys.patch" - patch -p1 -i "${srcdir}/0004-Globally-provide-DESTDIR-for-all-platforms.patch" - patch -p1 -i "${srcdir}/0005-not-install-msvc-files.patch" - patch -p1 -i "${srcdir}/0006-llvm-config-look-for-unversioned-shared-lib-on-win32.patch" - patch -p1 -i "${srcdir}/0007-add-pthread-as-system-lib-for-mingw.patch" - patch -p1 -i "${srcdir}/0008-fix-bugpoint-multiple-definition.patch" + patch -p1 -i "${srcdir}/0001-mingw-w64-use-MSVC-style-ByteAlignment.patch" + patch -p1 -i "${srcdir}/0002-Fix-GetHostTriple-for-mingw-w64-in-msys.patch" + patch -p1 -i "${srcdir}/0003-Globally-provide-DESTDIR-for-all-platforms.patch" + patch -p1 -i "${srcdir}/0004-llvm-config-look-for-unversioned-shared-lib-on-win32.patch" + patch -p1 -i "${srcdir}/0005-add-pthread-as-system-lib-for-mingw.patch" + patch -p1 -i "${srcdir}/0006-fix-bugpoint-multiple-definition.patch" cd "${srcdir}/cfe-${pkgver}.src" - patch -p1 -i "${srcdir}/0101-mingw-w64-enable-support-for-__declspec-selectany.patch" - patch -p1 -i "${srcdir}/0102-Allow-build-static-clang-library-for-mingw.patch" - patch -p1 -i "${srcdir}/0103-fix-libclang-name-for-mingw.patch" - patch -p1 -i "${srcdir}/0104-don-t-use-GCC-headers.patch" - patch -p1 -i "${srcdir}/0105-Set-the-x86-arch-name-to-i686-for-mingw-w64.patch" - patch -p1 -i "${srcdir}/0106-link-pthread-with-mingw.patch" - patch -p1 -i "${srcdir}/0107-enable-__float128-for-X86-MinGW.patch" - patch -p1 -i "${srcdir}/0108-Don-t-create-cl-executable-for-mingw.patch" - patch -p1 -i "${srcdir}/0109-use-emulated-tls-with-mingw.patch" + patch -p1 -i "${srcdir}/0101-Allow-build-static-clang-library-for-mingw.patch" + patch -p1 -i "${srcdir}/0102-fix-libclang-name-for-mingw.patch" + patch -p1 -i "${srcdir}/0103-Set-the-x86-arch-name-to-i686-for-mingw-w64.patch" + patch -p1 -i "${srcdir}/0104-link-pthread-with-mingw.patch" + patch -p1 -i "${srcdir}/0105-use-emulated-tls-with-mingw.patch" cd "${srcdir}/compiler-rt-${pkgver}.src" patch -p1 -i "${srcdir}/0201-mingw-w64-__udivdi3-mangle-hack.patch" patch -p1 -i "${srcdir}/0202-compiler-rt-fix-mingw-build.patch" - # not ported for 4.0 #cd "${srcdir}/lld-${pkgver}.src" - ## cleanup file created by patch - #rm -rf cmake/modules/AddLLD.cmake || true - #patch -p1 -i "${srcdir}/0301-COFF-gnu-driver-support.patch" - #patch -p1 -i "${srcdir}/0302-add-install-target-for-the-lld-tool.patch" cd "${srcdir}/libcxx-${pkgver}.src" patch -p1 -i "${srcdir}/0401-mingw-w64-hack-and-slash-fixes-for-libc.patch" cd "${srcdir}/lldb-${pkgver}.src" - patch -p1 -i "${srcdir}/0501-minor-fixes-to-get-lldb-building.patch" - patch -p1 -i "${srcdir}/0502-hack-to-use-64-bit-time-for-mingw.patch" + patch -p1 -i "${srcdir}/0501-fixes-to-get-lldb-building.patch" + # There was big refactor/cleanup and it doesn't apply any more + # https://github.com/llvm-mirror/lldb/commit/456b31d616f3c71be31315ae26f6c8e174f4fd51#diff-2c5e3e9a387d499896aa082d15141bfb + # However 32 bit lldb is still crashing without it; temporary leaving patch for the reference until it's solved + #patch -p1 -i "${srcdir}/0502-hack-to-use-64-bit-time-for-mingw.patch" cd "${srcdir}/libunwind-${pkgver}.src" patch -p1 -i "${srcdir}/0601-libunwind-add-support-for-mingw-w64.patch" - cd "${srcdir}/libcxxabi-${pkgver}.src" - patch -p1 -i "${srcdir}/0701-fix-visibility-for-libc-abi-on-win32.patch" + #cd "${srcdir}/libcxxabi-${pkgver}.src" + + cd "${srcdir}/polly-${pkgver}.src" + patch -p1 -i "${srcdir}/0801-Don-t-build-LLVMPolly-on-WIN32.patch" # At the present, clang must reside inside the LLVM source code tree to build # See https://bugs.llvm.org/show_bug.cgi?id=4840 @@ -246,17 +215,11 @@ build() { # "Ninja" cant install each component seperately # https://github.com/martine/ninja/issues/932 - if [ "${_compiler}" == "gcc" ]; then - export CC='gcc' - export CXX='g++' - elif [ "${_compiler}" == "clang" ]; then + if [ "${_compiler}" == "clang" ]; then #export CC='clang -stdlib=libc++' #export CXX='clang++ -stdlib=libc++' export CC='clang' export CXX='clang++' - else - msg "undefined compiler" - exit 1 fi MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \ @@ -336,7 +299,8 @@ package_compiler-rt() { package_libcxxabi() { pkgdesc="C++ Standard Library Support (mingw-w64)" url="https://libcxxabi.llvm.org/" - depends="${MINGW_PACKAGE_PREFIX}-libunwind" + # Don't depend on libunwind until it actually works as installing it breaks some packages + #depends="${MINGW_PACKAGE_PREFIX}-libunwind" cd "${srcdir}/llvm-${pkgver}.src" make -C ../build-${CARCH}/projects/libcxxabi -j1 DESTDIR="${pkgdir}" install