Skip to content

Implement -fpatchable-function-entry flag#23251

Open
xoxorwr wants to merge 2 commits into
dlang:masterfrom
xoxorwr:patchable-fn
Open

Implement -fpatchable-function-entry flag#23251
xoxorwr wants to merge 2 commits into
dlang:masterfrom
xoxorwr:patchable-fn

Conversation

@xoxorwr

@xoxorwr xoxorwr commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Context: https://forum.dlang.org/post/110h05u$2tc6$1@digitalmars.com

This PR implements the -fpatchable-function-entry=total_nops[,prefix_nops] compiler flag to enable NOP padding for function entries.

It provides the same effect as the GCC/Clang/Rust -fpatchable-function-entry flag.

It facilitates atomic hotpatching and hot reloading scenarios.

https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fpatchable-function-entry

https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html#index-fpatchable-function-entry

@xoxorwr xoxorwr requested a review from ibuclaw as a code owner June 12, 2026 14:34
@dlang-bot

Copy link
Copy Markdown

Thanks for your pull request and interest in making D better, @xoxorwr! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#23251"

@xoxorwr

xoxorwr commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

cc @rikkimax

@rikkimax

Copy link
Copy Markdown
Contributor

I am aware that Microsoft uses this technique quite heavily in their products, including Windows.

I am also very hesitant to call this a good direction for D. There are some very difficult problems to solve in your -watch proposal, and I'd like to see how that proceeds before suggesting that this is a good feature for this purpose.

@xoxorwr

xoxorwr commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

Separate from the compiler daemon idea, this is a generally useful feature that could benefit a variety of tools.

In situations where you'd normally fall back to C (or even Rust), D becomes a viable option again.

Comment on lines +276 to +277
uint patchableFunctionEntryTotal = 0; /// Number of NOPs to pad function entries with
uint patchableFunctionEntryPrefix = 0; /// Number of NOPs before function entry label

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this in dmdparams as it's not used by the front-end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants