aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Function.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2021-04-22 18:07:29 -0700
committerFangrui Song <i@maskray.me>2021-04-22 18:07:30 -0700
commit2786e673c7d67ffca531ef38d679620ee3048a1e (patch)
treebfa8a40a80741ad2fd9565e50be742b9ad70bc4a /llvm/lib/IR/Function.cpp
parent879cbac08ba17566ad61ff2b9d7180bcab4a0d1e (diff)
downloadllvm-2786e673c7d67ffca531ef38d679620ee3048a1e.zip
llvm-2786e673c7d67ffca531ef38d679620ee3048a1e.tar.gz
llvm-2786e673c7d67ffca531ef38d679620ee3048a1e.tar.bz2
[IR][sanitizer] Add module flag "frame-pointer" and set it for cc1 -mframe-pointer={non-leaf,all}
The Linux kernel objtool diagnostic `call without frame pointer save/setup` arise in multiple instrumentation passes (asan/tsan/gcov). With the mechanism introduced in D100251, it's trivial to respect the command line -m[no-]omit-leaf-frame-pointer/-f[no-]omit-frame-pointer, so let's do it. Fix: https://github.com/ClangBuiltLinux/linux/issues/1236 (tsan) Fix: https://github.com/ClangBuiltLinux/linux/issues/1238 (asan) Also document the function attribute "frame-pointer" which is long overdue. Differential Revision: https://reviews.llvm.org/D101016
Diffstat (limited to 'llvm/lib/IR/Function.cpp')
-rw-r--r--llvm/lib/IR/Function.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp
index 32c7b87..0887b5c 100644
--- a/llvm/lib/IR/Function.cpp
+++ b/llvm/lib/IR/Function.cpp
@@ -335,8 +335,21 @@ Function *Function::createWithDefaultAttr(FunctionType *Ty,
unsigned AddrSpace, const Twine &N,
Module *M) {
auto *F = new Function(Ty, Linkage, AddrSpace, N, M);
+ AttrBuilder B;
if (M->getUwtable())
- F->addAttribute(AttributeList::FunctionIndex, Attribute::UWTable);
+ B.addAttribute(Attribute::UWTable);
+ switch (M->getFramePointer()) {
+ case FramePointerKind::None:
+ // 0 ("none") is the default.
+ break;
+ case FramePointerKind::NonLeaf:
+ B.addAttribute("frame-pointer", "non-leaf");
+ break;
+ case FramePointerKind::All:
+ B.addAttribute("frame-pointer", "all");
+ break;
+ }
+ F->addAttributes(AttributeList::FunctionIndex, B);
return F;
}