简体   繁体   English

Windows更新破坏了.Net 4.x中的结构构造

[英]Windows update corrupts struct construction in .Net 4.x

Since the installed of a Windows update on 14.9.2017 we have problems creating certain structs in our release builds. 自从14.9.2017安装Windows更新以来,我们在发布版本中创建某些结构时遇到了问题。 I have noticed that compiled code on computers without that update runs as expected ("Wrong start: 1.1.1990..."), on computer with the update in question installed, the code is not working correctly ("Wrong start: 1.1.2000..."). 我注意到没有更新的计算机上的编译代码按预期运行(“错误的启动:1.1.1990 ...”),在安装了相关更新的计算机上,代码无法正常工作(“错误的启动:1.1。 2000 ...“)。 This happens in all versions of the .NET Frameworks starting from version 4.x. 从版本4.x开始,所有版本的.NET框架都会发生这种情况。

 class Program
    {
        static void Main(string[] args)
        {
            DateTime start1 = new DateTime(1990, 1, 1, 6, 0, 0);
            DateTime end1 = new DateTime(2000, 1, 1, 6, 0, 0);
            var r2 = new DateTimeRange(start1, end1);
            var r3 = new Range<DateTime>(r2.From, r2.To);
            Console.WriteLine($"Wrong start: {r3.From}, correct start: {start1}");
            Console.ReadLine();
        }
    }

   public struct DateTimeRange 
    {
        private Range<DateTime> m_range;

        public DateTimeRange(DateTime from, DateTime to)
        {
            m_range = new Range<DateTime>(from, to);
        }


        public DateTime From
        {
            get { return m_range.From; }
        }

        public DateTime To
        {
            get { return m_range.To; }
        }
    }

    public struct Range<T> where T : struct
    {
        private T m_from;
        private T m_to;


        public Range(T from, T to)
        {
            m_from = from;
            m_to = to;
        }


        public T From
        {
            get { return m_from; }
        }

        public T To
        {
            get { return m_to; }
        }
    }

I see it, after rebooting my machine. 重新启动机器后,我看到了它。 Definitely quacks like bug in the update. 肯定会像更新中的bug那样嘎嘎作响。 On my machine I see C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\corjit.dll, dated 9/6/17, 9:23AM CDT, version 4.7.2110.0. 在我的机器上,我看到C:\\ Windows \\ Microsoft.NET \\ Framework64 \\ v4.0.30319 \\ corjit.dll,日期为9/6/17,上午9:23 CDT,版本4.7.2110.0。

The bug is specific to the x64 jitter and only occurs in the Release build with the optimizer enabled. 该错误特定于x64抖动,仅在启用了优化程序的Release版本中发生。 It matches the kind of bugs that I've seen in the jitter before, most optimizer bugs in the past were related to code handling structs. 它匹配我之前在抖动中看到的那种错误,过去大多数优化错误都与代码处理结构有关。

Unfortunately I have a hard time characterizing the bug, the code gen is too beefy and the workaround I found does not seem to make enough difference in the machine code on first glance. 不幸的是,我很难描述错误,代码生成太强大了,我发现的解决方法似乎没有在机器代码中乍看之下产生足够的差异。 But is otherwise the typical way to sail around these kind of optimizer bugs: 但是否则是绕过这些优化器错误的典型方式:

using System.Runtime.CompilerServices;
...
    public DateTime From {
        [MethodImpl(MethodImplOptions.NoInlining)]
        get { return m_range.From; }
    }

The other workarounds are forcing 32-bit mode or falling back to the legacy jitter . 其他解决方法是强制32位模式或回退到传统抖动 Please report the bug so they can fix it, let me know if you don't want to take the time and I'll take care of it. 报告错误,以便他们可以修复它,如果您不想花时间让我知道,我会照顾它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM