From b695bdf5e095212b3d081c59deb952792d55834d Mon Sep 17 00:00:00 2001 From: Jon Roelofs Date: Mon, 19 Feb 2024 10:20:32 -0800 Subject: [PATCH 1/3] Allow .alt_entry symbols to pass the .cfi nesting check Fixes: https://github.com/llvm/llvm-project/issues/82261 --- llvm/lib/MC/MCParser/AsmParser.cpp | 5 ++++- llvm/test/MC/AArch64/cfi-bad-nesting-darwin.s | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp index 8e508dbdb1c69..e8dc078c9610c 100644 --- a/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/llvm/lib/MC/MCParser/AsmParser.cpp @@ -44,6 +44,7 @@ #include "llvm/MC/MCSection.h" #include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSymbol.h" +#include "llvm/MC/MCSymbolMachO.h" #include "llvm/MC/MCTargetOptions.h" #include "llvm/MC/MCValue.h" #include "llvm/Support/Casting.h" @@ -1950,7 +1951,9 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info, Lex(); } - if (MAI.hasSubsectionsViaSymbols() && CFIStartProcLoc && Sym->isExternal()) + if (MAI.hasSubsectionsViaSymbols() && CFIStartProcLoc && + Sym->isExternal() && + (!isa(Sym) || !cast(Sym)->isAltEntry())) return Error(StartTokLoc, "non-private labels cannot appear between " ".cfi_startproc / .cfi_endproc pairs") && Error(*CFIStartProcLoc, "previous .cfi_startproc was here"); diff --git a/llvm/test/MC/AArch64/cfi-bad-nesting-darwin.s b/llvm/test/MC/AArch64/cfi-bad-nesting-darwin.s index 235b7d4480992..6a4dda3a77f05 100644 --- a/llvm/test/MC/AArch64/cfi-bad-nesting-darwin.s +++ b/llvm/test/MC/AArch64/cfi-bad-nesting-darwin.s @@ -8,6 +8,8 @@ .p2align 2 _locomotive: .cfi_startproc + .alt_entry _engineer +_engineer: ret ; It is invalid to have a non-private label between .cfi_startproc and @@ -17,7 +19,7 @@ _locomotive: .p2align 2 _caboose: ; DARWIN: [[#@LINE-1]]:1: error: non-private labels cannot appear between .cfi_startproc / .cfi_endproc pairs -; DARWIN: [[#@LINE-10]]:2: error: previous .cfi_startproc was here +; DARWIN: [[#@LINE-12]]:2: error: previous .cfi_startproc was here ret .cfi_endproc From 8594cc842128418e58e465d57dcae3fc41333cf4 Mon Sep 17 00:00:00 2001 From: Jon Roelofs Date: Mon, 19 Feb 2024 10:20:32 -0800 Subject: [PATCH 2/3] review feedback --- llvm/lib/MC/MCParser/AsmParser.cpp | 3 +-- llvm/test/MC/AArch64/cfi-bad-nesting-darwin.s | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp index e8dc078c9610c..026d252ec5bcd 100644 --- a/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/llvm/lib/MC/MCParser/AsmParser.cpp @@ -1952,8 +1952,7 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info, } if (MAI.hasSubsectionsViaSymbols() && CFIStartProcLoc && - Sym->isExternal() && - (!isa(Sym) || !cast(Sym)->isAltEntry())) + Sym->isExternal() && !cast(Sym)->isAltEntry()) return Error(StartTokLoc, "non-private labels cannot appear between " ".cfi_startproc / .cfi_endproc pairs") && Error(*CFIStartProcLoc, "previous .cfi_startproc was here"); diff --git a/llvm/test/MC/AArch64/cfi-bad-nesting-darwin.s b/llvm/test/MC/AArch64/cfi-bad-nesting-darwin.s index 6a4dda3a77f05..6ad29fb6532cd 100644 --- a/llvm/test/MC/AArch64/cfi-bad-nesting-darwin.s +++ b/llvm/test/MC/AArch64/cfi-bad-nesting-darwin.s @@ -8,6 +8,8 @@ .p2align 2 _locomotive: .cfi_startproc + ; An N_ALT_ENTRY symbol can be defined in the middle of a subsection, so + ; these are opted out of the .cfi_{start,end}proc nesting check. .alt_entry _engineer _engineer: ret From 2473c3f9306989b1ac4cbbddfa3a23407c378575 Mon Sep 17 00:00:00 2001 From: Jon Roelofs Date: Tue, 27 Feb 2024 18:15:56 -0800 Subject: [PATCH 3/3] fix offset in the test --- llvm/test/MC/AArch64/cfi-bad-nesting-darwin.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/test/MC/AArch64/cfi-bad-nesting-darwin.s b/llvm/test/MC/AArch64/cfi-bad-nesting-darwin.s index 6ad29fb6532cd..3a5af86defc59 100644 --- a/llvm/test/MC/AArch64/cfi-bad-nesting-darwin.s +++ b/llvm/test/MC/AArch64/cfi-bad-nesting-darwin.s @@ -21,7 +21,7 @@ _engineer: .p2align 2 _caboose: ; DARWIN: [[#@LINE-1]]:1: error: non-private labels cannot appear between .cfi_startproc / .cfi_endproc pairs -; DARWIN: [[#@LINE-12]]:2: error: previous .cfi_startproc was here +; DARWIN: [[#@LINE-14]]:2: error: previous .cfi_startproc was here ret .cfi_endproc