[llvm] [dyndbg][AsmPrinter] Add tail padding attributes (PR #194852)

Orlando Cazalet-Hyams via llvm-commits llvm-commits at lists.llvm.org
Tue May 5 09:43:24 PDT 2026


OCHyams wrote:

@efriedma-quic: 

> The problem is, how do you patch the entry point of a function that's currently executing? If there are no branches to the first five bytes, the debugger can stop the world, single-step any threads where PC points into the first five bytes, then patch the entry. If there are branches, you need to do something much more complicated: check if the function is anywhere in the callstack of any of the currently executing threads, and if it is do... something. I'm not sure what the debugger does at that point.

Oh right I see what you are saying, sorry. Yes that would be a concern. I chatted with our debugger team; our approch is that if the target function is on the call stack of any threads then the jump patch isn't applied. Instead a temporary breakpoint is added & we retry when it's hit. I suppose one could fall back to optimized-code debugging at that point.

---

@aganea, thanks for the review.

To your atomicity concerns, the debugger stops the process to insert the patch, so I'm not sure that's an issue.

Regarding 2GB jump size limit - I feel that is a seperate axis of concern to the patch-padding mechansim? The attribute as proposed is parameterised so one could imagine adding an absolute jump mode later if desired. Our debugger team is happy with 32 bit rel jump for now.

Adding the header to each function as per `/HOTPATCH` could increase the text size significantly (especially given we are preserving functions that might otherwise be discarded by the compiler). There's a related comment on this in my PR description.

> (sorry pasting here all the edge cases discussed with Claude)

Could we please keep discussion human to human?


> However if we want to go forward with the proposed scheme, perhaps we could reuse the same mechanics as -fms-hotpatch, such as:
> * Reuse LowerPATCHABLE_OP with a MinSize

That was an alternative course of action I mentioned in the PR description (`"-patchable-function"="prologue-short-redirect"`, adding support for near-rel +- near-abs, that option uses PATCHALE_OP). The reason we preferred not to so far is code size. As mentioned, if this is a sticky point we could go this route instead, though it is not our preference.

> * Force MF.ensureAlignement(Align(16))

Why? I don't think this is really needed for dynamic debugging as proposed, currently. If do we force alignment this way then this proposed patching is mostly redundant? (given that we don't have as many constraints as a true hot patching system, and we just want enough space two write the jump)

> * Document the 2 GB limit if we won't support that

Will do. Though as mentioned, we could always increase the patch-padding-size in the future (or add an option to do so).


https://github.com/llvm/llvm-project/pull/194852


More information about the llvm-commits mailing list