llvm-project/llvm/test/Transforms
Nick Desaulniers 2240d72f15 [X86] initial -mfunction-return=thunk-extern support
Adds support for:
* `-mfunction-return=<value>` command line flag, and
* `__attribute__((function_return("<value>")))` function attribute

Where the supported <value>s are:
* keep (disable)
* thunk-extern (enable)

thunk-extern enables clang to change ret instructions into jmps to an
external symbol named __x86_return_thunk, implemented as a new
MachineFunctionPass named "x86-return-thunks", keyed off the new IR
attribute fn_ret_thunk_extern.

The symbol __x86_return_thunk is expected to be provided by the runtime
the compiled code is linked against and is not defined by the compiler.
Enabling this option alone doesn't provide mitigations without
corresponding definitions of __x86_return_thunk!

This new MachineFunctionPass is very similar to "x86-lvi-ret".

The <value>s "thunk" and "thunk-inline" are currently unsupported. It's
not clear yet that they are necessary: whether the thunk pattern they
would emit is beneficial or used anywhere.

Should the <value>s "thunk" and "thunk-inline" become necessary,
x86-return-thunks could probably be merged into x86-retpoline-thunks
which has pre-existing machinery for emitting thunks (which could be
used to implement the <value> "thunk").

Has been found to build+boot with corresponding Linux
kernel patches. This helps the Linux kernel mitigate RETBLEED.
* CVE-2022-23816
* CVE-2022-28693
* CVE-2022-29901

See also:
* "RETBLEED: Arbitrary Speculative Code Execution with Return
Instructions."
* AMD SECURITY NOTICE AMD-SN-1037: AMD CPU Branch Type Confusion
* TECHNICAL GUIDANCE FOR MITIGATING BRANCH TYPE CONFUSION REVISION 1.0
  2022-07-12
* Return Stack Buffer Underflow / Return Stack Buffer Underflow /
  CVE-2022-29901, CVE-2022-28693 / INTEL-SA-00702

SystemZ may eventually want to support "thunk-extern" and "thunk"; both
options are used by the Linux kernel's CONFIG_EXPOLINE.

This functionality has been available in GCC since the 8.1 release, and
was backported to the 7.3 release.

Many thanks for folks that provided discrete review off list due to the
embargoed nature of this hardware vulnerability. Many Bothans died to
bring us this information.

Link: https://www.youtube.com/watch?v=IF6HbCKQHK8
Link: https://github.com/llvm/llvm-project/issues/54404
Link: https://gcc.gnu.org/legacy-ml/gcc-patches/2018-01/msg01197.html
Link: https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/advisory-guidance/return-stack-buffer-underflow.html
Link: https://arstechnica.com/information-technology/2022/07/intel-and-amd-cpus-vulnerable-to-a-new-speculative-execution-attack/?comments=1
Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ce114c866860aa9eae3f50974efc68241186ba60
Link: https://www.intel.com/content/www/us/en/security-center/advisory/intel-sa-00702.html
Link: https://www.intel.com/content/www/us/en/security-center/advisory/intel-sa-00707.html

Reviewed By: aaron.ballman, craig.topper

Differential Revision: https://reviews.llvm.org/D129572
2022-07-12 09:17:54 -07:00
..
ADCE [ADCE] Update tests to use opaque pointers (NFC) 2022-06-22 12:26:12 +02:00
AddDiscriminators [AddDiscriminators] Migrate tests to opaque pointers (NFC) 2022-06-22 12:47:12 +02:00
AggressiveInstCombine [AggressiveInstCombine] Update tests to use opaque pointers (NFC) 2022-06-22 12:33:06 +02:00
AlignmentFromAssumptions [AlignmentFromAssumptions] Migrate tests to opaque pointers (NFC) 2022-06-22 13:57:47 +02:00
ArgumentPromotion [ArgPromotion] Unify byval promotion with non-byval 2022-06-28 15:19:58 +03:00
AtomicExpand [PowerPC] Allow llvm.ppc.cfence to accept pointer types 2022-06-24 10:55:32 +08:00
Attributor Revert "[Attributor] Replace AAValueSimplify with AAPotentialValues" 2022-07-08 00:53:38 -05:00
BDCE
BlockExtractor [IR] Enable opaque pointers by default 2022-06-02 09:40:56 +02:00
BranchFolding
CallSiteSplitting [CallSiteSplitting] Regenerate test checks (NFC) 2022-07-08 09:24:11 +02:00
CalledValuePropagation
CanonicalizeAliases
CanonicalizeFreezeInLoops
CodeExtractor [ArgPromotion] Remove legacy PM support 2022-06-27 09:42:17 +02:00
CodeGenPrepare [CGP] Also freeze ctlz/cttz operand when despeculating 2022-06-10 09:46:10 +02:00
ConstantHoisting [OpaquePtr][AArch64] Use elementtype on ldxr/stxr 2022-03-14 10:09:59 -07:00
ConstantMerge [test] Use -passes syntax when specifying pipeline in some more tests 2021-11-27 09:52:55 +01:00
ConstraintElimination Recommit "[ConstraintElimination] Transfer info from ULT to signed system." 2022-06-24 09:27:14 +02:00
Coroutines [Debug] [Coroutines] Get rid of DW_ATE_address 2022-07-07 10:47:09 +08:00
CorrelatedValuePropagation [NFC] Switch a few uses of undef to poison as placeholders for unreachble code 2022-06-30 23:01:43 +01:00
CrossDSOCFI
DCE [DCE] Update tests to use opaque pointers (NFC) 2022-06-10 17:31:35 +02:00
DFAJumpThreading [NFC] Switch a few uses of undef to poison as placeholders for unreachble code 2022-07-03 14:34:03 +01:00
DeadArgElim [llvm] Add DW_CC_nocall to function debug metadata when either return values or arguments are removed 2022-06-15 03:30:15 +05:30
DeadStoreElimination [DSE] Don't remove nounwind invokes 2022-06-21 11:54:09 -07:00
DivRemPairs [Mips] Implement hasDivRemOp() 2022-05-16 14:45:40 +08:00
EarlyCSE [Tests] Remove unnecessary bitcasts from opaque pointer tests (NFC) 2022-06-22 14:15:46 +02:00
EliminateAvailableExternally
EntryExitInstrumenter
ExpandMemCmp [ExpandMemCmp] Properly expand `bcmp` to an equality pattern. 2022-04-15 11:26:24 +02:00
FixIrreducible LowerSwitch: Avoid inserting NewDefault block 2022-04-14 13:30:56 +08:00
Float2Int [Float2Int] Make sure dependent ranges are calculated first (PR54669) 2022-04-04 10:18:39 +02:00
ForcedFunctionAttrs
FunctionAttrs [RPOFuncAttrs] Fix norecurse detection 2022-06-18 12:20:10 -07:00
FunctionImport [Metadata] Utilize the resizing capability of MDNodes in Moduleflag processing. 2022-07-06 10:18:33 -07:00
FunctionSpecialization [SCCP] Don't mark edges feasible when resolving undefs 2022-06-22 10:28:27 +02:00
GCOVProfiling [IR] Enable opaque pointers by default 2022-06-02 09:40:56 +02:00
GVN [BasicBlockUtils] Allow critical edge splitting with callbr terminators 2022-07-08 09:20:44 +02:00
GVNHoist [GVNHoist] drop debug location according to the debug info guide 2022-03-30 20:17:53 -07:00
GVNSink Revert "[SimplifyCFG] Thread branches on same condition in more cases (PR54980)" 2022-07-05 16:57:46 +02:00
GlobalDCE [GlobalDCE] [VFE] Avoid dropping vfunc dependencies when an invalid vtable entry is present 2022-02-17 19:41:46 -08:00
GlobalMerge Fix the eh-filter.ll test. 2022-06-29 16:14:41 -05:00
GlobalOpt [GlobalOpt] Add test that requires splitting up global into many. 2022-07-11 16:34:07 -07:00
GlobalSplit
GuardWidening [GuardWidening] Add tests showing incorrect behavior of GW. 2022-06-29 13:41:59 +07:00
HardwareLoops [ARM] Update test comments after D114018. NFC 2021-11-16 22:48:45 +00:00
HelloNew
HotColdSplit [IR] Enable opaque pointers by default 2022-06-02 09:40:56 +02:00
IRCE [SCEV] Fix isImpliedViaMerge() with values from previous iteration (PR56242) 2022-07-05 15:31:23 +02:00
IROutliner [IR] Enable opaque pointers by default 2022-06-02 09:40:56 +02:00
IndVarSimplify [IndVars] Eliminate redundant type cast between integer and float 2022-07-08 17:07:20 +08:00
IndirectBrExpand
InferAddressSpaces [InferAddressSpaces] Check if AS are the same in isNoopPtrIntCastPair 2022-04-28 11:10:55 +08:00
InferFunctionAttrs BuildLibCalls: infer allockind attributes on relevant functions 2022-05-31 10:01:17 -04:00
Inline [X86] initial -mfunction-return=thunk-extern support 2022-07-12 09:17:54 -07:00
InstCombine [IR] Remove support for float binop constant expressions 2022-07-12 09:40:49 +02:00
InstMerge Reland "[LICM] Hoist LOAD without sinking the STORE" 2021-12-02 03:53:50 -08:00
InstNamer
InstSimplify [IR] Remove support for float binop constant expressions 2022-07-12 09:40:49 +02:00
InterleavedAccess [IR] Move vector.insert/vector.extract out of experimental namespace 2022-06-27 10:48:45 +00:00
Internalize
JumpThreading [JumpThreading] Avoid threadThroughTwoBasicBlocks when PredPred BB ends with indirectbranch 2022-07-08 09:29:17 +02:00
LCSSA
LICM [AArch64][NFC] Prepare test cases (for D128302) to show more accurate cost estimation of extract-element could generate better assembly code. 2022-07-07 09:39:29 -07:00
LoadStoreVectorizer [AMDGPU][FIX] Proper load-store-vectorizer result with opaque pointers 2022-04-15 13:42:46 -05:00
LoopBoundSplit
LoopDataPrefetch
LoopDeletion [LoopDeletion] Fix deletion with unusual predecessor terminator (PR56266) 2022-07-01 16:13:35 +02:00
LoopDistribute Autogen a couple of predicated SCEV tests 2022-02-11 13:56:35 -08:00
LoopFlatten [LoopFlatten] Fix crash if the inner loop trip count comes from a sext instruction. 2022-06-07 08:21:21 -07:00
LoopFusion [NFCI] Fixed missing colon in CHECK directives 2022-04-03 11:52:38 +02:00
LoopIdiom [LoopIdiom] Fix bailout for aliasing in memcpy transform. 2022-05-31 17:24:23 -07:00
LoopInstSimplify [LoopInstSimplify] Ignore users in unreachable blocks. PR55072 2022-04-25 17:35:28 +07:00
LoopInterchange [LoopInterchange] New cost model for loop interchange 2022-06-28 00:08:37 -04:00
LoopLoadElim [NFC][LAA] Match-up type sizes for possible extensions, based on actual bit-size rather than rounded-up byte size. 2022-04-22 23:16:20 -07:00
LoopPredication [SCEVExpander] Drop poison generating flags when reusing instructions 2021-11-29 15:23:34 -08:00
LoopReroll
LoopRotate Pipe potentially invalid InstructionCost through CodeMetrics 2022-06-09 15:17:24 -07:00
LoopSimplify [BasicBlockUtils] Do not move loop metadata if outer loop header. 2022-05-23 16:39:54 -07:00
LoopSimplifyCFG [LoopSimplifyCFG] use poison when replacing dead instructions instead of undef [NFC] 2022-06-26 14:15:55 +01:00
LoopStrengthReduce [BasicBlockUtils] Allow critical edge splitting with callbr terminators 2022-07-08 09:20:44 +02:00
LoopTransformWarning
LoopUnroll [LoopUnrollRuntime] Invalidate SCEV for exit phi in ConnectProlog. 2022-06-29 20:28:43 +01:00
LoopUnrollAndJam [LoopUnroll] Disable loop unroll when user explicitly asks for unroll-and-jam 2021-12-15 15:58:05 +00:00
LoopVectorize [LoopVectorize] Change PredicatedBBsAfterVectorization to be per VF 2022-07-12 14:53:20 +01:00
LoopVersioning [IRBuilder] Migrate and-folding to value-based FoldAnd. 2022-01-20 10:22:21 +00:00
LoopVersioningLICM
LowerAtomic [LLVM] Add the support for fmax and fmin in atomicrmw instruction 2022-07-06 10:57:53 -04:00
LowerConstantIntrinsics [builtin_object_size] Basic support for posix_memalign 2022-04-08 09:31:11 +02:00
LowerExpectIntrinsic
LowerGlobalDestructors Reland "Lower `@llvm.global_dtors` using `__cxa_atexit` on MachO" 2022-03-23 18:36:55 -07:00
LowerGuardIntrinsic
LowerInvoke
LowerMatrixIntrinsics [LowerMatrixMultiplication] Switch dummy values from undef to poison [NFC] 2022-07-03 12:32:19 +01:00
LowerSwitch LowerSwitch: Avoid inserting NewDefault block 2022-04-14 13:30:56 +08:00
LowerTypeTests [IR] Enable opaque pointers by default 2022-06-02 09:40:56 +02:00
LowerWidenableCondition
MakeGuardsExplicit
Mem2Reg [Mem2Reg] Consistently preserve nonnull assume for uninit load 2022-07-12 12:53:08 +02:00
MemCpyOpt [MemCpyOpt] Work around PR54682 2022-04-04 10:19:51 +02:00
MergeFunc [NFC] Switch a few uses of undef to poison as placeholders for unreachble code 2022-07-03 14:34:03 +01:00
MergeICmps Reapply [MergeICmps] Don't require GEP 2022-03-04 11:39:11 +01:00
MetaRenamer [TLI] Check that malloc argument has type size_t 2022-03-14 17:22:24 +01:00
NameAnonGlobals
NaryReassociate
NewGVN [NewGVN] add context instruction for SimplifyQuery 2022-06-22 12:25:24 +08:00
ObjCARC Reapply "[Intrinsics] Add `nocallback` to the default intrinsic attributes" 2022-03-25 09:36:50 -05:00
OpenMP Revert "[Attributor] Replace AAValueSimplify with AAPotentialValues" 2022-07-08 00:53:38 -05:00
PGOProfile [IR] Enable opaque pointers by default 2022-06-02 09:40:56 +02:00
PartialInlining
PartiallyInlineLibCalls [PartiallyInlineLibCalls] Don't partially inline a musttail libcall. 2022-04-05 22:30:50 +03:00
PhaseOrdering [PhaseOrdering] Add test for IndVars + SROA interaction (NFC) 2022-07-08 13:04:24 +02:00
PlaceSafepoints
PreISelIntrinsicLowering [ObjC][ARC] Replace uses of ObjC intrinsics that are arguments of 2021-11-08 21:19:07 -08:00
PruneEH
Reassociate [ConstantExpr] Don't create float binop expressions 2022-07-08 16:53:46 +02:00
Reg2Mem
RelLookupTableConverter/X86 [RelLookupTableConverter] Ensure that GV, GEP and load types match 2022-02-17 12:05:05 +01:00
RewriteStatepointsForGC [RS4GC] Handle freeze case for vector 2022-06-23 11:58:41 +07:00
SCCP [SCCP] Only handle unknown lattice values in resolvedUndefsIn() 2022-07-01 09:14:37 +02:00
SLPVectorizer [SLP] add test for load combining + shuffling; NFC 2022-07-04 10:55:07 -04:00
SROA [Tests] Remove unnecessary bitcasts from opaque pointer tests (NFC) 2022-06-22 14:15:46 +02:00
SafeStack [safestack] Support safestack in stack size diagnostics 2022-04-20 18:29:40 +00:00
SampleProfile [SampleProfile][Inline] Annotate sample profile inline remarks with link phase (prelink/postlink) information. 2022-06-22 17:00:53 -07:00
ScalarizeMaskedMemIntrin
Scalarizer [NFC] Switch a few uses of undef to poison as placeholders for unreachble code 2022-06-30 21:47:31 +01:00
SeparateConstOffsetFromGEP [test][RISCV] Precommit test for SeparateConstOffsetFromGEP (NFC) 2022-06-15 16:03:30 +03:00
SimpleLoopUnswitch [SimpleLoopUnswitch] Always skip trivial select and set condition. 2022-05-26 09:46:24 +01:00
SimplifyCFG [BasicBlockUtils] Allow splitting predecessors with callbr terminators 2022-07-07 09:13:25 +02:00
Sink [Sink] Don't sink non-willreturn calls (PR51188) 2022-04-07 16:35:05 +02:00
SpeculativeExecution
StraightLineStrengthReduce [CodeGen] Remove unneeded regex escaping in FileCheck patterns. NFC. 2022-02-18 16:10:56 +00:00
StripDeadPrototypes
StripSymbols
StructurizeCFG [StructurizeCFG] Improve basic block ordering 2022-06-22 16:10:41 -05:00
SyntheticCountsPropagation
TailCallElim [NFC] Switch a few uses of undef to poison as placeholders for unreachble code 2022-07-03 14:34:03 +01:00
ThinLTOBitcodeWriter [ThinLTO][MC] Use conditional assignments for promotion aliases 2021-12-10 12:21:37 -08:00
TypePromotion [TypePromotion] Avoid unnecessary trunc zext pairs 2022-05-24 15:34:36 +01:00
UnifyFunctionExitNodes
UnifyLoopExits [UnifyLoopExits] Reduce number of guard blocks 2022-06-22 15:44:23 -05:00
Util [Debugify] Port verify-debuginfo-preserve to NewPM 2022-07-06 17:07:20 +02:00
VectorCombine [VectorCombine] Avoid creating shuffle for extract-extract pattern on scalable vector. 2022-07-07 08:37:04 +00:00
WholeProgramDevirt [NFC] Switch a few uses of undef to poison as placeholders for unreachble code 2022-07-03 14:34:03 +01:00