Skip to content

Commit 6554a56

Browse files
committed
Auto merge of rust-lang#122338 - workingjubilee:rollup-xzpt4v4, r=workingjubilee
Rollup of 15 pull requests Successful merges: - rust-lang#116791 (Allow codegen backends to opt-out of parallel codegen) - rust-lang#116793 (Allow targets to override default codegen backend) - rust-lang#117458 (LLVM Bitcode Linker: A self contained linker for nvptx and other targets) - rust-lang#119385 (Fix type resolution of associated const equality bounds (take 2)) - rust-lang#121438 (std support for wasm32 panic=unwind) - rust-lang#121893 (Add tests (and a bit of cleanup) for interior mut handling in promotion and const-checking) - rust-lang#122080 (Clarity improvements to `DropTree`) - rust-lang#122152 (Improve diagnostics for parenthesized type arguments) - rust-lang#122166 (Remove the unused `field_remapping` field from `TypeLowering`) - rust-lang#122249 (interpret: do not call machine read hooks during validation) - rust-lang#122299 (Store backtrace for `must_produce_diag`) - rust-lang#122318 (Revision-related tweaks for next-solver tests) - rust-lang#122320 (Use ptradd for vtable indexing) - rust-lang#122328 (unix_sigpipe: Replace `inherit` with `sig_dfl` in syntax tests) - rust-lang#122330 (bootstrap readme: fix, improve, update) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 65cd843 + 7fa6fa4 commit 6554a56

File tree

251 files changed

+2111
-735
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

251 files changed

+2111
-735
lines changed

Cargo.lock

+11
Original file line numberDiff line numberDiff line change
@@ -2265,6 +2265,17 @@ checksum = "f9d642685b028806386b2b6e75685faadd3eb65a85fff7df711ce18446a422da"
22652265
name = "lld-wrapper"
22662266
version = "0.1.0"
22672267

2268+
[[package]]
2269+
name = "llvm-bitcode-linker"
2270+
version = "0.0.1"
2271+
dependencies = [
2272+
"anyhow",
2273+
"clap",
2274+
"thiserror",
2275+
"tracing",
2276+
"tracing-subscriber",
2277+
]
2278+
22682279
[[package]]
22692280
name = "lock_api"
22702281
version = "0.4.11"

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ members = [
3434
"src/tools/expand-yaml-anchors",
3535
"src/tools/jsondocck",
3636
"src/tools/jsondoclint",
37+
"src/tools/llvm-bitcode-linker",
3738
"src/tools/html-checker",
3839
"src/tools/bump-stage0",
3940
"src/tools/replace-version-placeholder",

compiler/rustc_codegen_llvm/src/context.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ pub struct CodegenCx<'ll, 'tcx> {
7777
/// See <https://llvm.org/docs/LangRef.html#the-llvm-compiler-used-global-variable> for details
7878
pub compiler_used_statics: RefCell<Vec<&'ll Value>>,
7979

80-
/// Mapping of non-scalar types to llvm types and field remapping if needed.
81-
pub type_lowering: RefCell<FxHashMap<(Ty<'tcx>, Option<VariantIdx>), TypeLowering<'ll>>>,
80+
/// Mapping of non-scalar types to llvm types.
81+
pub type_lowering: RefCell<FxHashMap<(Ty<'tcx>, Option<VariantIdx>), &'ll Type>>,
8282

8383
/// Mapping of scalar types to llvm types.
8484
pub scalar_lltypes: RefCell<FxHashMap<Ty<'tcx>, &'ll Type>>,
@@ -105,15 +105,6 @@ pub struct CodegenCx<'ll, 'tcx> {
105105
pub renamed_statics: RefCell<FxHashMap<DefId, &'ll Value>>,
106106
}
107107

108-
pub struct TypeLowering<'ll> {
109-
/// Associated LLVM type
110-
pub lltype: &'ll Type,
111-
112-
/// If padding is used the slice maps fields from source order
113-
/// to llvm order.
114-
pub field_remapping: Option<SmallVec<[u32; 4]>>,
115-
}
116-
117108
fn to_llvm_tls_model(tls_model: TlsModel) -> llvm::ThreadLocalMode {
118109
match tls_model {
119110
TlsModel::GeneralDynamic => llvm::ThreadLocalMode::GeneralDynamic,

compiler/rustc_codegen_llvm/src/llvm_util.rs

+9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::errors::{
55
};
66
use crate::llvm;
77
use libc::c_int;
8+
use rustc_codegen_ssa::base::wants_wasm_eh;
89
use rustc_codegen_ssa::traits::PrintBackendInfo;
910
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1011
use rustc_data_structures::small_c_str::SmallCStr;
@@ -98,6 +99,10 @@ unsafe fn configure_llvm(sess: &Session) {
9899
}
99100
}
100101

102+
if wants_wasm_eh(sess) {
103+
add("-wasm-enable-eh", false);
104+
}
105+
101106
if sess.target.os == "emscripten" && sess.panic_strategy() == PanicStrategy::Unwind {
102107
add("-enable-emscripten-cxx-exceptions", false);
103108
}
@@ -523,6 +528,10 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
523528
.map(String::from),
524529
);
525530

531+
if wants_wasm_eh(sess) && sess.panic_strategy() == PanicStrategy::Unwind {
532+
features.push("+exception-handling".into());
533+
}
534+
526535
// -Ctarget-features
527536
let supported_features = sess.target.supported_target_features();
528537
let mut featsmap = FxHashMap::default();

compiler/rustc_codegen_llvm/src/type_of.rs

+7-23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::common::*;
2-
use crate::context::TypeLowering;
32
use crate::type_::Type;
43
use rustc_codegen_ssa::traits::*;
54
use rustc_middle::bug;
@@ -10,15 +9,13 @@ use rustc_target::abi::HasDataLayout;
109
use rustc_target::abi::{Abi, Align, FieldsShape};
1110
use rustc_target::abi::{Int, Pointer, F128, F16, F32, F64};
1211
use rustc_target::abi::{Scalar, Size, Variants};
13-
use smallvec::{smallvec, SmallVec};
1412

1513
use std::fmt::Write;
1614

1715
fn uncached_llvm_type<'a, 'tcx>(
1816
cx: &CodegenCx<'a, 'tcx>,
1917
layout: TyAndLayout<'tcx>,
2018
defer: &mut Option<(&'a Type, TyAndLayout<'tcx>)>,
21-
field_remapping: &mut Option<SmallVec<[u32; 4]>>,
2219
) -> &'a Type {
2320
match layout.abi {
2421
Abi::Scalar(_) => bug!("handled elsewhere"),
@@ -71,8 +68,7 @@ fn uncached_llvm_type<'a, 'tcx>(
7168
FieldsShape::Array { count, .. } => cx.type_array(layout.field(cx, 0).llvm_type(cx), count),
7269
FieldsShape::Arbitrary { .. } => match name {
7370
None => {
74-
let (llfields, packed, new_field_remapping) = struct_llfields(cx, layout);
75-
*field_remapping = new_field_remapping;
71+
let (llfields, packed) = struct_llfields(cx, layout);
7672
cx.type_struct(&llfields, packed)
7773
}
7874
Some(ref name) => {
@@ -87,15 +83,14 @@ fn uncached_llvm_type<'a, 'tcx>(
8783
fn struct_llfields<'a, 'tcx>(
8884
cx: &CodegenCx<'a, 'tcx>,
8985
layout: TyAndLayout<'tcx>,
90-
) -> (Vec<&'a Type>, bool, Option<SmallVec<[u32; 4]>>) {
86+
) -> (Vec<&'a Type>, bool) {
9187
debug!("struct_llfields: {:#?}", layout);
9288
let field_count = layout.fields.count();
9389

9490
let mut packed = false;
9591
let mut offset = Size::ZERO;
9692
let mut prev_effective_align = layout.align.abi;
9793
let mut result: Vec<_> = Vec::with_capacity(1 + field_count * 2);
98-
let mut field_remapping = smallvec![0; field_count];
9994
for i in layout.fields.index_by_increasing_offset() {
10095
let target_offset = layout.fields.offset(i as usize);
10196
let field = layout.field(cx, i);
@@ -120,12 +115,10 @@ fn struct_llfields<'a, 'tcx>(
120115
result.push(cx.type_padding_filler(padding, padding_align));
121116
debug!(" padding before: {:?}", padding);
122117
}
123-
field_remapping[i] = result.len() as u32;
124118
result.push(field.llvm_type(cx));
125119
offset = target_offset + field.size;
126120
prev_effective_align = effective_field_align;
127121
}
128-
let padding_used = result.len() > field_count;
129122
if layout.is_sized() && field_count > 0 {
130123
if offset > layout.size {
131124
bug!("layout: {:#?} stride: {:?} offset: {:?}", layout, layout.size, offset);
@@ -143,8 +136,7 @@ fn struct_llfields<'a, 'tcx>(
143136
} else {
144137
debug!("struct_llfields: offset: {:?} stride: {:?}", offset, layout.size);
145138
}
146-
let field_remapping = padding_used.then_some(field_remapping);
147-
(result, packed, field_remapping)
139+
(result, packed)
148140
}
149141

150142
impl<'a, 'tcx> CodegenCx<'a, 'tcx> {
@@ -224,7 +216,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
224216
_ => None,
225217
};
226218
if let Some(llty) = cx.type_lowering.borrow().get(&(self.ty, variant_index)) {
227-
return llty.lltype;
219+
return llty;
228220
}
229221

230222
debug!("llvm_type({:#?})", self);
@@ -236,30 +228,22 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
236228
let normal_ty = cx.tcx.erase_regions(self.ty);
237229

238230
let mut defer = None;
239-
let mut field_remapping = None;
240231
let llty = if self.ty != normal_ty {
241232
let mut layout = cx.layout_of(normal_ty);
242233
if let Some(v) = variant_index {
243234
layout = layout.for_variant(cx, v);
244235
}
245236
layout.llvm_type(cx)
246237
} else {
247-
uncached_llvm_type(cx, *self, &mut defer, &mut field_remapping)
238+
uncached_llvm_type(cx, *self, &mut defer)
248239
};
249240
debug!("--> mapped {:#?} to llty={:?}", self, llty);
250241

251-
cx.type_lowering
252-
.borrow_mut()
253-
.insert((self.ty, variant_index), TypeLowering { lltype: llty, field_remapping });
242+
cx.type_lowering.borrow_mut().insert((self.ty, variant_index), llty);
254243

255244
if let Some((llty, layout)) = defer {
256-
let (llfields, packed, new_field_remapping) = struct_llfields(cx, layout);
245+
let (llfields, packed) = struct_llfields(cx, layout);
257246
cx.set_struct_body(llty, &llfields, packed);
258-
cx.type_lowering
259-
.borrow_mut()
260-
.get_mut(&(self.ty, variant_index))
261-
.unwrap()
262-
.field_remapping = new_field_remapping;
263247
}
264248
llty
265249
}

compiler/rustc_codegen_ssa/src/back/link.rs

+19-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use rustc_span::symbol::Symbol;
2424
use rustc_target::spec::crt_objects::CrtObjects;
2525
use rustc_target::spec::LinkSelfContainedComponents;
2626
use rustc_target::spec::LinkSelfContainedDefault;
27+
use rustc_target::spec::LinkerFlavorCli;
2728
use rustc_target::spec::{Cc, LinkOutputKind, LinkerFlavor, Lld, PanicStrategy};
2829
use rustc_target::spec::{RelocModel, RelroLevel, SanitizerSet, SplitDebuginfo};
2930

@@ -1350,6 +1351,7 @@ pub fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
13501351
}
13511352
}
13521353
LinkerFlavor::Bpf => "bpf-linker",
1354+
LinkerFlavor::Llbc => "llvm-bitcode-linker",
13531355
LinkerFlavor::Ptx => "rust-ptx-linker",
13541356
}),
13551357
flavor,
@@ -1367,8 +1369,17 @@ pub fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
13671369

13681370
// linker and linker flavor specified via command line have precedence over what the target
13691371
// specification specifies
1370-
let linker_flavor =
1371-
sess.opts.cg.linker_flavor.map(|flavor| sess.target.linker_flavor.with_cli_hints(flavor));
1372+
let linker_flavor = match sess.opts.cg.linker_flavor {
1373+
// The linker flavors that are non-target specific can be directly translated to LinkerFlavor
1374+
Some(LinkerFlavorCli::Llbc) => Some(LinkerFlavor::Llbc),
1375+
Some(LinkerFlavorCli::Ptx) => Some(LinkerFlavor::Ptx),
1376+
// The linker flavors that corresponds to targets needs logic that keeps the base LinkerFlavor
1377+
_ => sess
1378+
.opts
1379+
.cg
1380+
.linker_flavor
1381+
.map(|flavor| sess.target.linker_flavor.with_cli_hints(flavor)),
1382+
};
13721383
if let Some(ret) = infer_from(sess, sess.opts.cg.linker.clone(), linker_flavor) {
13731384
return ret;
13741385
}
@@ -2338,8 +2349,12 @@ fn add_order_independent_options(
23382349
});
23392350
}
23402351

2341-
if flavor == LinkerFlavor::Ptx {
2342-
// Provide the linker with fallback to internal `target-cpu`.
2352+
if flavor == LinkerFlavor::Llbc {
2353+
cmd.arg("--target");
2354+
cmd.arg(sess.target.llvm_target.as_ref());
2355+
cmd.arg("--target-cpu");
2356+
cmd.arg(&codegen_results.crate_info.target_cpu);
2357+
} else if flavor == LinkerFlavor::Ptx {
23432358
cmd.arg("--fallback-arch");
23442359
cmd.arg(&codegen_results.crate_info.target_cpu);
23452360
} else if flavor == LinkerFlavor::Bpf {

compiler/rustc_codegen_ssa/src/back/linker.rs

+100-1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ pub fn get_linker<'a>(
153153
LinkerFlavor::Msvc(..) => Box::new(MsvcLinker { cmd, sess }) as Box<dyn Linker>,
154154
LinkerFlavor::EmCc => Box::new(EmLinker { cmd, sess }) as Box<dyn Linker>,
155155
LinkerFlavor::Bpf => Box::new(BpfLinker { cmd, sess }) as Box<dyn Linker>,
156+
LinkerFlavor::Llbc => Box::new(LlbcLinker { cmd, sess }) as Box<dyn Linker>,
156157
LinkerFlavor::Ptx => Box::new(PtxLinker { cmd, sess }) as Box<dyn Linker>,
157158
}
158159
}
@@ -1824,7 +1825,7 @@ impl<'a> Linker for PtxLinker<'a> {
18241825
}
18251826

18261827
Lto::No => {}
1827-
};
1828+
}
18281829
}
18291830

18301831
fn output_filename(&mut self, path: &Path) {
@@ -1862,6 +1863,104 @@ impl<'a> Linker for PtxLinker<'a> {
18621863
fn linker_plugin_lto(&mut self) {}
18631864
}
18641865

1866+
/// The `self-contained` LLVM bitcode linker
1867+
pub struct LlbcLinker<'a> {
1868+
cmd: Command,
1869+
sess: &'a Session,
1870+
}
1871+
1872+
impl<'a> Linker for LlbcLinker<'a> {
1873+
fn cmd(&mut self) -> &mut Command {
1874+
&mut self.cmd
1875+
}
1876+
1877+
fn set_output_kind(&mut self, _output_kind: LinkOutputKind, _out_filename: &Path) {}
1878+
1879+
fn link_dylib_by_name(&mut self, _name: &str, _verbatim: bool, _as_needed: bool) {
1880+
panic!("external dylibs not supported")
1881+
}
1882+
1883+
fn link_staticlib_by_name(
1884+
&mut self,
1885+
_name: &str,
1886+
_verbatim: bool,
1887+
_whole_archive: bool,
1888+
_search_paths: &SearchPaths,
1889+
) {
1890+
panic!("staticlibs not supported")
1891+
}
1892+
1893+
fn link_staticlib_by_path(&mut self, path: &Path, _whole_archive: bool) {
1894+
self.cmd.arg(path);
1895+
}
1896+
1897+
fn include_path(&mut self, path: &Path) {
1898+
self.cmd.arg("-L").arg(path);
1899+
}
1900+
1901+
fn debuginfo(&mut self, _strip: Strip, _: &[PathBuf]) {
1902+
self.cmd.arg("--debug");
1903+
}
1904+
1905+
fn add_object(&mut self, path: &Path) {
1906+
self.cmd.arg(path);
1907+
}
1908+
1909+
fn optimize(&mut self) {
1910+
match self.sess.opts.optimize {
1911+
OptLevel::No => "-O0",
1912+
OptLevel::Less => "-O1",
1913+
OptLevel::Default => "-O2",
1914+
OptLevel::Aggressive => "-O3",
1915+
OptLevel::Size => "-Os",
1916+
OptLevel::SizeMin => "-Oz",
1917+
};
1918+
}
1919+
1920+
fn output_filename(&mut self, path: &Path) {
1921+
self.cmd.arg("-o").arg(path);
1922+
}
1923+
1924+
fn framework_path(&mut self, _path: &Path) {
1925+
panic!("frameworks not supported")
1926+
}
1927+
1928+
fn full_relro(&mut self) {}
1929+
1930+
fn partial_relro(&mut self) {}
1931+
1932+
fn no_relro(&mut self) {}
1933+
1934+
fn gc_sections(&mut self, _keep_metadata: bool) {}
1935+
1936+
fn no_gc_sections(&mut self) {}
1937+
1938+
fn pgo_gen(&mut self) {}
1939+
1940+
fn no_crt_objects(&mut self) {}
1941+
1942+
fn no_default_libraries(&mut self) {}
1943+
1944+
fn control_flow_guard(&mut self) {}
1945+
1946+
fn ehcont_guard(&mut self) {}
1947+
1948+
fn export_symbols(&mut self, _tmpdir: &Path, _crate_type: CrateType, symbols: &[String]) {
1949+
match _crate_type {
1950+
CrateType::Cdylib => {
1951+
for sym in symbols {
1952+
self.cmd.arg("--export-symbol").arg(sym);
1953+
}
1954+
}
1955+
_ => (),
1956+
}
1957+
}
1958+
1959+
fn subsystem(&mut self, _subsystem: &str) {}
1960+
1961+
fn linker_plugin_lto(&mut self) {}
1962+
}
1963+
18651964
pub struct BpfLinker<'a> {
18661965
cmd: Command,
18671966
sess: &'a Session,

0 commit comments

Comments
 (0)