Skip to content

Commit f8fe8b1

Browse files
committed
[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
1 parent 73df9f2 commit f8fe8b1

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

include/swift/AST/SemanticAttrs.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,8 @@ SEMANTICS_ATTR(NO_PERFORMANCE_ANALYSIS, "no_performance_analysis")
144144
// that may cause the user to think there is a bug in the compiler.
145145
SEMANTICS_ATTR(NO_MOVEONLY_DIAGNOSTICS, "sil.optimizer.moveonly.diagnostic.ignore")
146146

147+
// Force the use of the frame pointer for the specified function
148+
SEMANTICS_ATTR(USE_FRAME_POINTER, "use_frame_pointer")
149+
147150
#undef SEMANTICS_ATTR
148151

lib/IRGen/IRGenSIL.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "swift/AST/IRGenOptions.h"
2222
#include "swift/AST/ParameterList.h"
2323
#include "swift/AST/Pattern.h"
24+
#include "swift/AST/SemanticAttrs.h"
2425
#include "swift/AST/SubstitutionMap.h"
2526
#include "swift/AST/Types.h"
2627
#include "swift/Basic/ExternalUnion.h"
@@ -1835,6 +1836,11 @@ IRGenSILFunction::IRGenSILFunction(IRGenModule &IGM, SILFunction *f)
18351836
}
18361837
}
18371838

1839+
// If we have @_semantics("use_frame_pointer"), force the use of a
1840+
// frame pointer for this function.
1841+
if (f->hasSemanticsAttr(semantics::USE_FRAME_POINTER))
1842+
CurFn->addFnAttr("frame-pointer", "all");
1843+
18381844
// Disable inlining of coroutine functions until we split.
18391845
if (f->getLoweredFunctionType()->isCoroutine()) {
18401846
CurFn->addFnAttr(llvm::Attribute::NoInline);

0 commit comments

Comments
 (0)