Skip to content

Commit f949bca

Browse files
author
Greg Roth
authored
Merge pull request #5045 from pow2clk/cp-release-1.7.2212
Merge relevant changes into release 1.7.2212 7ce4986 Fix opt.exe external lib loading (#5049) 8f4d1f4 PIX: DxcPixDxilInstructionOffsets should operate on libs (#5046) 0795b94 Fix AppVeyor Linux tests failing loading dxil.so (#5024) 6d3574a Remove SO version from unix binaries (#5010) 6d480fd Allow libdxcompiler.so and dxc to find libdxil.so (#5004) d751bd8 Correct WinAdapter path assumptions in public headers (#5003) 484f1b0 Fix instruction order issue in scalarizer (#5001) d9d83d0 Fix two issues found in our internal build (#5002) c8603e4 Added a workaround for PDBs with empty defines. (#4945) 073d860 [bug] Fix memory leak in dxil validator (#4966) 87fc5b5 PIX: Symbol manager: don't allow static members to contribute to member offsets (#4952) 8588ecb Turn off structurize-returns when cleanup blocks are present. (#4927) bac7aa7 build: disable LLVM_ENABLE_TERMINFO by default. (#4908)
2 parents e8c4673 + 7ce4986 commit f949bca

38 files changed

Lines changed: 886 additions & 96 deletions

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ endif()
608608

609609
include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})
610610

611+
include_directories( ${LLVM_MAIN_INCLUDE_DIR}/dxc/Support) # HLSL Change
611612
include_directories( ${LLVM_INCLUDE_DIR}/dxc/Tracing) # HLSL Change
612613

613614
# when crosscompiling import the executable targets from a file

cmake/caches/PredefinedParams.cmake

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,20 @@ set(LLVM_INCLUDE_TESTS ${LLVM_TEST_VALUE} CACHE BOOL "")
2222
set(CLANG_INCLUDE_TESTS ${LLVM_TEST_VALUE} CACHE BOOL "")
2323

2424
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE BOOL "")
25-
set(LLVM_APPEND_VC_REV ON CACHE BOOL "")
25+
set(LLVM_APPEND_VC_REV ON CACHE BOOL "")
2626
set(LLVM_DEFAULT_TARGET_TRIPLE "dxil-ms-dx" CACHE STRING "")
27-
set(LLVM_ENABLE_EH ON CACHE BOOL "")
28-
set(LLVM_ENABLE_RTTI ON CACHE BOOL "")
29-
set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "")
30-
set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "")
31-
set(LLVM_OPTIMIZED_TABLEGEN OFF CACHE BOOL "")
27+
set(LLVM_ENABLE_EH ON CACHE BOOL "")
28+
set(LLVM_ENABLE_RTTI ON CACHE BOOL "")
29+
set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "")
30+
set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "")
31+
set(LLVM_OPTIMIZED_TABLEGEN OFF CACHE BOOL "")
3232
set(LLVM_TARGETS_TO_BUILD "None" CACHE STRING "")
33-
set(LIBCLANG_BUILD_STATIC ON CACHE BOOL "")
34-
set(CLANG_BUILD_EXAMPLES OFF CACHE BOOL "")
35-
set(CLANG_CL OFF CACHE BOOL "")
36-
set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "")
37-
set(CLANG_ENABLE_STATIC_ANALYZER OFF CACHE BOOL "")
38-
set(HLSL_INCLUDE_TESTS ON CACHE BOOL "")
39-
set(ENABLE_SPIRV_CODEGEN ON CACHE BOOL "")
33+
set(LIBCLANG_BUILD_STATIC ON CACHE BOOL "")
34+
set(CLANG_BUILD_EXAMPLES OFF CACHE BOOL "")
35+
set(CLANG_CL OFF CACHE BOOL "")
36+
set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "")
37+
set(CLANG_ENABLE_STATIC_ANALYZER OFF CACHE BOOL "")
38+
set(HLSL_INCLUDE_TESTS ON CACHE BOOL "")
39+
set(ENABLE_SPIRV_CODEGEN ON CACHE BOOL "")
4040
set(SPIRV_BUILD_TESTS ON CACHE BOOL "")
41+
set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")

cmake/modules/AddLLVM.cmake

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,20 @@ function(llvm_add_library name)
446446
)
447447
endif()
448448

449+
# HLSL Change Begin - Don't generate so versioned files.
449450
set_target_properties(${name}
450451
PROPERTIES
451452
SOVERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}
452-
VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX})
453+
VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}
454+
NO_SONAME On)
455+
if (APPLE)
456+
set_property(TARGET ${name} APPEND_STRING PROPERTY
457+
LINK_FLAGS " -Wl,-install_name,@rpath/${CMAKE_SHARED_LIBRARY_PREFIX}${name}${CMAKE_SHARED_LIBRARY_SUFFIX}")
458+
elseif(UNIX)
459+
set_property(TARGET ${name} APPEND_STRING PROPERTY
460+
LINK_FLAGS " -Wl,-soname,${CMAKE_SHARED_LIBRARY_PREFIX}${name}${CMAKE_SHARED_LIBRARY_SUFFIX}")
461+
endif()
462+
# HLSL Change End - Don't generate so versioned files.
453463
endif()
454464

455465
if(ARG_MODULE OR ARG_SHARED)

include/dxc/Support/dxcapi.use.h

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,41 @@
1616

1717
namespace dxc {
1818

19+
extern const char* kDxCompilerLib;
20+
extern const char* kDxilLib;
21+
1922
// Helper class to dynamically load the dxcompiler or a compatible libraries.
2023
class DxcDllSupport {
2124
protected:
2225
HMODULE m_dll;
2326
DxcCreateInstanceProc m_createFn;
2427
DxcCreateInstance2Proc m_createFn2;
2528

26-
HRESULT InitializeInternal(LPCWSTR dllName, LPCSTR fnName) {
29+
HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName) {
2730
if (m_dll != nullptr) return S_OK;
2831

2932
#ifdef _WIN32
30-
m_dll = LoadLibraryW(dllName);
31-
#else
32-
char nameStr[256];
33-
std::wcstombs(nameStr, dllName, 256);
34-
m_dll = ::dlopen(nameStr, RTLD_LAZY);
35-
#endif
36-
33+
m_dll = LoadLibraryA(dllName);
3734
if (m_dll == nullptr) return HRESULT_FROM_WIN32(GetLastError());
38-
39-
#ifdef _WIN32
4035
m_createFn = (DxcCreateInstanceProc)GetProcAddress(m_dll, fnName);
41-
#else
42-
m_createFn = (DxcCreateInstanceProc)::dlsym(m_dll, fnName);
43-
#endif
44-
36+
4537
if (m_createFn == nullptr) {
4638
HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
47-
#ifdef _WIN32
4839
FreeLibrary(m_dll);
40+
m_dll = nullptr;
41+
return hr;
42+
}
4943
#else
44+
m_dll = ::dlopen(dllName, RTLD_LAZY);
45+
if (m_dll == nullptr) return E_FAIL;
46+
m_createFn = (DxcCreateInstanceProc)::dlsym(m_dll, fnName);
47+
48+
if (m_createFn == nullptr) {
5049
::dlclose(m_dll);
51-
#endif
5250
m_dll = nullptr;
53-
return hr;
51+
return E_FAIL;
5452
}
53+
#endif
5554

5655
// Only basic functions used to avoid requiring additional headers.
5756
m_createFn2 = nullptr;
@@ -86,16 +85,10 @@ class DxcDllSupport {
8685
}
8786

8887
HRESULT Initialize() {
89-
#ifdef _WIN32
90-
return InitializeInternal(L"dxcompiler.dll", "DxcCreateInstance");
91-
#elif __APPLE__
92-
return InitializeInternal(L"libdxcompiler.dylib", "DxcCreateInstance");
93-
#else
94-
return InitializeInternal(L"libdxcompiler.so", "DxcCreateInstance");
95-
#endif
88+
return InitializeInternal(kDxCompilerLib, "DxcCreateInstance");
9689
}
9790

98-
HRESULT InitializeForDll(_In_z_ const wchar_t* dll, _In_z_ const char* entryPoint) {
91+
HRESULT InitializeForDll(_In_z_ LPCSTR dll, _In_z_ LPCSTR entryPoint) {
9992
return InitializeInternal(dll, entryPoint);
10093
}
10194

include/dxc/dxcapi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#else
3535

3636
#include <dlfcn.h>
37-
#include "dxc/Support/WinAdapter.h"
37+
#include "WinAdapter.h"
3838
#endif
3939

4040
struct IMalloc;

include/dxc/dxcisense.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#include "dxcapi.h"
1616
#ifndef _WIN32
17-
#include "Support/WinAdapter.h"
17+
#include "WinAdapter.h"
1818
#endif
1919

2020
typedef enum DxcGlobalOptions

lib/DxcSupport/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,12 @@ add_llvm_library(LLVMDxcSupport
1111
WinFunctions.cpp
1212
)
1313

14+
#generate header with platform-specific library name
15+
configure_file(
16+
${LLVM_MAIN_SRC_DIR}/lib/DxcSupport/SharedLibAffix.inc
17+
SharedLibAffix.h
18+
)
19+
20+
include_directories( ${LLVM_INCLUDE_DIR}/DxcSupport) #needed to find the generated header
21+
1422
add_dependencies(LLVMDxcSupport TablegenHLSLOptions)

lib/DxcSupport/HLSLOptions.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,9 +1183,8 @@ int SetupDxcDllSupport(const DxcOpts &opts, dxc::DxcDllSupport &dxcSupport,
11831183
llvm::raw_ostream &errors) {
11841184
if (!opts.ExternalLib.empty()) {
11851185
DXASSERT(!opts.ExternalFn.empty(), "else ReadDxcOpts should have failed");
1186-
StringRefWide externalLib(opts.ExternalLib);
11871186
HRESULT hrLoad =
1188-
dxcSupport.InitializeForDll(externalLib, opts.ExternalFn.data());
1187+
dxcSupport.InitializeForDll(opts.ExternalLib.data(), opts.ExternalFn.data());
11891188
if (DXC_FAILED(hrLoad)) {
11901189
errors << "Unable to load support for external DLL " << opts.ExternalLib
11911190
<< " with function " << opts.ExternalFn << " - error 0x";

lib/DxcSupport/SharedLibAffix.inc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
// //
3+
// SharedLibAffix.inc //
4+
// Copyright (C) Microsoft Corporation. All rights reserved. //
5+
// This file is distributed under the University of Illinois Open Source //
6+
// License. See LICENSE.TXT for details. //
7+
// //
8+
// Defines shared library prefixes and suffixes for the build platform. //
9+
// //
10+
///////////////////////////////////////////////////////////////////////////////
11+
12+
13+
#pragma once
14+
15+
#cmakedefine CMAKE_SHARED_LIBRARY_PREFIX "@CMAKE_SHARED_LIBRARY_PREFIX@"
16+
#cmakedefine CMAKE_SHARED_LIBRARY_SUFFIX "@CMAKE_SHARED_LIBRARY_SUFFIX@"
17+
18+
#ifndef CMAKE_SHARED_LIBRARY_PREFIX
19+
#define CMAKE_SHARED_LIBRARY_PREFIX
20+
#endif
21+
22+
#ifndef CMAKE_SHARED_LIBRARY_SUFFIX
23+
#define CMAKE_SHARED_LIBRARY_SUFFIX
24+
#endif

lib/DxcSupport/dxcapi.use.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@
1515
#include "dxc/Support/Unicode.h"
1616
#include "dxc/Support/FileIOHelper.h"
1717
#include "dxc/Support/WinFunctions.h"
18+
#include "SharedLibAffix.h"
1819

1920
namespace dxc {
2021

22+
const char* kDxCompilerLib = CMAKE_SHARED_LIBRARY_PREFIX "dxcompiler" CMAKE_SHARED_LIBRARY_SUFFIX;
23+
const char* kDxilLib = CMAKE_SHARED_LIBRARY_PREFIX "dxil" CMAKE_SHARED_LIBRARY_SUFFIX;
24+
2125
#ifdef _WIN32
2226
static void TrimEOL(_Inout_z_ char *pMsg) {
2327
char *pEnd = pMsg + strlen(pMsg);

0 commit comments

Comments
 (0)