diff --git a/mingw-w64-clang/0001-genlib-named-as-llvm-dlltool.patch b/mingw-w64-clang/0001-genlib-named-as-llvm-dlltool.patch new file mode 100644 index 0000000000..e3aafb100a --- /dev/null +++ b/mingw-w64-clang/0001-genlib-named-as-llvm-dlltool.patch @@ -0,0 +1,1424 @@ +From 5e9f6cde2f8389190f318da10d8d4e70939a0e3a Mon Sep 17 00:00:00 2001 +From: Martell Malone +Date: Tue, 9 Aug 2016 17:52:46 -0700 +Subject: [PATCH 1/3] 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) + +diff --git a/include/llvm/DllDriver/DllDriver.h b/include/llvm/DllDriver/DllDriver.h +new file mode 100644 +index 0000000..79fb7b7 +--- /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 9449421..03988a6 100644 +--- a/lib/CMakeLists.txt ++++ b/lib/CMakeLists.txt +@@ -20,4 +20,5 @@ add_subdirectory(LineEditor) + add_subdirectory(ProfileData) + add_subdirectory(Fuzzer) + add_subdirectory(Passes) ++add_subdirectory(DLLDriver) + add_subdirectory(LibDriver) +diff --git a/lib/DLLDriver/CMakeLists.txt b/lib/DLLDriver/CMakeLists.txt +new file mode 100644 +index 0000000..91fb2f0 +--- /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 0000000..d5a3d26 +--- /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 0000000..aa9adc8 +--- /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 0000000..8e2b1d65 +--- /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 0000000..486733e +--- /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 0000000..428049a +--- /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 0000000..62f33f3 +--- /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 4ede536..4e8c5f0 100644 +--- a/lib/Object/ArchiveWriter.cpp ++++ b/lib/Object/ArchiveWriter.cpp +@@ -285,7 +285,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 86233df..94cc205 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 +@@ -12,3 +13,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 40e4a3a..1ebded3 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" +@@ -844,6 +845,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)); +@@ -859,5 +863,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.8.3 + diff --git a/mingw-w64-clang/0002-COFF-Fix-short-import-lib-import-name-type-bitshift.patch b/mingw-w64-clang/0002-COFF-Fix-short-import-lib-import-name-type-bitshift.patch new file mode 100644 index 0000000000..33e9d467e3 --- /dev/null +++ b/mingw-w64-clang/0002-COFF-Fix-short-import-lib-import-name-type-bitshift.patch @@ -0,0 +1,30 @@ +From bb716cb613551806c92d48b7a96c2cd7e76a7e06 Mon Sep 17 00:00:00 2001 +From: Martell Malone +Date: Sat, 1 Oct 2016 09:37:25 +0000 +Subject: [PATCH] COFF: Fix short import lib import name type bitshift + +As per the PE COFF spec (section 8.3, Import Name Type) +Offset: 18 Size 2 bits Name: Type +Offset: 20 Size 3 bits Name: Name Type + +Offset: 20 added based on 18+2 + +Partially commited as rL279069 + +Differential Revision: https://reviews.llvm.org/D23540 + +diff --git a/include/llvm/Support/COFF.h b/include/llvm/Support/COFF.h +index 7dad3e8..1ca781b9 100644 +--- a/include/llvm/Support/COFF.h ++++ b/include/llvm/Support/COFF.h +@@ -657,7 +657,7 @@ namespace COFF { + } + + ImportNameType getNameType() const { +- return static_cast((TypeInfo & 0x1C) >> 3); ++ return static_cast((TypeInfo & 0x1C) >> 2); + } + }; + +-- +2.7.4 diff --git a/mingw-w64-clang/0003-generate-proper-library-names-mingw.patch b/mingw-w64-clang/0003-generate-proper-library-names-mingw.patch deleted file mode 100644 index 11015d94e9..0000000000 --- a/mingw-w64-clang/0003-generate-proper-library-names-mingw.patch +++ /dev/null @@ -1,22 +0,0 @@ ---- a/cmake/modules/AddLLVM.cmake 2015-12-25 11:45:24.447038200 +0300 -+++ b/cmake/modules/AddLLVM.cmake 2015-12-25 12:14:26.848945700 +0300 -@@ -399,10 +399,15 @@ - llvm_update_compile_flags(${name}) - add_link_opts( ${name} ) - if(ARG_OUTPUT_NAME) -- set_target_properties(${name} -- PROPERTIES -- OUTPUT_NAME ${ARG_OUTPUT_NAME} -- ) -+ if(MINGW) -+ string(REGEX REPLACE "^lib([A-Za-z]+)" "\\1" LIB_OUTPUT_NAME ${ARG_OUTPUT_NAME}) -+ set_target_properties(${name} PROPERTIES OUTPUT_NAME ${LIB_OUTPUT_NAME} RUNTIME_OUTPUT_NAME ${ARG_OUTPUT_NAME} ARCHIVE_OUTPUT_NAME ${LIB_OUTPUT_NAME}) -+ else() -+ set_target_properties(${name} -+ PROPERTIES -+ OUTPUT_NAME ${ARG_OUTPUT_NAME} -+ ) -+ endif() - endif() - - if(ARG_MODULE) diff --git a/mingw-w64-clang/0003-mingw-w64-use-MSVC-style-ByteAlignment.patch b/mingw-w64-clang/0003-mingw-w64-use-MSVC-style-ByteAlignment.patch new file mode 100644 index 0000000000..5d413c02b9 --- /dev/null +++ b/mingw-w64-clang/0003-mingw-w64-use-MSVC-style-ByteAlignment.patch @@ -0,0 +1,33 @@ +From c659c69306254b8068af5582803f79508e79ba63 Mon Sep 17 00:00:00 2001 +From: Martell Malone +Date: Tue, 16 Aug 2016 12:55:01 -0700 +Subject: [PATCH 3/3] 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 + +diff --git a/lib/MC/WinCOFFStreamer.cpp b/lib/MC/WinCOFFStreamer.cpp +index 5c6407e..f86cbc5 100644 +--- a/lib/MC/WinCOFFStreamer.cpp ++++ b/lib/MC/WinCOFFStreamer.cpp +@@ -208,7 +208,7 @@ void MCWinCOFFStreamer::EmitCommonSymbol(MCSymbol *S, uint64_t Size, + auto *Symbol = cast(S); + + const Triple &T = getContext().getObjectFileInfo()->getTargetTriple(); +- if (T.isKnownWindowsMSVCEnvironment()) { ++ if (T.getEnvironment() != Triple::Cygnus) { + if (ByteAlignment > 32) + report_fatal_error("alignment is limited to 32-bytes"); + +@@ -220,7 +220,7 @@ void MCWinCOFFStreamer::EmitCommonSymbol(MCSymbol *S, uint64_t Size, + Symbol->setExternal(true); + Symbol->setCommon(Size, ByteAlignment); + +- if (!T.isKnownWindowsMSVCEnvironment() && ByteAlignment > 1) { ++ if (T.getEnvironment() == Triple::Cygnus && ByteAlignment > 1) { + SmallString<128> Directive; + raw_svector_ostream OS(Directive); + const MCObjectFileInfo *MFI = getContext().getObjectFileInfo(); +-- +2.8.3 + diff --git a/mingw-w64-clang/0001-Fix-GetHostTriple-for-mingw-w64-in-msys.patch b/mingw-w64-clang/0005-Fix-GetHostTriple-for-mingw-w64-in-msys.patch similarity index 100% rename from mingw-w64-clang/0001-Fix-GetHostTriple-for-mingw-w64-in-msys.patch rename to mingw-w64-clang/0005-Fix-GetHostTriple-for-mingw-w64-in-msys.patch diff --git a/mingw-w64-clang/0002-use-DESTDIR-on-windows.patch b/mingw-w64-clang/0006-use-DESTDIR-on-windows.patch similarity index 100% rename from mingw-w64-clang/0002-use-DESTDIR-on-windows.patch rename to mingw-w64-clang/0006-use-DESTDIR-on-windows.patch diff --git a/mingw-w64-clang/0011-Revert-Revert-r253898-and-r253899-this-breaks-mingw-.patch b/mingw-w64-clang/0011-Revert-Revert-r253898-and-r253899-this-breaks-mingw-.patch new file mode 100644 index 0000000000..aefb57aed5 --- /dev/null +++ b/mingw-w64-clang/0011-Revert-Revert-r253898-and-r253899-this-breaks-mingw-.patch @@ -0,0 +1,44 @@ +From 42df5ed300973bfa10f155dd967768684c86f932 Mon Sep 17 00:00:00 2001 +From: Martell Malone +Date: Fri, 27 May 2016 20:30:18 -0700 +Subject: [PATCH 1/4] Revert "Revert r253898 and r253899, this breaks mingw + compilation on openSUSE." + +This reverts commit 0e2452f3055e2e2cad06a55c5ca9c2be13404781. + +diff --git a/lib/Driver/MinGWToolChain.cpp b/lib/Driver/MinGWToolChain.cpp +index 938440b..c5287bb 100644 +--- a/lib/Driver/MinGWToolChain.cpp ++++ b/lib/Driver/MinGWToolChain.cpp +@@ -66,23 +66,17 @@ MinGW::MinGW(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) + : ToolChain(D, Triple, Args) { + getProgramPaths().push_back(getDriver().getInstalledDir()); + +-// In Windows there aren't any standard install locations, we search +-// for gcc on the PATH. In Linux the base is always /usr. +-#ifdef LLVM_ON_WIN32 ++ // On Windows if there is no sysroot we search for gcc on the PATH. + if (getDriver().SysRoot.size()) +- Base = getDriver().SysRoot; ++ Base = getDriver().SysRoot; ++#ifdef LLVM_ON_WIN32 + else if (llvm::ErrorOr GPPName = + llvm::sys::findProgramByName("gcc")) + Base = llvm::sys::path::parent_path( + llvm::sys::path::parent_path(GPPName.get())); +- else +- Base = llvm::sys::path::parent_path(getDriver().getInstalledDir()); +-#else +- if (getDriver().SysRoot.size()) +- Base = getDriver().SysRoot; +- else +- Base = "/usr"; + #endif ++ if (!Base.size()) ++ Base = llvm::sys::path::parent_path(getDriver().getInstalledDir()); + + Base += llvm::sys::path::get_separator(); + findGccLibDir(); +-- +2.8.3 + diff --git a/mingw-w64-clang/0012-mingw-w64-setup-new-defaults-for-target.patch b/mingw-w64-clang/0012-mingw-w64-setup-new-defaults-for-target.patch new file mode 100644 index 0000000000..81f28a7c2b --- /dev/null +++ b/mingw-w64-clang/0012-mingw-w64-setup-new-defaults-for-target.patch @@ -0,0 +1,45 @@ +From ee9923897d733a852efe1e8836a1a98f41ea6cf9 Mon Sep 17 00:00:00 2001 +From: Martell Malone +Date: Wed, 16 Dec 2015 02:07:06 -0800 +Subject: [PATCH 2/4] mingw-w64: setup new defaults for target + +runtime: compiler-rt +c++ lib: libc++ +linker: lld + +diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h +index 61c559c..78fde9b 100644 +--- a/lib/Driver/ToolChains.h ++++ b/lib/Driver/ToolChains.h +@@ -677,6 +677,15 @@ public: + const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const override; + ++ RuntimeLibType GetDefaultRuntimeLibType() const override { ++ return RuntimeLibType::RLT_CompilerRT; ++ } ++ ++ CXXStdlibType ++ GetCXXStdlibType(const llvm::opt::ArgList &Args) const override { ++ return ToolChain::CST_Libcxx; ++ } ++ + protected: + Tool *getTool(Action::ActionClass AC) const override; + Tool *buildLinker() const override; +diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp +index 4900e20..6673e78 100644 +--- a/lib/Driver/Tools.cpp ++++ b/lib/Driver/Tools.cpp +@@ -10443,7 +10443,7 @@ void MinGW::Linker::ConstructJob(Compilation &C, const JobAction &JA, + // handled somewhere else. + Args.ClaimAllArgs(options::OPT_w); + +- StringRef LinkerName = Args.getLastArgValue(options::OPT_fuse_ld_EQ, "ld"); ++ StringRef LinkerName = Args.getLastArgValue(options::OPT_fuse_ld_EQ, "lld"); + if (LinkerName.equals_lower("lld")) { + CmdArgs.push_back("-flavor"); + CmdArgs.push_back("gnu"); +-- +2.8.3 + diff --git a/mingw-w64-clang/0013-mingw-w64-dont-have-dl-library.patch b/mingw-w64-clang/0013-mingw-w64-dont-have-dl-library.patch deleted file mode 100644 index 5048cb613b..0000000000 --- a/mingw-w64-clang/0013-mingw-w64-dont-have-dl-library.patch +++ /dev/null @@ -1,15 +0,0 @@ ---- cfe-3.7.0.src/tools/libclang/CMakeLists.txt 2015-09-02 12:21:21.242154800 +0300 -+++ cfe-3.7.0.src/tools/libclang/CMakeLists.txt.orig 2015-09-02 12:20:53.198959400 +0300 -@@ -51,10 +51,12 @@ - list(APPEND LIBS clangARCMigrate) - endif () - -+if (NOT MINGW) - find_library(DL_LIBRARY_PATH dl) - if (DL_LIBRARY_PATH) - list(APPEND LIBS dl) - endif() -+endif() - - option(LIBCLANG_BUILD_STATIC - "Build libclang as a static library (in addition to a shared one)" OFF) diff --git a/mingw-w64-clang/0013-mingw-w64-enable-support-for-__declspec-selectany.patch b/mingw-w64-clang/0013-mingw-w64-enable-support-for-__declspec-selectany.patch new file mode 100644 index 0000000000..434f1c9834 --- /dev/null +++ b/mingw-w64-clang/0013-mingw-w64-enable-support-for-__declspec-selectany.patch @@ -0,0 +1,25 @@ +From 05d6add74e34a5ff2aeadec722df981be2760e52 Mon Sep 17 00:00:00 2001 +From: Martell Malone +Date: Mon, 15 Aug 2016 20:57:27 -0700 +Subject: [PATCH 3/4] mingw-w64: enable support for __declspec(selectany) + + +diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td +index 7da1efe..2d4be9e 100644 +--- a/include/clang/Basic/Attr.td ++++ b/include/clang/Basic/Attr.td +@@ -2097,9 +2097,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.8.3 + diff --git a/mingw-w64-clang/0014-mingw-w64-support-static-builds-of-libc.patch b/mingw-w64-clang/0014-mingw-w64-support-static-builds-of-libc.patch new file mode 100644 index 0000000000..91a9ce3b5c --- /dev/null +++ b/mingw-w64-clang/0014-mingw-w64-support-static-builds-of-libc.patch @@ -0,0 +1,49 @@ +From 5364db7f4d3f9204530f33a05388b6f54f515b21 Mon Sep 17 00:00:00 2001 +From: Martell Malone +Date: Fri, 5 Aug 2016 21:50:38 -0700 +Subject: [PATCH 4/4] mingw-w64: support static builds of libc++ + +Static builds require libc++abi to be linked +Will add support for both modes in future + +diff --git a/lib/Driver/MinGWToolChain.cpp b/lib/Driver/MinGWToolChain.cpp +index c5287bb..9090be5 100644 +--- a/lib/Driver/MinGWToolChain.cpp ++++ b/lib/Driver/MinGWToolChain.cpp +@@ -242,3 +242,18 @@ void MinGW::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, + break; + } + } ++ ++void MinGW::AddCXXStdlibLibArgs(const ArgList &Args, ++ ArgStringList &CmdArgs) const { ++ switch (GetCXXStdlibType(Args)) { ++ case ToolChain::CST_Libcxx: ++ CmdArgs.push_back("-lc++"); ++ // Support only static libc++ for now ++ CmdArgs.push_back("-lc++abi"); ++ break; ++ ++ case ToolChain::CST_Libstdcxx: ++ CmdArgs.push_back("-lstdc++"); ++ break; ++ } ++} +diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h +index 78fde9b..d490969 100644 +--- a/lib/Driver/ToolChains.h ++++ b/lib/Driver/ToolChains.h +@@ -673,6 +673,10 @@ public: + void + AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const override; ++ ++ void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, ++ llvm::opt::ArgStringList &CmdArgs) const override; ++ + void AddClangCXXStdlibIncludeArgs( + const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const override; +-- +2.8.3 + diff --git a/mingw-w64-clang/0018-mingw-enable-static-libclang.patch b/mingw-w64-clang/0015-mingw-enable-static-libclang.patch similarity index 100% rename from mingw-w64-clang/0018-mingw-enable-static-libclang.patch rename to mingw-w64-clang/0015-mingw-enable-static-libclang.patch diff --git a/mingw-w64-clang/0016-generate-libclang-instead-of-liblibclang.patch b/mingw-w64-clang/0016-generate-libclang-instead-of-liblibclang.patch new file mode 100644 index 0000000000..811a5de9e0 --- /dev/null +++ b/mingw-w64-clang/0016-generate-libclang-instead-of-liblibclang.patch @@ -0,0 +1,12 @@ +diff -urN cfe-3.9.0.src.orig/tools/libclang/CMakeLists.txt cfe-3.9.0.src/tools/libclang/CMakeLists.txt +--- cfe-3.9.0.src.orig/tools/libclang/CMakeLists.txt 2016-03-03 12:09:43.000000000 +0100 ++++ cfe-3.9.0.src/tools/libclang/CMakeLists.txt 2016-09-26 19:40:33.887171200 +0200 +@@ -77,7 +77,7 @@ + set(ENABLE_STATIC STATIC) + endif() + +-if(WIN32) ++if(MSVC) + set(output_name "libclang") + else() + set(output_name "clang") diff --git a/mingw-w64-clang/0014-dont-create-cl-mingw.patch b/mingw-w64-clang/0017-dont-create-cl-mingw.patch similarity index 100% rename from mingw-w64-clang/0014-dont-create-cl-mingw.patch rename to mingw-w64-clang/0017-dont-create-cl-mingw.patch diff --git a/mingw-w64-clang/0018-experimental-workaround-for-limits-bug.patch b/mingw-w64-clang/0018-experimental-workaround-for-limits-bug.patch new file mode 100644 index 0000000000..27ed9142fa --- /dev/null +++ b/mingw-w64-clang/0018-experimental-workaround-for-limits-bug.patch @@ -0,0 +1,11 @@ +--- cfe-3.9.0.src.orig/lib/Headers/limits.h 2014-02-20 00:38:18.000000000 +0100 ++++ cfe-3.9.0.src/lib/Headers/limits.h 2016-09-27 15:18:14.024045800 +0200 +@@ -28,7 +28,7 @@ + /* The system's limits.h may, in turn, try to #include_next GCC's limits.h. + Avert this #include_next madness. */ + #if defined __GNUC__ && !defined _GCC_LIMITS_H_ +-#define _GCC_LIMITS_H_ ++#define _LIMITS_H___ + #endif + + /* System headers include a number of constants from POSIX in . diff --git a/mingw-w64-clang/0012-Set-the-x86-arch-name-to-i686-for-mingw-w64.patch b/mingw-w64-clang/0019-Set-the-x86-arch-name-to-i686-for-mingw-w64.patch similarity index 100% rename from mingw-w64-clang/0012-Set-the-x86-arch-name-to-i686-for-mingw-w64.patch rename to mingw-w64-clang/0019-Set-the-x86-arch-name-to-i686-for-mingw-w64.patch diff --git a/mingw-w64-clang/0021-missing-include.patch b/mingw-w64-clang/0021-missing-include.patch deleted file mode 100644 index 04a0a3c353..0000000000 --- a/mingw-w64-clang/0021-missing-include.patch +++ /dev/null @@ -1,10 +0,0 @@ ---- compiler-rt-3.8.0.src/lib/profile/WindowsMMap.h.orig 2015-12-25 10:56:22.521432100 +0300 -+++ compiler-rt-3.8.0.src/lib/profile/WindowsMMap.h 2015-12-25 12:18:32.484593900 +0300 -@@ -11,6 +11,7 @@ - - #if defined(_WIN32) - -+#include - #include - #include - #include diff --git a/mingw-w64-clang/0022-mingw-w64-__udivdi3-mangle-hack.patch b/mingw-w64-clang/0022-mingw-w64-__udivdi3-mangle-hack.patch new file mode 100644 index 0000000000..e69bc0eecf --- /dev/null +++ b/mingw-w64-clang/0022-mingw-w64-__udivdi3-mangle-hack.patch @@ -0,0 +1,27 @@ +From 67f899a1294d8ad56ea60b02a6ed5b111e2c2d24 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 + + +diff --git a/lib/builtins/udivdi3.c b/lib/builtins/udivdi3.c +index dc68e15..4c616fd 100644 +--- a/lib/builtins/udivdi3.c ++++ b/lib/builtins/udivdi3.c +@@ -17,7 +17,12 @@ + /* Returns: a / b */ + + COMPILER_RT_ABI du_int +-__udivdi3(du_int a, du_int b) ++#if defined (__MINGW32__) && !defined(_WIN64) ++___udivdi3 ++#else ++__udivdi3 ++#endif ++(du_int a, du_int b) + { + return __udivmoddi4(a, b, 0); + } +-- +2.8.3 + diff --git a/mingw-w64-clang/0023-mingw-fixes-for-compiler-rt.patch b/mingw-w64-clang/0023-mingw-fixes-for-compiler-rt.patch new file mode 100644 index 0000000000..fa7cc71f85 --- /dev/null +++ b/mingw-w64-clang/0023-mingw-fixes-for-compiler-rt.patch @@ -0,0 +1,41 @@ +diff -urN compiler-rt-3.9.0.src.orig/lib/profile/InstrProfilingPort.h compiler-rt-3.9.0.src/lib/profile/InstrProfilingPort.h +--- compiler-rt-3.9.0.src.orig/lib/profile/InstrProfilingPort.h 2016-07-15 20:48:14.000000000 +0200 ++++ compiler-rt-3.9.0.src/lib/profile/InstrProfilingPort.h 2016-09-23 00:20:25.833117600 +0200 +@@ -10,7 +10,7 @@ + #ifndef PROFILE_INSTRPROFILING_PORT_H_ + #define PROFILE_INSTRPROFILING_PORT_H_ + +-#ifdef _MSC_VER ++#ifdef _WIN32 + #define COMPILER_RT_ALIGNAS(x) __declspec(align(x)) + #define COMPILER_RT_VISIBILITY + /* FIXME: selectany does not have the same semantics as weak. */ +@@ -33,14 +33,14 @@ + #define COMPILER_RT_SEG "" + #endif + +-#ifdef _MSC_VER ++#ifdef _WIN32 + #define COMPILER_RT_SECTION(Sect) __declspec(allocate(Sect)) + #else + #define COMPILER_RT_SECTION(Sect) __attribute__((section(Sect))) + #endif + + #define COMPILER_RT_MAX_HOSTLEN 128 +-#ifdef _MSC_VER ++#ifdef _WIN32 + #define COMPILER_RT_GETHOSTNAME(Name, Len) gethostname(Name, Len) + #elif defined(__ORBIS__) + #define COMPILER_RT_GETHOSTNAME(Name, Len) ((void)(Name), (void)(Len), (-1)) +@@ -50,9 +50,9 @@ + #endif + + #if COMPILER_RT_HAS_ATOMICS == 1 +-#ifdef _MSC_VER ++#ifdef _WIN32 + #include +-#if _MSC_VER < 1900 ++#if defined(_MSC_VER) && _MSC_VER < 1900 + #define snprintf _snprintf + #endif + #if defined(_WIN64) diff --git a/mingw-w64-clang/0031-COFF-gnu-driver-support.patch b/mingw-w64-clang/0031-COFF-gnu-driver-support.patch new file mode 100644 index 0000000000..67a041dcab --- /dev/null +++ b/mingw-w64-clang/0031-COFF-gnu-driver-support.patch @@ -0,0 +1,230 @@ +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/0041-libcxx-add-support-for-mingw-w64.patch b/mingw-w64-clang/0041-libcxx-add-support-for-mingw-w64.patch deleted file mode 100644 index 4b4437b84d..0000000000 --- a/mingw-w64-clang/0041-libcxx-add-support-for-mingw-w64.patch +++ /dev/null @@ -1,35 +0,0 @@ -From 53625b291503734db14e4a6146ceb06f288fd987 Mon Sep 17 00:00:00 2001 -From: Martell Malone -Date: Sun, 5 Jul 2015 00:54:34 +0100 -Subject: [PATCH] libcxx: add support for mingw-w64 - - -diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt -index d3d5f38..4820f2c 100644 ---- a/lib/CMakeLists.txt -+++ b/lib/CMakeLists.txt -@@ -2,7 +2,7 @@ set(LIBCXX_LIB_CMAKEFILES_DIR "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTOR - - # Get sources - file(GLOB LIBCXX_SOURCES ../src/*.cpp) --if(WIN32) -+if(MSVC) - file(GLOB LIBCXX_WIN32_SOURCES ../src/support/win32/*.cpp) - list(APPEND LIBCXX_SOURCES ${LIBCXX_WIN32_SOURCES}) - elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS") -diff --git a/src/random.cpp b/src/random.cpp -index 4ab424e..d3062f5 100644 ---- a/src/random.cpp -+++ b/src/random.cpp -@@ -7,7 +7,7 @@ - // - //===----------------------------------------------------------------------===// - --#if defined(_LIBCPP_USING_WIN32_RANDOM) -+#if defined(_LIBCPP_USING_WIN32_RANDOM) || defined(__MINGW32__) - // Must be defined before including stdlib.h to enable rand_s(). - #define _CRT_RAND_S - #endif // defined(_LIBCPP_USING_WIN32_RANDOM) --- -2.4.5 - diff --git a/mingw-w64-clang/0041-mingw-w64-hack-and-slash-fixes-for-libc.patch b/mingw-w64-clang/0041-mingw-w64-hack-and-slash-fixes-for-libc.patch new file mode 100644 index 0000000000..0d1f5d8a13 --- /dev/null +++ b/mingw-w64-clang/0041-mingw-w64-hack-and-slash-fixes-for-libc.patch @@ -0,0 +1,268 @@ +From 57d48bf47108014aa5e0c5435c107581e86e3045 Mon Sep 17 00:00:00 2001 +From: Martell Malone +Date: Sat, 6 Aug 2016 03:54:22 -0700 +Subject: [PATCH] mingw-w64 hack and slash fixes for libc++ + +CMAKE_HOST_WIN32 change can be upstreamed in a different patch + +This is very hacky but gets libcxx to compile +Make sure you only install the headers after building +Will need to run the test suite and do more work here + +diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt +index 219d1b7..2a9337f 100644 +--- a/include/CMakeLists.txt ++++ b/include/CMakeLists.txt +@@ -27,7 +27,7 @@ if (LIBCXX_INSTALL_HEADERS) + + if (LIBCXX_NEEDS_SITE_CONFIG) + set(UNIX_CAT cat) +- if (WIN32) ++ if (CMAKE_HOST_WIN32) + set(UNIX_CAT type) + endif() + # Generate and install a custom __config header. The new header is created +diff --git a/include/__config b/include/__config +index 353ca10..b58c350 100644 +--- a/include/__config ++++ b/include/__config +@@ -152,6 +152,8 @@ + # // If mingw not explicitly detected, assume using MS C runtime only. + # ifndef __MINGW32__ + # define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library ++# else ++# define _LIBCPP_HAS_NO_CONSTEXPR + # endif + #endif // _WIN32 + +@@ -177,7 +179,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(_WIN32) ++#elif defined(_MSC_VER) + # define _LIBCPP_USING_WIN32_RANDOM + #else + # define _LIBCPP_USING_DEV_RANDOM +@@ -831,7 +833,8 @@ 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 + # else + # error "No thread API" +diff --git a/include/support/win32/locale_win32.h b/include/support/win32/locale_win32.h +index 7f3710e..d167309 100644 +--- a/include/support/win32/locale_win32.h ++++ b/include/support/win32/locale_win32.h +@@ -64,6 +64,15 @@ isupper_l(int c, _locale_t loc) + return _isupper_l((int)c, loc); + } + ++#define open _open ++#define close _close ++#define read _read ++ ++#define strtod_l _strtod_l ++ ++// TODO: add _strtof_l to mingw-w64 ++#define strtof_l _strtod_l ++ + #define isdigit_l _isdigit_l + #define isxdigit_l _isxdigit_l + #define strcoll_l _strcoll_l +@@ -93,6 +102,33 @@ int snprintf_l(char *ret, size_t n, locale_t loc, const char *format, ...); + int asprintf_l( char **ret, locale_t loc, const char *format, ... ); + int vasprintf_l( char **ret, locale_t loc, const char *format, va_list ap ); + ++#ifdef __MINGW32__ ++ ++// Stubs ++inline _locale_t _get_current_locale(void) { ++ return NULL; ++} ++ ++inline _locale_t _create_locale(int _Category,const char *_Locale) { ++ _locale_t loc; ++ return loc; ++} ++//extern "C" void _free_locale(_locale_t _Locale) {} ++//void __cdecl _free_locale(_locale_t _Locale); ++//inline _locale_t _free_locale(_locale_t _Locale) { ++// _locale_t loc; ++// return loc; ++//} ++ ++ ++#include ++ ++inline size_t _strftime_l(char* s, size_t n, const char * f, const struct tm * tm, _locale_t l) ++{ ++ return strftime(s, n, f, tm); ++} ++ ++#endif + + // not-so-pressing FIXME: use locale to determine blank characters + inline int isblank_l( int c, locale_t /*loc*/ ) +@@ -104,7 +140,7 @@ inline int iswblank_l( wint_t c, locale_t /*loc*/ ) + return ( c == L' ' || c == L'\t' ); + } + +-#if defined(_LIBCPP_MSVCRT) ++#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__) + inline int isblank( int c, locale_t /*loc*/ ) + { return ( c == ' ' || c == '\t' ); } + inline int iswblank( wint_t c, locale_t /*loc*/ ) +diff --git a/include/support/win32/support.h b/include/support/win32/support.h +index 5765bab..4955b3a 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 // __MINGW32__ ++ + 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(_LIBCPP_MSVCRT) + #define snprintf _snprintf +diff --git a/include/type_traits b/include/type_traits +index 0d578bb..88dfd99 100644 +--- a/include/type_traits ++++ b/include/type_traits +@@ -1671,7 +1671,7 @@ _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x800); + _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1000); + _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2000); + // MSDN says that MSVC does not support alignment beyond 8192 (=0x2000) +-#if !defined(_LIBCPP_MSVC) ++#if !defined(_LIBCPP_MSVC) && !defined(__MINGW32__) + _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4000); + #endif // !_LIBCPP_MSVC + +diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt +index cabf2e6..8729707 100644 +--- a/lib/CMakeLists.txt ++++ b/lib/CMakeLists.txt +@@ -33,9 +33,11 @@ add_link_flags_if(LIBCXX_CXX_ABI_LIBRARY_PATH "-L${LIBCXX_CXX_ABI_LIBRARY_PATH}" + + add_library_flags_if(LIBCXX_COVERAGE_LIBRARY "${LIBCXX_COVERAGE_LIBRARY}") + ++if(NOT MINGW) + add_library_flags_if(LIBCXX_ENABLE_STATIC_ABI_LIBRARY "-Wl,--whole-archive" "-Wl,-Bstatic") + add_library_flags("${LIBCXX_CXX_ABI_LIBRARY}") + add_library_flags_if(LIBCXX_ENABLE_STATIC_ABI_LIBRARY "-Wl,-Bdynamic" "-Wl,--no-whole-archive") ++endif() + + if (APPLE AND LLVM_USE_SANITIZER) + if ("${LLVM_USE_SANITIZER}" STREQUAL "Address") +@@ -71,9 +73,14 @@ add_library_flags_if(LIBCXX_HAS_RT_LIB rt) + add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s) + add_library_flags_if(LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB atomic) + +-# Setup flags. + add_flags_if_supported(-fPIC) +-add_link_flags_if_supported(-nodefaultlibs) ++ ++# Setup flags. ++if (NOT MINGW) ++ add_link_flags_if_supported(-nodefaultlibs) ++else() ++ add_library_flags(-lc++abi) ++endif() + + if ( APPLE AND (LIBCXX_CXX_ABI_LIBNAME STREQUAL "libcxxabi" OR + LIBCXX_CXX_ABI_LIBNAME STREQUAL "none")) +diff --git a/src/locale.cpp b/src/locale.cpp +index da2fd11..03696a7 100644 +--- a/src/locale.cpp ++++ b/src/locale.cpp +@@ -26,9 +26,9 @@ + #include "cstring" + #include "cwctype" + #include "__sso_allocator" +-#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__) ++#if defined(_LIBCPP_MSVCRT) + #include "support/win32/locale_win32.h" +-#elif !defined(__ANDROID__) ++#elif !defined(__ANDROID__) && !defined(__MINGW32__) + #include + #endif + #include +diff --git a/src/support/win32/locale_win32.cpp b/src/support/win32/locale_win32.cpp +index 5a43743..b220afe 100644 +--- a/src/support/win32/locale_win32.cpp ++++ b/src/support/win32/locale_win32.cpp +@@ -8,6 +8,11 @@ + // + //===----------------------------------------------------------------------===// + ++#ifdef __MINGW32__ ++#define _GNU_SOURCE ++#include ++#endif ++ + #include + #include // va_start, va_end + +diff --git a/src/support/win32/support.cpp b/src/support/win32/support.cpp +index e989681..0d60ef4 100644 +--- a/src/support/win32/support.cpp ++++ b/src/support/win32/support.cpp +@@ -8,6 +8,10 @@ + // + //===----------------------------------------------------------------------===// + ++#ifdef __MINGW32__ ++#define _GNU_SOURCE ++#endif ++ + #include // va_start, va_end + #include // size_t + #include // malloc +@@ -17,6 +21,7 @@ + + // 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 +56,7 @@ int vasprintf( char **sptr, const char *__restrict format, va_list ap ) + *sptr = p; + return count; + } ++#endif + + // 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 87f35ae..fdd56ea 100644 +--- a/src/system_error.cpp ++++ b/src/system_error.cpp +@@ -70,6 +70,12 @@ string do_strerror_r(int ev) { + char* ret = ::strerror_r(ev, buffer, strerror_buff_size); + return string(ret); + } ++#elif defined(_LIBCPP_MSVCRT) || defined(__MINGW32__) ++string do_strerror_r(int ev) { ++ char buffer[strerror_buff_size]; ++ std::snprintf(buffer, strerror_buff_size, "Win32 Unsupported %d", ev); ++ return string(buffer); ++} + #else + // POSIX version + string do_strerror_r(int ev) { +-- +2.8.3 + diff --git a/mingw-w64-clang/0042-fix-compilation-with-gcc.patch b/mingw-w64-clang/0042-fix-compilation-with-gcc.patch new file mode 100644 index 0000000000..60752164d0 --- /dev/null +++ b/mingw-w64-clang/0042-fix-compilation-with-gcc.patch @@ -0,0 +1,29 @@ +diff -urN libcxx-3.9.0.origlibcxx/include/__config libcxx-3.9.0libcxx/include/__config +--- libcxx-3.9.0.origlibcxx/include/__config 2016-09-21 16:28:09.452978000 +0200 ++++ libcxx-3.9.0libcxx/include/__config 2016-09-25 01:19:05.170475000 +0200 +@@ -150,8 +150,6 @@ + # // If mingw not explicitly detected, assume using MS C runtime only. + # ifndef __MINGW32__ + # define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library +-# else +-# define _LIBCPP_HAS_NO_CONSTEXPR + # endif + #endif // _WIN32 + +@@ -496,8 +494,14 @@ + #endif + + // Determine if GCC supports relaxed constexpr +-#if !defined(__cpp_constexpr) || __cpp_constexpr < 201304L +-#define _LIBCPP_HAS_NO_CXX14_CONSTEXPR ++// GCC 6.X is retarded, it thinks it supports __cpp_constexpr 201304 but ... ++// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66297 ++#if defined(__clang__) ++# if !defined(__cpp_constexpr) || __cpp_constexpr < 201304L ++# define _LIBCPP_HAS_NO_CXX14_CONSTEXPR ++# endif ++#elif defined(__GNUC__) ++# define _LIBCPP_HAS_NO_CXX14_CONSTEXPR + #endif + + // GCC 5 will support variable templates diff --git a/mingw-w64-clang/0051-lldb-mingw-fixes.patch b/mingw-w64-clang/0051-lldb-mingw-fixes.patch new file mode 100644 index 0000000000..769e49deba --- /dev/null +++ b/mingw-w64-clang/0051-lldb-mingw-fixes.patch @@ -0,0 +1,112 @@ +diff -urN lldb-3.9.0.src.orig/cmake/modules/LLDBConfig.cmake lldb-3.9.0.src/cmake/modules/LLDBConfig.cmake +--- lldb-3.9.0.src.orig/cmake/modules/LLDBConfig.cmake 2016-05-26 18:11:04.000000000 +0200 ++++ lldb-3.9.0.src/cmake/modules/LLDBConfig.cmake 2016-09-25 15:29:06.566435600 +0200 +@@ -249,7 +249,11 @@ + + # Use the Unicode (UTF-16) APIs by default on Win32 + if (CMAKE_SYSTEM_NAME MATCHES "Windows") +- add_definitions( /D _UNICODE /D UNICODE ) ++ if (MSVC) ++ add_definitions( /D _UNICODE /D UNICODE ) ++ else() ++ add_definitions( -D_UNICODE -DUNICODE ) ++ endif() + endif() + + set(LLDB_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +diff -urN lldb-3.9.0.src.orig/include/lldb/Host/windows/win32.h lldb-3.9.0.src/include/lldb/Host/windows/win32.h +--- lldb-3.9.0.src.orig/include/lldb/Host/windows/win32.h 2015-08-20 22:53:15.000000000 +0200 ++++ lldb-3.9.0.src/include/lldb/Host/windows/win32.h 2016-09-25 21:48:24.777553100 +0200 +@@ -14,7 +14,9 @@ + #include + + // posix utilities ++#ifndef __MINGW64_VERSION_MAJOR + int vasprintf(char **ret, const char *fmt, va_list ap); ++#endif + char * strcasestr(const char *s, const char* find); + char* realpath(const char * name, char * resolved); + +@@ -93,7 +95,7 @@ + + // timespec + // MSVC 2015 and higher have timespec. Otherwise we need to define it ourselves. +-#if defined(_MSC_VER) && _MSC_VER >= 1900 ++#if defined(_MSC_VER) && _MSC_VER >= 1900 || defined(__MINGW64_VERSION_MAJOR) + #include + #else + struct timespec +diff -urN lldb-3.9.0.src.orig/source/Host/common/File.cpp lldb-3.9.0.src/source/Host/common/File.cpp +--- lldb-3.9.0.src.orig/source/Host/common/File.cpp 2016-08-12 20:10:54.000000000 +0200 ++++ lldb-3.9.0.src/source/Host/common/File.cpp 2016-09-25 21:23:42.383498500 +0200 +@@ -17,6 +17,7 @@ + + #ifdef _WIN32 + #include "lldb/Host/windows/windows.h" ++#include + #else + #include + #endif +diff -urN lldb-3.9.0.src.orig/source/Host/windows/ProcessRunLock.cpp lldb-3.9.0.src/source/Host/windows/ProcessRunLock.cpp +--- lldb-3.9.0.src.orig/source/Host/windows/ProcessRunLock.cpp 2015-05-15 00:50:19.000000000 +0200 ++++ lldb-3.9.0.src/source/Host/windows/ProcessRunLock.cpp 2016-09-25 21:43:38.881978300 +0200 +@@ -3,7 +3,7 @@ + + namespace + { +-#if defined(__MINGW32__) ++#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) + // Taken from WinNT.h + typedef struct _RTL_SRWLOCK { + PVOID Ptr; +diff -urN lldb-3.9.0.src.orig/source/Host/windows/Windows.cpp lldb-3.9.0.src/source/Host/windows/Windows.cpp +--- lldb-3.9.0.src.orig/source/Host/windows/Windows.cpp 2016-04-19 03:09:37.000000000 +0200 ++++ lldb-3.9.0.src/source/Host/windows/Windows.cpp 2016-09-25 21:47:43.401828300 +0200 +@@ -53,6 +53,7 @@ + } + } + ++#ifndef __MINGW64_VERSION_MAJOR + int vasprintf(char **ret, const char *fmt, va_list ap) + { + char *buf; +@@ -79,6 +80,7 @@ + va_end(ap2); + return len; + } ++#endif //__MINGW64_VERSION_MAJOR + + char* strcasestr(const char *s, const char* find) + { +diff -urN lldb-3.9.0.src.orig/source/Target/ProcessLaunchInfo.cpp lldb-3.9.0.src/source/Target/ProcessLaunchInfo.cpp +--- lldb-3.9.0.src.orig/source/Target/ProcessLaunchInfo.cpp 2016-05-11 18:59:04.000000000 +0200 ++++ lldb-3.9.0.src/source/Target/ProcessLaunchInfo.cpp 2016-09-25 22:23:38.450694800 +0200 +@@ -362,7 +362,7 @@ + __FUNCTION__); + + int open_flags = O_RDWR | O_NOCTTY; +-#if !defined(_MSC_VER) ++#if !defined(_WIN32) + // We really shouldn't be specifying platform specific flags + // that are intended for a system call in generic code. But + // this will have to do for now. +diff -urN lldb-3.9.0.src.orig/source/Utility/PseudoTerminal.cpp lldb-3.9.0.src/source/Utility/PseudoTerminal.cpp +--- lldb-3.9.0.src.orig/source/Utility/PseudoTerminal.cpp 2015-05-12 03:10:56.000000000 +0200 ++++ lldb-3.9.0.src/source/Utility/PseudoTerminal.cpp 2016-09-25 22:29:40.256771400 +0200 +@@ -20,7 +20,11 @@ + + #ifdef _WIN32 + #include "lldb/Host/windows/win32.h" ++ ++#ifndef __MINGW64_VERSION_MAJOR + typedef uint32_t pid_t; ++#endif ++ + // empty functions + int posix_openpt(int flag) { return 0; } + +@@ -364,4 +368,3 @@ + m_slave_fd = invalid_fd; + return fd; + } +- diff --git a/mingw-w64-clang/0052-lldb-more-mingw-fixes.patch b/mingw-w64-clang/0052-lldb-more-mingw-fixes.patch new file mode 100644 index 0000000000..c6a5446768 --- /dev/null +++ b/mingw-w64-clang/0052-lldb-more-mingw-fixes.patch @@ -0,0 +1,62 @@ +diff -urN lldb-3.9.0.src.orig/cmake/LLDBDependencies.cmake lldb-3.9.0.src/cmake/LLDBDependencies.cmake +--- lldb-3.9.0.src.orig/cmake/LLDBDependencies.cmake 2016-06-29 14:30:18.000000000 +0200 ++++ lldb-3.9.0.src/cmake/LLDBDependencies.cmake 2016-10-08 10:52:57.689832300 +0200 +@@ -21,7 +21,7 @@ + lldbPluginDynamicLoaderPosixDYLD + lldbPluginDynamicLoaderHexagonDYLD + lldbPluginDynamicLoaderWindowsDYLD +- ++ + lldbPluginCPlusPlusLanguage + lldbPluginGoLanguage + lldbPluginJavaLanguage +@@ -92,6 +92,7 @@ + lldbPluginProcessWindowsCommon + Ws2_32 + Rpcrt4 ++ dbghelp + ) + endif () + +diff -urN lldb-3.9.0.src.orig/source/API/CMakeLists.txt lldb-3.9.0.src/source/API/CMakeLists.txt +--- lldb-3.9.0.src.orig/source/API/CMakeLists.txt 2016-06-23 10:35:37.000000000 +0200 ++++ lldb-3.9.0.src/source/API/CMakeLists.txt 2016-10-08 11:05:16.092749700 +0200 +@@ -101,7 +101,7 @@ + endif() + endif() + +-if ( CMAKE_SYSTEM_NAME MATCHES "Windows" ) ++if ( CMAKE_SYSTEM_NAME MATCHES "Windows" AND NOT MINGW ) + # Only MSVC has the ABI compatibility problem and avoids using FindPythonLibs, + # so only it needs to explicitly link against ${PYTHON_LIBRARY} + if (MSVC AND NOT LLDB_DISABLE_PYTHON) +Plik lldb-3.9.0.src.orig/test/testcases jest zwykły pusty plik, podczas gdy plik lldb-3.9.0.src/test/testcases jest katalog +diff -urN lldb-3.9.0.src.orig/tools/lldb-mi/MIDataTypes.h lldb-3.9.0.src/tools/lldb-mi/MIDataTypes.h +--- lldb-3.9.0.src.orig/tools/lldb-mi/MIDataTypes.h 2015-07-21 13:27:40.000000000 +0200 ++++ lldb-3.9.0.src/tools/lldb-mi/MIDataTypes.h 2016-10-08 11:28:13.197215200 +0200 +@@ -40,12 +40,12 @@ + #define MIunused(x) (void) x; + + // Portability issues +-#ifdef _WIN64 ++#if defined(_WIN64) && defined(_MSC_VER) + typedef unsigned __int64 size_t; + typedef __int64 MIint; + typedef unsigned __int64 MIuint; + #else +-#ifdef _WIN32 ++#if defined(_WIN32) && defined(_MSC_VER) + typedef unsigned int size_t; + typedef int MIint; + typedef unsigned int MIuint; +@@ -53,7 +53,10 @@ + typedef int MIint; + typedef unsigned int MIuint; + ++#ifndef __MINGW32__ + #define MAX_PATH 4096 ++#endif ++ + #endif // _WIN32 + #endif // _WIN64 + diff --git a/mingw-w64-clang/PKGBUILD b/mingw-w64-clang/PKGBUILD index b0c9856dac..ee5f7a1613 100644 --- a/mingw-w64-clang/PKGBUILD +++ b/mingw-w64-clang/PKGBUILD @@ -1,6 +1,11 @@ # Maintainer: Martell Malone # Maintainer: Alexey Pavlov # Contributor: Ray Donnelly +# Contributor: Mateusz Mikuła + +# choose the compiler that will be used +# clang compilation currently unspported due to mingw-w64 headers bugs +_compiler=gcc # clang, gcc _realname=clang pkgbase=mingw-w64-${_realname} @@ -11,9 +16,9 @@ pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}" "${MINGW_PACKAGE_PREFIX}-libc++abi" "${MINGW_PACKAGE_PREFIX}-libc++" "${MINGW_PACKAGE_PREFIX}-lld" - "${MINGW_PACKAGE_PREFIX}-libunwind" + #"${MINGW_PACKAGE_PREFIX}-libunwind" "${MINGW_PACKAGE_PREFIX}-llvm" - #"${MINGW_PACKAGE_PREFIX}-lldb" + "${MINGW_PACKAGE_PREFIX}-lldb" ) pkgver=3.9.0 pkgrel=1 @@ -22,7 +27,10 @@ arch=('any') url="http://llvm.org" license=("custom:University of Illinois/NCSA Open Source License") makedepends=("${MINGW_PACKAGE_PREFIX}-cmake" - "${MINGW_PACKAGE_PREFIX}-gcc" + $([[ "$_compiler" == "gcc" ]] && echo \ + "${MINGW_PACKAGE_PREFIX}-gcc") + $([[ "$_compiler" == "clang" ]] && echo \ + "${MINGW_PACKAGE_PREFIX}-clang") "${MINGW_PACKAGE_PREFIX}-libffi" "${MINGW_PACKAGE_PREFIX}-pkg-config" "${MINGW_PACKAGE_PREFIX}-python3-sphinx" @@ -41,16 +49,28 @@ source=(http://llvm.org/releases/${pkgver}/llvm-${pkgver}.src.tar.xz{,.sig} http://llvm.org/releases/${pkgver}/lld-${pkgver}.src.tar.xz{,.sig} http://llvm.org/releases/${pkgver}/lldb-${pkgver}.src.tar.xz{,.sig} http://llvm.org/releases/${pkgver}/libunwind-${pkgver}.src.tar.xz{,.sig} - "0001-Fix-GetHostTriple-for-mingw-w64-in-msys.patch" - "0002-use-DESTDIR-on-windows.patch" - "0003-generate-proper-library-names-mingw.patch" + "0001-genlib-named-as-llvm-dlltool.patch" + "0002-COFF-Fix-short-import-lib-import-name-type-bitshift.patch" + "0003-mingw-w64-use-MSVC-style-ByteAlignment.patch" "0004-killthedoctor-mingw.patch" - "0012-Set-the-x86-arch-name-to-i686-for-mingw-w64.patch" - "0013-mingw-w64-dont-have-dl-library.patch" - "0014-dont-create-cl-mingw.patch" - "0018-mingw-enable-static-libclang.patch" - "0021-missing-include.patch" - "0041-libcxx-add-support-for-mingw-w64.patch" + "0005-Fix-GetHostTriple-for-mingw-w64-in-msys.patch" + "0006-use-DESTDIR-on-windows.patch" + "0011-Revert-Revert-r253898-and-r253899-this-breaks-mingw-.patch" + "0012-mingw-w64-setup-new-defaults-for-target.patch" + "0013-mingw-w64-enable-support-for-__declspec-selectany.patch" + "0014-mingw-w64-support-static-builds-of-libc.patch" + "0015-mingw-enable-static-libclang.patch" + "0016-generate-libclang-instead-of-liblibclang.patch" + "0017-dont-create-cl-mingw.patch" + "0018-experimental-workaround-for-limits-bug.patch" + "0019-Set-the-x86-arch-name-to-i686-for-mingw-w64.patch" + "0022-mingw-w64-__udivdi3-mangle-hack.patch" + "0023-mingw-fixes-for-compiler-rt.patch" + "0031-COFF-gnu-driver-support.patch" + "0041-mingw-w64-hack-and-slash-fixes-for-libc.patch" + "0042-fix-compilation-with-gcc.patch" + "0051-lldb-mingw-fixes.patch" + "0052-lldb-more-mingw-fixes.patch" "0061-libunwind-add-support-for-mingw-w64.patch") # Some patch notes :) #0001-0009 -> llvm @@ -80,23 +100,34 @@ sha256sums=('66c73179da42cee1386371641241f79ded250e117a79f571bbd69e56daa48948' 'SKIP' '66675ddec5ba0d36689757da6008cb2596ee1a9067f4f598d89ce5a3b43f4c2b' 'SKIP' + 'a69d60c2ae36f253f34ab3cfaaa4ff10522692dd4a1a646f2f8fa8996fbd026b' + '89e86d7f53b97bbaef6ee02aa817e979bc122b4844e237b2f5f2af8c268c44c4' + '3c429a6762c66ffd18b0f378debe0527e15f27e5caa0bb47d2e88f8afe68b093' + 'e83fe9effaa3d0ba21d3bb98bfd471dc0acd2dd99c72695fb33685d69f8e2a76' '0804146b32138d55c611336cc81e1783c29a8fab0fe62f248ba1ad7acc711c4d' '76bcdcae0ef3a4d3ae7082b7fcd668e9560e63fb82068c3f889f9e89b9becf4a' - '6a95ed671876a6de04799d15bf7485d628016bb4a95a6764217ad452d8eed0d8' - 'e83fe9effaa3d0ba21d3bb98bfd471dc0acd2dd99c72695fb33685d69f8e2a76' - '13a95a61e9c1c44c18a69947734e07515332a549446394f48b86b52511d221de' - '8f35b80eca6c18df020b176eee4eb95901c31e3e640848a6d606983aca15a3af' - 'b03cfc7ebbbfb847e88ae3569d9dcafb01f179b06f1312de29fbd5b7cf906617' + '31e0f242f4463cadc1b867a87b38e4c2f689e70fdd6d64a44dcc3784f352b20f' + 'ba703d3d0f100d02ba01501319e6ec29565a199176fb20d11f89fa31b479df5f' + 'b00b3e2395d9262c999c6865da59837f0712454803e0d4e776181267df89f083' + '0c570da0d1357cfef276da685b67118d48a6a6f5a0fc4e281c2925c10f8be9ca' '0e45e76ee6d6658de52edb7b508a8bcc9f10ff0b295ff2a4e35577136a40c6a5' - 'a0933775b979b4879e220358b1076d8eeb9170403d0d190b1340d179fcd3cd1e' - '5b8edbbb638c906216e20229529e8348abc50d5886d20e07af08543e1e574e94' + 'ddc914887e512e0767b1465f17c80378cf38a041795538b37a40ac57889164fb' + 'b03cfc7ebbbfb847e88ae3569d9dcafb01f179b06f1312de29fbd5b7cf906617' + 'd6c483a99973ae674e85f8d816cb34e1538ee4d9cc64bfe63735322d86503f7c' + '13a95a61e9c1c44c18a69947734e07515332a549446394f48b86b52511d221de' + 'fb1ef06b26e88d37d52c3e0b3b261089e92bb7c08231ec8fa234465fdbdab308' + 'c19a3e49f692eba9143bb67c39a9e6df33fa604d85b0b7834d99cdd58a28d23a' + '852d55907b469739fca96b043e41c596824ad9d933268ce65a82100b975e91fb' + 'd9b46363c0db63316bdaa29580c446bfe5bc7b43eb8d00f894b72415066da53e' + '61059619286b1d1761c80788778999c215aca2e7098c491b14557fb24d2874a2' + '6bbf6b6fe11c6708d92d452ceaacebf6cc67675bbf4ece3063779d4f4927db61' + 'b9d21856176a9933354ef21caca59d0ea8a5b98fcf09494233d275cebc864a40' '0a5529a5e9871ec5252c3853f1fdda69253c1a7505837e9c45ae14bcb76a8660') -validpgpkeys=('B6C8F98282B944E3B0D5C2530FC3042E345AD05D') # Hans Wennborg, Google. +validpgpkeys=('B6C8F98282B944E3B0D5C2530FC3042E345AD05D') # Hans Wennborg, Google. noextract=(cfe-${pkgver}.src.tar.xz libcxx-${pkgver}.src.tar.xz lldb-${pkgver}.src.tar.xz - test-suite-${pkgver}.src.tar.xz - ) + test-suite-${pkgver}.src.tar.xz) prepare() { plain "Extracting clang-${pkgver}.src.tar.xz due to symlink(s) without pre-existing target(s)" @@ -112,27 +143,41 @@ prepare() { [[ -d ${srcdir}/lldb-${pkgver} ]] || tar -xJvf ${srcdir}/lldb-${pkgver}.src.tar.xz -C ${srcdir} || true cd "${srcdir}/llvm-${pkgver}.src" - patch -p1 -i "${srcdir}/0001-Fix-GetHostTriple-for-mingw-w64-in-msys.patch" - patch -p1 -i "${srcdir}/0002-use-DESTDIR-on-windows.patch" - patch -p1 -i "${srcdir}/0003-generate-proper-library-names-mingw.patch" + patch -p1 -i "${srcdir}/0001-genlib-named-as-llvm-dlltool.patch" + patch -p1 -i "${srcdir}/0002-COFF-Fix-short-import-lib-import-name-type-bitshift.patch" + patch -p1 -i "${srcdir}/0003-mingw-w64-use-MSVC-style-ByteAlignment.patch" patch -p1 -i "${srcdir}/0004-killthedoctor-mingw.patch" + patch -p1 -i "${srcdir}/0005-Fix-GetHostTriple-for-mingw-w64-in-msys.patch" + patch -p1 -i "${srcdir}/0006-use-DESTDIR-on-windows.patch" cd "${srcdir}/cfe-${pkgver}.src" - patch -p1 -i "${srcdir}/0012-Set-the-x86-arch-name-to-i686-for-mingw-w64.patch" - patch -p1 -i "${srcdir}/0013-mingw-w64-dont-have-dl-library.patch" - patch -p1 -i "${srcdir}/0014-dont-create-cl-mingw.patch" - patch -p1 -i "${srcdir}/0018-mingw-enable-static-libclang.patch" + patch -p1 -i "${srcdir}/0011-Revert-Revert-r253898-and-r253899-this-breaks-mingw-.patch" + #patch -p1 -i "${srcdir}/0012-mingw-w64-setup-new-defaults-for-target.patch" + patch -p1 -i "${srcdir}/0013-mingw-w64-enable-support-for-__declspec-selectany.patch" + patch -p1 -i "${srcdir}/0014-mingw-w64-support-static-builds-of-libc.patch" + patch -p1 -i "${srcdir}/0015-mingw-enable-static-libclang.patch" + patch -p1 -i "${srcdir}/0016-generate-libclang-instead-of-liblibclang.patch" + patch -p1 -i "${srcdir}/0017-dont-create-cl-mingw.patch" + patch -p1 -i "${srcdir}/0018-experimental-workaround-for-limits-bug.patch" + patch -p1 -i "${srcdir}/0019-Set-the-x86-arch-name-to-i686-for-mingw-w64.patch" cd "${srcdir}/compiler-rt-${pkgver}.src" - patch -p1 -i ${srcdir}/0021-missing-include.patch + # patch -p1 -i "${srcdir}/0022-mingw-w64-__udivdi3-mangle-hack.patch" + patch -p1 -i "${srcdir}/0023-mingw-fixes-for-compiler-rt.patch" cd "${srcdir}/lld-${pkgver}.src" + patch -p1 -i "${srcdir}/0031-COFF-gnu-driver-support.patch" cd "${srcdir}/libcxx-${pkgver}.src" - patch -p1 -i "${srcdir}/0041-libcxx-add-support-for-mingw-w64.patch" + patch -p1 -i "${srcdir}/0041-mingw-w64-hack-and-slash-fixes-for-libc.patch" + patch -p1 -i "${srcdir}/0042-fix-compilation-with-gcc.patch" + + cd "${srcdir}/lldb-${pkgver}.src" + patch -p1 -i "${srcdir}/0051-lldb-mingw-fixes.patch" + patch -p1 -i "${srcdir}/0052-lldb-more-mingw-fixes.patch" cd "${srcdir}/libunwind-${pkgver}.src" - patch -p1 -i "${srcdir}/0061-libunwind-add-support-for-mingw-w64.patch" + #patch -p1 -i "${srcdir}/0061-libunwind-add-support-for-mingw-w64.patch" # At the present, clang must reside inside the LLVM source code tree to build # See http://llvm.org/bugs/show_bug.cgi?id=4840 @@ -146,7 +191,7 @@ prepare() { mv "${srcdir}/compiler-rt-${pkgver}.src" projects/compiler-rt | true mv "${srcdir}/libcxxabi-${pkgver}.src" projects/libcxxabi | true mv "${srcdir}/libcxx-${pkgver}.src" projects/libcxx | true - mv "${srcdir}/libunwind-${pkgver}.src" projects/libunwind | true + #mv "${srcdir}/libunwind-${pkgver}.src" projects/libunwind | true #mv "${srcdir}/testsuite-${pkgver}.src" projects/test-suite | true } @@ -172,14 +217,25 @@ 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 + #export CC='clang -stdlib=libc++' + #export CXX='clang++ -stdlib=libc++' + export CC='clang' + export CXX='clang++' + else + msg "undefined compiler" + exit 1 + fi + PATH=${MINGW_PREFIX}/bin:/usr/bin \ MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \ ${MINGW_PREFIX}/bin/cmake.exe \ -G"MSYS Makefiles" \ -DCMAKE_SYSTEM_IGNORE_PATH=/usr/lib \ -DCMAKE_MAKE_PROGRAM="/usr/bin/make.exe" \ - -DCMAKE_C_COMPILER="${MINGW_PREFIX}/bin/gcc.exe" \ - -DCMAKE_CXX_COMPILER="${MINGW_PREFIX}/bin/g++.exe" \ -DFFI_INCLUDE_DIR="${FFI_INCLUDE_DIR}" \ -DCMAKE_C_FLAGS="${CFLAGS}" \ -DCMAKE_CXX_FLAGS="${CXXFLAGS} ${CPPFLAGS}" \ @@ -190,11 +246,12 @@ build() { -DPYTHON_EXECUTABLE=${MINGW_PREFIX}/bin/python2.exe \ -DLLVM_ENABLE_FFI=ON \ -DLLVM_ENABLE_SPHINX=ON \ - -DCMAKE_CXX_FLAGS="-D_GNU_SOURCE -D_LIBCPP_HAS_NO_CONSTEXPR" \ + -DCMAKE_CXX_FLAGS="-D_GNU_SOURCE" \ -DLIBCLANG_BUILD_STATIC=ON \ -DLIBCXX_ENABLE_SHARED=OFF \ -DLIBCXXABI_ENABLE_SHARED=OFF \ -DLIBUNWIND_ENABLE_SHARED=OFF \ + -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=OFF \ "${extra_config[@]}" \ ../llvm-${pkgver}.src @@ -247,7 +304,7 @@ package_compiler-rt() { package_libcxxabi() { pkgdesc="C++ Standard Library Support (mingw-w64)" url="http://libcxxabi.llvm.org/" - depends="${MINGW_PACKAGE_PREFIX}-libunwind" + # depends="${MINGW_PACKAGE_PREFIX}-libunwind" cd "${srcdir}/llvm-${pkgver}.src" make -C ../build-${CARCH}/projects/libcxxabi -j1 DESTDIR="${pkgdir}" install @@ -264,7 +321,7 @@ package_libcxx() { package_libunwind() { pkgdesc='A new implementation of a stack unwinder for C++ exceptions (mingw-w64)' url='http://llvm.org' - + cd "${srcdir}/llvm-${pkgver}.src" make -C ../build-${CARCH}/projects/libunwind -j1 DESTDIR="${pkgdir}" install }