Skip to content

Commit 5ba1949

Browse files
MaskRayllvmbot
authored andcommitted
[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 (cherry picked from commit ece72e2)
1 parent 943b432 commit 5ba1949

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

llvm/lib/MC/MCWinCOFFStreamer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ void MCWinCOFFStreamer::emitCOFFSafeSEH(MCSymbol const *Symbol) {
299299
return;
300300

301301
MCSection *SXData = getContext().getObjectFileInfo()->getSXDataSection();
302-
changeSection(SXData);
302+
pushSection();
303+
switchSection(SXData);
303304
SXData->ensureMinAlignment(Align(4));
304305

305306
insert(getContext().allocFragment<MCSymbolIdFragment>(Symbol));
@@ -310,6 +311,7 @@ void MCWinCOFFStreamer::emitCOFFSafeSEH(MCSymbol const *Symbol) {
310311
// function. Go ahead and oblige it here.
311312
CSymbol->setType(COFF::IMAGE_SYM_DTYPE_FUNCTION
312313
<< COFF::SCT_COMPLEX_TYPE_SHIFT);
314+
popSection();
313315
}
314316

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

llvm/test/CodeGen/X86/win32-eh.ll

Lines changed: 9 additions & 0 deletions
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)