From f8fe8b1ecc289a1a583497d513b9c9d303dfd22d Mon Sep 17 00:00:00 2001 From: Alastair Houghton Date: Mon, 5 Jun 2023 15:18:22 +0100 Subject: [PATCH] [Backtracing][IRGen] Add a semantic attribute to force frame pointer. The Swift backtracer's frame pointer unwinder cannot work on Linux without this change, because the compiler omits the frame pointer from the function in libSwift_Backtracing that actually captures the stack. rdar://110260855 --- include/swift/AST/SemanticAttrs.def | 3 +++ lib/IRGen/IRGenSIL.cpp | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/include/swift/AST/SemanticAttrs.def b/include/swift/AST/SemanticAttrs.def index 2faf8887c1555..a763eaeae767b 100644 --- a/include/swift/AST/SemanticAttrs.def +++ b/include/swift/AST/SemanticAttrs.def @@ -144,5 +144,8 @@ SEMANTICS_ATTR(NO_PERFORMANCE_ANALYSIS, "no_performance_analysis") // that may cause the user to think there is a bug in the compiler. SEMANTICS_ATTR(NO_MOVEONLY_DIAGNOSTICS, "sil.optimizer.moveonly.diagnostic.ignore") +// Force the use of the frame pointer for the specified function +SEMANTICS_ATTR(USE_FRAME_POINTER, "use_frame_pointer") + #undef SEMANTICS_ATTR diff --git a/lib/IRGen/IRGenSIL.cpp b/lib/IRGen/IRGenSIL.cpp index cf7f994338180..37770efcf7397 100644 --- a/lib/IRGen/IRGenSIL.cpp +++ b/lib/IRGen/IRGenSIL.cpp @@ -21,6 +21,7 @@ #include "swift/AST/IRGenOptions.h" #include "swift/AST/ParameterList.h" #include "swift/AST/Pattern.h" +#include "swift/AST/SemanticAttrs.h" #include "swift/AST/SubstitutionMap.h" #include "swift/AST/Types.h" #include "swift/Basic/ExternalUnion.h" @@ -1835,6 +1836,11 @@ IRGenSILFunction::IRGenSILFunction(IRGenModule &IGM, SILFunction *f) } } + // If we have @_semantics("use_frame_pointer"), force the use of a + // frame pointer for this function. + if (f->hasSemanticsAttr(semantics::USE_FRAME_POINTER)) + CurFn->addFnAttr("frame-pointer", "all"); + // Disable inlining of coroutine functions until we split. if (f->getLoweredFunctionType()->isCoroutine()) { CurFn->addFnAttr(llvm::Attribute::NoInline);