[PATCH] D91816: [Inline] prevent inlining on stack protector mismatch

Nick Desaulniers via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 19 12:34:45 PST 2020


nickdesaulniers created this revision.
nickdesaulniers added reviewers: void, pcc, rnk, manojgupta, MaskRay.
Herald added subscribers: llvm-commits, dexonsmith, jdoerfert, pengfei, steven_wu, haicheng, hiraditya, eraman.
Herald added a project: LLVM.
nickdesaulniers requested review of this revision.

It's common for code that manipulates the stack via inline assembly or
that has to set up its own stack canary (such as the Linux kernel) would
like to avoid stack protectors in certain functions. In this case, we've
been bitten by numerous bugs where a callee with a stack protector is
inlined into an attribute((no_stack_protector)) caller, which
generally breaks the caller's assumptions about not having a stack
protector. LTO exacerbates the issue.

While developers can avoid this by putting all no_stack_protector
functions in one translation unit together and compiling those with
-fno-stack-protector, it's generally not very ergonomic or as
ergonomic as a function attribute, and still doesn't work for LTO. See also:
https://lore.kernel.org/linux-pm/20200915172658.1432732-1-rkir@google.com/
https://lore.kernel.org/lkml/20200918201436.2932360-30-samitolvanen@google.com/T/#u

Typically, when inlining a callee into a caller, the caller will be
upgraded in its level of stack protection (see adjustCallerSSPLevel()).

Block inlining when the callee and caller differ in the case that one
contains ssp, sspstrong, or sspreq function attributes, but the other
has no such function attribute.

Functions that get synthesized by the compiler may not get inlined as a
result if they are not created with the same stack protector function
attribute as their callers.

Alternative approach to https://reviews.llvm.org/D87956.

Fixes ps/47479.

Signed-off-by: Nick Desaulniers <ndesaulniers at google.com>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91816

Files:
  llvm/include/llvm/IR/Function.h
  llvm/lib/Analysis/InlineCost.cpp
  llvm/lib/CodeGen/StackProtector.cpp
  llvm/lib/IR/Attributes.cpp
  llvm/lib/IR/Function.cpp
  llvm/test/CodeGen/AArch64/stack-guard-remat-bitcast.ll
  llvm/test/CodeGen/X86/stack-protector-2.ll
  llvm/test/ThinLTO/X86/Inputs/nossp.ll
  llvm/test/ThinLTO/X86/nossp.ll
  llvm/test/Transforms/CodeExtractor/PartialInlineAttributes.ll
  llvm/test/Transforms/Inline/devirtualize.ll
  llvm/test/Transforms/Inline/inline-byval-bonus.ll
  llvm/test/Transforms/Inline/inline_nossp.ll
  llvm/test/Transforms/Inline/inline_ssp.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91816.306506.patch
Type: text/x-patch
Size: 19499 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201119/b4364980/attachment.bin>


More information about the llvm-commits mailing list