[all-commits] [llvm/llvm-project] 8ecbfa: Hot-patch __ref_* variables should be placed in .r...

sivadeilra via All-commits all-commits at lists.llvm.org
Mon Jul 28 16:15:23 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 8ecbfa66cd314df805e2910783ded37f2f8621b4
      https://github.com/llvm/llvm-project/commit/8ecbfa66cd314df805e2910783ded37f2f8621b4
  Author: sivadeilra <ardavis at microsoft.com>
  Date:   2025-07-28 (Mon, 28 Jul 2025)

  Changed paths:
    M llvm/lib/CodeGen/WindowsSecureHotPatching.cpp

  Log Message:
  -----------
  Hot-patch __ref_* variables should be placed in .rdata, not .data (#151008)

This is a refinment of #145565 . That PR added support for "Windows
Secure Hot-patching". In this design, functions that are compiled for
hot-patching need to be modified when they access mutable global
variables. The modification is to insert a level of indirection, the
so-called `__ref_*` variables.

Ref variables are supposed to be inserted into the `.rdata` section, not
`.data`. This provides a degree of protection against modification
(accidental or malicious) of ref variables during program execution.
When the Windows hot-patch subsystem loads a module as a hot-patch, it
finds all ref variables and changes the page protections for the pages
containing them to read/write. Then it sets the ref variables to point
to the real variable locations within the base image. Then it changes
page protections back to read-only.

This relies on the variables being placed in the `.rdata` section, not
`.data`.

However, it is still important that the LLVM `GlobalVariable` that is
created for the ref variable be created with `isConstant = false`. This
prevents LLVM from optimizing accesses to the `GlobalVariable`, i.e.
assuming that the variable can never change and thus inlining its value
into expressions that would ordinarily dereference it. That optimization
would defeat the purpose of hot-patching, so `isConstant = false` is
still the correct value for these ref variables.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list