{"id":112514,"date":"2026-07-10T07:00:00","date_gmt":"2026-07-10T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=112514"},"modified":"2026-07-04T07:18:34","modified_gmt":"2026-07-04T14:18:34","slug":"20260710-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20260710-00\/?p=112514","title":{"rendered":"The case of the mysterious changes to integers when there shouldn&#8217;t have been any code generation effect"},"content":{"rendered":"<p>A colleague made some code changes that should not have had any effect on the generated binary. Specifically, they migrated from <a href=\"https:\/\/github.com\/tpn\/winsdk-10\/blob\/9b69fd26ac0c7d0b83d378dba01080e93349c2ed\/Include\/10.0.16299.0\/km\/ndis.h#L1153\"> the <code>NDIS_<wbr \/>STRING_<wbr \/>CONST<\/code> macro<\/a> to <a href=\"https:\/\/github.com\/tpn\/winsdk-10\/blob\/9b69fd26ac0c7d0b83d378dba01080e93349c2ed\/Include\/10.0.14393.0\/shared\/ntdef.h#L2037\"> the more type-safe <code>RTL_<wbr \/>CONSTANT_<wbr \/>STRING<\/code> macro<\/a>. The two macros produce the same results at the end of the day, so the expectation was that this would not result in any change to the binary.<\/p>\n<p>But they found a change to the binary.<\/p>\n<p>Specifically, four functions changed, and what is particularly strange is that none of them involved the macro changes. Three of the functions are in one source file, and the fourth is in a source file that wasn&#8217;t even touched!<\/p>\n<p>The changes looked like this:<\/p>\n<table class=\"cp3\" style=\"border-collapse: collapse;\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n<tbody>\n<tr>\n<th>Before<\/th>\n<th>After<\/th>\n<\/tr>\n<tr>\n<td colspan=\"2\" align=\"center\"><tt>contoso!Evt\u00adWdf\u00adWidget\u00adContext\u00adCleanup<\/tt><\/td>\n<\/tr>\n<tr>\n<td><tt>mov rax, [contoso!WdfFunctions_01031]<\/tt><br \/>\n<tt>lea rcx, [??_C@__0DK@MPBCIIPN@...]<\/tt><br \/>\n<tt>mov [rsp+20h], rcx<\/tt><br \/>\n<tt>mov r9d, <span style=\"border: solid 1px currentcolor;\">62Bh<\/span><\/tt><br \/>\n<tt>mov r8d, 52467443h<\/tt><br \/>\n<tt>mov rcx, [contoso!WdfDriverGlobals]<\/tt><br \/>\n<tt>mov rdx, rbx<\/tt><br \/>\n<tt>mov rax, [rax+670h]<\/tt><br \/>\n<tt>call __guard_dispatch_call<\/tt><\/td>\n<td><tt>mov rax, [contoso!WdfFunctions_01031]<\/tt><br \/>\n<tt>lea rcx, [??_C@__0DK@MPBCIIPN@...]<\/tt><br \/>\n<tt>mov [rsp+20h], rcx<\/tt><br \/>\n<tt>mov r9d, <span style=\"border: solid 1px currentcolor;\">62Ah<\/span><\/tt><br \/>\n<tt>mov r8d, 52467443h<\/tt><br \/>\n<tt>mov rcx, [contoso!WdfDriverGlobals]<\/tt><br \/>\n<tt>mov rdx, rbx<\/tt><br \/>\n<tt>mov rax, [rax+670h]<\/tt><br \/>\n<tt>call __guard_dispatch_call<\/tt><\/td>\n<\/tr>\n<tr>\n<td colspan=\"2\" align=\"center\"><tt>contoso!Function2<\/tt><\/td>\n<\/tr>\n<tr>\n<td><tt>mov rax, [contoso!WdfFunctions_01031]<\/tt><br \/>\n<tt>lea rcx, [??_C@__0DK@MPBCIIPN@...]<\/tt><br \/>\n<tt>mov [rsp+20h], rcx<\/tt><br \/>\n<tt>mov r9d, <span style=\"border: solid 1px currentcolor;\">616h<\/span><\/tt><br \/>\n<tt>mov rcx, [contoso!WdfDriverGlobals]<\/tt><br \/>\n<tt>mov r8d, 52467443h<\/tt><br \/>\n<tt>mov rdx, rdi<\/tt><br \/>\n<tt>mov rax, [rax+668h]<\/tt><br \/>\n<tt>call __guard_dispatch_call<\/tt><\/td>\n<td><tt>mov rax, [contoso!WdfFunctions_01031]<\/tt><br \/>\n<tt>lea rcx, [??_C@__0DK@MPBCIIPN@...]<\/tt><br \/>\n<tt>mov [rsp+20h], rcx<\/tt><br \/>\n<tt>mov r9d, <span style=\"border: solid 1px currentcolor;\">615h<\/span><\/tt><br \/>\n<tt>mov rcx, [contoso!WdfDriverGlobals]<\/tt><br \/>\n<tt>mov r8d, 52467443h<\/tt><br \/>\n<tt>mov rdx, rdi<\/tt><br \/>\n<tt>mov rax, [rax+668h]<\/tt><br \/>\n<tt>call __guard_dispatch_call<\/tt><\/td>\n<\/tr>\n<tr>\n<td colspan=\"2\" align=\"center\"><tt>contoso!Function3<\/tt><\/td>\n<\/tr>\n<tr>\n<td><tt>mov rax, [contoso!WdfFunctions_01031]<\/tt><br \/>\n<tt>lea rcx, [??_C@__0DK@MPBCIIPN@...]<\/tt><br \/>\n<tt>mov [r11-20h], rcx<\/tt><br \/>\n<tt>xor r8d, r8d<\/tt><br \/>\n<tt>mov rcx, [contoso!WdfDriverGlobals]<\/tt><br \/>\n<tt>mov r9d, <span style=\"border: solid 1px currentcolor;\">35Dh<\/span><\/tt><br \/>\n<tt>mov rax, [rax+0DB0h]<\/tt><br \/>\n<tt>call __guard_dispatch_call<\/tt><\/td>\n<td><tt>mov rax, [contoso!WdfFunctions_01031]<\/tt><br \/>\n<tt>lea rcx, [??_C@__0DK@MPBCIIPN@...]<\/tt><br \/>\n<tt>mov [r11-20h], rcx<\/tt><br \/>\n<tt>xor r8d, r8d<\/tt><br \/>\n<tt>mov rcx, [contoso!WdfDriverGlobals]<\/tt><br \/>\n<tt>mov r9d, <span style=\"border: solid 1px currentcolor;\">35Ch<\/span><\/tt><br \/>\n<tt>mov rax, [rax+0DB0h]<\/tt><br \/>\n<tt>call __guard_dispatch_call<\/tt><\/td>\n<\/tr>\n<tr>\n<td colspan=\"2\" align=\"center\"><tt>contoso!Function4<\/tt><\/td>\n<\/tr>\n<tr>\n<td><tt>mov rax, [contoso!WdfFunctions_01031]<\/tt><br \/>\n<tt>lea rcx, [??_C@__0DK@MPBCIIPN@...]<\/tt><br \/>\n<tt>mov rdx, [rbp+8]<\/tt><br \/>\n<tt>mov r9d, <span style=\"border: solid 1px currentcolor;\">377h<\/span><\/tt><br \/>\n<tt>mov [rsp+20h], rcx<\/tt><br \/>\n<tt>mov r8d, 49507443h<\/tt><br \/>\n<tt>mov rcx, [contoso!WdfDriverGlobals]<\/tt><br \/>\n<tt>mov rax, [rax+0DB8h]<\/tt><br \/>\n<tt>call __guard_dispatch_call<\/tt><\/td>\n<td><tt>mov rax, [contoso!WdfFunctions_01031]<\/tt><br \/>\n<tt>lea rcx, [??_C@__0DK@MPBCIIPN@...]<\/tt><br \/>\n<tt>mov rdx, [rbp+8]<\/tt><br \/>\n<tt>mov r9d, <span style=\"border: solid 1px currentcolor;\">376h<\/span><\/tt><br \/>\n<tt>mov [rsp+20h], rcx<\/tt><br \/>\n<tt>mov r8d, 49507443h<\/tt><br \/>\n<tt>mov rcx, [contoso!WdfDriverGlobals]<\/tt><br \/>\n<tt>mov rax, [rax+0DB8h]<\/tt><br \/>\n<tt>call __guard_dispatch_call<\/tt><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>In all of the cases, the change is that a single integer changed to a value one smaller.<\/p>\n<p>My colleague asked an LLM to explain this change, and it suggested that the changes were related to control flow guard metadata. Does this make sense?<\/p>\n<p>It didn&#8217;t make sense to me, on two points. First, for the guard dispatch call, the only parameter to control flow guard is the <tt>rax<\/tt> register, which is the function being checked. All the other registers contain the parameters to the called function. Since the changes are to the <tt>r9d<\/tt> register, they are not related to control flow guard.<\/p>\n<p>Second, the control flow guard metadata is not stored in code. It&#8217;s stored <a title=\"What to do when you have a crash in the runtime control flow guard check\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20251029-00\/?p=111738\"> as a data block inside the binary<\/a>.<\/p>\n<p>So what are we seeing?<\/p>\n<p>I took a look a <code>Evt\u00adWdf\u00adWidget\u00adContext\u00adCleanup<\/code>.<\/p>\n<pre>void EvtWdfWidgetContextCleanup(_In_ WDFOBJECT Object)\r\n{\r\n    auto widgetContext = GetContextFromWidgetHandle(Object);\r\n    if (widgetContext-&gt;NeedsDereference)\r\n    {\r\n        widgetContext-&gt;NeedsDereference = FALSE;\r\n        WdfObjectDereferenceWithTag(Object, CONTOSO_WIDGET_TAG);\r\n    }\r\n}\r\n<\/pre>\n<p>The compiler points to the <code>Wdf\u00adObject\u00adDereference\u00adWith\u00adTag<\/code> as the location of the change. And we see that <a href=\"https:\/\/github.com\/microsoft\/Windows-Driver-Frameworks\/blob\/b6191d9543441329154da32f7ab9bdd97228dd3c\/src\/publicinc\/wdf\/kmdf\/1.31\/wdfobject.h#L848-L849\"> it is defined as a macro<\/a>:<\/p>\n<pre>#define WdfObjectDereferenceWithTag(Handle, Tag) \\\r\n        WdfObjectDereferenceActual(Handle, Tag, __LINE__, __FILE__)\r\n<\/pre>\n<p>which is itself <a href=\"https:\/\/github.com\/microsoft\/Windows-Driver-Frameworks\/blob\/b6191d9543441329154da32f7ab9bdd97228dd3c\/src\/publicinc\/wdf\/kmdf\/1.31\/wdfobject.h#L701-L715\"> an inline function: <\/a><\/p>\n<pre>_IRQL_requires_max_(DISPATCH_LEVEL)\r\nVOID\r\nFORCEINLINE\r\nWdfObjectReferenceActual(\r\n    _In_\r\n    WDFOBJECT Handle,\r\n    _In_opt_\r\n    PVOID Tag,\r\n    _In_\r\n    LONG Line,\r\n    _In_z_\r\n    PCCH File\r\n    )\r\n{\r\n    ((PFN_WDFOBJECTREFERENCEACTUAL) WdfFunctions[WdfObjectReferenceActualTableIndex])\r\n        (WdfDriverGlobals, Handle, Tag, Line, File);\r\n}\r\n<\/pre>\n<p>The last little detail is that <a href=\"https:\/\/github.com\/microsoft\/Windows-Driver-Frameworks\/blob\/b6191d9543441329154da32f7ab9bdd97228dd3c\/src\/publicinc\/wdf\/umdf\/1.31\/wdf.h#L60\"> <code>WdfFunctions<\/code> is a macro that expands to <code>WdfFunctions_01031<\/code><\/a>. The WDF header files give each version a unique name so that mismatched versions lead to a linker error rather than undefined behavior at runtime.<\/p>\n<p>Now we can see how this code maps to the compiler output.<\/p>\n<pre>    mov rax, [contoso!WdfFunctions_01031]   ; WdfFunctions\r\n    lea rcx, [??_C@__0DK@MPBCIIPN@...]      ; Address of something\r\n    mov [rsp+20h], rcx                      ; is the File parameter\r\n    mov r9d, 62Bh                           ; Line parameter\r\n    mov r8d, 52467443h                      ; Tag parameter\r\n    mov rcx, [contoso!WdfDriverGlobals]     ; hard-coded parameter\r\n    mov rdx, rbx                            ; Handle parameter\r\n    mov rax, [rax+670h]                     ; Load the function pointer\r\n    call __guard_dispatch_call              ; Validate and call\u00b9\r\n<\/pre>\n<p>So the value that changed is the <i>line number<\/i>.<\/p>\n<p>I went back to the pull request and observed that the pull requested deleted a line from the source file.<\/p>\n<pre>#include &lt;strsafe.h&gt;\r\n<span style=\"text-decoration: line-through;\">#include \"stringutils.h\"<\/span>\r\n<\/pre>\n<p>Part of the pull request included deleting the no-longer-needed header because it contained a private definition of the <code>NDIS_<wbr \/>STRING_<wbr \/>CONST<\/code> macro, which the code no longer uses.<\/p>\n<p>Deleting a line from the source file causes all the line numbers to shift by one!<\/p>\n<p>So what they were seeing was just a change to the line numbers. No change in functionality.<\/p>\n<p>If they really wanted to make this a &#8220;no binary effect&#8221; change, they could replace the <code>#include \"stringutils.h<\/code> with a comment or just leave it as a blank line.<\/p>\n<p>Or they could just accept that line numbers can change when you change lines.<\/p>\n<p><b>Bonus chatter<\/b>: But wait, I said that three of the changes were in one file, the one with the deleted line, but a fourth was in a file that didn&#8217;t change at all. What&#8217;s that about?<\/p>\n<p>The fourth function contained a call to a function in the modified file, and link-time code generation decided to inline that call. The changed line number propagated into the inline function and resulted in a code generation change in a file that wasn&#8217;t even affected by the pull request.<\/p>\n<p>\u00b9 Recall that <a title=\"The other kind of control flow guard check: The combined validate and call\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20260708-00\/?p=112510\"> in the validate-and-call pattern<\/a>, the function pointer is passed in the <code>rax<\/code> register, and everthing else is set up as if you were calling the function yourself.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Decoding where those integer came from.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-112514","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Decoding where those integer came from.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/112514","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=112514"}],"version-history":[{"count":1,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/112514\/revisions"}],"predecessor-version":[{"id":112517,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/112514\/revisions\/112517"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=112514"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=112514"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=112514"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}