【问题标题】:Memory corruption error on Windows build of MPIRWindows 版本的 MPIR 内存损坏错误
【发布时间】:2021-06-15 23:08:54
【问题描述】:

我在使用 Windows 版本的 MPIR 时遇到了内存损坏错误,该错误显示在以下最小测试用例中。

Microsoft (R) C/C++ 优化编译器版本 19.25.28610.4 for x64

使用此脚本从 github checkout 编译 MPIR(刚刚验证问题仍然在最新版本中重现):

pushd \mpir\msvc\vs19
call msbuild.bat gc DLL x64 Debug
call msbuild.bat gc LIB x64 Release
popd
copy \mpir\dll\x64\Debug\mpir.dll

使用这个源文件作为测试用例:

#include <stdio.h>
#include <gmp.h>

int main(int argc, const char **argv) {
  mpz_t x;
  mpz_init_set_str(x,"123",10);
  mpz_out_str(stdout,10,x);
  putchar('\n');
  return 0;
}

这样编译:

cl /I\mpir /MTd a.cc \mpir\dll\x64\Debug\mpir.lib

运行生成的程序,产生正确的输出,但在退出时显示堆损坏,在弹出窗口中显示错误消息,不幸的是不允许复制粘贴,但它在

C:\Program Files (x86)\Windows Kits\10\Source\10.0.18362.0\ucrt\heap\debug_heap.cpp

第 996 行,即

        _ASSERTE(__acrt_first_block == header);

这是已知解决方案的问题吗?还是有一种已知的方法可以准确地找出问题所在?

【问题讨论】:

  • 您是否使用此 call msbuild.bat gc LIB x64 Release 构建了 mpir.lib 的发布版本?然后使用 CRT 的多线程调试版本 (/MTd) 将此 mpir.lib 链接到您的 exe?
  • @nevilad 好吧,目前使用的是mpir.lib 的调试版本,但除此之外还有这些标志,是的。
  • 因此没有混合调试/发布 CRT 版本。 mpir 也是用/MTd 构建的吗?混合多线程和单线程 CRT 是此类错误的另一个常见来源。
  • @nevilad 据我所知,是的。但是您可能是对的,问题出在构建过程中的某个地方。我已经发布了一个进一步扩展的答案。

标签: c++ windows visual-c++ memory-corruption mpir


【解决方案1】:

我从未追查过问题的确切原因,但我认为它与构建过程有关,构建过程通过许多抽象层使用 MSBuild,因此几乎不可能确定到底发生了什么.

我已经使用简单的透明构建过程组合了 MPIR 的分发,并且与此版本链接,不会出现问题。

https://github.com/russellw/mpir

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-16
    相关资源
    最近更新 更多