This commit adds LLVM Control Flow Integrity (CFI) support to the Rust
compiler. It initially provides forward-edge control flow protection for
Rust-compiled code only by aggregating function pointers in groups
identified by their number of arguments.
Forward-edge control flow protection for C or C++ and Rust -compiled
code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code
share the same virtual address space) will be provided in later work as
part of this project by defining and using compatible type identifiers
(see Type metadata in the design document in the tracking issue #89653).
LLVM CFI can be enabled with -Zsanitizer=cfi and requires LTO (i.e.,
-Clto).
Create more accurate debuginfo for vtables.
Before this PR all vtables would have the same name (`"vtable"`) in debuginfo. Now they get an unambiguous name that identifies the implementing type and the trait that is being implemented.
This is only one of several possible improvements:
- This PR describes vtables as arrays of `*const u8` pointers. It would nice to describe them as structs where function pointer is represented by a field with a name indicative of the method it maps to. However, this requires coming up with a naming scheme that avoids clashes between methods with the same name (which is possible if the vtable contains multiple traits).
- The PR does not update the debuginfo we generate for the vtable-pointer field in a fat `dyn` pointer. Right now there does not seem to be an easy way of getting ahold of a vtable-layout without also knowing the concrete self-type of a trait object.
r? `@wesleywiser`
Before this commit all vtables would have the same name "vtable" in
debuginfo. Now they get a name that identifies the implementing type
and the trait that is being implemented.
* Make define_global() return a RValue directly
* Return LValue in functions declaring a global variable
* Remove useless cast
* Fix bytes_in_context to use an array rvalue
* Remove global_names which is unused
* Make const_struct create a constant struct
* Correctly initialize global in static_addr_of_mut
* Fix global variable initialization
* Remove workaround for ARGV
* Implement `black_box` as intrinsic
Responsibility of implementing the black box is now lies on backend
* Remove some TODOs
* Update to nightly-2021-09-17
* CI: don't fail on warnings
* Implement basic support for inline assembly
* Disable LTO
We don't support it yet at all
* Handle `inout(reg) var` correctly
Turns out that `+` readwrite output registers cannot be tied with
input variables.
* Add limited support for llvm_asm!
* Handle CHANNEL correctly
* Add support for arbitrary explicit registers
* Handle symbols properly
* Add rudimentary asm tests
* Exclude llvm_asm! tests from tests runs
* Insert `__builtin_unreachable()` after diverging asm blocks