#
cff5bef9 |
| 15-Feb-2022 |
Sami Tolvanen <samitolvanen@google.com> |
KCFI sanitizer
The KCFI sanitizer, enabled with `-fsanitize=kcfi`, implements a forward-edge control flow integrity scheme for indirect calls. It uses a !kcfi_type metadata node to attach a type ide
KCFI sanitizer
The KCFI sanitizer, enabled with `-fsanitize=kcfi`, implements a forward-edge control flow integrity scheme for indirect calls. It uses a !kcfi_type metadata node to attach a type identifier for each function and injects verification code before indirect calls.
Unlike the current CFI schemes implemented in LLVM, KCFI does not require LTO, does not alter function references to point to a jump table, and never breaks function address equality. KCFI is intended to be used in low-level code, such as operating system kernels, where the existing schemes can cause undue complications because of the aforementioned properties. However, unlike the existing schemes, KCFI is limited to validating only function pointers and is not compatible with executable-only memory.
KCFI does not provide runtime support, but always traps when a type mismatch is encountered. Users of the scheme are expected to handle the trap. With `-fsanitize=kcfi`, Clang emits a `kcfi` operand bundle to indirect calls, and LLVM lowers this to a known architecture-specific sequence of instructions for each callsite to make runtime patching easier for users who require this functionality.
A KCFI type identifier is a 32-bit constant produced by taking the lower half of xxHash64 from a C++ mangled typename. If a program contains indirect calls to assembly functions, they must be manually annotated with the expected type identifiers to prevent errors. To make this easier, Clang generates a weak SHN_ABS `__kcfi_typeid_<function>` symbol for each address-taken function declaration, which can be used to annotate functions in assembly as long as at least one C translation unit linked into the program takes the function address. For example on AArch64, we might have the following code:
``` .c: int f(void); int (*p)(void) = f; p();
.s: .4byte __kcfi_typeid_f .global f f: ... ```
Note that X86 uses a different preamble format for compatibility with Linux kernel tooling. See the comments in `X86AsmPrinter::emitKCFITypeId` for details.
As users of KCFI may need to locate trap locations for binary validation and error handling, LLVM can additionally emit the locations of traps to a `.kcfi_traps` section.
Similarly to other sanitizers, KCFI checking can be disabled for a function with a `no_sanitize("kcfi")` function attribute.
Relands 67504c95494ff05be2a613129110c9bcf17f6c13 with a fix for 32-bit builds.
Reviewed By: nickdesaulniers, kees, joaomoreira, MaskRay
Differential Revision: https://reviews.llvm.org/D119296
show more ...
|
#
a79060e2 |
| 24-Aug-2022 |
Sami Tolvanen <samitolvanen@google.com> |
Revert "KCFI sanitizer"
This reverts commit 67504c95494ff05be2a613129110c9bcf17f6c13 as using PointerEmbeddedInt to store 32 bits breaks 32-bit arm builds.
|
#
67504c95 |
| 15-Feb-2022 |
Sami Tolvanen <samitolvanen@google.com> |
KCFI sanitizer
The KCFI sanitizer, enabled with `-fsanitize=kcfi`, implements a forward-edge control flow integrity scheme for indirect calls. It uses a !kcfi_type metadata node to attach a type ide
KCFI sanitizer
The KCFI sanitizer, enabled with `-fsanitize=kcfi`, implements a forward-edge control flow integrity scheme for indirect calls. It uses a !kcfi_type metadata node to attach a type identifier for each function and injects verification code before indirect calls.
Unlike the current CFI schemes implemented in LLVM, KCFI does not require LTO, does not alter function references to point to a jump table, and never breaks function address equality. KCFI is intended to be used in low-level code, such as operating system kernels, where the existing schemes can cause undue complications because of the aforementioned properties. However, unlike the existing schemes, KCFI is limited to validating only function pointers and is not compatible with executable-only memory.
KCFI does not provide runtime support, but always traps when a type mismatch is encountered. Users of the scheme are expected to handle the trap. With `-fsanitize=kcfi`, Clang emits a `kcfi` operand bundle to indirect calls, and LLVM lowers this to a known architecture-specific sequence of instructions for each callsite to make runtime patching easier for users who require this functionality.
A KCFI type identifier is a 32-bit constant produced by taking the lower half of xxHash64 from a C++ mangled typename. If a program contains indirect calls to assembly functions, they must be manually annotated with the expected type identifiers to prevent errors. To make this easier, Clang generates a weak SHN_ABS `__kcfi_typeid_<function>` symbol for each address-taken function declaration, which can be used to annotate functions in assembly as long as at least one C translation unit linked into the program takes the function address. For example on AArch64, we might have the following code:
``` .c: int f(void); int (*p)(void) = f; p();
.s: .4byte __kcfi_typeid_f .global f f: ... ```
Note that X86 uses a different preamble format for compatibility with Linux kernel tooling. See the comments in `X86AsmPrinter::emitKCFITypeId` for details.
As users of KCFI may need to locate trap locations for binary validation and error handling, LLVM can additionally emit the locations of traps to a `.kcfi_traps` section.
Similarly to other sanitizers, KCFI checking can be disabled for a function with a `no_sanitize("kcfi")` function attribute.
Reviewed By: nickdesaulniers, kees, joaomoreira, MaskRay
Differential Revision: https://reviews.llvm.org/D119296
show more ...
|
#
f9969a3d |
| 22-Aug-2022 |
Yuanfang Chen <yuanfang.chen@sony.com> |
[CodeGen] Sort llvm.global_ctors by lexing order before emission
Fixes https://github.com/llvm/llvm-project/issues/55804
The lexing order is already bookkept in DelayedCXXInitPosition but we were n
[CodeGen] Sort llvm.global_ctors by lexing order before emission
Fixes https://github.com/llvm/llvm-project/issues/55804
The lexing order is already bookkept in DelayedCXXInitPosition but we were not using it based on the wrong assumption that inline variable is unordered. This patch fixes it by ordering entries in llvm.global_ctors by orders in DelayedCXXInitPosition.
for llvm.global_ctors entries without a lexing order, ordering them by the insertion order.
(This *mostly* orders the template instantiation in https://reviews.llvm.org/D126341 intuitively, minus one tweak for which I'll submit a separate patch.)
Reviewed By: efriedma
Differential Revision: https://reviews.llvm.org/D127233
show more ...
|
#
1a60e003 |
| 19-Aug-2022 |
Craig Topper <craig.topper@sifive.com> |
[RISCV] Use Triple::isRISCV/isRISCV32/isRISCV64 helps in some places. NFC
Reviewed By: reames
Differential Revision: https://reviews.llvm.org/D132197
|
#
8564e2fe |
| 05-Jul-2022 |
Wolfgang Pieb <wolfgang_pieb@playstation.sony.com> |
[Inlining] Add a clang option to limit inlining of functions
Add the clang option -finline-max-stacksize=<N> to suppress inlining of functions whose stack size exceeds the given value.
Reviewed By:
[Inlining] Add a clang option to limit inlining of functions
Add the clang option -finline-max-stacksize=<N> to suppress inlining of functions whose stack size exceeds the given value.
Reviewed By: aeubanks
Differential Revision: https://reviews.llvm.org/D131986
show more ...
|
#
585f62be |
| 16-Aug-2022 |
Saleem Abdulrasool <compnerd@compnerd.org> |
CodeGen: correct handling of debug info generation for aliases
When aliasing a static array, the aliasee is going to be a GEP which points to the value. We should strip pointer casts before forming
CodeGen: correct handling of debug info generation for aliases
When aliasing a static array, the aliasee is going to be a GEP which points to the value. We should strip pointer casts before forming the reference. This was occluded by the use of opaque pointers.
This problem has existed since the introduction of the debug info generation for aliases in b1ea0191a42074341847d767609f66a26b6d5a41. The test case would assert due to the invalid cast with or without `-no-opaque-pointers` at that revision.
Fixes: #57179
show more ...
|
#
3f18f7c0 |
| 08-Aug-2022 |
Fangrui Song <i@maskray.me> |
[clang] LLVM_FALLTHROUGH => [[fallthrough]]. NFC
With C++17 there is no Clang pedantic warning or MSVC C5051.
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D131346
|
#
b2c9ff72 |
| 05-Aug-2022 |
Xiang Li <python3kgae@outlook.com> |
[NFC][HLSL] Fix build error caused missing typo update.
setHLSLFnuctionAttributes to setHLSLFunctionAttributes.
Differential Revision: https://reviews.llvm.org/D131240
|
#
906e41f4 |
| 02-May-2022 |
Xiang Li <python3kgae@outlook.com> |
[HLSL] clang codeGen for HLSLShaderAttr.
Translate HLSLShaderAttr to IR level. 1. Skip mangle for hlsl entry functions. 2. Add function attribute for hlsl entry functions.
Reviewed By: Anastasia
[HLSL] clang codeGen for HLSLShaderAttr.
Translate HLSLShaderAttr to IR level. 1. Skip mangle for hlsl entry functions. 2. Add function attribute for hlsl entry functions.
Reviewed By: Anastasia
Differential Revision: https://reviews.llvm.org/D124752
show more ...
|
#
6f4c3c0f |
| 29-Jul-2022 |
Ellis Hoag <ellis.sparky.hoag@gmail.com> |
[InstrProf][attempt 2] Add new format for -fprofile-list=
In D130807 we added the `skipprofile` attribute. This commit changes the format so we can either `forbid` or `skip` profiling functions by a
[InstrProf][attempt 2] Add new format for -fprofile-list=
In D130807 we added the `skipprofile` attribute. This commit changes the format so we can either `forbid` or `skip` profiling functions by adding the `noprofile` or `skipprofile` attributes, respectively. The behavior of the original format remains unchanged.
Also, add the `skipprofile` attribute when using `-fprofile-function-groups`.
This was originally landed as https://reviews.llvm.org/D130808 but was reverted due to a Windows test failure.
Differential Revision: https://reviews.llvm.org/D131195
show more ...
|
#
0eb7d86f |
| 04-Aug-2022 |
Nico Weber <thakis@chromium.org> |
Revert "[InstrProf] Add new format for -fprofile-list="
This reverts commit b692312ca432d9a379f67a8d83177a6f1722baaa. Breaks tests on Windows, see https://reviews.llvm.org/D130808#3699952
|
#
b692312c |
| 29-Jul-2022 |
Ellis Hoag <ellis.sparky.hoag@gmail.com> |
[InstrProf] Add new format for -fprofile-list=
In D130807 we added the `skipprofile` attribute. This commit changes the format so we can either `forbid` or `skip` profiling functions by adding the `
[InstrProf] Add new format for -fprofile-list=
In D130807 we added the `skipprofile` attribute. This commit changes the format so we can either `forbid` or `skip` profiling functions by adding the `noprofile` or `skipprofile` attributes, respectively. The behavior of the original format remains unchanged.
Also, add the `skipprofile` attribute when using `-fprofile-function-groups`.
Reviewed By: phosek
Differential Revision: https://reviews.llvm.org/D130808
show more ...
|
#
6f867f91 |
| 29-Jul-2022 |
Phoebe Wang <phoebe.wang@intel.com> |
[X86] Support ``-mindirect-branch-cs-prefix`` for call and jmp to indirect thunk
This is to address feature request from https://github.com/ClangBuiltLinux/linux/issues/1665
Reviewed By: nickdesaul
[X86] Support ``-mindirect-branch-cs-prefix`` for call and jmp to indirect thunk
This is to address feature request from https://github.com/ClangBuiltLinux/linux/issues/1665
Reviewed By: nickdesaulniers, MaskRay
Differential Revision: https://reviews.llvm.org/D130754
show more ...
|
#
6d10733d |
| 02-Aug-2022 |
Chuanqi Xu <yedeng.yd@linux.alibaba.com> |
[C++20] [Modules] Handle initializer for Header Units
Previously when we add module initializer, we forget to handle header units. This results that we couldn't compile a Hello World Example with He
[C++20] [Modules] Handle initializer for Header Units
Previously when we add module initializer, we forget to handle header units. This results that we couldn't compile a Hello World Example with Header Units. This patch tries to fix this.
Reviewed By: iains
Differential Revision: https://reviews.llvm.org/D130871
show more ...
|
#
39cfde23 |
| 02-Aug-2022 |
Chuanqi Xu <yedeng.yd@linux.alibaba.com> |
Revert "[C++20] [Modules] Handle initializer for Header Units"
This reverts commit db6152ad66d7cf48f9f5c3eb28bf54c092978773.
This commit fails in ppc64. Since we want to backport it to 15.x. So rev
Revert "[C++20] [Modules] Handle initializer for Header Units"
This reverts commit db6152ad66d7cf48f9f5c3eb28bf54c092978773.
This commit fails in ppc64. Since we want to backport it to 15.x. So revert it now to keep the patch complete.
show more ...
|
#
db6152ad |
| 02-Aug-2022 |
Chuanqi Xu <yedeng.yd@linux.alibaba.com> |
[C++20] [Modules] Handle initializer for Header Units
Previously when we add module initializer, we forget to handle header units. This results that we couldn't compile a Hello World Example with He
[C++20] [Modules] Handle initializer for Header Units
Previously when we add module initializer, we forget to handle header units. This results that we couldn't compile a Hello World Example with Header Units. This patch tries to fix this.
Reviewed By: iains
Differential Revision: https://reviews.llvm.org/D130871
show more ...
|
#
3da13953 |
| 31-Jul-2022 |
Jun Zhang <jun@junz.org> |
[CodeGen][NFC] Use isa_and_nonnull instead of explicit check
Signed-off-by: Jun Zhang <jun@junz.org>
|
#
15f3cd6b |
| 11-Oct-2021 |
Matheus Izvekov <mizvekov@gmail.com> |
[clang] Implement ElaboratedType sugaring for types written bare
Without this patch, clang will not wrap in an ElaboratedType node types written without a keyword and nested name qualifier, which go
[clang] Implement ElaboratedType sugaring for types written bare
Without this patch, clang will not wrap in an ElaboratedType node types written without a keyword and nested name qualifier, which goes against the intent that we should produce an AST which retains enough details to recover how things are written.
The lack of this sugar is incompatible with the intent of the type printer default policy, which is to print types as written, but to fall back and print them fully qualified when they are desugared.
An ElaboratedTypeLoc without keyword / NNS uses no storage by itself, but still requires pointer alignment due to pre-existing bug in the TypeLoc buffer handling.
---
Troubleshooting list to deal with any breakage seen with this patch:
1) The most likely effect one would see by this patch is a change in how a type is printed. The type printer will, by design and default, print types as written. There are customization options there, but not that many, and they mainly apply to how to print a type that we somehow failed to track how it was written. This patch fixes a problem where we failed to distinguish between a type that was written without any elaborated-type qualifiers, such as a 'struct'/'class' tags and name spacifiers such as 'std::', and one that has been stripped of any 'metadata' that identifies such, the so called canonical types. Example: ``` namespace foo { struct A {}; A a; }; ``` If one were to print the type of `foo::a`, prior to this patch, this would result in `foo::A`. This is how the type printer would have, by default, printed the canonical type of A as well. As soon as you add any name qualifiers to A, the type printer would suddenly start accurately printing the type as written. This patch will make it print it accurately even when written without qualifiers, so we will just print `A` for the initial example, as the user did not really write that `foo::` namespace qualifier.
2) This patch could expose a bug in some AST matcher. Matching types is harder to get right when there is sugar involved. For example, if you want to match a type against being a pointer to some type A, then you have to account for getting a type that is sugar for a pointer to A, or being a pointer to sugar to A, or both! Usually you would get the second part wrong, and this would work for a very simple test where you don't use any name qualifiers, but you would discover is broken when you do. The usual fix is to either use the matcher which strips sugar, which is annoying to use as for example if you match an N level pointer, you have to put N+1 such matchers in there, beginning to end and between all those levels. But in a lot of cases, if the property you want to match is present in the canonical type, it's easier and faster to just match on that... This goes with what is said in 1), if you want to match against the name of a type, and you want the name string to be something stable, perhaps matching on the name of the canonical type is the better choice.
3) This patch could expose a bug in how you get the source range of some TypeLoc. For some reason, a lot of code is using getLocalSourceRange(), which only looks at the given TypeLoc node. This patch introduces a new, and more common TypeLoc node which contains no source locations on itself. This is not an inovation here, and some other, more rare TypeLoc nodes could also have this property, but if you use getLocalSourceRange on them, it's not going to return any valid locations, because it doesn't have any. The right fix here is to always use getSourceRange() or getBeginLoc/getEndLoc which will dive into the inner TypeLoc to get the source range if it doesn't find it on the top level one. You can use getLocalSourceRange if you are really into micro-optimizations and you have some outside knowledge that the TypeLocs you are dealing with will always include some source location.
4) Exposed a bug somewhere in the use of the normal clang type class API, where you have some type, you want to see if that type is some particular kind, you try a `dyn_cast` such as `dyn_cast<TypedefType>` and that fails because now you have an ElaboratedType which has a TypeDefType inside of it, which is what you wanted to match. Again, like 2), this would usually have been tested poorly with some simple tests with no qualifications, and would have been broken had there been any other kind of type sugar, be it an ElaboratedType or a TemplateSpecializationType or a SubstTemplateParmType. The usual fix here is to use `getAs` instead of `dyn_cast`, which will look deeper into the type. Or use `getAsAdjusted` when dealing with TypeLocs. For some reason the API is inconsistent there and on TypeLocs getAs behaves like a dyn_cast.
5) It could be a bug in this patch perhaps.
Let me know if you need any help!
Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>
Differential Revision: https://reviews.llvm.org/D112374
show more ...
|
#
8dfaecc4 |
| 23-Jul-2022 |
Argyrios Kyrtzidis <kyrtzidis@apple.com> |
[CGDebugInfo] Access the current working directory from the `VFS`
...instead of calling `llvm::sys::fs::current_path()` directly.
Differential Revision: https://reviews.llvm.org/D130443
|
#
de1b5c91 |
| 26-Jul-2022 |
Fangrui Song <i@maskray.me> |
[AArch64] Simplify BTI/PAC-RET module flags
These module flags use the Min merge behavior with a default value of zero, so we don't need to emit them if zero.
Reviewed By: danielkiss
Differential
[AArch64] Simplify BTI/PAC-RET module flags
These module flags use the Min merge behavior with a default value of zero, so we don't need to emit them if zero.
Reviewed By: danielkiss
Differential Revision: https://reviews.llvm.org/D130145
show more ...
|
#
58c94808 |
| 23-Jul-2022 |
Jun Zhang <jun@junz.org> |
[CodeGen] Consider MangleCtx when move lazy emission States
Also move MangleCtx when moving some lazy emission states in CodeGenModule. Without this patch clang-repl hits an invalid address access w
[CodeGen] Consider MangleCtx when move lazy emission States
Also move MangleCtx when moving some lazy emission states in CodeGenModule. Without this patch clang-repl hits an invalid address access when passing `-Xcc -O2` flag.
Signed-off-by: Jun Zhang <jun@junz.org>
Differential Revision: https://reviews.llvm.org/D130420
show more ...
|
#
1a3a2eec |
| 23-Jul-2022 |
Jun Zhang <jun@junz.org> |
[NFC] Move function definition to cpp file
Signed-off-by: Jun Zhang <jun@junz.org>
|
#
37502e04 |
| 22-Jul-2022 |
Sergei Barannikov <barannikov88@gmail.com> |
[clang][CodeGen] Only include ABIInfo.h where required (NFC)
Reviewed By: MaskRay
Differential Revision: https://reviews.llvm.org/D130322
|
#
afda39a5 |
| 15-May-2022 |
Iain Sandoe <iain@sandoe.co.uk> |
re-land [C++20][Modules] Build module static initializers per P1874R1.
The re-land fixes module map module dependencies seen on Greendragon, but not in the clang test suite.
---
Currently we only
re-land [C++20][Modules] Build module static initializers per P1874R1.
The re-land fixes module map module dependencies seen on Greendragon, but not in the clang test suite.
---
Currently we only implement this for the Itanium ABI since the correct mangling for the initializers in other ABIs is not yet known.
Intended result:
For a module interface [which includes partition interface and implementation units] (instead of the generic CXX initializer) we emit a module init that:
- wraps the contained initializations in a control variable to ensure that the inits only happen once, even if a module is imported many times by imports of the main unit.
- calls module initializers for imported modules first. Note that the order of module import is not significant, and therefore neither is the order of imported module initializers.
- We then call initializers for the Global Module Fragment (if present) - We then call initializers for the current module. - We then call initializers for the Private Module Fragment (if present)
For a module implementation unit, or a non-module TU that imports at least one module we emit a regular CXX init that:
- Calls the initializers for any imported modules first. - Then proceeds as normal with remaining inits.
For all module unit kinds we include a global constructor entry, this allows for the (in most cases unusual) possibility that a module object could be included in a final binary without a specific call to its initializer.
Implementation:
- We provide the module pointer in the AST Context so that CodeGen can act on it and its sub-modules.
- We need to account for module build lines like this: ` clang -cc1 -std=c++20 Foo.pcm -emit-obj -o Foo.o` or ` clang -cc1 -std=c++20 -xc++-module Foo.cpp -emit-obj -o Foo.o`
- in order to do this, we add to ParseAST to set the module pointer in the ASTContext, once we establish that this is a module build and we know the module pointer. To be able to do this, we make the query for current module public in Sema.
- In CodeGen, we determine if the current build requires a CXX20-style module init and, if so, we defer any module initializers during the "Eagerly Emitted" phase.
- We then walk the module initializers at the end of the TU but before emitting deferred inits (which adds any hidden and static ones, fixing https://github.com/llvm/llvm-project/issues/51873 ).
- We then proceed to emit the deferred inits and continue to emit the CXX init function.
Differential Revision: https://reviews.llvm.org/D126189
show more ...
|