diff --git a/CMakeLists.txt b/CMakeLists.txt index 5210718005..db43ce77c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,7 +109,9 @@ if(WIN32) add_compile_options(/guard:cf) add_link_options(/guard:cf) else() - add_compile_options(-fcf-protection) + if(LLVM_NATIVE_ARCH MATCHES "X86") + add_compile_options(-fcf-protection) + endif() endif() endif(WIN32) diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake index d5769abce7..b9fcc9c6e1 100644 --- a/cmake/modules/HandleLLVMOptions.cmake +++ b/cmake/modules/HandleLLVMOptions.cmake @@ -238,6 +238,10 @@ endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 ) if (LLVM_BUILD_STATIC) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static") + if(MINGW) + # We want to mimic MSVC standalone build here + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static") + endif() endif() if( XCODE ) @@ -425,12 +429,18 @@ elseif( LLVM_COMPILER_IS_GCC_COMPATIBLE ) append("-Wno-unknown-pragmas" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) if (MINGW) + append("-Wno-cast-function-type-mismatch" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) append("-Wno-implicit-fallthrough" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) append("-Wno-missing-exception-spec" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) append("-Wno-reorder-ctor" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) append("-Wno-sign-compare" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) append("-Wno-unused-const-variable" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) append("-Wno-unused-function" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + append("-Wno-unused-private-field" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + + if (CMAKE_BUILD_TYPE STREQUAL "Debug") + append("-Wno-gnu-zero-variadic-macro-arguments" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + endif() endif() add_flag_if_supported("-Wno-unused-but-set-variable" UNUSED_BUT_SET_VARIABLE) diff --git a/include/dxc/Support/Global.h b/include/dxc/Support/Global.h index 3a6c0aaa5e..45060405d9 100644 --- a/include/dxc/Support/Global.h +++ b/include/dxc/Support/Global.h @@ -229,7 +229,7 @@ template T *VerifyNullAndThrow(T *p) { } #define VNT(__p) VerifyNullAndThrow(__p) -#ifdef _MSC_VER +#ifdef _WIN32 extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA( const char *msg); @@ -270,7 +270,7 @@ inline void OutputDebugFormatA(const char *pszFormat, ...) { va_list argList; va_start(argList, pszFormat); - int count = vsnprintf_s(buffer, bufferSize, pszFormat, argList); + int count = vsnprintf_s(buffer, bufferSize, bufferSize, pszFormat, argList); va_end(argList); OutputDebugStringA(buffer); @@ -279,7 +279,7 @@ inline void OutputDebugFormatA(const char *pszFormat, ...) { } } -#endif // _MSC_VER +#endif // _WIN32 #ifndef NDEBUG @@ -302,7 +302,7 @@ inline void OutputDebugFormatA(const char *pszFormat, ...) { if (!(exp)) { \ OutputDebugFormatA( \ "Error: \t%s\nFile:\n%s(%d)\nFunc:\t%s.\n\t" fmt "\n", \ - "!(" #exp ")", __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__); \ + "!(" #exp ")", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \ __debugbreak(); \ } \ } while (0) diff --git a/include/dxc/WinAdapter.h b/include/dxc/WinAdapter.h index 986149217f..6ec1607ac3 100644 --- a/include/dxc/WinAdapter.h +++ b/include/dxc/WinAdapter.h @@ -15,7 +15,7 @@ #ifndef LLVM_SUPPORT_WIN_ADAPTER_H #define LLVM_SUPPORT_WIN_ADAPTER_H -#ifndef _WIN32 +#ifndef _MSC_VER #ifdef __cplusplus #include @@ -33,6 +33,148 @@ #include #endif // __cplusplus +#ifdef __MINGW32__ + +#undef _WIN32_WINNT +#undef _WIN32_IE + +// Require at least Windows 7 (Updated from XP) +#define _WIN32_WINNT 0x0601 +#define _WIN32_IE 0x0800 + +#define WIN32_LEAN_AND_MEAN +#define STRSAFE_NO_DEPRECATE + +#include +#include +#include +#include +#include +#include + +#undef EN +#undef IN +#undef OUT + +#ifdef MemoryFence +#undef MemoryFence +#endif + +#define EventRegisterMicrosoft_Windows_DXCompiler_API() +#define EventRegisterMicrosoft_Windows_DxcRuntime_API() +#define EventUnregisterMicrosoft_Windows_DXCompiler_API() +#define EventUnregisterMicrosoft_Windows_DxcRuntime_API() + +#define DxcEtw_DXCompilerCompile_Start() +#define DxcEtw_DXCompilerCompile_Stop(hr) +#define DxcEtw_DXCompilerCreateInstance_Start() +#define DxcEtw_DXCompilerCreateInstance_Stop(hr) +#define DxcEtw_DXCompilerDisassemble_Start() +#define DxcEtw_DXCompilerDisassemble_Stop(hr) +#define DxcEtw_DXCompilerInitialization_Start() +#define DxcEtw_DXCompilerInitialization_Stop(hr) +#define DxcEtw_DXCompilerPreprocess_Start() +#define DxcEtw_DXCompilerPreprocess_Stop(hr) +#define DxcEtw_DXCompilerShutdown_Start() +#define DxcEtw_DXCompilerShutdown_Stop(hr) +#define DxcEtw_DxcValidation_Start() +#define DxcEtw_DxcValidation_Stop(hr) +#define DxcRuntimeEtw_DxcRuntimeInitialization_Start() +#define DxcRuntimeEtw_DxcRuntimeInitialization_Stop(HR) +#define DxcRuntimeEtw_DxcRuntimeShutdown_Start() +#define DxcRuntimeEtw_DxcRuntimeShutdown_Stop(S_OK) + +#define ATLASSERT assert +#define ATLASSUME(expr) \ + do { \ + ATLASSERT(expr); \ + __analysis_assume(!!(expr)); \ + } while (0) +#define ATLENSURE_THROW(expr, hr) \ + do { \ + int __atl_condVal = !!(expr); \ + ATLASSUME(__atl_condVal); \ + if (!(__atl_condVal)) \ + throw(hr); \ + } while (0) + +// Disable all calling conventions +#define __cdecl +#define __stdcall +#define __vectorcall +#define __thiscall +#define __fastcall +#define __clrcall + +// FIXME: missing from intsafe.h +#define Int32ToUInt32 IntToUInt +#define UInt32Add UIntAdd +#define UInt32Mult UIntMult + +// FIXME: missing from sal.h +#define _Maybenull_ +#define _Notnull_ + +// FIXME: missing from d3d12shader.h +#define D3D_SHADER_REQUIRES_EARLY_DEPTH_STENCIL 0x00000002 +#define D3D12_SHVER_GET_TYPE(_Version) (((_Version) >> 16) & 0xffff) +#define D3D12_SHVER_GET_MAJOR(_Version) (((_Version) >> 4) & 0xf) +#define D3D12_SHVER_GET_MINOR(_Version) (((_Version) >> 0) & 0xf) + +#ifdef __cplusplus + +constexpr uint8_t nybble_from_hex(char c) { + return ((c >= '0' && c <= '9') + ? (c - '0') + : ((c >= 'a' && c <= 'f') + ? (c - 'a' + 10) + : ((c >= 'A' && c <= 'F') ? (c - 'A' + 10) + : /* Should be an error */ -1))); +} + +constexpr uint8_t byte_from_hex(char c1, char c2) { + return nybble_from_hex(c1) << 4 | nybble_from_hex(c2); +} + +constexpr uint8_t byte_from_hexstr(const char str[2]) { + return nybble_from_hex(str[0]) << 4 | nybble_from_hex(str[1]); +} + +constexpr GUID guid_from_string(const char str[37]) { + return GUID{static_cast(byte_from_hexstr(str)) << 24 | + static_cast(byte_from_hexstr(str + 2)) << 16 | + static_cast(byte_from_hexstr(str + 4)) << 8 | + byte_from_hexstr(str + 6), + static_cast( + static_cast(byte_from_hexstr(str + 9)) << 8 | + byte_from_hexstr(str + 11)), + static_cast( + static_cast(byte_from_hexstr(str + 14)) << 8 | + byte_from_hexstr(str + 16)), + {byte_from_hexstr(str + 19), byte_from_hexstr(str + 21), + byte_from_hexstr(str + 24), byte_from_hexstr(str + 26), + byte_from_hexstr(str + 28), byte_from_hexstr(str + 30), + byte_from_hexstr(str + 32), byte_from_hexstr(str + 34)}}; +} + +#define CROSS_PLATFORM_UUIDOF(name, spec) \ + struct __declspec(uuid(spec)) name; \ + extern "C++" { \ + template <> struct __mingw_uuidof_s { \ + static constexpr IID __uuid_inst = guid_from_string(spec); \ + }; \ + template <> constexpr const GUID &__mingw_uuidof() { \ + return __mingw_uuidof_s::__uuid_inst; \ + } \ + template <> constexpr const GUID &__mingw_uuidof() { \ + return __mingw_uuidof_s::__uuid_inst; \ + } \ + } + +#endif // __cplusplus + +#else // !__MINGW32__ + #define COM_NO_WINDOWS_H // needed to inform d3d headers that this isn't windows //===----------------------------------------------------------------------===// @@ -631,6 +773,12 @@ CROSS_PLATFORM_UUIDOF(ID3D12LibraryReflection, CROSS_PLATFORM_UUIDOF(ID3D12ShaderReflection, "5A58797D-A72C-478D-8BA2-EFC6B0EFE88E") +#endif // __cplusplus + +#endif // !__MINGW32__ + +#ifdef __cplusplus + //===--------------------- COM Pointer Types ------------------------------===// class CAllocator { @@ -898,6 +1046,7 @@ class CHeapPtr : public CHeapPtrBase { #define CComHeapPtr CHeapPtr +#ifndef __MINGW32__ //===--------------------------- BSTR Allocation --------------------------===// void SysFreeString(BSTR bstrString); @@ -999,6 +1148,145 @@ template class CA2WEX { typedef CA2WEX<> CA2W; +#else // __MINGW32__ + +inline UINT WINAPI _AtlGetConversionACP() { return CP_THREAD_ACP; } + +template +inline void AtlConvAllocMemory(_CharType **ppBuff, int nLength, + _CharType *pszFixedBuffer, + int nFixedBufferLength) { + ATLENSURE_THROW(ppBuff != NULL, E_INVALIDARG); + ATLENSURE_THROW(nLength >= 0, E_INVALIDARG); + ATLENSURE_THROW(pszFixedBuffer != NULL, E_INVALIDARG); + + if (*ppBuff != pszFixedBuffer) { + if (nLength > nFixedBufferLength) { +#if __MSVCRT_VERSION__ >= 0x900 + _CharType *ppReallocBuf = static_cast<_CharType *>( + _recalloc(*ppBuff, nLength, sizeof(_CharType))); + if (ppReallocBuf == NULL) { + E_OUTOFMEMORY; + } + *ppBuff = ppReallocBuf; + } else { +#endif + free(*ppBuff); + *ppBuff = pszFixedBuffer; + } + + } else { + if (nLength > nFixedBufferLength) { + *ppBuff = static_cast<_CharType *>(calloc(nLength, sizeof(_CharType))); + } else { + *ppBuff = pszFixedBuffer; + } + } + + if (*ppBuff == NULL) { + E_OUTOFMEMORY; + } +} + +template +inline void AtlConvFreeMemory(_CharType *pBuff, _CharType *pszFixedBuffer, + int nFixedBufferLength) { + if (pBuff != pszFixedBuffer) { + free(pBuff); + } +} + +template class CW2AEX { +public: + CW2AEX(LPCWSTR psz) : m_psz(m_szBuffer) { Init(psz, _AtlGetConversionACP()); } + CW2AEX(LPCWSTR psz, UINT nCodePage) : m_psz(m_szBuffer) { + Init(psz, nCodePage); + } + ~CW2AEX() { AtlConvFreeMemory(m_psz, m_szBuffer, t_nBufferLength); } + + operator LPSTR() const { return (m_psz); } + +private: + void Init(LPCWSTR psz, UINT nConvertCodePage) { + if (psz == NULL) { + m_psz = NULL; + return; + } + int nLengthW = lstrlenW(psz) + 1; + int nLengthA = nLengthW * 4; + + AtlConvAllocMemory(&m_psz, nLengthA, m_szBuffer, t_nBufferLength); + + BOOL bFailed = + (0 == ::WideCharToMultiByte(nConvertCodePage, 0, psz, nLengthW, m_psz, + nLengthA, NULL, NULL)); + if (bFailed) { + if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { + nLengthA = ::WideCharToMultiByte(nConvertCodePage, 0, psz, nLengthW, + NULL, 0, NULL, NULL); + AtlConvAllocMemory(&m_psz, nLengthA, m_szBuffer, t_nBufferLength); + bFailed = + (0 == ::WideCharToMultiByte(nConvertCodePage, 0, psz, nLengthW, + m_psz, nLengthA, NULL, NULL)); + } + } + } + +public: + LPSTR m_psz; + char m_szBuffer[t_nBufferLength]; + +private: + CW2AEX(const CW2AEX &); + CW2AEX &operator=(const CW2AEX &); +}; +typedef CW2AEX<> CW2A; + +template class CA2WEX { +public: + CA2WEX(LPCSTR psz) : m_psz(m_szBuffer) { Init(psz, _AtlGetConversionACP()); } + CA2WEX(LPCSTR psz, UINT nCodePage) : m_psz(m_szBuffer) { + Init(psz, nCodePage); + } + ~CA2WEX() { AtlConvFreeMemory(m_psz, m_szBuffer, t_nBufferLength); } + + operator LPWSTR() const { return (m_psz); } + +private: + void Init(LPCSTR psz, UINT nCodePage) { + if (psz == NULL) { + m_psz = NULL; + return; + } + int nLengthA = lstrlenA(psz) + 1; + int nLengthW = nLengthA; + + AtlConvAllocMemory(&m_psz, nLengthW, m_szBuffer, t_nBufferLength); + + BOOL bFailed = (0 == ::MultiByteToWideChar(nCodePage, 0, psz, nLengthA, + m_psz, nLengthW)); + if (bFailed) { + if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { + nLengthW = ::MultiByteToWideChar(nCodePage, 0, psz, nLengthA, NULL, 0); + AtlConvAllocMemory(&m_psz, nLengthW, m_szBuffer, t_nBufferLength); + bFailed = (0 == ::MultiByteToWideChar(nCodePage, 0, psz, nLengthA, + m_psz, nLengthW)); + } + } + } + +public: + LPWSTR m_psz; + wchar_t m_szBuffer[t_nBufferLength]; + +private: + CA2WEX(const CA2WEX &); + CA2WEX &operator=(const CA2WEX &); +}; +typedef CA2WEX<> CA2W; + +#endif // __MINGW32__ + //===--------- File IO Related Types ----------------===// class CHandle { @@ -1051,6 +1339,6 @@ class WArgV { #endif // __cplusplus -#endif // _WIN32 +#endif // _MSC_VER #endif // LLVM_SUPPORT_WIN_ADAPTER_H diff --git a/include/dxc/dxcapi.internal.h b/include/dxc/dxcapi.internal.h index ca4b892748..519828745b 100644 --- a/include/dxc/dxcapi.internal.h +++ b/include/dxc/dxcapi.internal.h @@ -12,7 +12,7 @@ #ifndef __DXC_API_INTERNAL__ #define __DXC_API_INTERNAL__ -#include "dxcapi.h" +#include "dxc/dxcapi.h" /////////////////////////////////////////////////////////////////////////////// // Forward declarations. diff --git a/include/dxc/dxcisense.h b/include/dxc/dxcisense.h index 661de1680a..266bed4653 100644 --- a/include/dxc/dxcisense.h +++ b/include/dxc/dxcisense.h @@ -12,7 +12,7 @@ #ifndef __DXC_ISENSE__ #define __DXC_ISENSE__ -#include "dxcapi.h" +#include "dxc/dxcapi.h" #ifndef _WIN32 #include "WinAdapter.h" #endif diff --git a/include/llvm/ADT/StringRef.h b/include/llvm/ADT/StringRef.h index c103fdbf3b..72918b5bca 100644 --- a/include/llvm/ADT/StringRef.h +++ b/include/llvm/ADT/StringRef.h @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -570,24 +571,4 @@ namespace llvm { template <> struct isPodLike { static const bool value = true; }; } -// HLSL Change Starts -// StringRef provides an operator string; that trips up the std::pair noexcept specification, -// which (a) enables the moves constructor (because conversion is allowed), but (b) -// misclassifies the the construction as nothrow. -namespace std { - template<> - struct is_nothrow_constructible - : std::false_type { - }; - template<> - struct is_nothrow_constructible - : std::false_type { - }; - template<> - struct is_nothrow_constructible - : std::false_type { - }; -} -// HLSL Change Ends - #endif diff --git a/include/llvm/Object/COFF.h b/include/llvm/Object/COFF.h index 025a9dbc6b..76479c0f0e 100644 --- a/include/llvm/Object/COFF.h +++ b/include/llvm/Object/COFF.h @@ -20,6 +20,8 @@ #include "llvm/Support/Endian.h" #include "llvm/Support/ErrorOr.h" +using namespace llvm::COFF; + namespace llvm { template class ArrayRef; @@ -334,31 +336,31 @@ class COFFSymbolRef { } bool isExternal() const { - return getStorageClass() == COFF::IMAGE_SYM_CLASS_EXTERNAL; + return getStorageClass() == IMAGE_SYM_CLASS_EXTERNAL; } bool isCommon() const { - return isExternal() && getSectionNumber() == COFF::IMAGE_SYM_UNDEFINED && + return isExternal() && getSectionNumber() == IMAGE_SYM_UNDEFINED && getValue() != 0; } bool isUndefined() const { - return isExternal() && getSectionNumber() == COFF::IMAGE_SYM_UNDEFINED && + return isExternal() && getSectionNumber() == IMAGE_SYM_UNDEFINED && getValue() == 0; } bool isWeakExternal() const { - return getStorageClass() == COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL; + return getStorageClass() == IMAGE_SYM_CLASS_WEAK_EXTERNAL; } bool isFunctionDefinition() const { - return isExternal() && getBaseType() == COFF::IMAGE_SYM_TYPE_NULL && - getComplexType() == COFF::IMAGE_SYM_DTYPE_FUNCTION && + return isExternal() && getBaseType() == IMAGE_SYM_TYPE_NULL && + getComplexType() == IMAGE_SYM_DTYPE_FUNCTION && !COFF::isReservedSectionNumber(getSectionNumber()); } bool isFunctionLineInfo() const { - return getStorageClass() == COFF::IMAGE_SYM_CLASS_FUNCTION; + return getStorageClass() == IMAGE_SYM_CLASS_FUNCTION; } bool isAnyUndefined() const { @@ -366,27 +368,26 @@ class COFFSymbolRef { } bool isFileRecord() const { - return getStorageClass() == COFF::IMAGE_SYM_CLASS_FILE; + return getStorageClass() == IMAGE_SYM_CLASS_FILE; } bool isSection() const { - return getStorageClass() == COFF::IMAGE_SYM_CLASS_SECTION; + return getStorageClass() == IMAGE_SYM_CLASS_SECTION; } bool isSectionDefinition() const { // C++/CLI creates external ABS symbols for non-const appdomain globals. // These are also followed by an auxiliary section definition. - bool isAppdomainGlobal = - getStorageClass() == COFF::IMAGE_SYM_CLASS_EXTERNAL && - getSectionNumber() == COFF::IMAGE_SYM_ABSOLUTE; - bool isOrdinarySection = getStorageClass() == COFF::IMAGE_SYM_CLASS_STATIC; + bool isAppdomainGlobal = getStorageClass() == IMAGE_SYM_CLASS_EXTERNAL && + getSectionNumber() == IMAGE_SYM_ABSOLUTE; + bool isOrdinarySection = getStorageClass() == IMAGE_SYM_CLASS_STATIC; if (!getNumberOfAuxSymbols()) return false; return isAppdomainGlobal || isOrdinarySection; } bool isCLRToken() const { - return getStorageClass() == COFF::IMAGE_SYM_CLASS_CLR_TOKEN; + return getStorageClass() == IMAGE_SYM_CLASS_CLR_TOKEN; } private: @@ -411,7 +412,7 @@ struct coff_section { // Returns true if the actual number of relocations is stored in // VirtualAddress field of the first relocation table entry. bool hasExtendedRelocations() const { - return (Characteristics & COFF::IMAGE_SCN_LNK_NRELOC_OVFL) && + return (Characteristics & IMAGE_SCN_LNK_NRELOC_OVFL) && NumberOfRelocations == UINT16_MAX; } }; diff --git a/include/llvm/Object/RelocVisitor.h b/include/llvm/Object/RelocVisitor.h index d5e4258cb0..9bb52819bb 100644 --- a/include/llvm/Object/RelocVisitor.h +++ b/include/llvm/Object/RelocVisitor.h @@ -26,6 +26,8 @@ #include "llvm/Support/MachO.h" #include "llvm/Support/raw_ostream.h" +using namespace llvm::COFF; + namespace llvm { namespace object { @@ -206,17 +208,17 @@ class RelocVisitor { switch (ObjToVisit.getArch()) { case Triple::x86: switch (RelocType) { - case COFF::IMAGE_REL_I386_SECREL: + case IMAGE_REL_I386_SECREL: return visitCOFF_I386_SECREL(R, Value); - case COFF::IMAGE_REL_I386_DIR32: + case IMAGE_REL_I386_DIR32: return visitCOFF_I386_DIR32(R, Value); } break; case Triple::x86_64: switch (RelocType) { - case COFF::IMAGE_REL_AMD64_SECREL: + case IMAGE_REL_AMD64_SECREL: return visitCOFF_AMD64_SECREL(R, Value); - case COFF::IMAGE_REL_AMD64_ADDR64: + case IMAGE_REL_AMD64_ADDR64: return visitCOFF_AMD64_ADDR64(R, Value); } break; diff --git a/include/llvm/Support/COFF.h b/include/llvm/Support/COFF.h index 3c5ee06969..280a0e893a 100644 --- a/include/llvm/Support/COFF.h +++ b/include/llvm/Support/COFF.h @@ -80,6 +80,7 @@ namespace COFF { uint32_t NumberOfSymbols; }; +#ifndef __MINGW32__ enum MachineTypes { MT_Invalid = 0xffff, @@ -145,6 +146,7 @@ namespace COFF { /// and should be 0. IMAGE_FILE_BYTES_REVERSED_HI = 0x8000 }; +#endif // __MINGW32__ struct symbol { char Name[NameSize]; @@ -155,6 +157,12 @@ namespace COFF { uint8_t NumberOfAuxSymbols; }; +#ifdef __MINGW32__ + enum SymbolComplexType { + /// Type is formed as (base + (derived << SCT_COMPLEX_TYPE_SHIFT)) + SCT_COMPLEX_TYPE_SHIFT = 4 + }; +#else enum SymbolSectionNumber : int32_t { IMAGE_SYM_DEBUG = -2, IMAGE_SYM_ABSOLUTE = -1, @@ -226,6 +234,7 @@ namespace COFF { /// Type is formed as (base + (derived << SCT_COMPLEX_TYPE_SHIFT)) SCT_COMPLEX_TYPE_SHIFT = 4 }; +#endif // __MINGW32__ enum AuxSymbolType { IMAGE_AUX_SYMBOL_TYPE_TOKEN_DEF = 1 @@ -244,6 +253,7 @@ namespace COFF { uint32_t Characteristics; }; +#ifndef __MINGW32__ enum SectionCharacteristics : uint32_t { SC_Invalid = 0xffffffff, @@ -283,6 +293,7 @@ namespace COFF { IMAGE_SCN_MEM_READ = 0x40000000, IMAGE_SCN_MEM_WRITE = 0x80000000 }; +#endif // __MINGW32__ struct relocation { uint32_t VirtualAddress; @@ -290,6 +301,7 @@ namespace COFF { uint16_t Type; }; +#ifndef __MINGW32__ enum RelocationTypeI386 { IMAGE_REL_I386_ABSOLUTE = 0x0000, IMAGE_REL_I386_DIR16 = 0x0001, @@ -351,6 +363,7 @@ namespace COFF { IMAGE_COMDAT_SELECT_LARGEST, IMAGE_COMDAT_SELECT_NEWEST }; +#endif // __MINGW32__ // Auxiliary Symbol Formats struct AuxiliaryFunctionDefinition { @@ -375,12 +388,14 @@ namespace COFF { uint8_t unused[10]; }; +#ifndef __MINGW32__ /// These are not documented in the spec, but are located in WinNT.h. enum WeakExternalCharacteristics { IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY = 1, IMAGE_WEAK_EXTERN_SEARCH_LIBRARY = 2, IMAGE_WEAK_EXTERN_SEARCH_ALIAS = 3 }; +#endif // __MINGW32__ struct AuxiliarySectionDefinition { uint32_t Length; @@ -541,6 +556,7 @@ namespace COFF { NUM_DATA_DIRECTORIES }; +#ifndef __MINGW32__ enum WindowsSubsystem { IMAGE_SUBSYSTEM_UNKNOWN = 0, ///< An unknown subsystem. IMAGE_SUBSYSTEM_NATIVE = 1, ///< Device drivers and native Windows processes @@ -612,6 +628,7 @@ namespace COFF { IMAGE_REL_BASED_MIPS_JMPADDR16 = 9, IMAGE_REL_BASED_DIR64 = 10 }; +#endif // __MINGW32__ enum ImportType { IMPORT_CODE = 0, diff --git a/lib/DxcSupport/WinAdapter.cpp b/lib/DxcSupport/WinAdapter.cpp index c3aaab8818..df1f9f463a 100644 --- a/lib/DxcSupport/WinAdapter.cpp +++ b/lib/DxcSupport/WinAdapter.cpp @@ -10,7 +10,8 @@ #include "assert.h" #include "dxc/Support/WinFunctions.h" #include "dxc/Support/WinIncludes.h" -#ifndef _WIN32 + +#ifndef _MSC_VER #include "dxc/Support/Unicode.h" @@ -22,6 +23,8 @@ void *CAllocator::Reallocate(void *p, size_t nBytes) throw() { void *CAllocator::Allocate(size_t nBytes) throw() { return malloc(nBytes); } void CAllocator::Free(void *p) throw() { free(p); } +#ifndef __MINGW32__ + //===--------------------------- BSTR Allocation --------------------------===// void SysFreeString(BSTR bstrString) { @@ -61,6 +64,8 @@ unsigned int SysStringLen(const BSTR bstrString) { return blobIn[0] / sizeof(OLECHAR); } +#endif // !__MINGW32__ + //===--------------------------- CHandle -------------------------------===// CHandle::CHandle(HANDLE h) { m_h = h; } diff --git a/lib/IR/PassRegistry.cpp b/lib/IR/PassRegistry.cpp index b77d2bf36d..6b57363a62 100644 --- a/lib/IR/PassRegistry.cpp +++ b/lib/IR/PassRegistry.cpp @@ -35,7 +35,9 @@ using namespace llvm; // A simple global initialized at DllMain-time will do (still does more work // than we should likely perform though). static uint32_t g_PassRegistryTid; +#ifdef _MSC_VER extern "C" uint32_t __stdcall GetCurrentThreadId(void); +#endif static void CheckThreadId() { if (g_PassRegistryTid == 0) g_PassRegistryTid = GetCurrentThreadId(); diff --git a/projects/CMakeLists.txt b/projects/CMakeLists.txt index 9f361a95e5..93ee2d85ad 100644 --- a/projects/CMakeLists.txt +++ b/projects/CMakeLists.txt @@ -1,11 +1,11 @@ set(DXC_PROJECTS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(DXC_PROJECTS_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) -if(WIN32) +if(MSVC) add_subdirectory(include/Tracing) # DxcRuntimeEtw target if(HLSL_BUILD_DXILCONV) add_subdirectory(dxilconv) endif (HLSL_BUILD_DXILCONV) -endif (WIN32) +endif (MSVC) diff --git a/tools/clang/CMakeLists.txt b/tools/clang/CMakeLists.txt index 449e6c28b4..fca026d790 100644 --- a/tools/clang/CMakeLists.txt +++ b/tools/clang/CMakeLists.txt @@ -431,6 +431,9 @@ install(DIRECTORY include/clang-c ) add_definitions( -D_GNU_SOURCE ) +if (MINGW) + add_definitions( -DMS_SUPPORT_VARIABLE_LANGOPTS ) +endif() option(CLANG_ENABLE_ARCMT "Build ARCMT." ON) if (CLANG_ENABLE_ARCMT) diff --git a/tools/clang/include/clang/AST/Attr.h b/tools/clang/include/clang/AST/Attr.h index 4e282d68b7..a4b3a7f4df 100644 --- a/tools/clang/include/clang/AST/Attr.h +++ b/tools/clang/include/clang/AST/Attr.h @@ -149,6 +149,11 @@ class InheritableParamAttr : public InheritableAttr { } }; +// MinGW defines interface as struct +#ifdef interface +#undef interface +#endif + #include "clang/AST/Attrs.inc" inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, diff --git a/tools/clang/tools/dxclib/CMakeLists.txt b/tools/clang/tools/dxclib/CMakeLists.txt index 74927fd403..a85549bb8b 100644 --- a/tools/clang/tools/dxclib/CMakeLists.txt +++ b/tools/clang/tools/dxclib/CMakeLists.txt @@ -37,4 +37,4 @@ endif (MSVC) target_compile_definitions(dxclib PRIVATE VERSION_STRING_SUFFIX=" for ${CMAKE_SYSTEM_NAME}") -add_dependencies(dxclib TablegenHLSLOptions dxcompiler) +add_dependencies(dxclib TablegenHLSLOptions) diff --git a/tools/clang/tools/dxclib/dxc.cpp b/tools/clang/tools/dxclib/dxc.cpp index 744534d7a6..3149e3956b 100644 --- a/tools/clang/tools/dxclib/dxc.cpp +++ b/tools/clang/tools/dxclib/dxc.cpp @@ -62,14 +62,14 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" -#ifdef _WIN32 +#ifdef _MSC_VER #include #include #endif #include #include -#ifdef _WIN32 +#ifdef _MSC_VER #pragma comment(lib, "version.lib") #endif @@ -138,12 +138,12 @@ class DxcContext { IDxcBlob **ppResult); // Dia is only supported on Windows. -#ifdef _WIN32 +#ifdef _MSC_VER // TODO : Refactor two functions below. There are duplicate functions in // DxcContext in dxa.cpp HRESULT GetDxcDiaTable(IDxcLibrary *pLibrary, IDxcBlob *pTargetBlob, IDiaTable **ppTable, LPCWSTR tableName); -#endif // _WIN32 +#endif // _MSC_VER HRESULT FindModuleBlob(hlsl::DxilFourCC fourCC, IDxcBlob *pSource, IDxcLibrary *pLibrary, IDxcBlob **ppTargetBlob); @@ -1149,7 +1149,7 @@ HRESULT DxcContext::FindModuleBlob(hlsl::DxilFourCC fourCC, IDxcBlob *pSource, // This function is currently only supported on Windows due to usage of // IDiaTable. -#ifdef _WIN32 +#ifdef _MSC_VER // TODO : There is an identical code in DxaContext in Dxa.cpp. Refactor this // function. HRESULT DxcContext::GetDxcDiaTable(IDxcLibrary *pLibrary, IDxcBlob *pTargetBlob, @@ -1183,7 +1183,7 @@ HRESULT DxcContext::GetDxcDiaTable(IDxcLibrary *pLibrary, IDxcBlob *pTargetBlob, *ppTable = pTable.Detach(); return S_OK; } -#endif // _WIN32 +#endif // _MSC_VER bool GetDLLFileVersionInfo(const char *dllPath, unsigned int *version) { // This function is used to get version information from the DLL file. diff --git a/tools/clang/tools/dxcompiler/DXCompiler.cpp b/tools/clang/tools/dxcompiler/DXCompiler.cpp index c7ffcbffa1..8af61b6663 100644 --- a/tools/clang/tools/dxcompiler/DXCompiler.cpp +++ b/tools/clang/tools/dxcompiler/DXCompiler.cpp @@ -16,7 +16,7 @@ #include "dxc/config.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/ManagedStatic.h" -#ifdef LLVM_ON_WIN32 +#ifdef _MSC_VER #include "dxcetw.h" #endif diff --git a/tools/clang/tools/dxcompiler/DXCompiler.rc b/tools/clang/tools/dxcompiler/DXCompiler.rc index 4bec9e092e..75b2d9e600 100644 --- a/tools/clang/tools/dxcompiler/DXCompiler.rc +++ b/tools/clang/tools/dxcompiler/DXCompiler.rc @@ -11,4 +11,6 @@ #define VER_ORIGINALFILENAME_STR "DXCompiler.dll" // #include +#ifdef _MSC_VER #include "dxcetw.rc" +#endif diff --git a/tools/clang/tools/dxcompiler/dxcapi.cpp b/tools/clang/tools/dxcompiler/dxcapi.cpp index d4e85bc35c..6af016ae07 100644 --- a/tools/clang/tools/dxcompiler/dxcapi.cpp +++ b/tools/clang/tools/dxcompiler/dxcapi.cpp @@ -11,7 +11,7 @@ #include "dxc/Support/WinIncludes.h" -#ifdef _WIN32 +#ifdef _MSC_VER #define DXC_API_IMPORT __declspec(dllexport) #else #define DXC_API_IMPORT __attribute__((visibility("default"))) @@ -21,7 +21,7 @@ #include "dxc/config.h" #include "dxc/dxcisense.h" #include "dxc/dxctools.h" -#ifdef _WIN32 +#ifdef _MSC_VER #include "dxcetw.h" #endif #include "dxc/DxilContainer/DxcContainerBuilder.h" @@ -96,7 +96,7 @@ static HRESULT ThreadMallocDxcCreateInstance(REFCLSID rclsid, REFIID riid, hr = CreateDxcLinker(riid, ppv); } // Note: The following targets are not yet enabled for non-Windows platforms. -#ifdef _WIN32 +#ifdef _MSC_VER else if (IsEqualCLSID(rclsid, CLSID_DxcDiaDataSource)) { hr = CreateDxcDiaDataSource(riid, ppv); } diff --git a/tools/clang/tools/dxcompiler/dxcompilerobj.cpp b/tools/clang/tools/dxcompiler/dxcompilerobj.cpp index e39381e8d7..442d1a5365 100644 --- a/tools/clang/tools/dxcompiler/dxcompilerobj.cpp +++ b/tools/clang/tools/dxcompiler/dxcompilerobj.cpp @@ -50,7 +50,7 @@ #include "dxc/Support/dxcapi.use.h" #include "dxc/Support/microcom.h" -#ifdef _WIN32 +#ifdef _MSC_VER #include "dxcetw.h" #endif #include "dxcompileradapter.h" diff --git a/tools/clang/tools/dxcompiler/dxcpdbutils.cpp b/tools/clang/tools/dxcompiler/dxcpdbutils.cpp index 2fc224f3c5..e3ad375d49 100644 --- a/tools/clang/tools/dxcompiler/dxcpdbutils.cpp +++ b/tools/clang/tools/dxcompiler/dxcpdbutils.cpp @@ -47,7 +47,7 @@ #include #include -#ifdef _WIN32 +#ifdef _MSC_VER #include "dxc/dxcpix.h" #include #endif @@ -273,7 +273,7 @@ struct DxcPdbUtilsAdapter : public IDxcPdbUtils { }; struct DxcPdbUtils : public IDxcPdbUtils2 -#ifdef _WIN32 +#ifdef _MSC_VER // Skip Pix debug info on linux for dia dependence. , public IDxcPixDxilDebugInfoFactory @@ -843,7 +843,7 @@ struct DxcPdbUtils : public IDxcPdbUtils2 HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void **ppvObject) override { -#ifdef _WIN32 +#ifdef _MSC_VER HRESULT hr = DoBasicQueryInterface( this, iid, ppvObject); @@ -1071,7 +1071,7 @@ struct DxcPdbUtils : public IDxcPdbUtils2 return CopyBlobWide(m_Name, ppResult); } -#ifdef _WIN32 +#ifdef _MSC_VER virtual STDMETHODIMP NewDxcPixDxilDebugInfo(IDxcPixDxilDebugInfo **ppDxilDebugInfo) override { if (!m_pDebugProgramBlob) diff --git a/tools/clang/tools/dxcvalidator/CMakeLists.txt b/tools/clang/tools/dxcvalidator/CMakeLists.txt index 28e56ab7ac..3a51214b0b 100644 --- a/tools/clang/tools/dxcvalidator/CMakeLists.txt +++ b/tools/clang/tools/dxcvalidator/CMakeLists.txt @@ -19,10 +19,5 @@ add_clang_library(dxcvalidator dxcvalidator.cpp ) -if (MINGW) - target_link_options(dxcvalidator PUBLIC -mconsole -municode) - target_link_libraries(dxcvalidator PRIVATE version) -endif() - target_compile_definitions(dxcvalidator PRIVATE VERSION_STRING_SUFFIX=" for ${CMAKE_SYSTEM_NAME}") diff --git a/tools/clang/tools/dxcvalidator/dxcvalidator.cpp b/tools/clang/tools/dxcvalidator/dxcvalidator.cpp index 60ad35036f..42038c5aec 100644 --- a/tools/clang/tools/dxcvalidator/dxcvalidator.cpp +++ b/tools/clang/tools/dxcvalidator/dxcvalidator.cpp @@ -26,7 +26,7 @@ #include "dxc/Support/Global.h" #include "dxc/Support/dxcapi.impl.h" -#ifdef _WIN32 +#ifdef _MSC_VER #include "dxcetw.h" #endif diff --git a/tools/clang/tools/dxildll/CMakeLists.txt b/tools/clang/tools/dxildll/CMakeLists.txt index 67a24d1107..4974da843c 100644 --- a/tools/clang/tools/dxildll/CMakeLists.txt +++ b/tools/clang/tools/dxildll/CMakeLists.txt @@ -41,7 +41,7 @@ set(sources dxcvalidator.cpp ) -if (WIN32) +if (MSVC) add_clang_library(dxildll SHARED ${sources}) list(APPEND DXCLibs kernel32.lib @@ -58,7 +58,7 @@ target_link_libraries(dxildll PRIVATE dxcvalidator ) -if (WIN32) +if (MSVC) add_dependencies(dxildll ${DXCDependencies} DxcEtw @@ -77,7 +77,7 @@ if (WIN32) set_target_properties(${target_name} PROPERTIES SOURCES "${sources}") set_property(SOURCE dxildll.rc PROPERTY COMPILE_DEFINITIONS "INCLUDE_HLSL_VERSION_FILE=1") - set_property(SOURCE dxildll.rc PROPERTY COMPILE_OPTIONS "/I" "${HLSL_VERSION_LOCATION}" "/I" "${LLVM_MAIN_SRC_DIR}") + set_property(SOURCE dxildll.rc PROPERTY COMPILE_OPTIONS "-I" "${HLSL_VERSION_LOCATION}" "-I" "${LLVM_MAIN_SRC_DIR}") endif() set_target_properties(dxildll diff --git a/tools/clang/tools/dxildll/dxildll.cpp b/tools/clang/tools/dxildll/dxildll.cpp index 12ca2026ca..29aea842d6 100644 --- a/tools/clang/tools/dxildll/dxildll.cpp +++ b/tools/clang/tools/dxildll/dxildll.cpp @@ -10,7 +10,7 @@ // // /////////////////////////////////////////////////////////////////////////////// -#ifdef _WIN32 +#ifdef _MSC_VER #define DXC_API_IMPORT #else #define DXC_API_IMPORT __attribute__((visibility("default"))) @@ -22,7 +22,7 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/ManagedStatic.h" #include -#ifdef _WIN32 +#ifdef _MSC_VER #include "Tracing/DxcRuntimeEtw.h" #include "dxc/Tracing/dxcetw.h" #endif