Skip to content

Commit af74d76

Browse files
authored
Merge pull request #551 from bratpiorka/rrudnick_dll_safe_load_list
load DLLs only from safe load list
2 parents 2e09eeb + 38e126e commit af74d76

File tree

4 files changed

+74
-3
lines changed

4 files changed

+74
-3
lines changed

.github/scripts/check_dll_flags.ps1

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright (C) 2023-2024 Intel Corporation
2+
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
# Invoke-CmdScript runs a command script and updates the current environment
6+
# with any flag changes set by the script.
7+
function Invoke-CmdScript {
8+
param(
9+
[String] $scriptName
10+
)
11+
$cmdLine = """$scriptName"" $args & set"
12+
& $Env:SystemRoot\system32\cmd.exe /c $cmdLine |
13+
select-string '^([^=]*)=(.*)$' | foreach-object {
14+
$varName = $_.Matches[0].Groups[1].Value
15+
$varValue = $_.Matches[0].Groups[2].Value
16+
set-item Env:$varName $varValue
17+
}
18+
}
19+
20+
# Get the path to vcvarsall.bat
21+
$vsPath = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" `
22+
-latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 `
23+
-property installationPath
24+
$vsPath = "$vsPath\VC\Auxiliary\Build"
25+
$vcvarsall = "${vsPath}\vcvarsall.bat"
26+
echo "Visual Studio path: $vsPath"
27+
echo "vcvarsall.bat path: $vcvarsall"
28+
29+
# Call vcvarsall.bat so we can run MSVC commands
30+
echo "Setting up MSVC environment..."
31+
Invoke-CmdScript "$vcvarsall" x86
32+
33+
# Get umf.dll configuration flags and check if DEPENDENTLOADFLAG is set to 0x2000
34+
$flags = & "${env:VCToolsInstallDir}\bin\Hostx64\x64\dumpbin.exe" /LOADCONFIG "$args"
35+
if (($flags | Where-Object { $_ -match '(\d+).*Dependent' } | ForEach-Object { $matches[1] } ) -eq "2000") {
36+
echo "The DEPENDENTLOADFLAG is correctly set to 0x2000."
37+
exit 0
38+
} else {
39+
echo "The DEPENDENTLOADFLAG is not correctly set"
40+
echo "$flags"
41+
exit 1
42+
}

.github/workflows/basic.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ jobs:
148148
name: Windows
149149
env:
150150
VCPKG_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows;${{github.workspace}}/build/vcpkg/packages/tbb_x64-windows;${{github.workspace}}/build/vcpkg/packages/jemalloc_x64-windows"
151-
BUILD_DIR : "${{github.workspace}}/build/${{matrix.build_type}}"
151+
BUILD_DIR : "${{github.workspace}}/build/"
152152
INSTL_DIR : "${{github.workspace}}/../install-dir"
153153
strategy:
154154
matrix:
@@ -227,11 +227,21 @@ jobs:
227227
--proxy
228228
--umf-version ${{env.UMF_VERSION}}
229229
${{ matrix.shared_library == 'ON' && '--shared-library' || ''}}
230+
231+
- name: check /DEPENDENTLOADFLAG in umf.dll
232+
if: ${{matrix.shared_library == 'ON' && matrix.compiler.cxx == 'cl'}}
233+
run: ${{github.workspace}}/.github/scripts/check_dll_flags.ps1 ${{github.workspace}}/build/bin/${{matrix.build_type}}/umf.dll
234+
shell: pwsh
235+
236+
- name: check /DEPENDENTLOADFLAG in umf_proxy.dll
237+
if: ${{matrix.compiler.cxx == 'cl'}}
238+
run: ${{github.workspace}}/.github/scripts/check_dll_flags.ps1 ${{github.workspace}}/build/src/proxy_lib/${{matrix.build_type}}/umf_proxy.dll
239+
shell: pwsh
230240

231241
windows-dynamic_build_hwloc:
232242
name: "Windows dynamic UMF + static hwloc"
233243
env:
234-
BUILD_DIR : "${{github.workspace}}/build/${{matrix.build_type}}"
244+
BUILD_DIR : "${{github.workspace}}/build"
235245
strategy:
236246
matrix:
237247
build_type: [Release]
@@ -263,10 +273,16 @@ jobs:
263273
working-directory: ${{env.BUILD_DIR}}
264274
run: ctest -C ${{matrix.build_type}} --output-on-failure --test-dir test
265275

276+
# we check umf.dll only here - note that the proxy library is disabled in
277+
# this configuration
278+
- name: check /DEPENDENTLOADFLAG in umf.dll
279+
run: ${{github.workspace}}/.github/scripts/check_dll_flags.ps1 ${{github.workspace}}/build/bin/${{matrix.build_type}}/umf.dll
280+
shell: pwsh
281+
266282
windows-static_build_hwloc:
267283
name: "Windows static UMF + static hwloc"
268284
env:
269-
BUILD_DIR : "${{github.workspace}}/build/${{matrix.build_type}}"
285+
BUILD_DIR : "${{github.workspace}}/build"
270286
strategy:
271287
matrix:
272288
build_type: [Release]

.github/workflows/pr_push.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ jobs:
104104
-DUMF_BUILD_EXAMPLES=ON
105105
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=ON
106106
-DUMF_TESTS_FAIL_ON_SKIP=ON
107+
-DUMF_BUILD_SHARED_LIBRARY=ON
107108
${{matrix.extra_build_options}}
108109
109110
- name: Configure CMake (simple)
@@ -127,6 +128,16 @@ jobs:
127128
working-directory: ${{github.workspace}}/build
128129
run: ctest --output-on-failure --test-dir test -C Release
129130

131+
- name: check /DEPENDENTLOADFLAG (Windows only)
132+
if: matrix.os == 'windows-latest'
133+
run: ${{github.workspace}}/.github/scripts/check_dll_flags.ps1 ${{github.workspace}}/build/bin/Release/umf.dll
134+
shell: pwsh
135+
136+
- name: check /DEPENDENTLOADFLAG in umf_proxy.dll
137+
if: matrix.os == 'windows-latest'
138+
run: ${{github.workspace}}/.github/scripts/check_dll_flags.ps1 ${{github.workspace}}/build/src/proxy_lib/Release/umf_proxy.dll
139+
shell: pwsh
140+
130141
CodeStyle:
131142
name: Coding style
132143
runs-on: ubuntu-latest

cmake/helpers.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ function(add_umf_target_link_options name)
158158
PRIVATE
159159
/DYNAMICBASE
160160
/HIGHENTROPYVA
161+
$<$<C_COMPILER_ID:MSVC>:/DEPENDENTLOADFLAG:0x2000>
162+
$<$<CXX_COMPILER_ID:MSVC>:/DEPENDENTLOADFLAG:0x2000>
161163
/NXCOMPAT)
162164
endif()
163165
endfunction()

0 commit comments

Comments
 (0)