Explicitly link the VC exe with MSVCRT.dll

Create an import library containing the necessary CRT functions and link
with that, rather than the compiler's own version.
This commit is contained in:
Jason Hood 2018-05-11 12:16:58 +10:00
parent f215223810
commit f2843b1d10
3 changed files with 59 additions and 32 deletions

29
acrt.def Normal file
View File

@ -0,0 +1,29 @@
EXPORTS
__iob_func
_fileno
_iob
_isatty
_setmode
_snwprintf
_wcsicmp
_wtoi
fflush
fputws
free
fwprintf
iswctype
malloc
memchr
memcpy
memmove
qsort
setlocale
sprintf
towlower
wcschr
wcscmp
wcscpy
wcslen
wcspbrk
wcsstr
wprintf

View File

@ -433,14 +433,12 @@ arg_out:
{ {
if (*cmd == '\0') if (*cmd == '\0')
{ {
if (GetEnvironmentVariable( L"ComSpec", arg, MAX_PATH )) if (!GetEnvironmentVariable( L"ComSpec", arg, MAX_PATH ))
cmd = arg;
else
{ {
// CreateProcessW writes to the string, so can't simply point to "cmd". // CreateProcessW writes to the string, so can't simply point to "cmd".
static TCHAR cmdstr[] = L"cmd"; wcscpy( arg, L"cmd" );
cmd = cmdstr;
} }
cmd = arg;
} }
ZeroMemory( &si, sizeof(si) ); ZeroMemory( &si, sizeof(si) );

View File

@ -19,12 +19,10 @@
# 18 July, 2013: # 18 July, 2013:
# hide the commands (use V=1 to show them). # hide the commands (use V=1 to show them).
# #
# 30 April, 2018: # 30 April, 8 to 11 May 2018:
# use undocumented rc option /s to remove its logo; # use a batch rule (even if this project is too small to make a difference);
# use a batch rule (even if this project is too small to make a difference). # add /nologo to RFLAGS if rc supports it;
# # explicitly link the exe with MSVCRT.DLL.
# 8 May, 2018:
# rc /s only removes the logo as a side-effect; use /nologo when available.
#BITS = 32 #BITS = 32
#BITS = 64 #BITS = 64
@ -48,29 +46,27 @@ DIR = x64
!ENDIF !ENDIF
# Disable security checks, but VC6 & 7 don't have /GS-. # Disable security checks, but VC6 & 7 don't have /GS-.
!IF "$(_NMAKE_VER)" == "7.00.8882" && $(BITS) == 32 !IF "$(_NMAKE_VER)" != "7.00.8882" || $(BITS) == 64
NOSECCHK =
RFLAGS =
# The 2003 Toolkit doesn't have MSVCRT.LIB, but VC98 does.
!IF !DEFINED(SHARE) && !DEFINED(MSVCDIR)
SHARE =
!ENDIF
!ELSE
NOSECCHK = /GS- NOSECCHK = /GS-
!ENDIF !ENDIF
# 2008 (SDK v6) and earlier rc do not have /nologo. # 2008 (SDK v6) and earlier rc do not have /nologo.
!IF [cmd /d /c exit /b $(_NMAKE_VER)] <= 9 !IF [cmd /d /c exit $(_NMAKE_VER)] <= 9
RFLAGS = RFLAGS =
!ENDIF !ENDIF
# Link with MSVCRT.LIB by default. # Link with MSVCRT.LIB by default.
!IFNDEF SHARE !IFNDEF SHARE
SHARE = /MD SHARE = /MD
CRT = $(DIR)\acrt.lib
LINK = /entry:main /nod
# The 2003 Toolkit has chkstk in libc, but the rest have it as itself.
!IF "$(_NMAKE_VER)" == "7.00.8882" && $(BITS) == 32 && !DEFINED(MSVCDIR)
LIBS = libc.lib
!ELSE
LIBS = chkstk.obj
!ENDIF
!ENDIF !ENDIF
# Manifest tool to embed the manifest required by 2008.
MT = mt.exe
!IFNDEF RFLAGS !IFNDEF RFLAGS
RFLAGS = /nologo RFLAGS = /nologo
@ -79,10 +75,10 @@ RFLAGS = /nologo
RFLAGS = $(RFLAGS) /D_WIN64 RFLAGS = $(RFLAGS) /D_WIN64
!ENDIF !ENDIF
CFLAGS = /nologo /W3 /O2 $(NOSECCHK) /D_CRT_SECURE_NO_WARNINGS CFLAGS = /nologo /W3 /O2 $(NOSECCHK) /D_CRT_SECURE_NO_WARNINGS
LIBS = kernel32.lib advapi32.lib LIBS = $(LIBS) kernel32.lib advapi32.lib
# Identify ansicon.exe using "ANSI" as a version number. # Identify ansicon.exe using "ANSI" as a version number.
LINK = /link /version:20033.18771 LINK = /link /version:20033.18771 $(LINK) /fixed
X86OBJS = x86\injdll.obj x86\procrva.obj x86\proctype.obj x86\util.obj X86OBJS = x86\injdll.obj x86\procrva.obj x86\proctype.obj x86\util.obj
X64OBJS = x64\injdll.obj x64\procrva.obj x64\proctype.obj x64\util.obj X64OBJS = x64\injdll.obj x64\procrva.obj x64\proctype.obj x64\util.obj
@ -95,7 +91,6 @@ V = 0
CCmsg = @ CCmsg = @
RCmsg = @echo $<& RCmsg = @echo $<&
LDmsg = @echo $@& LDmsg = @echo $@&
MTmsg = @echo Embedding manifest&
!ENDIF !ENDIF
{}.c{$(DIR)}.obj:: {}.c{$(DIR)}.obj::
@ -113,29 +108,28 @@ ansicon64: x64 x64\ANSI64.dll x64\ansicon.exe
x86: x86:
mkdir x86 mkdir x86
x86\ansicon.exe: x86\ansicon.obj x86\ansi32.lib x86\ansicon.res x86\ansicon.exe: x86\ansicon.obj x86\ansi32.lib $(CRT) x86\ansicon.res
$(LDmsg)$(CC) /nologo $(SHARE) /Fe$@ $** $(LIBS) $(LINK) /filealign:512 $(LDmsg)$(CC) /nologo $(SHARE) /Fe$@ $** $(LIBS) $(LINK) /filealign:512
!IF "$(_NMAKE_VER)" == "9.00.30729.01" !IF "$(_NMAKE_VER)" == "9.00.30729.01"
$(MTmsg)$(MT) /nologo -manifest $@.manifest -outputresource:$@;1
@del $@.manifest @del $@.manifest
!ENDIF !ENDIF
x86\ANSI32.dll: x86\ANSI.obj $(X86OBJS) x86\ansi.res x86\ANSI32.dll: x86\ANSI.obj $(X86OBJS) x86\ansi.res
$(LDmsg)$(CC) /nologo /LD /Fe$@ $** $(LIBS) /link \ $(LDmsg)$(CC) /nologo /LD /Fe$@ $** kernel32.lib /link \
/base:0xAC0000 /entry:DllMain /filealign:512 /base:0xAC0000 /entry:DllMain /filealign:512
x64: x64:
mkdir x64 mkdir x64
x64\ansicon.exe: x64\ansicon.obj x64\ansi64.lib x64\ansicon.res x64\ansicon.exe: x64\ansicon.obj x64\ansi64.lib $(CRT) x64\ansicon.res
$(LDmsg)$(CC) /nologo $(SHARE) /Fe$@ $** $(LIBS) $(LINK) $(LDmsg)$(CC) /nologo $(SHARE) /Fe$@ $** $(LIBS) $(LINK)
x64\ANSI64.dll: x64\ANSI.obj $(X64OBJS) x64\ansi.res x64\ANSI64.dll: x64\ANSI.obj $(X64OBJS) x64\ansi.res
$(LDmsg)$(CC) /nologo /LD /Fe$@ $** $(LIBS) /link \ $(LDmsg)$(CC) /nologo /LD /Fe$@ $** kernel32.lib /link \
/base:0xAC000000 /entry:DllMain /base:0xAC000000 /entry:DllMain
x64\ANSI32.dll: x64\ANSI32.obj $(X6432OBJS) x86\ansi.res x64\ANSI32.dll: x64\ANSI32.obj $(X6432OBJS) x86\ansi.res
$(LDmsg)$(CC) /nologo /LD /Fe$@ $** $(LIBS) /link \ $(LDmsg)$(CC) /nologo /LD /Fe$@ $** kernel32.lib /link \
/base:0xAC0000 /entry:DllMain /filealign:512 \ /base:0xAC0000 /entry:DllMain /filealign:512 \
/largeaddressaware /largeaddressaware
@ -157,6 +151,12 @@ x64\ANSI32.obj: ANSI.c
x64\proctype32.obj: proctype.c x64\proctype32.obj: proctype.c
$(CCmsg)$(CC) /DW32ON64 /c $(CFLAGS) /Fo$@ $? $(CCmsg)$(CC) /DW32ON64 /c $(CFLAGS) /Fo$@ $?
x86\acrt.lib: acrt.def
$(LDmsg)link /lib /nologo /def:acrt.def /machine:ix86 /name:msvcrt /out:$@
x64\acrt.lib: acrt.def
$(LDmsg)link /lib /nologo /def:acrt.def /machine:amd64 /name:msvcrt /out:$@
clean: clean:
-del $(DIR)\*.obj $(DIR)\*.res $(DIR)\*.lib $(DIR)\*.exp -del $(DIR)\*.obj $(DIR)\*.res $(DIR)\*.lib $(DIR)\*.exp
!IF $(BITS) == 32 !IF $(BITS) == 32