hvpp icon indicating copy to clipboard operation
hvpp copied to clipboard

Can't build on latest vs2019, LNK4210 and C2131

Open h4nsbr1x opened this issue 3 years ago • 10 comments

I've tried cloning and building this in vs2019 and I'm getting the following errors:

3>device_custom.cpp
3>C:\Users\User\source\repos\hvpp\src\hvpp\hvpp\interrupt.h(107,31): error C2131: expression did not evaluate to a constant
3>C:\Users\User\source\repos\hvpp\src\hvpp\hvpp\interrupt.h(107,31): message : failure was caused by a read of an uninitialized symbol
3>C:\Users\User\source\repos\hvpp\src\hvpp\hvpp\interrupt.h(107,31): message : see usage of 'ia32::vmx::interrupt_info_t::<unnamed-tag>::nmi_unblocking'
3>C:\Users\User\source\repos\hvpp\src\hvpp\hvpp\interrupt.h(113,33): error C2131: expression did not evaluate to a constant
3>C:\Users\User\source\repos\hvpp\src\hvpp\hvpp\interrupt.h(113,33): message : failure was caused by a read of an uninitialized symbol
3>C:\Users\User\source\repos\hvpp\src\hvpp\hvpp\interrupt.h(113,33): message : see usage of 'ia32::vmx::interrupt_info_t::<unnamed-tag>::nmi_unblocking'
3>C:\Users\User\source\repos\hvpp\src\hvpp\hvpp\interrupt.h(119,42): error C2131: expression did not evaluate to a constant
3>C:\Users\User\source\repos\hvpp\src\hvpp\hvpp\interrupt.h(119,42): message : failure was caused by a read of an uninitialized symbol
3>C:\Users\User\source\repos\hvpp\src\hvpp\hvpp\interrupt.h(119,42): message : see usage of 'ia32::vmx::interrupt_info_t::<unnamed-tag>::nmi_unblocking'
3>C:\Users\User\source\repos\hvpp\src\hvpp\hvpp\interrupt.h(125,46): error C2131: expression did not evaluate to a constant
3>C:\Users\User\source\repos\hvpp\src\hvpp\hvpp\interrupt.h(125,46): message : failure was caused by a read of an uninitialized symbol
3>C:\Users\User\source\repos\hvpp\src\hvpp\hvpp\interrupt.h(125,46): message : see usage of 'ia32::vmx::interrupt_info_t::<unnamed-tag>::nmi_unblocking'
3>C:\Users\User\source\repos\hvpp\src\hvpp\hvpp\interrupt.h(132,38): error C2131: expression did not evaluate to a constant
3>C:\Users\User\source\repos\hvpp\src\hvpp\hvpp\interrupt.h(132,38): message : failure was caused by a read of an uninitialized symbol
3>C:\Users\User\source\repos\hvpp\src\hvpp\hvpp\interrupt.h(132,38): message : see usage of 'ia32::vmx::interrupt_info_t::<unnamed-tag>::nmi_unblocking'
2>Generating code
2>Finished generating code
2>hvpp.lib(hvpp.cpp.obj) : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
2>LINK : error LNK1218: warning treated as error; no output file generated

The first error seems to be here:

static constexpr auto nmi =
      interrupt_t {
        vmx::interrupt_type::nmi,
        exception_vector::nmi_interrupt
      };

This looks related: https://stackoverflow.com/questions/63558400/vs2019-latest-update-constexpr-expression-did-not-evaluate-to-a-constant-for and if I apply the fix it seems to solve the problem.

As for the second fault, no idea what's causing this (LNK4210)

h4nsbr1x avatar Sep 11 '20 12:09 h4nsbr1x

modify the interrupt_t private constructor like below

constexpr
interrupt_t(
  vmx::interrupt_type    interrupt_type,
  exception_vector       exception_vector,
  exception_error_code_t exception_code,
  bool                   exception_code_valid,
  int                    rip_adjust
) noexcept
  : info_{
      .vector = static_cast<uint32_t>(exception_vector),
      .type = static_cast<uint32_t>(interrupt_type),
      //
      // Final sanitization of the following fields takes place
      // in vcpu::interrupt_inject_force().
      //
      .error_code_valid = exception_code_valid,
      .nmi_unblocking = 0,
      .reserved = 0,
      .valid = true,
    }
    , error_code_{exception_code}
    , rip_adjust_{rip_adjust}
{
}

Beholder avatar Dec 17 '20 08:12 Beholder

After update Visual Studio to 16.10.0, this LNK4210 issue should be fixed.

b1tg avatar May 26 '21 08:05 b1tg

After update Visual Studio to 16.10.0, this LNK4210 issue should be fixed.

It's still there

SuperHexBot avatar Jun 08 '21 12:06 SuperHexBot

After update Visual Studio to 16.10.0, this LNK4210 issue should be fixed.

It's still there

Hi,Do you solve tis problem about LNK4210

KuNgia09 avatar Jun 14 '21 08:06 KuNgia09

The problem still seems to be present with latest 16.10.4. Some header is including chrono which is pulling in dynamic initializer that is incompatible with kernel.

<snip>
Dump of file hvpp.lib

File Type: LIBRARY

  Summary

          10 .CRT$XCU <--- hvpp.lib includes these CRT sections.
        2B74 .bss
        A048 .chks64
</snip>

Using the showIncludes option during compilation we can see that gets included which sometimes includes and hence the issue.

<snip>
bin\x64\Debug\hdrs.txt
69891:         COMDAT; sym= "public: __cdecl std::locale::id::id(unsigned __int64)" (??0id@locale@std@@QEAA@_K@Z)
70155:         COMDAT; sym= "void __cdecl `dynamic initializer for 'public: static class std::locale::id std::numpunct<char>::id''(void)" (??__E?id@?$numpunct@D@std@@2V0locale@2@A@@YAXXZ)
70188:         COMDAT; sym= "void __cdecl `dynamic initializer for 'public: static class std::locale::id std::numpunct<unsigned short>::id''(void)" (??__E?id@?$numpunct@G@std@@2V0locale@2@A@@YAXXZ)
</snip>

manurautela avatar Aug 06 '21 08:08 manurautela

1>Note: including file:   J:\dev\hypervisor\hvpp\src\hvpp\hvpp\ia32\arch/**xsave.h** <--- one such instance
1>Note: including file:  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\cinttypes
1>Note: including file:   C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\inttypes.h
1>Note: including file:  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\numeric
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\mutex
1>Note: including file:  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\chrono <--- This is where chrono is getting included
1>Note: including file:   C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\ratio
1>Note: including file:   C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\__msvc_tzdb.hpp
1>Note: including file:   C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\cmath
1>Note: including file:   C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\forward_list
1>Note: including file:   C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\istream
1>Note: including file:    C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\ostream
1>Note: including file:     C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\ios
1>Note: including file:      C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\xlocnum
1>Note: including file:       C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\iterator
1>Note: including file:       C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\streambuf
1>Note: including file:        C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\xiosbase
1>Note: including file:         C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\share.h
1>Note: including file:         C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\xlocale
1>Note: including file:          C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\memory
1>Note: including file:           C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\typeinfo
1>Note: including file:            C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\vcruntime_typeinfo.h
1>Note: including file:             C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\vcruntime_exception.h
1>Note: including file:              C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\eh.h
1>Note: including file:               C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\corecrt_terminate.h
1>Note: including file:          C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\xfacet
1>Note: including file:          C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\xlocinfo
1>Note: including file:           C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\xlocinfo.h
1>Note: including file:            C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\cctype
1>Note: including file:             C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\ctype.h
1>Note: including file:            C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\clocale
1>Note: including file:             C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\locale.h
1>Note: including file:   C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\optional
1>Note: including file:    C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\xsmf_control.h
1>Note: including file:   C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\sstream
1>Note: including file:    C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\string
1>Note: including file:   C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\vector
1>Note: including file:   C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\xloctime
1>Note: including file:   C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\format 

manurautela avatar Aug 06 '21 08:08 manurautela

@manurautela you build it success ?

ansnapx avatar Aug 10 '21 03:08 ansnapx

@manurautela you build it success ?

No, it fails with the above mentioned LNK4210.

But if you disable the linker warning "4210" it links properly and generates .sys file. Although disabling this warning might not be desirable, as it allows devs to introduce such code unintentionally.

I was able to load and run the test binary hvppctrl.exe after loading the driver.

image

manurautela avatar Aug 12 '21 04:08 manurautela

  1. VS 2019 (latest updates 16.11.0 ), WDK - Win10 (10.0.19041.685)
  2. C2131 errors (with non initialized members in constexpr) is still present, you can disable the constexpr as : static auto nmi = // delete the constexpr interrupt_t { vmx::interrupt_type::nmi, exception_vector::nmi_interrupt }; // interrupt.h
  3. C2220 error : Configuration Properties > C++ > WX- Configuration Properties > C++ > Command Line : /Zc:strictStrings-
  4. LNK4210 : Configuration Properties > Linker > Command Line /IGNORE:4210

ansnapx avatar Aug 13 '21 09:08 ansnapx

some references regarding the .CRT link warning http://www.zer0mem.sk/?p=517 https://github.com/jxy-s/stlkrn https://docs.microsoft.com/en-us/windows-hardware/drivers/develop/using-the-microsoft-c-runtime-with-user-mode-drivers-and-apps

danyhm avatar Mar 20 '22 05:03 danyhm