Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c837970

Browse files
aganeatstellar
authored andcommitted
[Codegen][X86] Fix /HOTPATCH with clang-cl and inline asm (llvm#87639)
This fixes an edge case where functions starting with inline assembly would assert while trying to lower that inline asm instruction. After this PR, for now we always add a no-op (xchgw in this case) without considering the size of the next inline asm instruction. We might want to revisit this in the future. This fixes Unreal Engine 5.3.2 compilation with clang-cl and /HOTPATCH. Should close llvm#56234 (cherry picked from commit ec1af63)
1 parent d0ddcce commit c837970

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

llvm/lib/Target/X86/X86MCInstLower.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -959,8 +959,10 @@ void X86AsmPrinter::LowerPATCHABLE_OP(const MachineInstr &MI,
959959
SmallString<256> Code;
960960
unsigned MinSize = MI.getOperand(0).getImm();
961961

962-
if (NextMI != MI.getParent()->end()) {
962+
if (NextMI != MI.getParent()->end() && !NextMI->isInlineAsm()) {
963963
// Lower the next MachineInstr to find its byte size.
964+
// If the next instruction is inline assembly, we skip lowering it for now,
965+
// and assume we should always generate NOPs.
964966
MCInst MCI;
965967
MCIL.Lower(&*NextMI, MCI);
966968

llvm/test/CodeGen/X86/patchable-prologue.ll

+17
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,20 @@ do.body: ; preds = %do.body, %entry
193193
do.end: ; preds = %do.body
194194
ret void
195195
}
196+
197+
198+
; Test that inline asm is properly hotpatched. We currently don't examine the
199+
; asm instruction when printing it, thus we always emit patching NOPs.
200+
201+
; 64: inline_asm:
202+
; 64-NEXT: # %bb.0:
203+
; 64-NEXT: xchgw %ax, %ax # encoding: [0x66,0x90]
204+
; 64-NEXT: #APP
205+
; 64-NEXT: int3 # encoding: [0xcc]
206+
; 64-NEXT: #NO_APP
207+
208+
define dso_local void @inline_asm() "patchable-function"="prologue-short-redirect" {
209+
entry:
210+
call void asm sideeffect "int3", "~{dirflag},~{fpsr},~{flags}"()
211+
ret void
212+
}

0 commit comments

Comments
 (0)