Commit Graph

849 Commits

Author SHA1 Message Date
Albert Larsan
5dcda26aa6 Change src/test to tests in source files, fix tidy and tests 2023-02-28 22:03:21 -05:00
Michael Goulet
fa874b03e4 Simplify some iterator combinators 2023-02-28 22:00:40 -05:00
Jeremy Stucki
3a1d3241b4 Add missing anonymous lifetime 2023-02-28 21:59:38 -05:00
Jeremy Stucki
888137d7d2 rustc: Remove needless lifetimes 2023-02-28 21:59:38 -05:00
bjorn3
c2e83dce57 Destruct landing_pad return value before passing it to cg_ssa 2023-02-28 21:59:37 -05:00
Ramon de C Valle
7c2db89ce4 Add LLVM KCFI support to the Rust compiler
This commit adds LLVM Kernel Control Flow Integrity (KCFI) support to
the Rust compiler. It initially provides forward-edge control flow
protection for operating systems kernels for Rust-compiled code only by
aggregating function pointers in groups identified by their return and
parameter types. (See llvm/llvm-project@cff5bef.)

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 identifying C char and integer type uses at the
time types are encoded (see Type metadata in the design document in the
tracking issue #89653).

LLVM KCFI can be enabled with -Zsanitizer=kcfi.

Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com>
2023-02-28 21:51:37 -05:00
Peter Collingbourne
43f868b1c3 Move linkage type check to HIR analysis and fix semantics issues.
This ensures that the error is printed even for unused variables,
as well as unifying the handling between the LLVM and GCC backends.

This also fixes unusual behavior around exported Rust-defined variables
with linkage attributes. With the previous behavior, it appears to be
impossible to define such a variable such that it can actually be imported
and used by another crate. This is because on the importing side, the
variable is required to be a pointer, but on the exporting side, the
type checker rejects static variables of pointer type because they do
not implement `Sync`. Even if it were possible to import such a type, it
appears that code generation on the importing side would add an unexpected
additional level of pointer indirection, which would break type safety.

This highlighted that the semantics of linkage on Rust-defined variables
is different to linkage on foreign items. As such, we now model the
difference with two different codegen attributes: linkage for Rust-defined
variables, and import_linkage for foreign items.

This change gives semantics to the test
src/test/ui/linkage-attr/auxiliary/def_illtyped_external.rs which was
previously expected to fail to compile. Therefore, convert it into a
test that is expected to successfully compile.

The update to the GCC backend is speculative and untested.
2023-02-28 21:51:36 -05:00
bjorn3
d1eb38f5b5 Rewrite LLVM's archive writer in Rust
This allows it to be used by other codegen backends
2023-02-28 19:24:11 -05:00
Maybe Waffle
634a709549 Prefer doc comments over //-comments in compiler 2023-02-28 19:22:27 -05:00
Chris Denton
6f7a01796d Remove more redundant alls 2023-02-28 19:22:27 -05:00
Ayush Singh
21af0df1e5 Use custom entry name in gcc
This is a continuation of 9f0a8620bd for
gcc.

Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2023-02-28 19:22:27 -05:00
Nicholas Nethercote
bf4e1e49ea Use &mut Bx more.
For the next commit, `FunctionCx::codegen_*_terminator` need to take a
`&mut Bx` instead of consuming a `Bx`. This triggers a cascade of
similar changes across multiple functions. The resulting code is more
concise and replaces many `&mut bx` expressions with `bx`.
2023-02-28 19:22:27 -05:00
Caleb Zulawski
5b9b849a19 Allow actual AVX512-related feature names in the case of some misleading aliases 2023-02-28 19:22:27 -05:00
Camille GILLOT
4cbf5e6813 Introduce composite debuginfo. 2023-02-28 19:22:27 -05:00
Ralf Jung
5378b465f0 fix cranelift and gcc 2023-02-28 19:22:27 -05:00
Ralf Jung
fb747d0e24 add is_sized method on Abi and Layout, and use it 2023-02-28 19:22:27 -05:00
Ayush Singh
a897864150 Add type_array to BaseTypeMethods
Moved type_array function to rustc_codegen_ssa::BaseTypeMethods trait.
This allows using normal alloca function to create arrays as suggested in
https://github.com/rust-lang/rust/pull/104022.

Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2023-02-28 19:22:26 -05:00
Amanieu d'Antras
dd930a3b5c Rewrite implementation of #[alloc_error_handler]
The new implementation doesn't use weak lang items and instead changes
`#[alloc_error_handler]` to an attribute macro just like
`#[global_allocator]`.

The attribute will generate the `__rg_oom` function which is called by
the compiler-generated `__rust_alloc_error_handler`. If no `__rg_oom`
function is defined in any crate then the compiler shim will call
`__rdl_oom` in the alloc crate which will simply panic.

This also fixes link errors with `-C link-dead-code` with
`default_alloc_error_handler`: `__rg_oom` was previously defined in the
alloc crate and would attempt to reference the `oom` lang item, even if
it didn't exist. This worked as long as `__rg_oom` was excluded from
linking since it was not called.

This is a prerequisite for the stabilization of
`default_alloc_error_handler` (#102318).
2023-02-28 19:19:57 -05:00
Daniel Paoliello
4c0a6e610e Support raw-dylib functions being used inside inlined functions 2023-02-28 19:18:41 -05:00
Nilstrieb
dbe3df3d84 Migrate all diagnostics 2023-02-28 19:18:41 -05:00
Amanieu d'Antras
affe23bc3b Stabilize asm_sym 2023-02-28 19:18:41 -05:00
bjorn3
4310bbdfa6 Remove type argument of array_alloca and rename to byte_array_alloca 2023-02-28 19:18:41 -05:00
bjorn3
b909493151 Remove dynamic_alloca from BuilderMethods 2023-02-28 19:18:41 -05:00
bjorn3
d9933199cd Merge apply_attrs_callsite into call and invoke
Some codegen backends are not able to apply callsite attrs after the fact.
2023-02-28 19:18:40 -05:00
bjorn3
15b0747049 Remove unused target_cpu and tune_cpu methods from ExtraBackendMethods 2023-02-28 19:13:19 -05:00
bjorn3
5d5c5f92fb Remove several unused methods from MiscMethods 2023-02-28 19:13:19 -05:00
bjorn3
5943166b29 Remove unused Context assoc type from WriteBackendMethods 2023-02-28 19:13:19 -05:00
Ellis Hoag
5c30c25f07 print <signal> when ranlib failed without an exit code 2023-02-28 19:13:19 -05:00
Ellis Hoag
9c67dcfe42 lint and remove unused diagnostic 2023-02-28 19:13:19 -05:00
Ellis Hoag
70aeb9e2b3 remove comment 2023-02-28 19:13:19 -05:00
Ellis Hoag
925b11ece0 fix lifetime error 2023-02-28 19:13:19 -05:00
Ellis Hoag
9bbb49150a rebase and update trait names 2023-02-28 19:13:19 -05:00
Ellis Hoag
2e46dc2cff impl SessionDiagnostic for LayoutError and Spanned<T> 2023-02-28 19:13:19 -05:00
Ellis Hoag
ef3aaa1f21 Add monomorphization errors 2023-02-28 19:13:18 -05:00
Ellis Hoag
f21041d7c3 lint type 2023-02-28 19:07:24 -05:00
Ellis Hoag
4718beead6 Add wrapper type for ExitCode for use in RanlibFailure 2023-02-28 19:07:24 -05:00
Ellis Hoag
c4149da9fd remove IntoDiagnosticArg impl for Option 2023-02-28 19:07:24 -05:00
Ellis Hoag
b4a051e3b3 Lint against untranslatable diagnostics in rustc_codegen_gcc 2023-02-28 19:07:24 -05:00
Ellis Hoag
1b5dd4bf5e Add LayoutSizeOverflow 2023-02-28 19:07:24 -05:00
Ellis Hoag
4a861c140a Add LTONotSupported 2023-02-28 19:07:24 -05:00
Ellis Hoag
2592befa7c Add UnwindingInlineAsm 2023-02-28 19:07:24 -05:00
Ellis Hoag
5a9ec83a17 Add LinkageConstOrMutType 2023-02-28 19:07:24 -05:00
Ellis Hoag
c503d978dc Add RanlibFailure 2023-02-28 19:07:24 -05:00
Urgau
a900ba9163 Stabilize bench_black_box 2023-02-28 19:07:23 -05:00
Oli Scherer
a50c15275f Remove dead broken code from const zst handling in backends 2023-02-28 18:57:14 -05:00
Josh Stone
91cf28428e Move the cast_float_to_int fallback code to GCC
Now that we require at least LLVM 13, that codegen backend is always
using its intrinsic `fptosi.sat` and `fptoui.sat` conversions, so it
doesn't need the manual implementation. However, the GCC backend still
needs it, so we can move all of that code down there.
2023-02-28 18:57:14 -05:00
Ralf Jung
80b1c8dab5 interpret: rename relocation → provenance 2023-02-28 18:57:14 -05:00
Maybe Waffle
5eedd541a9 Fix ptr_mask impl in cg gcc 2023-02-28 18:57:14 -05:00
Maybe Waffle
a7f6e7ebaf Implement ptr_mask intrinsic in cg gcc 2023-02-28 18:57:14 -05:00
Nicholas Nethercote
b3f2942156 Move ArgAbi::pad_i32 into PassMode::Cast.
Because it's only needed for that variant. This shrinks the types and
clarifies the logic.
2023-02-28 18:57:14 -05:00