Skip to content

Commit

Permalink
Opt, 默认开启干净导入表模式模式(功能转正)
Browse files Browse the repository at this point in the history
  • Loading branch information
mingkuang-Chuyu committed May 25, 2024
1 parent 6dfe24b commit d6328ba
Show file tree
Hide file tree
Showing 15 changed files with 12 additions and 163 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ indent_size = 4
[*.{vcxproj,xml,nuspec,props,targets}]
indent_style = space
indent_size = 2

[*.cmd]
charset = unset
1 change: 0 additions & 1 deletion Nuget/build/net8.0-windows7.0/VC-LTL.targets
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<LTLWindowsTargetPlatformMinVersion Condition="'$(LTLWindowsTargetPlatformMinVersion)' == '' and '$(LTLPlatform)'=='x86'">5.1.2600.0</LTLWindowsTargetPlatformMinVersion>
</PropertyGroup>
<ItemGroup Condition="'$(LTLWindowsTargetPlatformMinVersion)' != '' and '$(LTLPlatform)' != ''">
<AdditionalNativeLibraryDirectories Include="$(MSBuildThisFileDirectory)..\native\TargetPlatform\$(LTLWindowsTargetPlatformMinVersion)\lib\$(LTLPlatform)\CleanImport" />
<AdditionalNativeLibraryDirectories Include="$(MSBuildThisFileDirectory)..\native\TargetPlatform\$(LTLWindowsTargetPlatformMinVersion)\lib\$(LTLPlatform)" />
</ItemGroup>
</Target>
Expand Down
51 changes: 1 addition & 50 deletions UnitTest/UnitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ namespace UnitTest
{
DllImportInfo Info;

Info.DllName = L"api-ms-win-crt-runtime-l1-1-0.dll";
Info.DllName = L"ucrtbase.dll";
Info.ImportNames.push_back(L"_beginthread");

TestLib(
Expand Down Expand Up @@ -631,55 +631,6 @@ namespace UnitTest
Info
);
}


TEST_METHOD(ucrt_ucrt清洁模式所有符号可以被链接)
{
DllImportInfo Info;

Info.DllName = L"ucrtbase.dll";
Info.ImportNames.push_back(L"_beginthread");

TestLib(
CurrentUniversalCRTSdkDir LR"(ucrt\x86\ucrt.lib)",
L"ucrt",
L"Win32",
{ L"Dynamic", L"Static" },
{ L"10.0.10240.0", L"10.0.19041.0" },
Info,
L"CleanImport=true"
);

TestLib(
CurrentUniversalCRTSdkDir LR"(ucrt\x64\ucrt.lib)",
L"ucrt",
L"x64",
{ L"Dynamic", L"Static" },
{ L"10.0.10240.0", L"10.0.19041.0" },
Info,
L"CleanImport=true"
);

TestLib(
CurrentUniversalCRTSdkDir LR"(ucrt\arm\ucrt.lib)",
L"ucrt",
L"arm",
{ L"Dynamic", L"Static" },
{ L"10.0.10240.0", L"10.0.19041.0" },
Info,
L"CleanImport=true"
);

TestLib(
CurrentUniversalCRTSdkDir LR"(ucrt\arm64\ucrt.lib)",
L"ucrt",
L"arm64",
{ L"Dynamic", L"Static" },
{ L"10.0.10240.0", L"10.0.19041.0" },
Info,
L"CleanImport=true"
);
}
private:
static LSTATUS TestLib(
LPCWSTR SrcLibPath,
Expand Down
52 changes: 0 additions & 52 deletions UnitTest/VC-LTL_HelperUnitTest/PowerShell/PowerShellUnitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,58 +89,6 @@ namespace UnitTest
auto _oImportInfo = GetDllImportInfo(_szOutDir + LR"(\NMakeExample.exe)");


for (auto _szIncludeDllName : _oConfig.IncludeDllNames)
{
auto _pInfo = FindDllImport(_oImportInfo, _szIncludeDllName);
Assert::IsNotNull(_pInfo, CStringW(_oConfig.szPlatform) + L" Include:" + _szIncludeDllName);
}

for (auto _szExcludeDllName : _oConfig.ExcludeDllNames)
{
auto _pInfo = FindDllImport(_oImportInfo, _szExcludeDllName);
Assert::IsNull(_pInfo, CStringW(_oConfig.szPlatform) + L" Exclude:" + _szExcludeDllName);
}
}
}

TEST_METHOD(CleanImport生效检查)
{
struct CheckConfig
{
LPCWSTR szPlatform;
LPCWSTR szAppend;
std::vector<LPCSTR> IncludeDllNames;
std::vector<LPCSTR> ExcludeDllNames;
};

static const CheckConfig _oConfigList[] =
{
// 默认情况不开启 CleanImport,会依赖 api-ms-win-crt-stdio
{L"x86", L" -WindowsTargetPlatformMinVersion 10.0.10240.0", {"ucrtbase.dll", "api-ms-win-crt-stdio-l1-1-0.dll"}, {"vcruntime140.dll"}},
// 显式指定关闭 CleanImport,会依赖 api-ms-win-crt-stdio
{L"x86", L" -WindowsTargetPlatformMinVersion 10.0.10240.0 -CleanImport false", {"ucrtbase.dll", "api-ms-win-crt-stdio-l1-1-0.dll"}, {"vcruntime140.dll"}},
// 开启时不依赖 api-ms-win-crt-stdio
{L"x86", L" -WindowsTargetPlatformMinVersion 10.0.10240.0 -CleanImport true", {"ucrtbase.dll"}, {"vcruntime140.dll", "api-ms-win-crt-stdio-l1-1-0.dll"}},
};

for (auto& _oConfig : _oConfigList)
{
CString _szOutDir = szTestDllPath;
_szOutDir += LR"(out\HelperForPowerShellCleanImportUnitTest\)";
_szOutDir += _oConfig.szPlatform;

CString _szCmd;
_szCmd.Format(LR"(powershell.exe -File "%wsPowerShellBuildUnitTest.ps1" -arch %ws -OutDir "%ws")", szPSRootPath.GetString(), _oConfig.szPlatform, _szOutDir.GetString());

_szCmd += _oConfig.szAppend;

CString _szOut;
auto _lStatus = RunCmd(nullptr, _szCmd, &_szOut);
Assert::AreEqual(_lStatus, (LSTATUS)ERROR_SUCCESS);

auto _oImportInfo = GetDllImportInfo(_szOutDir + LR"(\NMakeExample.exe)");


for (auto _szIncludeDllName : _oConfig.IncludeDllNames)
{
auto _pInfo = FindDllImport(_oImportInfo, _szIncludeDllName);
Expand Down
5 changes: 1 addition & 4 deletions VC-LTL helper for Visual Studio.props
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ VC-LTL默认搜索顺序
<PropertyGroup>
<!--控制TargetPlatform版本,目前可用版本为 5.1.2600.0 6.0.6000.0(默认) 6.2.9200.0 10.0.10240.0 10.0.19041.0-->
<!--<WindowsTargetPlatformMinVersion>10.0.10240.0</WindowsTargetPlatformMinVersion>-->

<!--启用干净的导入表,消除 ucrt apiset(如:api-ms-win-crt-time-l1-1-0.dll),满足强迫症患者。-->
<!--<CleanImport>true</CleanImport>-->
</PropertyGroup>
<!--####################################################################################################################################################-->

Expand Down Expand Up @@ -66,4 +63,4 @@ VC-LTL默认搜索顺序
<!--兼容模式,尝试加载老版本-->
<Import Project="$(VC_LTL_Root)\ltlvcrt.props" Condition="(!Exists('$(VC_LTL_Root)\Config\config.props')) And (Exists('$(VC_LTL_Root)\ltlvcrt.props'))"/>
</ImportGroup>
</Project>
</Project>
3 changes: 0 additions & 3 deletions VC-LTL helper for cmake.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
#控制TargetPlatform版本,目前可用版本为5.1.2600.0 6.0.6000.0(默认) 6.2.9200.0 10.0.10240.0 10.0.19041.0
#set(WindowsTargetPlatformMinVersion "10.0.10240.0")

#启用干净的导入表,消除 ucrt apiset(如:api-ms-win-crt-time-l1-1-0.dll),满足强迫症患者。
#set(CleanImport "true")

####################################################################################################################################################

if(NOT VC_LTL_Root)
Expand Down
3 changes: 0 additions & 3 deletions VC-LTL helper for nmake.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
::控制TargetPlatform版本,目前可用版本为 5.1.2600.0 6.0.6000.0(默认) 6.2.9200.0 10.0.10240.0 10.0.19041.0
::set WindowsTargetPlatformMinVersion=10.0.10240.0

::启用干净的导入表,消除 ucrt apiset(如:api-ms-win-crt-time-l1-1-0.dll),满足强迫症患者。
::set CleanImport=true

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


Expand Down
3 changes: 0 additions & 3 deletions VC-LTL helper for nmake.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
# 控制TargetPlatform版本,目前可用版本为 5.1.2600.0 6.0.6000.0(默认) 6.2.9200.0 10.0.10240.0 10.0.19041.0
# $env:WindowsTargetPlatformMinVersion="10.0.10240.0"

# 启用干净的导入表,消除 ucrt apiset(如:api-ms-win-crt-time-l1-1-0.dll),满足强迫症患者。
# $env:CleanImport="true"

################################################################################################################################

do
Expand Down
5 changes: 1 addition & 4 deletions VC-LTL helper for qmake.pri
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Release {
Release {

# 作者:GPBeta(https://github.com/GPBeta),mingkuang(https://github.com/mingkuang-Chuyu)
# 修改日期:2021-08-20
Expand Down Expand Up @@ -30,9 +30,6 @@ Release {
# 控制TargetPlatform版本,目前可用版本为 6.0.6000.0(默认) 6.2.9200.0 10.0.10240.0 10.0.19041.0
# WindowsTargetPlatformMinVersion = 10.0.10240.0

# 启用干净的导入表,消除 ucrt apiset(如:api-ms-win-crt-time-l1-1-0.dll),满足强迫症患者。
# CleanImport=true

# -----------------------------------------------------------------------------------------------------------------------------------------------------


Expand Down
10 changes: 0 additions & 10 deletions config/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ if(NOT SupportLTL)
set(SupportLTL "true")
endif()

if(NOT CleanImport)
set(CleanImport "false")
endif()

if(${SupportLTL} STREQUAL "true")
if(NOT CMAKE_SYSTEM_NAME)
message(WARNING "VC-LTL not load, because CMAKE_SYSTEM_NAME is not defined!!!")
Expand Down Expand Up @@ -207,12 +203,6 @@ if(${SupportLTL} STREQUAL "true")
set(VC_LTL_Include ${VC_LTL_Root}/TargetPlatform/header;${VC_LTL_Root}/TargetPlatform/${LTLWindowsTargetPlatformMinVersion}/header)
set(VC_LTL_Library ${VC_LTL_Root}/TargetPlatform/${LTLWindowsTargetPlatformMinVersion}/lib/${LTLPlatform})

# 如果开启了 CleanImport 那么优先使用 CleanImport
if(${CleanImport} STREQUAL "true")
if(EXISTS ${VC_LTL_Root}/TargetPlatform/${LTLWindowsTargetPlatformMinVersion}/lib/${LTLPlatform}/CleanImport)
set(VC_LTL_Library ${VC_LTL_Root}/TargetPlatform/${LTLWindowsTargetPlatformMinVersion}/lib/${LTLPlatform}/CleanImport;${VC_LTL_Library})
endif()
endif()
#message("INCLUDE " $ENV{INCLUDE})
#message("LIB " $ENV{LIB})

Expand Down
2 changes: 0 additions & 2 deletions config/config.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ echo Platform : %LTLPlatform%
set INCLUDE=%VC_LTL_Root%TargetPlatform\header;%VC_LTL_Root%TargetPlatform\%LTLWindowsTargetPlatformMinVersion%\header;%INCLUDE%
set LIB=%VC_LTL_Root%TargetPlatform\%LTLWindowsTargetPlatformMinVersion%\lib\%LTLPlatform%;%LIB%

if /i "%CleanImport%" == "true" if exist "%VC_LTL_Root%TargetPlatform\%LTLWindowsTargetPlatformMinVersion%\lib\%LTLPlatform%\CleanImport"(set "LIB=%VC_LTL_Root%TargetPlatform\%LTLWindowsTargetPlatformMinVersion%\lib\%LTLPlatform%\CleanImport;%LIB%")

goto:eof


Expand Down
15 changes: 1 addition & 14 deletions config/config.pri
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#
#
# 请不要直接使用此配置,应该使用VC-LTL helper for qmake.pri
#

Expand Down Expand Up @@ -33,12 +33,6 @@ equals(LTLPlatform, x86) {
LTLPlatform = Win32
}

# 环境变量选项
CleanImport = $$CleanImport
isEmpty(CleanImport){
CleanImport=false
}

# 环境变量选项
SupportWinXP_t = $$SupportWinXP
isEmpty(SupportWinXP_t){
Expand Down Expand Up @@ -125,12 +119,5 @@ QMAKE_INCDIR += \
$$VC_LTL_Root/TargetPlatform/header \
$$VC_LTL_Root/TargetPlatform/$$LTLWindowsTargetPlatformMinVersion/header

equals(CleanImport, true) {
exists($$VC_LTL_Root/TargetPlatform/$$LTLWindowsTargetPlatformMinVersion/lib/$$LTLPlatform/CleanImport) {
QMAKE_LIBS += \
-L$$VC_LTL_Root/TargetPlatform/$$LTLWindowsTargetPlatformMinVersion/lib/$$LTLPlatform/CleanImport
}
}

QMAKE_LIBS += \
-L$$VC_LTL_Root/TargetPlatform/$$LTLWindowsTargetPlatformMinVersion/lib/$$LTLPlatform
3 changes: 0 additions & 3 deletions config/config.props
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@

<VC_LTL_Include>$(VC_LTL_Root)TargetPlatform\header;$(VC_LTL_Root)TargetPlatform\$(LTLWindowsTargetPlatformMinVersion)\header</VC_LTL_Include>
<VC_LTL_Library>$(VC_LTL_Root)TargetPlatform\$(LTLWindowsTargetPlatformMinVersion)\lib\$(Platform);$(IntDir)VC-LTL5.tmp\$(LTLWindowsTargetPlatformMinVersion)\$(Platform)</VC_LTL_Library>

<!--如果启用了干净导入表模式,那么额外附加CleanImport的路径-->
<VC_LTL_Library Condition="'$(CleanImport)' == 'true' and Exists('$(VC_LTL_Root)TargetPlatform\$(LTLWindowsTargetPlatformMinVersion)\lib\$(Platform)\CleanImport')">$(VC_LTL_Root)TargetPlatform\$(LTLWindowsTargetPlatformMinVersion)\lib\$(Platform)\CleanImport;$(VC_LTL_Library)</VC_LTL_Library>
</PropertyGroup>

<PropertyGroup Condition=" '$(SupportLTL)'=='true' or '$(SupportLTL)'=='ucrt'">
Expand Down
7 changes: 0 additions & 7 deletions config/config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,3 @@ Write-Host "$LTLPlatform" -ForegroundColor Green
$env:INCLUDE="$env:VC_LTL_Root\TargetPlatform\header;$env:VC_LTL_Root\TargetPlatform\$LTLWindowsTargetPlatformMinVersion\header;$env:INCLUDE"
$env:LIB="$env:VC_LTL_Root\TargetPlatform\$LTLWindowsTargetPlatformMinVersion\lib\$LTLPlatform;$env:LIB"

if($CleanImport -ieq "true")
{
if(Test-Path "$env:VC_LTL_Root\TargetPlatform\$LTLWindowsTargetPlatformMinVersion\lib\$LTLPlatform\CleanImport")
{
$env:LIB="$env:VC_LTL_Root\TargetPlatform\$LTLWindowsTargetPlatformMinVersion\lib\$LTLPlatform\CleanImport;$env:LIB"
}
}
12 changes: 5 additions & 7 deletions ucrtbase.ucrtbase/ucrtbase.ucrtbase.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -833,11 +833,9 @@
<Exec Command="%22$(SolutionDir)Tools\LibMaker.exe%22 CreateWeaks /MACHINE:$(PlatformShortName) /def:%22$(SolutionDir)Tools\Shared\ucrtbase.debug.weak.def%22 /out:%22$(IntDir)objs\weak%22" Condition="'$(UseDebugLibraries)' == 'true'" />
<Exec Command="lib %22$(IntDir)ucrt_CleanImport.lib%22 %22$(IntDir)objs\weak\*%22" Condition="'$(UseDebugLibraries)' == 'true'" />
</Target>
<Target Name="CopyFiles" AfterTargets="_Lib" Inputs="$(UniversalCRTSdkDir)Lib\$(WindowsTargetPlatformVersion)\ucrt\$(PlatformShortName)\ucrt.lib" Outputs="$(OutDir)libucrt.lib;$(OutDir)CleanImport\ucrt.lib;$(OutDir)CleanImport\libucrt.lib" Condition="'$(Configuration)' == 'Static'">
<Copy SourceFiles="$(UniversalCRTSdkDir)Lib\$(WindowsTargetPlatformVersion)\ucrt\$(PlatformShortName)\ucrt.lib" DestinationFiles="$(OutDir)libucrt.lib" />
<!--顺道再产生干净导入表模式-->
<MakeDir Directories="$(OutDir)CleanImport" />
<Copy SourceFiles="$(IntDir)ucrt_CleanImport.lib" DestinationFiles="$(OutDir)CleanImport\ucrt.lib" />
<Copy SourceFiles="$(IntDir)ucrt_CleanImport.lib" DestinationFiles="$(OutDir)CleanImport\libucrt.lib" />
<Target Name="CopyFiles" AfterTargets="_Lib" Inputs="$(IntDir)ucrt_CleanImport.lib" Outputs="$(OutDir)ucrt.lib;$(OutDir)libucrt.lib" Condition="'$(Configuration)' == 'Static'">
<!--复制干净导入表的UCRT库-->
<Copy SourceFiles="$(IntDir)ucrt_CleanImport.lib" DestinationFiles="$(OutDir)ucrt.lib" />
<Copy SourceFiles="$(IntDir)ucrt_CleanImport.lib" DestinationFiles="$(OutDir)libucrt.lib" />
</Target>
</Project>
</Project>

0 comments on commit d6328ba

Please sign in to comment.