unresolved external symbol __GSHandlerCheck and /GS- switch
Question
Friday, August 12, 2016 8:01 PM
I'm trying to build an executable which is not linking to Microsoft's C Standard Library, but it looks like the '/GS-' switch of CL.EXE is ignored (same goes for '/sdl-').
Linking with 'bufferoverflowU.lib' removes a few linker errors for the security cookies, but leaves the __GSHandlerCheck undefined. I could not find the symbol in any of the CRT's source files, and neither could I find it in any of the compiled libraries. It's always defined as an external symbol in any of Microsoft's CRT libraries.
However, I found it in LINK.EXE: http://puu.sh/qz4QL/77eb840cc0.png
Any ideas how to get this working, without copying the sources from LINK.EXE into mine?
All replies (3)
Monday, August 15, 2016 9:24 AM ✅Answered
Hi ArvidGerstmann,
thanks for posting here.
>>Linking with 'bufferoverflowU.lib' removes a few linker errors for the security cookies
You could try to set C/C++ -> Code Generation -> Buffer Security Check = NO.
>>unresolved external symbol __GSHandlerCheck
For this case, I suggest you try these two options.
1.Explicitly include “libcmt.lib” in the list of additional libs to link
2.Adding secchk.lib to the linker settings for the project
Here is a document about CRT Library Features, you could refer to.
https://msdn.microsoft.com/en-us/library/abx4dbyh.aspx
Best Regards,
Sera Yu
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Sunday, August 14, 2016 4:24 PM
In VS2015 I could build apps that did not link to the C Standard Library by doing the following --
1. Define an alternate entry entrypoint function and set the appropriate linker advanced option to use it. The prototype that I used was int __stdcall RawEntry(). Use this instead of main() or WinMain().
2. I set both /sdl- and /GS-
3. In the compiler options for code generation set all "Basic Runtime Checks" to "Default".
I verified that there was no linkage to any of the VC++ CRT DLLs by checking the executables with depends.exe
The following map was produced by the linker when I created a Win32 program using the above methods. You can see there is no CRT linkage
NoCRTWin
Timestamp is 57b09b82 (Sun Aug 14 12:25:38 2016)
Preferred load address is 00400000
Start Length Name Class
0001:00000000 00010000H .textbss DATA
0002:00000000 00001534H .text$mn CODE
0003:00000000 00000144H .rdata DATA
0003:00000143 00000000H .edata DATA
0003:00000144 00000194H .rdata$zzzdbg DATA
0004:00000000 000001f0H .bss DATA
0005:00000000 000000b4H .idata$5 DATA
0005:000000b4 00000028H .idata$2 DATA
0005:000000dc 00000014H .idata$3 DATA
0005:000000f0 000000b4H .idata$4 DATA
0005:000001a4 0000028cH .idata$6 DATA
0006:00000000 00000780H .rsrc$01 DATA
0006:00000780 0001b65cH .rsrc$02 DATA
Address Publics by Value Rva+Base Lib:Object
0000:00000000 ___guard_fids_count 00000000 <absolute>
0000:00000000 ___guard_iat_count 00000000 <absolute>
0000:00000000 ___safe_se_handler_count 00000000 <absolute>
0000:00000000 ___dynamic_value_reloc_table 00000000 <absolute>
0000:00000000 ___safe_se_handler_table 00000000 <absolute>
0000:00000000 ___guard_iat_table 00000000 <absolute>
0000:00000000 ___guard_longjmp_table 00000000 <absolute>
0000:00000000 ___guard_longjmp_count 00000000 <absolute>
0000:00000000 ___guard_flags 00000000 <absolute>
0000:00000000 ___guard_fids_table 00000000 <absolute>
0001:00000000 __enc$textbss$begin 00401000 <linker-defined>
0001:00010000 __enc$textbss$end 00411000 <linker-defined>
0002:00000100 ?About@@YGHPAUHWND__@@IIJ@Z 00411100 f NoCRTWin.obj
0002:00000190 ?InitInstance@@YAHPAUHINSTANCE__@@H@Z 00411190 f NoCRTWin.obj
0002:00000220 ?MyRegisterClass@@YAGPAUHINSTANCE__@@@Z 00411220 f NoCRTWin.obj
0002:000002d0 ?RawEntry@@YGHXZ 004112d0 f NoCRTWin.obj
0002:000003c0 ?WndProc@@YGJPAUHWND__@@IIJ@Z 004113c0 f NoCRTWin.obj
0002:000004f4 _GetModuleHandleW@4 004114f4 f kernel32:KERNEL32.dll
0002:000004fa _LoadStringW@16 004114fa f user32:USER32.dll
0002:00000500 _GetMessageW@16 00411500 f user32:USER32.dll
0002:00000506 _TranslateMessage@4 00411506 f user32:USER32.dll
0002:0000050c _DispatchMessageW@4 0041150c f user32:USER32.dll
0002:00000512 _DefWindowProcW@16 00411512 f user32:USER32.dll
0002:00000518 _PostQuitMessage@4 00411518 f user32:USER32.dll
0002:0000051e _RegisterClassExW@4 0041151e f user32:USER32.dll
0002:00000524 _CreateWindowExW@48 00411524 f user32:USER32.dll
0002:0000052a _DestroyWindow@4 0041152a f user32:USER32.dll
0002:00000530 _ShowWindow@8 00411530 f user32:USER32.dll
0002:00000536 _DialogBoxParamW@20 00411536 f user32:USER32.dll
0002:0000053c _EndDialog@8 0041153c f user32:USER32.dll
0002:00000542 _LoadAcceleratorsW@8 00411542 f user32:USER32.dll
0002:00000548 _TranslateAcceleratorW@12 00411548 f user32:USER32.dll
0002:0000054e _UpdateWindow@4 0041154e f user32:USER32.dll
0002:00000554 _BeginPaint@8 00411554 f user32:USER32.dll
0002:0000055a _EndPaint@8 0041155a f user32:USER32.dll
0002:00000560 _LoadCursorW@8 00411560 f user32:USER32.dll
0002:00000566 _LoadIconW@8 00411566 f user32:USER32.dll
0004:00000000 ?hInst@@3PAUHINSTANCE__@@A 00414000 NoCRTWin.obj
0004:00000008 ?szTitle@@3PA_WA 00414008 NoCRTWin.obj
0004:000000d0 ?szWindowClass@@3PA_WA 004140d0 NoCRTWin.obj
0004:000001ec ___@@_PchSym_@00@UfhvihUvirxUwlxfnvmghUerhfzoLhgfwrlLCABFUkilqvxghUmlxigdrmUmlxigdrmUwvyftUhgwzucOlyq@A8EB28F30AC2176C 004141ec stdafx.obj
0005:00000000 __imp__GetModuleHandleW@4 00415000 kernel32:KERNEL32.dll
0005:00000004 \177KERNEL32_NULL_THUNK_DATA 00415004 kernel32:KERNEL32.dll
0005:00000030 __imp__LoadStringW@16 00415030 user32:USER32.dll
0005:00000034 __imp__GetMessageW@16 00415034 user32:USER32.dll
0005:00000038 __imp__TranslateMessage@4 00415038 user32:USER32.dll
0005:0000003c __imp__DispatchMessageW@4 0041503c user32:USER32.dll
0005:00000040 __imp__DefWindowProcW@16 00415040 user32:USER32.dll
0005:00000044 __imp__PostQuitMessage@4 00415044 user32:USER32.dll
0005:00000048 __imp__RegisterClassExW@4 00415048 user32:USER32.dll
0005:0000004c __imp__CreateWindowExW@48 0041504c user32:USER32.dll
0005:00000050 __imp__DestroyWindow@4 00415050 user32:USER32.dll
0005:00000054 __imp__ShowWindow@8 00415054 user32:USER32.dll
0005:00000058 __imp__DialogBoxParamW@20 00415058 user32:USER32.dll
0005:0000005c __imp__EndDialog@8 0041505c user32:USER32.dll
0005:00000060 __imp__LoadAcceleratorsW@8 00415060 user32:USER32.dll
0005:00000064 __imp__TranslateAcceleratorW@12 00415064 user32:USER32.dll
0005:00000068 __imp__UpdateWindow@4 00415068 user32:USER32.dll
0005:0000006c __imp__BeginPaint@8 0041506c user32:USER32.dll
0005:00000070 __imp__EndPaint@8 00415070 user32:USER32.dll
0005:00000074 __imp__LoadCursorW@8 00415074 user32:USER32.dll
0005:00000078 __imp__LoadIconW@8 00415078 user32:USER32.dll
0005:0000007c \177USER32_NULL_THUNK_DATA 0041507c user32:USER32.dll
0005:000000b4 __IMPORT_DESCRIPTOR_KERNEL32 004150b4 kernel32:KERNEL32.dll
0005:000000c8 __IMPORT_DESCRIPTOR_USER32 004150c8 user32:USER32.dll
0005:000000dc __NULL_IMPORT_DESCRIPTOR 004150dc kernel32:KERNEL32.dll
Monday, August 15, 2016 10:59 AM
What version of VC++ is being used?
Beginning with Windows SDK 6.0 bufferoverflowU.lib hasn't been included in the SDK.