Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MC,COFF] .safeseh: avoid changeSection #132624

Merged
merged 1 commit into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion llvm/lib/MC/MCWinCOFFStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ void MCWinCOFFStreamer::emitCOFFSafeSEH(MCSymbol const *Symbol) {
return;

MCSection *SXData = getContext().getObjectFileInfo()->getSXDataSection();
changeSection(SXData);
pushSection();
switchSection(SXData);
SXData->ensureMinAlignment(Align(4));

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

void MCWinCOFFStreamer::emitCOFFSymbolIndex(MCSymbol const *Symbol) {
Expand Down
9 changes: 9 additions & 0 deletions llvm/test/CodeGen/X86/win32-eh.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
; RUN: llc -mtriple=i686-pc-windows-msvc < %s | FileCheck %s
; RUN: llc -mtriple=i686-pc-windows-msvc -filetype=obj < %s -o %t

declare void @may_throw_or_crash()
declare i32 @_except_handler3(...)
Expand Down Expand Up @@ -208,6 +209,14 @@ catch:
; CHECK-NEXT: .long 0
; CHECK-NEXT: .long 1

; CHECK-LABEL: inlineasm:
; CHECK: .safeseh my_handler
define i32 @inlineasm() {
entry:
call void asm sideeffect ".safeseh my_handler", "~{dirflag},~{fpsr},~{flags}"()
ret i32 0
}

; CHECK-LABEL: ___ehhandler$use_CxxFrameHandler3:
; CHECK: movl $L__ehtable$use_CxxFrameHandler3, %eax
; CHECK-NEXT: jmp ___CxxFrameHandler3 # TAILCALL
Expand Down