Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Support for /HOTPATCH and /FUNCTIONPADMIN #35748

Open Quuxplusone opened 6 years ago

Quuxplusone commented 6 years ago
Bugzilla Link PR36775
Status NEW
Importance P enhancement
Reported by Alexandre Ganea (alex_toresh@yahoo.fr)
Reported on 2018-03-16 13:45:19 -0700
Last modified on 2019-04-29 06:17:14 -0700
Version unspecified
Hardware PC Windows NT
CC llvm-bugs@lists.llvm.org, nicolasweber@gmx.de, ruiu@google.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also

In order to use real-time code updating tools such as Recode (www.indefiant.com), one needs to add /FUNCTIONPADMIN to the linker flags, and/or /HOTPATCH, depending on whether /INCREMENTAL is specified or not. Such as specified here: https://www.indefiant.com/recode/help/build.html

Is there a remote chance that these flags could be added to LLD?

Quuxplusone commented 5 years ago

r354716 added /functionpadmin. Is this enough for this bug, or is /hotpatch still needed?

Quuxplusone commented 5 years ago

I haven't added support for /HOTPATCH in clang yet. I'm not sure how much work that would be. Microsoft generates 0x8B 0xFF (mov edi,edi) at the beginning of each function when /HOTPATCH is specified / implied (x64), so that one could patch that by 0xEB 0xF9 (jmp -7) in order for hot patching can occur on the fly (see https://www.codeproject.com/Articles/27339/API-hooking-for-hotpatchable-operating-systems).

There's also the fact that a 2 GB virtual space should be .bss/left unused around the code when specifying /FUNCTIONPADMIN, so that a hotpatching tool can insert modified code around +/- 2 GB, which in turn is required for 32-bit JMP. This has yet to be done in LLD. Currently, this can be worked around by using /dynamicbase (otherwise the EXE is loaded at 0x140000000 and other things, like heap and VirtualAllocs, are using the space around that address).