Skip to content

Commit ece72e2

Browse files
authored
[MC,COFF] .safeseh: avoid changeSection (#132624)
The directive temporarily switches to the .sxdata section to emit data, and then calls `insert`, which makes `CurFrag` out of sync of the current section. Call push/switch/pop instead. Related to #132464
1 parent 1752d52 commit ece72e2

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Diff for: llvm/lib/MC/MCWinCOFFStreamer.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ void MCWinCOFFStreamer::emitCOFFSafeSEH(MCSymbol const *Symbol) {
287287
return;
288288

289289
MCSection *SXData = getContext().getObjectFileInfo()->getSXDataSection();
290-
changeSection(SXData);
290+
pushSection();
291+
switchSection(SXData);
291292
SXData->ensureMinAlignment(Align(4));
292293

293294
insert(getContext().allocFragment<MCSymbolIdFragment>(Symbol));
@@ -298,6 +299,7 @@ void MCWinCOFFStreamer::emitCOFFSafeSEH(MCSymbol const *Symbol) {
298299
// function. Go ahead and oblige it here.
299300
CSymbol->setType(COFF::IMAGE_SYM_DTYPE_FUNCTION
300301
<< COFF::SCT_COMPLEX_TYPE_SHIFT);
302+
popSection();
301303
}
302304

303305
void MCWinCOFFStreamer::emitCOFFSymbolIndex(MCSymbol const *Symbol) {

Diff for: llvm/test/CodeGen/X86/win32-eh.ll

+9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
; RUN: llc -mtriple=i686-pc-windows-msvc < %s | FileCheck %s
2+
; RUN: llc -mtriple=i686-pc-windows-msvc -filetype=obj < %s -o %t
23

34
declare void @may_throw_or_crash()
45
declare i32 @_except_handler3(...)
@@ -208,6 +209,14 @@ catch:
208209
; CHECK-NEXT: .long 0
209210
; CHECK-NEXT: .long 1
210211

212+
; CHECK-LABEL: inlineasm:
213+
; CHECK: .safeseh my_handler
214+
define i32 @inlineasm() {
215+
entry:
216+
call void asm sideeffect ".safeseh my_handler", "~{dirflag},~{fpsr},~{flags}"()
217+
ret i32 0
218+
}
219+
211220
; CHECK-LABEL: ___ehhandler$use_CxxFrameHandler3:
212221
; CHECK: movl $L__ehtable$use_CxxFrameHandler3, %eax
213222
; CHECK-NEXT: jmp ___CxxFrameHandler3 # TAILCALL

0 commit comments

Comments
 (0)