llvm/clang/test/Frontend
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
..
Inputs Use functions with prototypes when appropriate; NFC 2022-02-09 17:16:10 -05:00
aarch64-target-cpu.c
aarch64-vscale-min.c [IR] Remove unbounded as possible value for vscale_range minimum 2021-12-07 09:52:21 +00:00
absolute-paths-symlinks.c
absolute-paths-windows.test
absolute-paths.c Use functions with prototypes when appropriate; NFC 2022-02-09 17:16:10 -05:00
aix-unsupported.c
arm-branch-protection-default-arch.c [clang][ARM] Emit warnings when PACBTI-M is used with unsupported architectures 2022-01-28 09:59:58 +00:00
arm-ignore-branch-protection-option.c Support the min of module flags when linking, use for AArch64 BTI/PAC-RET 2022-04-13 09:31:51 +02:00
arm-invalid-branch-protection.c [clang][ARM] Emit warnings when PACBTI-M is used with unsupported architectures 2022-01-28 09:59:58 +00:00
ast-codegen.c Use functions with prototypes when appropriate; NFC 2022-02-09 17:16:10 -05:00
ast-main.c Use functions with prototypes when appropriate; NFC 2022-02-09 17:16:10 -05:00
ast-main.cpp
backend-attribute-error-warning-optimize.c Reland [clang] Rework dontcall attributes 2021-09-28 15:31:30 -07:00
backend-attribute-error-warning.c Reland [clang] Rework dontcall attributes 2021-09-28 15:31:30 -07:00
backend-attribute-error-warning.cpp [test] Specify triple in backend-attribute-error-warning.cpp 2021-09-28 17:00:10 -07:00
backend-diagnostic.c Use functions with prototypes when appropriate; NFC 2022-02-09 17:16:10 -05:00
cc1-return-codes.c
clang-abi-compat.cpp
compiler-options-dump.cpp
cpp-output.c
crash-diagnostic-renderer.cpp [clang][Frontend] Fix a crash in DiagnosticRenderer. 2021-02-17 09:02:49 +01:00
darwin-eabi.c
darwin-version.c [Clang] Add DriverKit support 2022-05-13 20:34:57 +01:00
dependency-gen-escaping.c
dependency-gen-extradeps-phony.c
dependency-gen-has-include.c
dependency-gen-symlink.c
dependency-gen-windows-duplicates.c [clang] In DependencyCollector on Windows, ignore case and separators when discarding duplicate dependency file paths. 2021-05-17 10:32:52 -04:00
dependency-gen.c [clang] accept -fsanitize-ignorelist= in addition to -fsanitize-blacklist= 2021-05-04 10:24:00 -04:00
dependency-generation-crash.c
diagnostics-option-names.c
diagnostics-order.c [clang][cli] Parse Lang and CodeGen options separately 2021-01-19 09:52:46 +01:00
disable-output.c
embed-bitcode-noopt.c Use functions with prototypes when appropriate; NFC 2022-02-09 17:16:10 -05:00
embed-bitcode-noopt.ll Add REQUIRES to embed-bitcode-noopt.ll 2020-09-23 10:13:09 -07:00
embed-bitcode.ll
embed-object.c [Metadata] Add 'exclude' metadata to add the exclude flags on globals 2022-07-07 12:20:40 -04:00
embed-object.ll [Metadata] Add 'exclude' metadata to add the exclude flags on globals 2022-07-07 12:20:40 -04:00
exceptions.c
fixed_point_add.c [OpaquePtrs][Clang] Add -no-opaque-pointers to tests (NFC) 2022-04-07 12:09:47 +02:00
fixed_point_add_const.c
fixed_point_bit_widths.c
fixed_point_comparisons.c [OpaquePtrs][Clang] Add -no-opaque-pointers to tests (NFC) 2022-04-07 12:09:47 +02:00
fixed_point_compound.c [OpaquePtrs][Clang] Add -no-opaque-pointers to tests (NFC) 2022-04-07 12:09:47 +02:00
fixed_point_conversions.c [OpaquePtrs][Clang] Add -no-opaque-pointers to tests (NFC) 2022-04-07 12:09:47 +02:00
fixed_point_conversions_const.c [Fixed Point] Add fixed-point to floating point cast types and consteval. 2020-10-13 13:26:56 +02:00
fixed_point_conversions_half.c [OpaquePtrs][Clang] Add -no-opaque-pointers to tests (NFC) 2022-04-07 12:09:47 +02:00
fixed_point_crash.c Use functions with prototypes when appropriate; NFC 2022-02-09 17:16:10 -05:00
fixed_point_declarations.c
fixed_point_div.c [OpaquePtrs][Clang] Add -no-opaque-pointers to tests (NFC) 2022-04-07 12:09:47 +02:00
fixed_point_div_const.c
fixed_point_errors.c Change the behavior of implicit int diagnostics 2022-05-04 08:35:47 -04:00
fixed_point_errors.cpp
fixed_point_mul.c [OpaquePtrs][Clang] Add -no-opaque-pointers to tests (NFC) 2022-04-07 12:09:47 +02:00
fixed_point_mul_const.c
fixed_point_not_enabled.c Change the behavior of implicit int diagnostics 2022-05-04 08:35:47 -04:00
fixed_point_same_fbits.c [Clang] Add -no-opaque-pointers to more tests (NFC) 2022-04-07 12:53:29 +02:00
fixed_point_shift.c [OpaquePtrs][Clang] Add -no-opaque-pointers to tests (NFC) 2022-04-07 12:09:47 +02:00
fixed_point_shift_const.c
fixed_point_sub.c [OpaquePtrs][Clang] Add -no-opaque-pointers to tests (NFC) 2022-04-07 12:09:47 +02:00
fixed_point_sub_const.c
fixed_point_to_bool.c [OpaquePtrs][Clang] Add -no-opaque-pointers to tests (NFC) 2022-04-07 12:09:47 +02:00
fixed_point_unary.c [OpaquePtrs][Clang] Add -no-opaque-pointers to tests (NFC) 2022-04-07 12:09:47 +02:00
fixed_point_unknown_conversions.c Use functions with prototypes when appropriate; NFC 2022-02-09 17:16:10 -05:00
force-include-not-found.c
ftime-report-template-decl.cpp
fwarn-stack-size.c [IR] convert warn-stack-size from module flag to fn attr 2021-06-21 15:09:25 -07:00
gnu-inline.c
gnu-mcount.c Move EntryExitInstrumentation pass location 2021-03-01 10:08:10 -08:00
hexagon-target-basic.c
iframework.c
include-duplicate-removal.c
int128.cpp
invalid-cxx-abi.cpp Correct a lot of diagnostic wordings for the driver 2021-08-05 07:04:55 -04:00
invalid-o-level.c
ir-support-codegen.ll
ir-support-errors.ll
ir-support.c Use functions with prototypes when appropriate; NFC 2022-02-09 17:16:10 -05:00
lit.local.cfg
macro_defined_type.cpp
macros.c
mfpmath.c
mfunction-return.c [X86] initial -mfunction-return=thunk-extern support 2022-07-12 09:17:54 -07:00
minimize_source_to_dependency_directives.c
mips-long-double.c
no-knr-functions.c [C2x] Disallow functions without prototypes/functions with identifier lists 2022-04-20 13:28:15 -04:00
noderef.c [clang] Reject non-declaration C++11 attributes on declarations 2022-06-15 11:58:26 +02:00
noderef.cpp Ignore noderef attribute in unevaluated context 2020-11-23 08:10:35 -05:00
noderef_on_non_pointers.m Use functions with prototypes when appropriate; NFC 2022-02-09 17:16:10 -05:00
noderef_templates.cpp
nostdlib-for-asmpp.s
objc-bool-is-bool.m
opencl.cl [OpenCL] Add support of __opencl_c_device_enqueue feature macro. 2022-01-27 14:25:59 +03:00
optimization-remark-analysis.c [clang] Make -Rpass imply -Rpass=.* 2021-09-21 14:35:56 -07:00
optimization-remark-extra-analysis.c
optimization-remark-line-directive.c [test] Remove tests pinned to the legacy PM 2021-10-18 16:40:46 -07:00
optimization-remark-new-pm.c [test] Remove various legacy pass manager tests 2022-04-11 14:02:17 -07:00
optimization-remark-options.c [LV] Add back CantReorderMemOps remark. 2022-07-04 17:23:47 +01:00
optimization-remark-with-hotness-new-pm.c [test] Remove references to -fexperimental-new-pass-manager in tests 2022-04-11 13:29:08 -07:00
optimization-remark.c [test] Remove various legacy pass manager tests 2022-04-11 14:02:17 -07:00
output-paths.c [test] Use host platform specific error message substitution in lit tests 2021-01-29 07:16:30 -05:00
plugin-annotate-functions.c Fix clang/test/Frontend/plugin-annotate-functions.c 2021-04-21 14:00:38 +01:00
plugin-attribute.cpp Fix test after aee4925507. 2021-11-09 16:59:45 -05:00
plugin-call-super.cpp [clang][driver] Add -fplugin-arg- to pass arguments to plugins 2021-11-25 10:47:55 +01:00
plugin-delayed-template.cpp
plugin-unknown.c
plugin-vs-debug-info.cpp
plugins-order.c [clang] Add plugin ActionType to run command line plugin before main action 2021-10-20 08:58:20 -07:00
plugins.c
pp-only-no-editor-placeholders.c
preprocessed-input.i
preprocessed-output-macro-first-token.c
print-header-includes.c [clang] accept -fsanitize-ignorelist= in addition to -fsanitize-blacklist= 2021-05-04 10:24:00 -04:00
profile-sample-use-loc-tracking.c
region-pragmas.c
remarks-hotness.cpp [test] Remove references to -fexperimental-new-pass-manager in tests 2022-04-11 13:29:08 -07:00
remove-file-on-signal.c
rewrite-includes-bom.c
rewrite-includes-cli-include.c
rewrite-includes-conditions.c
rewrite-includes-eof.c
rewrite-includes-filenotfound.c
rewrite-includes-header-cmd-line.c
rewrite-includes-invalid-hasinclude.c
rewrite-includes-line-markers.c
rewrite-includes-macros.cpp [Windows] Add test coverage for line endings when rewriting includes 2021-04-06 15:38:19 -04:00
rewrite-includes-messages.c
rewrite-includes-missing.c
rewrite-includes-modules.c
rewrite-includes-warnings.c
rewrite-includes.c
rewrite-macros.c
round-trip-cc1-args.c Correct a lot of diagnostic wordings for the driver 2021-08-05 07:04:55 -04:00
source-col-map.c
stack-usage-safestack.c Revert "[clang][safestack] Remove triple from stack usage test" 2022-04-21 22:47:56 +00:00
stats-file.c [test] Use host platform specific error message substitution in lit tests 2021-01-29 07:16:30 -05:00
stdin-input.c Use functions with prototypes when appropriate; NFC 2022-02-09 17:16:10 -05:00
stdin.c
stdlang.c [OpenCL] C++ for OpenCL version 2021 introduced to command line. 2021-08-18 10:08:59 +01:00
sycl-aux-triple.cpp [SYCL] Rework the SYCL driver options 2021-03-17 08:27:19 -04:00
sycl.cpp [SYCL] Rework the SYCL driver options 2021-03-17 08:27:19 -04:00
system-header-line-directive-ms-lineendings.c Use functions with prototypes when appropriate; NFC 2022-02-09 17:16:10 -05:00
system-header-line-directive.c Change the behavior of implicit int diagnostics 2022-05-04 08:35:47 -04:00
system-header-prefix.c
trigraphs.cpp
undef.c
unknown-arg.c [clang][driver] Disable non-functional --version option for clang -cc1 2022-03-25 19:04:27 +01:00
unknown-pragmas.c
valid-cxx-abi.cpp [clang][test] Update -fc++-abi tests 2021-05-04 15:53:00 -07:00
verify-any-file.c
verify-any-file.h
verify-directive.h
verify-fatal.c
verify-ignore-unexpected.c
verify-marker.c
verify-marker.h
verify-prefixes.c Use functions with prototypes when appropriate; NFC 2022-02-09 17:16:10 -05:00
verify-unknown-arg.c
verify.c
verify2.c
verify2.h
verify3.c
warn-device-init-fun.cu
warning-mapping-1.c
warning-mapping-2.c [C11/C2x] Change the behavior of the implicit function declaration warning 2022-04-20 11:30:12 -04:00
warning-mapping-3.c
warning-mapping-4.c
warning-mapping-5.c
warning-mapping-6.c
warning-options.cpp [Sema] Special case -Werror-implicit-function-declaration and reject other -Werror- 2020-11-05 10:25:30 -08:00
warning-poison-system-directories.c
Weverything.c
windows-exceptions.cpp [clang][cli] Squash multiple cc1 -fxxx-exceptions flags into single -exception-model=xxx option 2020-12-15 10:15:58 +01:00
windows-nul.c
Wno-everything.c
x86-embed-bitcode.ll
x86-target-cpu.c [X86] Update tests for znver3 2021-01-07 11:51:50 +05:30
x86_64-nacl-types.cpp