From 3216078b78585666a79705be959dcd86e8262fef Mon Sep 17 00:00:00 2001 From: bors Date: Mon, 11 Dec 2023 07:49:53 +0000 Subject: [PATCH 001/103] Auto merge of #11538 - Jarcho:proc_mac, r=dswij Fix `is_from_proc_macro` patterns fixes #11533 changelog: none --- .../clippy/clippy_lints/src/as_conversions.rs | 9 +- .../clippy_lints/src/borrow_deref_ref.rs | 107 +++++++++--------- .../clippy_lints/src/manual_float_methods.rs | 4 +- .../src/methods/unnecessary_lazy_eval.rs | 6 +- .../clippy/clippy_lints/src/needless_if.rs | 2 +- .../src/operators/arithmetic_side_effects.rs | 25 ++-- .../clippy/clippy_lints/src/single_call_fn.rs | 2 +- .../clippy_utils/src/check_proc_macro.rs | 80 ++++++------- src/tools/clippy/tests/ui/doc_unsafe.rs | 2 +- .../tests/ui/needless_pass_by_ref_mut.rs | 13 +++ .../tests/ui/needless_pass_by_ref_mut.stderr | 62 +++++++++- .../tests/ui/unnecessary_unsafety_doc.rs | 2 +- 12 files changed, 192 insertions(+), 122 deletions(-) diff --git a/src/tools/clippy/clippy_lints/src/as_conversions.rs b/src/tools/clippy/clippy_lints/src/as_conversions.rs index b9dda49ca4124..2de205d80efcd 100644 --- a/src/tools/clippy/clippy_lints/src/as_conversions.rs +++ b/src/tools/clippy/clippy_lints/src/as_conversions.rs @@ -48,11 +48,10 @@ declare_lint_pass!(AsConversions => [AS_CONVERSIONS]); impl<'tcx> LateLintPass<'tcx> for AsConversions { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'tcx>) { - if in_external_macro(cx.sess(), expr.span) || is_from_proc_macro(cx, expr) { - return; - } - - if let ExprKind::Cast(_, _) = expr.kind { + if let ExprKind::Cast(_, _) = expr.kind + && !in_external_macro(cx.sess(), expr.span) + && !is_from_proc_macro(cx, expr) + { span_lint_and_help( cx, AS_CONVERSIONS, diff --git a/src/tools/clippy/clippy_lints/src/borrow_deref_ref.rs b/src/tools/clippy/clippy_lints/src/borrow_deref_ref.rs index 739ce8f67c236..a38269083262b 100644 --- a/src/tools/clippy/clippy_lints/src/borrow_deref_ref.rs +++ b/src/tools/clippy/clippy_lints/src/borrow_deref_ref.rs @@ -49,69 +49,64 @@ declare_lint_pass!(BorrowDerefRef => [BORROW_DEREF_REF]); impl<'tcx> LateLintPass<'tcx> for BorrowDerefRef { fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &rustc_hir::Expr<'tcx>) { - if_chain! { - if !e.span.from_expansion(); - if let ExprKind::AddrOf(_, Mutability::Not, addrof_target) = e.kind; - if !addrof_target.span.from_expansion(); - if let ExprKind::Unary(UnOp::Deref, deref_target) = addrof_target.kind; - if !deref_target.span.from_expansion(); - if !matches!(deref_target.kind, ExprKind::Unary(UnOp::Deref, ..) ); - let ref_ty = cx.typeck_results().expr_ty(deref_target); - if let ty::Ref(_, inner_ty, Mutability::Not) = ref_ty.kind(); - if !is_from_proc_macro(cx, e); - then{ - - if let Some(parent_expr) = get_parent_expr(cx, e){ - if matches!(parent_expr.kind, ExprKind::Unary(UnOp::Deref, ..)) && - !is_lint_allowed(cx, DEREF_ADDROF, parent_expr.hir_id) { - return; - } + if !e.span.from_expansion() + && let ExprKind::AddrOf(_, Mutability::Not, addrof_target) = e.kind + && !addrof_target.span.from_expansion() + && let ExprKind::Unary(UnOp::Deref, deref_target) = addrof_target.kind + && !deref_target.span.from_expansion() + && !matches!(deref_target.kind, ExprKind::Unary(UnOp::Deref, ..)) + && let ref_ty = cx.typeck_results().expr_ty(deref_target) + && let ty::Ref(_, inner_ty, Mutability::Not) = ref_ty.kind() + { + if let Some(parent_expr) = get_parent_expr(cx, e) { + if matches!(parent_expr.kind, ExprKind::Unary(UnOp::Deref, ..)) + && !is_lint_allowed(cx, DEREF_ADDROF, parent_expr.hir_id) + { + return; + } - // modification to `&mut &*x` is different from `&mut x` - if matches!(deref_target.kind, ExprKind::Path(..) - | ExprKind::Field(..) - | ExprKind::Index(..) - | ExprKind::Unary(UnOp::Deref, ..)) - && matches!(parent_expr.kind, ExprKind::AddrOf(_, Mutability::Mut, _)) { - return; - } + // modification to `&mut &*x` is different from `&mut x` + if matches!( + deref_target.kind, + ExprKind::Path(..) | ExprKind::Field(..) | ExprKind::Index(..) | ExprKind::Unary(UnOp::Deref, ..) + ) && matches!(parent_expr.kind, ExprKind::AddrOf(_, Mutability::Mut, _)) + { + return; } + } + if is_from_proc_macro(cx, e) { + return; + } - span_lint_and_then( - cx, - BORROW_DEREF_REF, - e.span, - "deref on an immutable reference", - |diag| { - diag.span_suggestion( - e.span, - "if you would like to reborrow, try removing `&*`", - snippet_opt(cx, deref_target.span).unwrap(), - Applicability::MachineApplicable - ); + span_lint_and_then( + cx, + BORROW_DEREF_REF, + e.span, + "deref on an immutable reference", + |diag| { + diag.span_suggestion( + e.span, + "if you would like to reborrow, try removing `&*`", + snippet_opt(cx, deref_target.span).unwrap(), + Applicability::MachineApplicable, + ); - // has deref trait -> give 2 help - // doesn't have deref trait -> give 1 help - if let Some(deref_trait_id) = cx.tcx.lang_items().deref_trait(){ - if !implements_trait(cx, *inner_ty, deref_trait_id, &[]) { - return; - } + // has deref trait -> give 2 help + // doesn't have deref trait -> give 1 help + if let Some(deref_trait_id) = cx.tcx.lang_items().deref_trait() { + if !implements_trait(cx, *inner_ty, deref_trait_id, &[]) { + return; } - - diag.span_suggestion( - e.span, - "if you would like to deref, try using `&**`", - format!( - "&**{}", - &snippet_opt(cx, deref_target.span).unwrap(), - ), - Applicability::MaybeIncorrect - ); - } - ); - } + diag.span_suggestion( + e.span, + "if you would like to deref, try using `&**`", + format!("&**{}", &snippet_opt(cx, deref_target.span).unwrap()), + Applicability::MaybeIncorrect, + ); + }, + ); } } } diff --git a/src/tools/clippy/clippy_lints/src/manual_float_methods.rs b/src/tools/clippy/clippy_lints/src/manual_float_methods.rs index 0c4101ceb6bb3..f923e0ac82008 100644 --- a/src/tools/clippy/clippy_lints/src/manual_float_methods.rs +++ b/src/tools/clippy/clippy_lints/src/manual_float_methods.rs @@ -105,7 +105,6 @@ impl<'tcx> LateLintPass<'tcx> for ManualFloatMethods { // case somebody does that for some reason && (is_infinity(const_1) && is_neg_infinity(const_2) || is_neg_infinity(const_1) && is_infinity(const_2)) - && !is_from_proc_macro(cx, expr) && let Some(local_snippet) = snippet_opt(cx, first.span) { let variant = match (kind.node, lhs_kind.node, rhs_kind.node) { @@ -113,6 +112,9 @@ impl<'tcx> LateLintPass<'tcx> for ManualFloatMethods { (BinOpKind::And, BinOpKind::Ne, BinOpKind::Ne) => Variant::ManualIsFinite, _ => return, }; + if is_from_proc_macro(cx, expr) { + return; + } span_lint_and_then(cx, variant.lint(), expr.span, variant.msg(), |diag| { match variant { diff --git a/src/tools/clippy/clippy_lints/src/methods/unnecessary_lazy_eval.rs b/src/tools/clippy/clippy_lints/src/methods/unnecessary_lazy_eval.rs index 4a651396f14d0..4429f0326058a 100644 --- a/src/tools/clippy/clippy_lints/src/methods/unnecessary_lazy_eval.rs +++ b/src/tools/clippy/clippy_lints/src/methods/unnecessary_lazy_eval.rs @@ -19,10 +19,6 @@ pub(super) fn check<'tcx>( arg: &'tcx hir::Expr<'_>, simplify_using: &str, ) { - if is_from_proc_macro(cx, expr) { - return; - } - let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Option); let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result); let is_bool = cx.typeck_results().expr_ty(recv).is_bool(); @@ -32,7 +28,7 @@ pub(super) fn check<'tcx>( let body = cx.tcx.hir().body(body); let body_expr = &body.value; - if usage::BindingUsageFinder::are_params_used(cx, body) { + if usage::BindingUsageFinder::are_params_used(cx, body) || is_from_proc_macro(cx, expr) { return; } diff --git a/src/tools/clippy/clippy_lints/src/needless_if.rs b/src/tools/clippy/clippy_lints/src/needless_if.rs index 1ed7ea6b32554..23aabc548a57d 100644 --- a/src/tools/clippy/clippy_lints/src/needless_if.rs +++ b/src/tools/clippy/clippy_lints/src/needless_if.rs @@ -44,7 +44,6 @@ impl LateLintPass<'_> for NeedlessIf { && block.stmts.is_empty() && block.expr.is_none() && !in_external_macro(cx.sess(), expr.span) - && !is_from_proc_macro(cx, expr) && let Some(then_snippet) = snippet_opt(cx, then.span) // Ignore // - empty macro expansions @@ -53,6 +52,7 @@ impl LateLintPass<'_> for NeedlessIf { // - #[cfg]'d out code && then_snippet.chars().all(|ch| matches!(ch, '{' | '}') || ch.is_ascii_whitespace()) && let Some(cond_snippet) = snippet_opt(cx, cond.span) + && !is_from_proc_macro(cx, expr) { span_lint_and_sugg( cx, diff --git a/src/tools/clippy/clippy_lints/src/operators/arithmetic_side_effects.rs b/src/tools/clippy/clippy_lints/src/operators/arithmetic_side_effects.rs index f7d9650b2f8db..4c6462b7747b4 100644 --- a/src/tools/clippy/clippy_lints/src/operators/arithmetic_side_effects.rs +++ b/src/tools/clippy/clippy_lints/src/operators/arithmetic_side_effects.rs @@ -132,7 +132,11 @@ impl ArithmeticSideEffects { } // Common entry-point to avoid code duplication. - fn issue_lint(&mut self, cx: &LateContext<'_>, expr: &hir::Expr<'_>) { + fn issue_lint<'tcx>(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { + if is_from_proc_macro(cx, expr) { + return; + } + let msg = "arithmetic operation that can potentially result in unexpected side-effects"; span_lint(cx, ARITHMETIC_SIDE_EFFECTS, expr.span, msg); self.expr_span = Some(expr.span); @@ -160,10 +164,10 @@ impl ArithmeticSideEffects { fn manage_bin_ops<'tcx>( &mut self, cx: &LateContext<'tcx>, - expr: &hir::Expr<'tcx>, + expr: &'tcx hir::Expr<'_>, op: &Spanned, - lhs: &hir::Expr<'tcx>, - rhs: &hir::Expr<'tcx>, + lhs: &'tcx hir::Expr<'_>, + rhs: &'tcx hir::Expr<'_>, ) { if constant_simple(cx, cx.typeck_results(), expr).is_some() { return; @@ -236,10 +240,10 @@ impl ArithmeticSideEffects { /// provided input. fn manage_method_call<'tcx>( &mut self, - args: &[hir::Expr<'tcx>], + args: &'tcx [hir::Expr<'_>], cx: &LateContext<'tcx>, - ps: &hir::PathSegment<'tcx>, - receiver: &hir::Expr<'tcx>, + ps: &'tcx hir::PathSegment<'_>, + receiver: &'tcx hir::Expr<'_>, ) { let Some(arg) = args.first() else { return; @@ -264,8 +268,8 @@ impl ArithmeticSideEffects { fn manage_unary_ops<'tcx>( &mut self, cx: &LateContext<'tcx>, - expr: &hir::Expr<'tcx>, - un_expr: &hir::Expr<'tcx>, + expr: &'tcx hir::Expr<'_>, + un_expr: &'tcx hir::Expr<'_>, un_op: hir::UnOp, ) { let hir::UnOp::Neg = un_op else { @@ -287,14 +291,13 @@ impl ArithmeticSideEffects { fn should_skip_expr<'tcx>(&mut self, cx: &LateContext<'tcx>, expr: &hir::Expr<'tcx>) -> bool { is_lint_allowed(cx, ARITHMETIC_SIDE_EFFECTS, expr.hir_id) - || is_from_proc_macro(cx, expr) || self.expr_span.is_some() || self.const_span.map_or(false, |sp| sp.contains(expr.span)) } } impl<'tcx> LateLintPass<'tcx> for ArithmeticSideEffects { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &hir::Expr<'tcx>) { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) { if self.should_skip_expr(cx, expr) { return; } diff --git a/src/tools/clippy/clippy_lints/src/single_call_fn.rs b/src/tools/clippy/clippy_lints/src/single_call_fn.rs index ae81e1198af26..0492df68daddc 100644 --- a/src/tools/clippy/clippy_lints/src/single_call_fn.rs +++ b/src/tools/clippy/clippy_lints/src/single_call_fn.rs @@ -72,8 +72,8 @@ impl<'tcx> LateLintPass<'tcx> for SingleCallFn { ) { if self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(def_id) || in_external_macro(cx.sess(), span) - || is_from_proc_macro(cx, &(&kind, body, cx.tcx.local_def_id_to_hir_id(def_id), span)) || is_in_test_function(cx.tcx, body.value.hir_id) + || is_from_proc_macro(cx, &(&kind, body, cx.tcx.local_def_id_to_hir_id(def_id), span)) { return; } diff --git a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs index 3bac0626f8858..2f619a306fe02 100644 --- a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs +++ b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs @@ -12,14 +12,14 @@ //! code was written, and check if the span contains that text. Note this will only work correctly //! if the span is not from a `macro_rules` based macro. -use rustc_ast::ast::{AttrKind, Attribute, IntTy, LitIntType, LitKind, StrStyle, UintTy}; +use rustc_ast::ast::{AttrKind, Attribute, IntTy, LitIntType, LitKind, StrStyle, TraitObjectSyntax, UintTy}; use rustc_ast::token::CommentKind; use rustc_ast::AttrStyle; use rustc_hir::intravisit::FnKind; use rustc_hir::{ - Block, BlockCheckMode, Body, Closure, Destination, Expr, ExprKind, FieldDef, FnHeader, HirId, Impl, ImplItem, - ImplItemKind, IsAuto, Item, ItemKind, LoopSource, MatchSource, MutTy, Node, QPath, TraitItem, TraitItemKind, Ty, - TyKind, UnOp, UnsafeSource, Unsafety, Variant, VariantData, YieldSource, + Block, BlockCheckMode, Body, Closure, Destination, Expr, ExprKind, FieldDef, FnHeader, FnRetTy, HirId, Impl, + ImplItem, ImplItemKind, IsAuto, Item, ItemKind, LoopSource, MatchSource, MutTy, Node, QPath, TraitItem, + TraitItemKind, Ty, TyKind, UnOp, UnsafeSource, Unsafety, Variant, VariantData, YieldSource, }; use rustc_lint::{LateContext, LintContext}; use rustc_middle::ty::TyCtxt; @@ -33,8 +33,6 @@ use rustc_target::spec::abi::Abi; pub enum Pat { /// A single string. Str(&'static str), - /// A single string. - OwnedStr(String), /// Any of the given strings. MultiStr(&'static [&'static str]), /// Any of the given strings. @@ -59,14 +57,12 @@ fn span_matches_pat(sess: &Session, span: Span, start_pat: Pat, end_pat: Pat) -> let end_str = s.trim_end_matches(|c: char| c.is_whitespace() || c == ')' || c == ','); (match start_pat { Pat::Str(text) => start_str.starts_with(text), - Pat::OwnedStr(text) => start_str.starts_with(&text), Pat::MultiStr(texts) => texts.iter().any(|s| start_str.starts_with(s)), Pat::OwnedMultiStr(texts) => texts.iter().any(|s| start_str.starts_with(s)), Pat::Sym(sym) => start_str.starts_with(sym.as_str()), Pat::Num => start_str.as_bytes().first().map_or(false, u8::is_ascii_digit), } && match end_pat { Pat::Str(text) => end_str.ends_with(text), - Pat::OwnedStr(text) => end_str.starts_with(&text), Pat::MultiStr(texts) => texts.iter().any(|s| start_str.ends_with(s)), Pat::OwnedMultiStr(texts) => texts.iter().any(|s| start_str.starts_with(s)), Pat::Sym(sym) => end_str.ends_with(sym.as_str()), @@ -125,6 +121,8 @@ fn qpath_search_pat(path: &QPath<'_>) -> (Pat, Pat) { fn expr_search_pat(tcx: TyCtxt<'_>, e: &Expr<'_>) -> (Pat, Pat) { match e.kind { ExprKind::ConstBlock(_) => (Pat::Str("const"), Pat::Str("}")), + // Parenthesis are trimmed from the text before the search patterns are matched. + // See: `span_matches_pat` ExprKind::Tup([]) => (Pat::Str(")"), Pat::Str("(")), ExprKind::Unary(UnOp::Deref, e) => (Pat::Str("*"), expr_search_pat(tcx, e).1), ExprKind::Unary(UnOp::Not, e) => (Pat::Str("!"), expr_search_pat(tcx, e).1), @@ -286,23 +284,17 @@ fn fn_kind_pat(tcx: TyCtxt<'_>, kind: &FnKind<'_>, body: &Body<'_>, hir_id: HirI fn attr_search_pat(attr: &Attribute) -> (Pat, Pat) { match attr.kind { AttrKind::Normal(..) => { - let mut pat = if matches!(attr.style, AttrStyle::Outer) { - (Pat::Str("#["), Pat::Str("]")) - } else { - (Pat::Str("#!["), Pat::Str("]")) - }; - - if let Some(ident) = attr.ident() - && let Pat::Str(old_pat) = pat.0 - { + if let Some(ident) = attr.ident() { // TODO: I feel like it's likely we can use `Cow` instead but this will require quite a bit of // refactoring // NOTE: This will likely have false positives, like `allow = 1` - pat.0 = Pat::OwnedMultiStr(vec![ident.to_string(), old_pat.to_owned()]); - pat.1 = Pat::Str(""); + ( + Pat::OwnedMultiStr(vec![ident.to_string(), "#".to_owned()]), + Pat::Str(""), + ) + } else { + (Pat::Str("#"), Pat::Str("]")) } - - pat }, AttrKind::DocComment(_kind @ CommentKind::Line, ..) => { if matches!(attr.style, AttrStyle::Outer) { @@ -324,32 +316,42 @@ fn attr_search_pat(attr: &Attribute) -> (Pat, Pat) { fn ty_search_pat(ty: &Ty<'_>) -> (Pat, Pat) { match ty.kind { TyKind::Slice(..) | TyKind::Array(..) => (Pat::Str("["), Pat::Str("]")), - TyKind::Ptr(MutTy { mutbl, ty }) => ( - if mutbl.is_mut() { - Pat::Str("*const") - } else { - Pat::Str("*mut") - }, - ty_search_pat(ty).1, - ), + TyKind::Ptr(MutTy { ty, .. }) => (Pat::Str("*"), ty_search_pat(ty).1), TyKind::Ref(_, MutTy { ty, .. }) => (Pat::Str("&"), ty_search_pat(ty).1), TyKind::BareFn(bare_fn) => ( - Pat::OwnedStr(format!("{}{} fn", bare_fn.unsafety.prefix_str(), bare_fn.abi.name())), - ty_search_pat(ty).1, + if bare_fn.unsafety == Unsafety::Unsafe { + Pat::Str("unsafe") + } else if bare_fn.abi != Abi::Rust { + Pat::Str("extern") + } else { + Pat::MultiStr(&["fn", "extern"]) + }, + match bare_fn.decl.output { + FnRetTy::DefaultReturn(_) => { + if let [.., ty] = bare_fn.decl.inputs { + ty_search_pat(ty).1 + } else { + Pat::Str("(") + } + }, + FnRetTy::Return(ty) => ty_search_pat(ty).1, + }, ), - TyKind::Never => (Pat::Str("!"), Pat::Str("")), - TyKind::Tup(..) => (Pat::Str("("), Pat::Str(")")), + TyKind::Never => (Pat::Str("!"), Pat::Str("!")), + // Parenthesis are trimmed from the text before the search patterns are matched. + // See: `span_matches_pat` + TyKind::Tup([]) => (Pat::Str(")"), Pat::Str("(")), + TyKind::Tup([ty]) => ty_search_pat(ty), + TyKind::Tup([head, .., tail]) => (ty_search_pat(head).0, ty_search_pat(tail).1), TyKind::OpaqueDef(..) => (Pat::Str("impl"), Pat::Str("")), TyKind::Path(qpath) => qpath_search_pat(&qpath), - // NOTE: This is missing `TraitObject`. It will always return true then. + TyKind::Infer => (Pat::Str("_"), Pat::Str("_")), + TyKind::TraitObject(_, _, TraitObjectSyntax::Dyn) => (Pat::Str("dyn"), Pat::Str("")), + // NOTE: `TraitObject` is incomplete. It will always return true then. _ => (Pat::Str(""), Pat::Str("")), } } -fn ident_search_pat(ident: Ident) -> (Pat, Pat) { - (Pat::OwnedStr(ident.name.as_str().to_owned()), Pat::Str("")) -} - pub trait WithSearchPat<'cx> { type Context: LintContext; fn search_pat(&self, cx: &Self::Context) -> (Pat, Pat); @@ -408,7 +410,7 @@ impl<'cx> WithSearchPat<'cx> for Ident { type Context = LateContext<'cx>; fn search_pat(&self, _cx: &Self::Context) -> (Pat, Pat) { - ident_search_pat(*self) + (Pat::Sym(self.name), Pat::Sym(self.name)) } fn span(&self) -> Span { diff --git a/src/tools/clippy/tests/ui/doc_unsafe.rs b/src/tools/clippy/tests/ui/doc_unsafe.rs index 0c8eac5ccffc3..f7f41c915e3f0 100644 --- a/src/tools/clippy/tests/ui/doc_unsafe.rs +++ b/src/tools/clippy/tests/ui/doc_unsafe.rs @@ -1,6 +1,6 @@ //@aux-build:proc_macros.rs -#![allow(clippy::let_unit_value)] +#![allow(clippy::let_unit_value, clippy::needless_pass_by_ref_mut)] extern crate proc_macros; use proc_macros::external; diff --git a/src/tools/clippy/tests/ui/needless_pass_by_ref_mut.rs b/src/tools/clippy/tests/ui/needless_pass_by_ref_mut.rs index ea5e74c4c0067..bdb6d40d9f61a 100644 --- a/src/tools/clippy/tests/ui/needless_pass_by_ref_mut.rs +++ b/src/tools/clippy/tests/ui/needless_pass_by_ref_mut.rs @@ -302,6 +302,19 @@ fn filter_copy(predicate: &mut impl FnMut(T) -> bool) -> impl FnMut(&T) move |&item| predicate(item) } +// `is_from_proc_macro` stress tests +fn _empty_tup(x: &mut (())) {} +fn _single_tup(x: &mut ((i32,))) {} +fn _multi_tup(x: &mut ((i32, u32))) {} +fn _fn(x: &mut (fn())) {} +#[rustfmt::skip] +fn _extern_rust_fn(x: &mut extern "Rust" fn()) {} +fn _extern_c_fn(x: &mut extern "C" fn()) {} +fn _unsafe_fn(x: &mut unsafe fn()) {} +fn _unsafe_extern_fn(x: &mut unsafe extern "C" fn()) {} +fn _fn_with_arg(x: &mut unsafe extern "C" fn(i32)) {} +fn _fn_with_ret(x: &mut unsafe extern "C" fn() -> (i32)) {} + fn main() { let mut u = 0; let mut v = vec![0]; diff --git a/src/tools/clippy/tests/ui/needless_pass_by_ref_mut.stderr b/src/tools/clippy/tests/ui/needless_pass_by_ref_mut.stderr index aa937c3f6af2b..3e1415be08f82 100644 --- a/src/tools/clippy/tests/ui/needless_pass_by_ref_mut.stderr +++ b/src/tools/clippy/tests/ui/needless_pass_by_ref_mut.stderr @@ -139,5 +139,65 @@ LL | pub async fn closure4(n: &mut usize) { | = warning: changing this function will impact semver compatibility -error: aborting due to 21 previous errors +error: this argument is a mutable reference, but not used mutably + --> $DIR/needless_pass_by_ref_mut.rs:306:18 + | +LL | fn _empty_tup(x: &mut (())) {} + | ^^^^^^^^^ help: consider changing to: `&()` + +error: this argument is a mutable reference, but not used mutably + --> $DIR/needless_pass_by_ref_mut.rs:307:19 + | +LL | fn _single_tup(x: &mut ((i32,))) {} + | ^^^^^^^^^^^^^ help: consider changing to: `&(i32,)` + +error: this argument is a mutable reference, but not used mutably + --> $DIR/needless_pass_by_ref_mut.rs:308:18 + | +LL | fn _multi_tup(x: &mut ((i32, u32))) {} + | ^^^^^^^^^^^^^^^^^ help: consider changing to: `&(i32, u32)` + +error: this argument is a mutable reference, but not used mutably + --> $DIR/needless_pass_by_ref_mut.rs:309:11 + | +LL | fn _fn(x: &mut (fn())) {} + | ^^^^^^^^^^^ help: consider changing to: `&fn()` + +error: this argument is a mutable reference, but not used mutably + --> $DIR/needless_pass_by_ref_mut.rs:311:23 + | +LL | fn _extern_rust_fn(x: &mut extern "Rust" fn()) {} + | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&extern "Rust" fn()` + +error: this argument is a mutable reference, but not used mutably + --> $DIR/needless_pass_by_ref_mut.rs:312:20 + | +LL | fn _extern_c_fn(x: &mut extern "C" fn()) {} + | ^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&extern "C" fn()` + +error: this argument is a mutable reference, but not used mutably + --> $DIR/needless_pass_by_ref_mut.rs:313:18 + | +LL | fn _unsafe_fn(x: &mut unsafe fn()) {} + | ^^^^^^^^^^^^^^^^ help: consider changing to: `&unsafe fn()` + +error: this argument is a mutable reference, but not used mutably + --> $DIR/needless_pass_by_ref_mut.rs:314:25 + | +LL | fn _unsafe_extern_fn(x: &mut unsafe extern "C" fn()) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&unsafe extern "C" fn()` + +error: this argument is a mutable reference, but not used mutably + --> $DIR/needless_pass_by_ref_mut.rs:315:20 + | +LL | fn _fn_with_arg(x: &mut unsafe extern "C" fn(i32)) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&unsafe extern "C" fn(i32)` + +error: this argument is a mutable reference, but not used mutably + --> $DIR/needless_pass_by_ref_mut.rs:316:20 + | +LL | fn _fn_with_ret(x: &mut unsafe extern "C" fn() -> (i32)) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&unsafe extern "C" fn() -> (i32)` + +error: aborting due to 31 previous errors diff --git a/src/tools/clippy/tests/ui/unnecessary_unsafety_doc.rs b/src/tools/clippy/tests/ui/unnecessary_unsafety_doc.rs index 373b18470f695..5ad117eb8db6e 100644 --- a/src/tools/clippy/tests/ui/unnecessary_unsafety_doc.rs +++ b/src/tools/clippy/tests/ui/unnecessary_unsafety_doc.rs @@ -1,6 +1,6 @@ //@aux-build:proc_macros.rs -#![allow(clippy::let_unit_value)] +#![allow(clippy::let_unit_value, clippy::needless_pass_by_ref_mut)] #![warn(clippy::unnecessary_safety_doc)] extern crate proc_macros; From 6a30b10f03a4cc18f062bbcd62a42bb7c9b528c7 Mon Sep 17 00:00:00 2001 From: bors Date: Fri, 3 Nov 2023 23:39:14 +0000 Subject: [PATCH 002/103] Auto merge of #11756 - y21:issue11755, r=Manishearth [`unused_enumerate_index`]: don't ICE on empty tuples Fixes #11755 changelog: [`unused_enumerate_index`]: don't ICE on empty tuples I'm going to nominate for beta backport because the code that is needed to trigger this seems likely to occur in real code `@rustbot` label +beta-nominated --- .../clippy/clippy_lints/src/loops/unused_enumerate_index.rs | 6 +++--- src/tools/clippy/tests/ui/crashes/ice-11755.rs | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 src/tools/clippy/tests/ui/crashes/ice-11755.rs diff --git a/src/tools/clippy/clippy_lints/src/loops/unused_enumerate_index.rs b/src/tools/clippy/clippy_lints/src/loops/unused_enumerate_index.rs index 62a2ab1ccb4c7..dd7fae79d9ba8 100644 --- a/src/tools/clippy/clippy_lints/src/loops/unused_enumerate_index.rs +++ b/src/tools/clippy/clippy_lints/src/loops/unused_enumerate_index.rs @@ -9,7 +9,7 @@ use rustc_middle::ty; /// Checks for the `UNUSED_ENUMERATE_INDEX` lint. pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, arg: &'tcx Expr<'_>, body: &'tcx Expr<'_>) { - let PatKind::Tuple(tuple, _) = pat.kind else { + let PatKind::Tuple([index, elem], _) = pat.kind else { return; }; @@ -19,7 +19,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, arg: &'tcx let ty = cx.typeck_results().expr_ty(arg); - if !pat_is_wild(cx, &tuple[0].kind, body) { + if !pat_is_wild(cx, &index.kind, body) { return; } @@ -53,7 +53,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, arg: &'tcx diag, "remove the `.enumerate()` call", vec![ - (pat.span, snippet(cx, tuple[1].span, "..").into_owned()), + (pat.span, snippet(cx, elem.span, "..").into_owned()), (arg.span, base_iter.to_string()), ], ); diff --git a/src/tools/clippy/tests/ui/crashes/ice-11755.rs b/src/tools/clippy/tests/ui/crashes/ice-11755.rs new file mode 100644 index 0000000000000..367cb69985786 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-11755.rs @@ -0,0 +1,5 @@ +#![warn(clippy::unused_enumerate_index)] + +fn main() { + for () in [()].iter() {} +} From 05f142fda74baed337b1f518b471eb019cdb6917 Mon Sep 17 00:00:00 2001 From: bors Date: Sun, 12 Nov 2023 22:15:43 +0000 Subject: [PATCH 003/103] Auto merge of #11760 - compiler-errors:escaping, r=Jarcho Don't check for late-bound vars, check for escaping bound vars Fixes an assertion that didn't make sense. Many valid and well-formed types *have* late-bound vars (e.g. `for<'a> fn(&'a ())`), they just must not have *escaping* late-bound vars in order to be normalized correctly. Addresses rust-lang/rust-clippy#11230, cc `@jyn514` and `@matthiaskrgr` changelog: don't check for late-bound vars, check for escaping bound vars. Addresses rust-lang/rust-clippy#11230 --- src/tools/clippy/clippy_utils/src/ty.rs | 14 ++++++++++++-- src/tools/clippy/tests/ui/crashes/ice-11230.rs | 6 ++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 src/tools/clippy/tests/ui/crashes/ice-11230.rs diff --git a/src/tools/clippy/clippy_utils/src/ty.rs b/src/tools/clippy/clippy_utils/src/ty.rs index 7eff93881b26e..842a206f96b35 100644 --- a/src/tools/clippy/clippy_utils/src/ty.rs +++ b/src/tools/clippy/clippy_utils/src/ty.rs @@ -1160,7 +1160,12 @@ pub fn make_normalized_projection<'tcx>( ) -> Option> { fn helper<'tcx>(tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: AliasTy<'tcx>) -> Option> { #[cfg(debug_assertions)] - if let Some((i, arg)) = ty.args.iter().enumerate().find(|(_, arg)| arg.has_late_bound_regions()) { + if let Some((i, arg)) = ty + .args + .iter() + .enumerate() + .find(|(_, arg)| arg.has_escaping_bound_vars()) + { debug_assert!( false, "args contain late-bound region at index `{i}` which can't be normalized.\n\ @@ -1233,7 +1238,12 @@ pub fn make_normalized_projection_with_regions<'tcx>( ) -> Option> { fn helper<'tcx>(tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: AliasTy<'tcx>) -> Option> { #[cfg(debug_assertions)] - if let Some((i, arg)) = ty.args.iter().enumerate().find(|(_, arg)| arg.has_late_bound_regions()) { + if let Some((i, arg)) = ty + .args + .iter() + .enumerate() + .find(|(_, arg)| arg.has_escaping_bound_vars()) + { debug_assert!( false, "args contain late-bound region at index `{i}` which can't be normalized.\n\ diff --git a/src/tools/clippy/tests/ui/crashes/ice-11230.rs b/src/tools/clippy/tests/ui/crashes/ice-11230.rs new file mode 100644 index 0000000000000..5761882273e00 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-11230.rs @@ -0,0 +1,6 @@ +/// Test for https://github.com/rust-lang/rust-clippy/issues/11230 + +fn main() { + const A: &[for<'a> fn(&'a ())] = &[]; + for v in A.iter() {} +} From 7a7673153dc21235d7917bfef9fbb14590e96087 Mon Sep 17 00:00:00 2001 From: bors Date: Wed, 13 Dec 2023 18:57:50 +0000 Subject: [PATCH 004/103] Auto merge of #11953 - Jarcho:issue_11952, r=Alexendoo Fix binder handling in `unnecessary_to_owned` fixes #11952 The use of `rebind` instead of `EarlyBinder::bind` isn't technically needed, but it is the semantically correct operation. changelog: None --- .../src/methods/unnecessary_to_owned.rs | 31 ++- .../tests/ui/unnecessary_to_owned.fixed | 23 ++- .../clippy/tests/ui/unnecessary_to_owned.rs | 23 ++- .../tests/ui/unnecessary_to_owned.stderr | 176 +++++++++--------- 4 files changed, 150 insertions(+), 103 deletions(-) diff --git a/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs b/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs index 772686d93dd7e..7a50feff68ef1 100644 --- a/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -15,8 +15,7 @@ use rustc_lint::LateContext; use rustc_middle::mir::Mutability; use rustc_middle::ty::adjustment::{Adjust, Adjustment, OverloadedDeref}; use rustc_middle::ty::{ - self, ClauseKind, EarlyBinder, GenericArg, GenericArgKind, GenericArgsRef, ParamTy, ProjectionPredicate, - TraitPredicate, Ty, + self, ClauseKind, GenericArg, GenericArgKind, GenericArgsRef, ParamTy, ProjectionPredicate, TraitPredicate, Ty, }; use rustc_span::{sym, Symbol}; use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _; @@ -375,6 +374,7 @@ fn get_input_traits_and_projections<'tcx>( (trait_predicates, projection_predicates) } +#[expect(clippy::too_many_lines)] fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<'a>) -> bool { for (_, node) in cx.tcx.hir().parent_iter(expr.hir_id) { match node { @@ -403,22 +403,21 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< if let Some((callee_def_id, call_generic_args, recv, call_args)) = get_callee_generic_args_and_args(cx, parent_expr) { - // FIXME: the `instantiate_identity()` below seems incorrect, since we eventually - // call `tcx.try_instantiate_and_normalize_erasing_regions` further down - // (i.e., we are explicitly not in the identity context). - let fn_sig = cx.tcx.fn_sig(callee_def_id).instantiate_identity().skip_binder(); + let bound_fn_sig = cx.tcx.fn_sig(callee_def_id); + let fn_sig = bound_fn_sig.skip_binder(); if let Some(arg_index) = recv.into_iter().chain(call_args).position(|arg| arg.hir_id == expr.hir_id) - && let Some(param_ty) = fn_sig.inputs().get(arg_index) - && let ty::Param(ParamTy { index: param_index , ..}) = param_ty.kind() + && let param_ty = fn_sig.input(arg_index).skip_binder() + && let ty::Param(ParamTy { index: param_index , ..}) = *param_ty.kind() // https://github.com/rust-lang/rust-clippy/issues/9504 and https://github.com/rust-lang/rust-clippy/issues/10021 - && (*param_index as usize) < call_generic_args.len() + && (param_index as usize) < call_generic_args.len() { if fn_sig + .skip_binder() .inputs() .iter() .enumerate() .filter(|(i, _)| *i != arg_index) - .any(|(_, ty)| ty.contains(*param_ty)) + .any(|(_, ty)| ty.contains(param_ty)) { return false; } @@ -430,7 +429,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< .iter() .filter(|predicate| { if let ClauseKind::Trait(trait_predicate) = predicate.kind().skip_binder() - && trait_predicate.trait_ref.self_ty() == *param_ty + && trait_predicate.trait_ref.self_ty() == param_ty { true } else { @@ -441,7 +440,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< let new_subst = cx .tcx .mk_args_from_iter(call_generic_args.iter().enumerate().map(|(i, t)| { - if i == (*param_index as usize) { + if i == param_index as usize { GenericArg::from(ty) } else { t @@ -449,7 +448,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< })); if trait_predicates.any(|predicate| { - let predicate = EarlyBinder::bind(predicate).instantiate(cx.tcx, new_subst); + let predicate = bound_fn_sig.rebind(predicate).instantiate(cx.tcx, new_subst); let obligation = Obligation::new(cx.tcx, ObligationCause::dummy(), cx.param_env, predicate); !cx.tcx .infer_ctxt() @@ -459,12 +458,12 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< return false; } - let output_ty = fn_sig.output(); - if output_ty.contains(*param_ty) { + let output_ty = cx.tcx.erase_late_bound_regions(fn_sig.output()); + if output_ty.contains(param_ty) { if let Ok(new_ty) = cx.tcx.try_instantiate_and_normalize_erasing_regions( new_subst, cx.param_env, - EarlyBinder::bind(output_ty), + bound_fn_sig.rebind(output_ty), ) { expr = parent_expr; ty = new_ty; diff --git a/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed b/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed index 67faabc53cb5e..2dd1d746626f3 100644 --- a/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed +++ b/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed @@ -1,4 +1,10 @@ -#![allow(clippy::needless_borrow, clippy::needless_borrows_for_generic_args, clippy::ptr_arg)] +#![allow( + clippy::needless_borrow, + clippy::needless_borrows_for_generic_args, + clippy::ptr_arg, + clippy::manual_async_fn, + clippy::needless_lifetimes +)] #![warn(clippy::unnecessary_to_owned, clippy::redundant_clone)] use std::borrow::Cow; @@ -506,3 +512,18 @@ mod issue_10033 { } } } + +mod issue_11952 { + use core::future::{Future, IntoFuture}; + + fn foo<'a, T: AsRef<[u8]>>(x: T, y: &'a i32) -> impl 'a + Future> { + async move { + let _y = y; + Ok(()) + } + } + + fn bar() { + IntoFuture::into_future(foo([], &0)); + } +} diff --git a/src/tools/clippy/tests/ui/unnecessary_to_owned.rs b/src/tools/clippy/tests/ui/unnecessary_to_owned.rs index 99f9136427d4d..17fad33402b58 100644 --- a/src/tools/clippy/tests/ui/unnecessary_to_owned.rs +++ b/src/tools/clippy/tests/ui/unnecessary_to_owned.rs @@ -1,4 +1,10 @@ -#![allow(clippy::needless_borrow, clippy::needless_borrows_for_generic_args, clippy::ptr_arg)] +#![allow( + clippy::needless_borrow, + clippy::needless_borrows_for_generic_args, + clippy::ptr_arg, + clippy::manual_async_fn, + clippy::needless_lifetimes +)] #![warn(clippy::unnecessary_to_owned, clippy::redundant_clone)] use std::borrow::Cow; @@ -506,3 +512,18 @@ mod issue_10033 { } } } + +mod issue_11952 { + use core::future::{Future, IntoFuture}; + + fn foo<'a, T: AsRef<[u8]>>(x: T, y: &'a i32) -> impl 'a + Future> { + async move { + let _y = y; + Ok(()) + } + } + + fn bar() { + IntoFuture::into_future(foo([].to_vec(), &0)); + } +} diff --git a/src/tools/clippy/tests/ui/unnecessary_to_owned.stderr b/src/tools/clippy/tests/ui/unnecessary_to_owned.stderr index d8971b51dcadd..ad6fa422b8cd2 100644 --- a/src/tools/clippy/tests/ui/unnecessary_to_owned.stderr +++ b/src/tools/clippy/tests/ui/unnecessary_to_owned.stderr @@ -1,11 +1,11 @@ error: redundant clone - --> $DIR/unnecessary_to_owned.rs:148:64 + --> $DIR/unnecessary_to_owned.rs:154:64 | LL | require_c_str(&CString::from_vec_with_nul(vec![0]).unwrap().to_owned()); | ^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/unnecessary_to_owned.rs:148:20 + --> $DIR/unnecessary_to_owned.rs:154:20 | LL | require_c_str(&CString::from_vec_with_nul(vec![0]).unwrap().to_owned()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,55 +13,55 @@ LL | require_c_str(&CString::from_vec_with_nul(vec![0]).unwrap().to_owned()) = help: to override `-D warnings` add `#[allow(clippy::redundant_clone)]` error: redundant clone - --> $DIR/unnecessary_to_owned.rs:149:40 + --> $DIR/unnecessary_to_owned.rs:155:40 | LL | require_os_str(&OsString::from("x").to_os_string()); | ^^^^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/unnecessary_to_owned.rs:149:21 + --> $DIR/unnecessary_to_owned.rs:155:21 | LL | require_os_str(&OsString::from("x").to_os_string()); | ^^^^^^^^^^^^^^^^^^^ error: redundant clone - --> $DIR/unnecessary_to_owned.rs:150:48 + --> $DIR/unnecessary_to_owned.rs:156:48 | LL | require_path(&std::path::PathBuf::from("x").to_path_buf()); | ^^^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/unnecessary_to_owned.rs:150:19 + --> $DIR/unnecessary_to_owned.rs:156:19 | LL | require_path(&std::path::PathBuf::from("x").to_path_buf()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant clone - --> $DIR/unnecessary_to_owned.rs:151:35 + --> $DIR/unnecessary_to_owned.rs:157:35 | LL | require_str(&String::from("x").to_string()); | ^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/unnecessary_to_owned.rs:151:18 + --> $DIR/unnecessary_to_owned.rs:157:18 | LL | require_str(&String::from("x").to_string()); | ^^^^^^^^^^^^^^^^^ error: redundant clone - --> $DIR/unnecessary_to_owned.rs:152:39 + --> $DIR/unnecessary_to_owned.rs:158:39 | LL | require_slice(&[String::from("x")].to_owned()); | ^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/unnecessary_to_owned.rs:152:20 + --> $DIR/unnecessary_to_owned.rs:158:20 | LL | require_slice(&[String::from("x")].to_owned()); | ^^^^^^^^^^^^^^^^^^^ error: unnecessary use of `into_owned` - --> $DIR/unnecessary_to_owned.rs:57:36 + --> $DIR/unnecessary_to_owned.rs:63:36 | LL | require_c_str(&Cow::from(c_str).into_owned()); | ^^^^^^^^^^^^^ help: remove this @@ -70,415 +70,415 @@ LL | require_c_str(&Cow::from(c_str).into_owned()); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_to_owned)]` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:58:19 + --> $DIR/unnecessary_to_owned.rs:64:19 | LL | require_c_str(&c_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_os_string` - --> $DIR/unnecessary_to_owned.rs:60:20 + --> $DIR/unnecessary_to_owned.rs:66:20 | LL | require_os_str(&os_str.to_os_string()); | ^^^^^^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `into_owned` - --> $DIR/unnecessary_to_owned.rs:61:38 + --> $DIR/unnecessary_to_owned.rs:67:38 | LL | require_os_str(&Cow::from(os_str).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:62:20 + --> $DIR/unnecessary_to_owned.rs:68:20 | LL | require_os_str(&os_str.to_owned()); | ^^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_path_buf` - --> $DIR/unnecessary_to_owned.rs:64:18 + --> $DIR/unnecessary_to_owned.rs:70:18 | LL | require_path(&path.to_path_buf()); | ^^^^^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `into_owned` - --> $DIR/unnecessary_to_owned.rs:65:34 + --> $DIR/unnecessary_to_owned.rs:71:34 | LL | require_path(&Cow::from(path).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:66:18 + --> $DIR/unnecessary_to_owned.rs:72:18 | LL | require_path(&path.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_string` - --> $DIR/unnecessary_to_owned.rs:68:17 + --> $DIR/unnecessary_to_owned.rs:74:17 | LL | require_str(&s.to_string()); | ^^^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `into_owned` - --> $DIR/unnecessary_to_owned.rs:69:30 + --> $DIR/unnecessary_to_owned.rs:75:30 | LL | require_str(&Cow::from(s).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:70:17 + --> $DIR/unnecessary_to_owned.rs:76:17 | LL | require_str(&s.to_owned()); | ^^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_string` - --> $DIR/unnecessary_to_owned.rs:71:17 + --> $DIR/unnecessary_to_owned.rs:77:17 | LL | require_str(&x_ref.to_string()); | ^^^^^^^^^^^^^^^^^^ help: use: `x_ref.as_ref()` error: unnecessary use of `to_vec` - --> $DIR/unnecessary_to_owned.rs:73:19 + --> $DIR/unnecessary_to_owned.rs:79:19 | LL | require_slice(&slice.to_vec()); | ^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `into_owned` - --> $DIR/unnecessary_to_owned.rs:74:36 + --> $DIR/unnecessary_to_owned.rs:80:36 | LL | require_slice(&Cow::from(slice).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:75:19 + --> $DIR/unnecessary_to_owned.rs:81:19 | LL | require_slice(&array.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `array.as_ref()` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:76:19 + --> $DIR/unnecessary_to_owned.rs:82:19 | LL | require_slice(&array_ref.to_owned()); | ^^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref.as_ref()` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:77:19 + --> $DIR/unnecessary_to_owned.rs:83:19 | LL | require_slice(&slice.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `into_owned` - --> $DIR/unnecessary_to_owned.rs:80:42 + --> $DIR/unnecessary_to_owned.rs:86:42 | LL | require_x(&Cow::::Owned(x.clone()).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:83:25 + --> $DIR/unnecessary_to_owned.rs:89:25 | LL | require_deref_c_str(c_str.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:84:26 + --> $DIR/unnecessary_to_owned.rs:90:26 | LL | require_deref_os_str(os_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:85:24 + --> $DIR/unnecessary_to_owned.rs:91:24 | LL | require_deref_path(path.to_owned()); | ^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:86:23 + --> $DIR/unnecessary_to_owned.rs:92:23 | LL | require_deref_str(s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:87:25 + --> $DIR/unnecessary_to_owned.rs:93:25 | LL | require_deref_slice(slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:89:30 + --> $DIR/unnecessary_to_owned.rs:95:30 | LL | require_impl_deref_c_str(c_str.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:90:31 + --> $DIR/unnecessary_to_owned.rs:96:31 | LL | require_impl_deref_os_str(os_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:91:29 + --> $DIR/unnecessary_to_owned.rs:97:29 | LL | require_impl_deref_path(path.to_owned()); | ^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:92:28 + --> $DIR/unnecessary_to_owned.rs:98:28 | LL | require_impl_deref_str(s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:93:30 + --> $DIR/unnecessary_to_owned.rs:99:30 | LL | require_impl_deref_slice(slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:95:29 + --> $DIR/unnecessary_to_owned.rs:101:29 | LL | require_deref_str_slice(s.to_owned(), slice.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:95:43 + --> $DIR/unnecessary_to_owned.rs:101:43 | LL | require_deref_str_slice(s.to_owned(), slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:96:29 + --> $DIR/unnecessary_to_owned.rs:102:29 | LL | require_deref_slice_str(slice.to_owned(), s.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:96:47 + --> $DIR/unnecessary_to_owned.rs:102:47 | LL | require_deref_slice_str(slice.to_owned(), s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:98:26 + --> $DIR/unnecessary_to_owned.rs:104:26 | LL | require_as_ref_c_str(c_str.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:99:27 + --> $DIR/unnecessary_to_owned.rs:105:27 | LL | require_as_ref_os_str(os_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:100:25 + --> $DIR/unnecessary_to_owned.rs:106:25 | LL | require_as_ref_path(path.to_owned()); | ^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:101:24 + --> $DIR/unnecessary_to_owned.rs:107:24 | LL | require_as_ref_str(s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:102:24 + --> $DIR/unnecessary_to_owned.rs:108:24 | LL | require_as_ref_str(x.to_owned()); | ^^^^^^^^^^^^ help: use: `&x` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:103:26 + --> $DIR/unnecessary_to_owned.rs:109:26 | LL | require_as_ref_slice(array.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `array` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:104:26 + --> $DIR/unnecessary_to_owned.rs:110:26 | LL | require_as_ref_slice(array_ref.to_owned()); | ^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:105:26 + --> $DIR/unnecessary_to_owned.rs:111:26 | LL | require_as_ref_slice(slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:107:31 + --> $DIR/unnecessary_to_owned.rs:113:31 | LL | require_impl_as_ref_c_str(c_str.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:108:32 + --> $DIR/unnecessary_to_owned.rs:114:32 | LL | require_impl_as_ref_os_str(os_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:109:30 + --> $DIR/unnecessary_to_owned.rs:115:30 | LL | require_impl_as_ref_path(path.to_owned()); | ^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:110:29 + --> $DIR/unnecessary_to_owned.rs:116:29 | LL | require_impl_as_ref_str(s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:111:29 + --> $DIR/unnecessary_to_owned.rs:117:29 | LL | require_impl_as_ref_str(x.to_owned()); | ^^^^^^^^^^^^ help: use: `&x` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:112:31 + --> $DIR/unnecessary_to_owned.rs:118:31 | LL | require_impl_as_ref_slice(array.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `array` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:113:31 + --> $DIR/unnecessary_to_owned.rs:119:31 | LL | require_impl_as_ref_slice(array_ref.to_owned()); | ^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:114:31 + --> $DIR/unnecessary_to_owned.rs:120:31 | LL | require_impl_as_ref_slice(slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:116:30 + --> $DIR/unnecessary_to_owned.rs:122:30 | LL | require_as_ref_str_slice(s.to_owned(), array.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:116:44 + --> $DIR/unnecessary_to_owned.rs:122:44 | LL | require_as_ref_str_slice(s.to_owned(), array.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `array` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:117:30 + --> $DIR/unnecessary_to_owned.rs:123:30 | LL | require_as_ref_str_slice(s.to_owned(), array_ref.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:117:44 + --> $DIR/unnecessary_to_owned.rs:123:44 | LL | require_as_ref_str_slice(s.to_owned(), array_ref.to_owned()); | ^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:118:30 + --> $DIR/unnecessary_to_owned.rs:124:30 | LL | require_as_ref_str_slice(s.to_owned(), slice.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:118:44 + --> $DIR/unnecessary_to_owned.rs:124:44 | LL | require_as_ref_str_slice(s.to_owned(), slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:119:30 + --> $DIR/unnecessary_to_owned.rs:125:30 | LL | require_as_ref_slice_str(array.to_owned(), s.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `array` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:119:48 + --> $DIR/unnecessary_to_owned.rs:125:48 | LL | require_as_ref_slice_str(array.to_owned(), s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:120:30 + --> $DIR/unnecessary_to_owned.rs:126:30 | LL | require_as_ref_slice_str(array_ref.to_owned(), s.to_owned()); | ^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:120:52 + --> $DIR/unnecessary_to_owned.rs:126:52 | LL | require_as_ref_slice_str(array_ref.to_owned(), s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:121:30 + --> $DIR/unnecessary_to_owned.rs:127:30 | LL | require_as_ref_slice_str(slice.to_owned(), s.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:121:48 + --> $DIR/unnecessary_to_owned.rs:127:48 | LL | require_as_ref_slice_str(slice.to_owned(), s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_string` - --> $DIR/unnecessary_to_owned.rs:123:20 + --> $DIR/unnecessary_to_owned.rs:129:20 | LL | let _ = x.join(&x_ref.to_string()); | ^^^^^^^^^^^^^^^^^^ help: use: `x_ref` error: unnecessary use of `to_vec` - --> $DIR/unnecessary_to_owned.rs:125:13 + --> $DIR/unnecessary_to_owned.rs:131:13 | LL | let _ = slice.to_vec().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:126:13 + --> $DIR/unnecessary_to_owned.rs:132:13 | LL | let _ = slice.to_owned().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()` error: unnecessary use of `to_vec` - --> $DIR/unnecessary_to_owned.rs:127:13 + --> $DIR/unnecessary_to_owned.rs:133:13 | LL | let _ = [std::path::PathBuf::new()][..].to_vec().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[std::path::PathBuf::new()][..].iter().cloned()` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:128:13 + --> $DIR/unnecessary_to_owned.rs:134:13 | LL | let _ = [std::path::PathBuf::new()][..].to_owned().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[std::path::PathBuf::new()][..].iter().cloned()` error: unnecessary use of `to_vec` - --> $DIR/unnecessary_to_owned.rs:130:13 + --> $DIR/unnecessary_to_owned.rs:136:13 | LL | let _ = IntoIterator::into_iter(slice.to_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:131:13 + --> $DIR/unnecessary_to_owned.rs:137:13 | LL | let _ = IntoIterator::into_iter(slice.to_owned()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()` error: unnecessary use of `to_vec` - --> $DIR/unnecessary_to_owned.rs:132:13 + --> $DIR/unnecessary_to_owned.rs:138:13 | LL | let _ = IntoIterator::into_iter([std::path::PathBuf::new()][..].to_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[std::path::PathBuf::new()][..].iter().cloned()` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:133:13 + --> $DIR/unnecessary_to_owned.rs:139:13 | LL | let _ = IntoIterator::into_iter([std::path::PathBuf::new()][..].to_owned()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[std::path::PathBuf::new()][..].iter().cloned()` error: unnecessary use of `to_vec` - --> $DIR/unnecessary_to_owned.rs:195:14 + --> $DIR/unnecessary_to_owned.rs:201:14 | LL | for t in file_types.to_vec() { | ^^^^^^^^^^^^^^^^^^^ @@ -494,28 +494,34 @@ LL + let path = match get_file_path(t) { | error: unnecessary use of `to_vec` - --> $DIR/unnecessary_to_owned.rs:218:14 + --> $DIR/unnecessary_to_owned.rs:224:14 | LL | let _ = &["x"][..].to_vec().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `["x"][..].iter().cloned()` error: unnecessary use of `to_vec` - --> $DIR/unnecessary_to_owned.rs:223:14 + --> $DIR/unnecessary_to_owned.rs:229:14 | LL | let _ = &["x"][..].to_vec().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `["x"][..].iter().copied()` error: unnecessary use of `to_string` - --> $DIR/unnecessary_to_owned.rs:270:24 + --> $DIR/unnecessary_to_owned.rs:276:24 | LL | Box::new(build(y.to_string())) | ^^^^^^^^^^^^^ help: use: `y` error: unnecessary use of `to_string` - --> $DIR/unnecessary_to_owned.rs:378:12 + --> $DIR/unnecessary_to_owned.rs:384:12 | LL | id("abc".to_string()) | ^^^^^^^^^^^^^^^^^ help: use: `"abc"` -error: aborting due to 79 previous errors +error: unnecessary use of `to_vec` + --> $DIR/unnecessary_to_owned.rs:527:37 + | +LL | IntoFuture::into_future(foo([].to_vec(), &0)); + | ^^^^^^^^^^^ help: use: `[]` + +error: aborting due to 80 previous errors From 56d4e57be443a1d58d1483504a63fa9088cb7b69 Mon Sep 17 00:00:00 2001 From: Jack May Date: Wed, 13 Feb 2019 15:37:57 -0800 Subject: [PATCH 005/103] [SOL] Use Solana's LLVM fork --- .gitmodules | 4 ++-- src/llvm-project | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index 9bb68b37081f5..716ccb5c8c8af 100644 --- a/.gitmodules +++ b/.gitmodules @@ -32,8 +32,8 @@ shallow = true [submodule "src/llvm-project"] path = src/llvm-project - url = https://github.com/rust-lang/llvm-project.git - branch = rustc/17.0-2023-12-14 + url = https://github.com/solana-labs/llvm-project.git + branch = solana-rustc/17.0-2023-12-14 shallow = true [submodule "src/doc/embedded-book"] path = src/doc/embedded-book diff --git a/src/llvm-project b/src/llvm-project index 2c4de6c2492d5..741642838f9c1 160000 --- a/src/llvm-project +++ b/src/llvm-project @@ -1 +1 @@ -Subproject commit 2c4de6c2492d5530de3f19f41d8f88ba984c2fe2 +Subproject commit 741642838f9c1df60956a0d2fd9810d5638dddba From 1a0feafa1a0a9d197eb5fc49436f341dc3ba3504 Mon Sep 17 00:00:00 2001 From: Jack May Date: Wed, 13 Feb 2019 15:38:43 -0800 Subject: [PATCH 006/103] [SOL] Enable LLVM backend --- compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp index 31565db1b7929..36b61bcbbf4fe 100644 --- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp @@ -163,6 +163,12 @@ extern "C" void LLVMTimeTraceProfilerFinish(const char* FileName) { #define SUBTARGET_LOONGARCH #endif +#ifdef LLVM_COMPONENT_BPF +#define SUBTARGET_BPF SUBTARGET(BPF) +#else +#define SUBTARGET_BPF +#endif + #define GEN_SUBTARGETS \ SUBTARGET_X86 \ SUBTARGET_ARM \ @@ -178,6 +184,7 @@ extern "C" void LLVMTimeTraceProfilerFinish(const char* FileName) { SUBTARGET_HEXAGON \ SUBTARGET_RISCV \ SUBTARGET_LOONGARCH \ + SUBTARGET_BPF \ #define SUBTARGET(x) \ namespace llvm { \ From e401ce78859b9d8e131ed95dc333482e1280c84c Mon Sep 17 00:00:00 2001 From: Jack May Date: Thu, 14 Feb 2019 09:17:13 -0800 Subject: [PATCH 007/103] [SOL] Implement C abi modifier --- compiler/rustc_target/src/abi/call/bpf.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_target/src/abi/call/bpf.rs b/compiler/rustc_target/src/abi/call/bpf.rs index 780e7df438373..fe2757b0a56e7 100644 --- a/compiler/rustc_target/src/abi/call/bpf.rs +++ b/compiler/rustc_target/src/abi/call/bpf.rs @@ -5,7 +5,7 @@ fn classify_ret(ret: &mut ArgAbi<'_, Ty>) { if ret.layout.is_aggregate() || ret.layout.size.bits() > 64 { ret.make_indirect(); } else { - ret.extend_integer_width_to(32); + ret.extend_integer_width_to(64); } } @@ -13,7 +13,7 @@ fn classify_arg(arg: &mut ArgAbi<'_, Ty>) { if arg.layout.is_aggregate() || arg.layout.size.bits() > 64 { arg.make_indirect(); } else { - arg.extend_integer_width_to(32); + arg.extend_integer_width_to(64); } } From a313218a8b65fd4e786686c55aa94173be582130 Mon Sep 17 00:00:00 2001 From: Jack May Date: Thu, 14 Feb 2019 09:18:13 -0800 Subject: [PATCH 008/103] [SOL] Add custom build configuration --- .gitignore | 1 - config.toml | 521 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 521 insertions(+), 1 deletion(-) create mode 100644 config.toml diff --git a/.gitignore b/.gitignore index 485968d9c56ff..1e81f0de3b287 100644 --- a/.gitignore +++ b/.gitignore @@ -30,7 +30,6 @@ Session.vim !/tests/run-make/thumb-none-qemu/example/.cargo ## Configuration -/config.toml /Makefile config.mk config.stamp diff --git a/config.toml b/config.toml new file mode 100644 index 0000000000000..8fbf1afe5f7f7 --- /dev/null +++ b/config.toml @@ -0,0 +1,521 @@ +# Sample TOML configuration file for building Rust. +# +# To configure rustbuild, copy this file to the directory from which you will be +# running the build, and name it config.toml. +# +# All options are commented out by default in this file, and they're commented +# out with their default values. The build system by default looks for +# `config.toml` in the current directory of a build for build configuration, but +# a custom configuration file can also be specified with `--config` to the build +# system. + +# ============================================================================= +# Tweaking how LLVM is compiled +# ============================================================================= +[llvm] + +# Indicates whether rustc will support compilation with LLVM +# note: rustc does not compile without LLVM at the moment +#enabled = true + +# Indicates whether the LLVM build is a Release or Debug build +#optimize = true + +# Indicates whether LLVM should be built with ThinLTO. Note that this will +# only succeed if you use clang, lld, llvm-ar, and llvm-ranlib in your C/C++ +# toolchain (see the `cc`, `cxx`, `linker`, `ar`, and `ranlib` options below). +# More info at: https://clang.llvm.org/docs/ThinLTO.html#clang-bootstrap +#thin-lto = false + +# Indicates whether an LLVM Release build should include debug info +release-debuginfo = true + +# Indicates whether the LLVM assertions are enabled or not +assertions = true + +# Indicates whether ccache is used when building LLVM +#ccache = false +# or alternatively ... +#ccache = "/path/to/ccache" + +# If an external LLVM root is specified, we automatically check the version by +# default to make sure it's within the range that we're expecting, but setting +# this flag will indicate that this version check should not be done. +#version-check = true + +# Link libstdc++ statically into the librustc_llvm instead of relying on a +# dynamic version to be available. +#static-libstdcpp = false + +# Tell the LLVM build system to use Ninja instead of the platform default for +# the generated build system. This can sometimes be faster than make, for +# example. +#ninja = false + +# LLVM targets to build support for. +# Note: this is NOT related to Rust compilation targets. However, as Rust is +# dependent on LLVM for code generation, turning targets off here WILL lead to +# the resulting rustc being unable to compile for the disabled architectures. +# Also worth pointing out is that, in case support for new targets are added to +# LLVM, enabling them here doesn't mean Rust is automatically gaining said +# support. You'll need to write a target specification at least, and most +# likely, teach rustc about the C ABI of the target. Get in touch with the +# Rust team and file an issue if you need assistance in porting! +#targets = "X86;ARM;AArch64;Mips;PowerPC;SystemZ;JSBackend;MSP430;Sparc;NVPTX;Hexagon" + +# LLVM experimental targets to build support for. These targets are specified in +# the same format as above, but since these targets are experimental, they are +# not built by default and the experimental Rust compilation targets that depend +# on them will not work unless the user opts in to building them. By default the +# `WebAssembly` and `RISCV` targets are enabled when compiling LLVM from scratch. +experimental-targets = "WebAssembly;BPF" + +# Cap the number of parallel linker invocations when compiling LLVM. +# This can be useful when building LLVM with debug info, which significantly +# increases the size of binaries and consequently the memory required by +# each linker process. +# If absent or 0, linker invocations are treated like any other job and +# controlled by rustbuild's -j parameter. +#link-jobs = 0 + +# When invoking `llvm-config` this configures whether the `--shared` argument is +# passed to prefer linking to shared libraries. +#link-shared = false + +# When building llvm, this configures what is being appended to the version. +# If absent, we let the version as-is. +#version-suffix = "-rust" + +# On MSVC you can compile LLVM with clang-cl, but the test suite doesn't pass +# with clang-cl, so this is special in that it only compiles LLVM with clang-cl +#clang-cl = '/path/to/clang-cl.exe' + +# Pass extra compiler and linker flags to the LLVM CMake build. +#cflags = "-fextra-flag" +#cxxflags = "-fextra-flag" +#ldflags = "-Wl,extra-flag" + +# Use libc++ when building LLVM instead of libstdc++. This is the default on +# platforms already use libc++ as the default C++ library, but this option +# allows you to use libc++ even on platforms when it's not. You need to ensure +# that your host compiler ships with libc++. +#use-libcxx = true + +# The value specified here will be passed as `-DLLVM_USE_LINKER` to CMake. +#use-linker = "lld" + + +# ============================================================================= +# General build configuration options +# ============================================================================= +[build] + +# Build triple for the original snapshot compiler. This must be a compiler that +# nightlies are already produced for. The current platform must be able to run +# binaries of this build triple and the nightly will be used to bootstrap the +# first compiler. +#build = "x86_64-unknown-linux-gnu" # defaults to your host platform + +# In addition to the build triple, other triples to produce full compiler +# toolchains for. Each of these triples will be bootstrapped from the build +# triple and then will continue to bootstrap themselves. This platform must +# currently be able to run all of the triples provided here. +#host = ["x86_64-unknown-linux-gnu"] # defaults to just the build triple + +# In addition to all host triples, other triples to produce the standard library +# for. Each host triple will be used to produce a copy of the standard library +# for each target triple. +#target = ["x86_64-unknown-linux-gnu"] # defaults to just the build triple + +# Instead of downloading the src/stage0.txt version of Cargo specified, use +# this Cargo binary instead to build all Rust code +#cargo = "/path/to/bin/cargo" + +# Instead of downloading the src/stage0.txt version of the compiler +# specified, use this rustc binary instead as the stage0 snapshot compiler. +#rustc = "/path/to/bin/rustc" + +# Flag to specify whether any documentation is built. If false, rustdoc and +# friends will still be compiled but they will not be used to generate any +# documentation. +docs = false + +# Indicate whether the compiler should be documented in addition to the standard +# library and facade crates. +#compiler-docs = false + +# Indicate whether submodules are managed and updated automatically. +#submodules = true + +# Update submodules only when the checked out commit in the submodules differs +# from what is committed in the main rustc repo. +#fast-submodules = true + +# The path to (or name of) the GDB executable to use. This is only used for +# executing the debuginfo test suite. +#gdb = "gdb" + +# The node.js executable to use. Note that this is only used for the emscripten +# target when running tests, otherwise this can be omitted. +#nodejs = "node" + +# Python interpreter to use for various tasks throughout the build, notably +# rustdoc tests, the lldb python interpreter, and some dist bits and pieces. +# Note that Python 2 is currently required. +#python = "python2.7" + +# Force Cargo to check that Cargo.lock describes the precise dependency +# set that all the Cargo.toml files create, instead of updating it. +#locked-deps = false + +# Indicate whether the vendored sources are used for Rust dependencies or not +#vendor = false + +# Typically the build system will build the rust compiler twice. The second +# compiler, however, will simply use its own libraries to link against. If you +# would rather to perform a full bootstrap, compiling the compiler three times, +# then you can set this option to true. You shouldn't ever need to set this +# option to true. +#full-bootstrap = false + +# Enable a build of the extended rust tool set which is not only the compiler +# but also tools such as Cargo. This will also produce "combined installers" +# which are used to install Rust and Cargo together. This is disabled by +# default. +#extended = false + +# Installs chosen set of extended tools if enables. By default builds all. +# If chosen tool failed to build the installation fails. +#tools = ["cargo", "rls", "clippy", "rustfmt", "analysis", "src"] + +# Verbosity level: 0 == not verbose, 1 == verbose, 2 == very verbose +#verbose = 0 + +# Build the sanitizer runtimes +#sanitizers = false + +# Build the profiler runtime +#profiler = false + +# Indicates whether the native libraries linked into Cargo will be statically +# linked or not. +#cargo-native-static = false + +# Run the build with low priority, by setting the process group's "nice" value +# to +10 on Unix platforms, and by using a "low priority" job object on Windows. +#low-priority = false + +# Arguments passed to the `./configure` script, used during distcheck. You +# probably won't fill this in but rather it's filled in by the `./configure` +# script. +#configure-args = [] + +# Indicates that a local rebuild is occurring instead of a full bootstrap, +# essentially skipping stage0 as the local compiler is recompiling itself again. +#local-rebuild = false + +# Print out how long each rustbuild step took (mostly intended for CI and +# tracking over time) +#print-step-timings = false + +# ============================================================================= +# General install configuration options +# ============================================================================= +[install] + +# Instead of installing to /usr/local, install to this path instead. +prefix = "opt/bpf-rust" + +# Where to install system configuration files +# If this is a relative path, it will get installed in `prefix` above +#sysconfdir = "/etc" + +# Where to install documentation in `prefix` above +#docdir = "share/doc/rust" + +# Where to install binaries in `prefix` above +#bindir = "bin" + +# Where to install libraries in `prefix` above +#libdir = "lib" + +# Where to install man pages in `prefix` above +#mandir = "share/man" + +# Where to install data in `prefix` above (currently unused) +#datadir = "share" + +# Where to install additional info in `prefix` above (currently unused) +#infodir = "share/info" + +# Where to install local state (currently unused) +# If this is a relative path, it will get installed in `prefix` above +#localstatedir = "/var/lib" + +# ============================================================================= +# Options for compiling Rust code itself +# ============================================================================= +[rust] + +# Whether or not to optimize the compiler and standard library. +# +# Note: the slowness of the non optimized compiler compiling itself usually +# outweighs the time gains in not doing optimizations, therefore a +# full bootstrap takes much more time with `optimize` set to false. +optimize = true + +# Indicates that the build should be configured for debugging Rust. A +# `debug`-enabled compiler and standard library will be somewhat +# slower (due to e.g. checking of debug assertions) but should remain +# usable. +# +# Note: If this value is set to `true`, it will affect a number of +# configuration options below as well, if they have been left +# unconfigured in this file. +# +# Note: changes to the `debug` setting do *not* affect `optimize` +# above. In theory, a "maximally debuggable" environment would +# set `optimize` to `false` above to assist the introspection +# facilities of debuggers like lldb and gdb. To recreate such an +# environment, explicitly set `optimize` to `false` and `debug` +# to `true`. In practice, everyone leaves `optimize` set to +# `true`, because an unoptimized rustc with debugging +# enabled becomes *unusably slow* (e.g. rust-lang/rust#24840 +# reported a 25x slowdown) and bootstrapping the supposed +# "maximally debuggable" environment (notably libstd) takes +# hours to build. +# +debug = true + +# Number of codegen units to use for each compiler invocation. A value of 0 +# means "the number of cores on this machine", and 1+ is passed through to the +# compiler. +#codegen-units = 1 + +# Sets the number of codegen units to build the standard library with, +# regardless of what the codegen-unit setting for the rest of the compiler is. +#codegen-units-std = 1 + +# Whether or not debug assertions are enabled for the compiler and standard +# library. +debug-assertions = true + +# Whether or not debuginfo is emitted +#debuginfo = false + +# Whether or not line number debug information is emitted +#debuginfo-lines = false + +# Whether or not to only build debuginfo for the standard library if enabled. +# If enabled, this will not compile the compiler with debuginfo, just the +# standard library. +#debuginfo-only-std = false + +# Enable debuginfo for the extended tools: cargo, rls, rustfmt +# Adding debuginfo makes them several times larger. +#debuginfo-tools = false + +# Whether or not `panic!`s generate backtraces (RUST_BACKTRACE) +#backtrace = true + +# Whether to always use incremental compilation when building rustc +#incremental = false + +# Build a multi-threaded rustc +#parallel-compiler = false + +# The default linker that will be hard-coded into the generated compiler for +# targets that don't specify linker explicitly in their target specifications. +# Note that this is not the linker used to link said compiler. +#default-linker = "cc" + +# The "channel" for the Rust build to produce. The stable/beta channels only +# allow using stable features, whereas the nightly and dev channels allow using +# nightly features +#channel = "dev" + +# By default the `rustc` executable is built with `-Wl,-rpath` flags on Unix +# platforms to ensure that the compiler is usable by default from the build +# directory (as it links to a number of dynamic libraries). This may not be +# desired in distributions, for example. +#rpath = true + +# Emits extraneous output from tests to ensure that failures of the test +# harness are debuggable just from logfiles. +#verbose-tests = false + +# Flag indicating whether tests are compiled with optimizations (the -O flag) or +# with debuginfo (the -g flag) +#optimize-tests = true +#debuginfo-tests = true + +# Flag indicating whether codegen tests will be run or not. If you get an error +# saying that the FileCheck executable is missing, you may want to disable this. +# Also see the target's llvm-filecheck option. +#codegen-tests = true + +# Flag indicating whether git info will be retrieved from .git automatically. +# Having the git information can cause a lot of rebuilds during development. +# Note: If this attribute is not explicitly set (e.g. if left commented out) it +# will default to true if channel = "dev", but will default to false otherwise. +#ignore-git = true + +# When creating source tarballs whether or not to create a source tarball. +#dist-src = false + +# Whether to also run the Miri tests suite when running tests. +# As a side-effect also generates MIR for all libraries. +#test-miri = false + +# After building or testing extended tools (e.g. clippy and rustfmt), append the +# result (broken, compiling, testing) into this JSON file. +#save-toolstates = "/path/to/toolstates.json" + +# This is an array of the codegen backends that will be compiled for the rustc +# that's being compiled. The default is to only build the LLVM codegen backend, +# but you can also optionally enable the "emscripten" backend for asm.js or +# make this an empty array (but that probably won't get too far in the +# bootstrap) +#codegen-backends = ["llvm"] + +# This is the name of the directory in which codegen backends will get installed +#codegen-backends-dir = "codegen-backends" + +# Flag indicating whether `libstd` calls an imported function to handle basic IO +# when targeting WebAssembly. Enable this to debug tests for the `wasm32-unknown-unknown` +# target, as without this option the test output will not be captured. +#wasm-syscall = false + +# Indicates whether LLD will be compiled and made available in the sysroot for +# rustc to execute. +#lld = false + +# Indicates whether some LLVM tools, like llvm-objdump, will be made available in the +# sysroot. +#llvm-tools = false + +# Indicates whether LLDB will be made available in the sysroot. +# This is only built if LLVM is also being built. +#lldb = false + +# Whether to deny warnings in crates +#deny-warnings = true + +# Print backtrace on internal compiler errors during bootstrap +#backtrace-on-ice = false + +# Whether to verify generated LLVM IR +#verify-llvm-ir = false + +# Map all debuginfo paths for libstd and crates to `/rust/$sha/$crate/...`, +# generally only set for releases +#remap-debuginfo = false + +# Link the compiler against `jemalloc`, where on Linux and OSX it should +# override the default allocator for rustc and LLVM. +#jemalloc = false + +# Run tests in various test suites with the "nll compare mode" in addition to +# running the tests in normal mode. Largely only used on CI and during local +# development of NLL +#test-compare-mode = false + +# ============================================================================= +# Options for specific targets +# +# Each of the following options is scoped to the specific target triple in +# question and is used for determining how to compile each target. +# ============================================================================= +[target.x86_64-unknown-linux-gnu] + +# C compiler to be used to compiler C code. Note that the +# default value is platform specific, and if not specified it may also depend on +# what platform is crossing to what platform. +#cc = "cc" + +# C++ compiler to be used to compiler C++ code (e.g. LLVM and our LLVM shims). +# This is only used for host targets. +#cxx = "c++" + +# Archiver to be used to assemble static libraries compiled from C/C++ code. +# Note: an absolute path should be used, otherwise LLVM build will break. +#ar = "ar" + +# Ranlib to be used to assemble static libraries compiled from C/C++ code. +# Note: an absolute path should be used, otherwise LLVM build will break. +#ranlib = "ranlib" + +# Linker to be used to link Rust code. Note that the +# default value is platform specific, and if not specified it may also depend on +# what platform is crossing to what platform. +#linker = "cc" + +# Path to the `llvm-config` binary of the installation of a custom LLVM to link +# against. Note that if this is specified we don't compile LLVM at all for this +# target. +#llvm-config = "../path/to/llvm/root/bin/llvm-config" + +# Normally the build system can find LLVM's FileCheck utility, but if +# not, you can specify an explicit file name for it. +#llvm-filecheck = "/path/to/FileCheck" + +# If this target is for Android, this option will be required to specify where +# the NDK for the target lives. This is used to find the C compiler to link and +# build native code. +#android-ndk = "/path/to/ndk" + +# Force static or dynamic linkage of the standard library for this target. If +# this target is a host for rustc, this will also affect the linkage of the +# compiler itself. This is useful for building rustc on targets that normally +# only use static libraries. If unset, the target's default linkage is used. +#crt-static = false + +# The root location of the MUSL installation directory. The library directory +# will also need to contain libunwind.a for an unwinding implementation. Note +# that this option only makes sense for MUSL targets that produce statically +# linked binaries +#musl-root = "..." + +# Used in testing for configuring where the QEMU images are located, you +# probably don't want to use this. +#qemu-rootfs = "..." + +# ============================================================================= +# Distribution options +# +# These options are related to distribution, mostly for the Rust project itself. +# You probably won't need to concern yourself with any of these options +# ============================================================================= +[dist] + +# This is the folder of artifacts that the build system will sign. All files in +# this directory will be signed with the default gpg key using the system `gpg` +# binary. The `asc` and `sha256` files will all be output into the standard dist +# output folder (currently `build/dist`) +# +# This folder should be populated ahead of time before the build system is +# invoked. +#sign-folder = "path/to/folder/to/sign" + +# This is a file which contains the password of the default gpg key. This will +# be passed to `gpg` down the road when signing all files in `sign-folder` +# above. This should be stored in plaintext. +#gpg-password-file = "path/to/gpg/password" + +# The remote address that all artifacts will eventually be uploaded to. The +# build system generates manifests which will point to these urls, and for the +# manifests to be correct they'll have to have the right URLs encoded. +# +# Note that this address should not contain a trailing slash as file names will +# be appended to it. +#upload-addr = "https://example.com/folder" + +# Whether to build a plain source tarball to upload +# We disable that on Windows not to override the one already uploaded on S3 +# as the one built on Windows will contain backslashes in paths causing problems +# on linux +#src-tarball = true +# + +# Whether to allow failures when building tools +#missing-tools = false From c3b3675ed17e3686d63bd48597457844cdcd0dcd Mon Sep 17 00:00:00 2001 From: Jack May Date: Thu, 14 Feb 2019 09:19:01 -0800 Subject: [PATCH 009/103] [SOL] Don't build rustdoc to save time --- src/bootstrap/Cargo.toml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bootstrap/Cargo.toml b/src/bootstrap/Cargo.toml index e4d359141cec1..e0c8f434dbf85 100644 --- a/src/bootstrap/Cargo.toml +++ b/src/bootstrap/Cargo.toml @@ -22,10 +22,10 @@ name = "rustc" path = "src/bin/rustc.rs" test = false -[[bin]] -name = "rustdoc" -path = "src/bin/rustdoc.rs" -test = false +#[[bin]] +#name = "rustdoc" +#path = "bin/rustdoc.rs" +#test = false [[bin]] name = "sccache-plus-cl" From b16951cc9cedac8aa778ed2c862e572d671a7f35 Mon Sep 17 00:00:00 2001 From: Jack May Date: Thu, 14 Feb 2019 10:26:36 -0800 Subject: [PATCH 010/103] [SOL] Custom README.md --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index a88ee4b8bf061..fb7ab6ebb902f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,10 @@ +# Fork of the Rust Programming Language that supports Berkley Packet Filter (BPF) targets + + +This fork of Rust contains changes that enables rustc to build BPF modules. It depends on a customized [fork](https://github.com/solana-labs/llvm-project) of Rust's LLVM fork + +--- + # The Rust Programming Language [![Rust Community](https://img.shields.io/badge/Rust_Community%20-Join_us-brightgreen?style=plastic&logo=rust)](https://www.rust-lang.org/community) From fad85b6b56d8c08e6688a7f4eb8e348ca4a9596c Mon Sep 17 00:00:00 2001 From: Jack May Date: Tue, 19 Feb 2019 19:11:07 -0800 Subject: [PATCH 011/103] [SOL] Add build script --- build.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 build.sh diff --git a/build.sh b/build.sh new file mode 100755 index 0000000000000..6c42b8f8484e5 --- /dev/null +++ b/build.sh @@ -0,0 +1,19 @@ +./#!/usr/bin/env bash + +set -x + +if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then + echo "--llvm to rebuild llvm"; + exit; +fi + +if [ "$1" == "--llvm" ]; then + rm build/x86_64-apple-darwin/llvm/llvm-finished-building; +fi +./x.py build --stage 1 + +# Not needed so save space +rm -rf build/x86_64-apple-darwin/stage1/lib/rustlib/x86_64-apple-darwin/lib + + + From 5e453933688e2f3e0cafe75b51eb2a5f025b266a Mon Sep 17 00:00:00 2001 From: Jack May Date: Wed, 20 Feb 2019 09:41:50 -0800 Subject: [PATCH 012/103] [SOL] Preserve lib dir, needed for sysroot building --- build.sh | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/build.sh b/build.sh index 6c42b8f8484e5..b821637ea79ca 100755 --- a/build.sh +++ b/build.sh @@ -1,4 +1,4 @@ -./#!/usr/bin/env bash +#!/usr/bin/env bash set -x @@ -11,9 +11,3 @@ if [ "$1" == "--llvm" ]; then rm build/x86_64-apple-darwin/llvm/llvm-finished-building; fi ./x.py build --stage 1 - -# Not needed so save space -rm -rf build/x86_64-apple-darwin/stage1/lib/rustlib/x86_64-apple-darwin/lib - - - From 89c012cb4293d43398cdc86fc9af59dac577d093 Mon Sep 17 00:00:00 2001 From: Jack May Date: Wed, 20 Feb 2019 09:44:24 -0800 Subject: [PATCH 013/103] [SOL] Allow older gcc, debian does not support a newer one yet --- src/bootstrap/src/core/build_steps/llvm.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index a1f6fac8a518a..f76bed4890065 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -315,6 +315,7 @@ impl Step for Llvm { cfg.out_dir(&out_dir) .profile(profile) + .define("LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN", "ON") .define("LLVM_ENABLE_ASSERTIONS", assertions) .define("LLVM_UNREACHABLE_OPTIMIZE", "OFF") .define("LLVM_ENABLE_PLUGINS", plugins) From d1f2075846f8d111679faed681b22dce70964073 Mon Sep 17 00:00:00 2001 From: Jack May Date: Fri, 22 Feb 2019 16:53:31 -0800 Subject: [PATCH 014/103] [SOL] Reduce size of output binaries --- config.toml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/config.toml b/config.toml index 8fbf1afe5f7f7..b2d4cc9583a09 100644 --- a/config.toml +++ b/config.toml @@ -19,7 +19,7 @@ #enabled = true # Indicates whether the LLVM build is a Release or Debug build -#optimize = true +optimize = true # Indicates whether LLVM should be built with ThinLTO. Note that this will # only succeed if you use clang, lld, llvm-ar, and llvm-ranlib in your C/C++ @@ -28,10 +28,10 @@ #thin-lto = false # Indicates whether an LLVM Release build should include debug info -release-debuginfo = true +release-debuginfo = false # Indicates whether the LLVM assertions are enabled or not -assertions = true +assertions = false # Indicates whether ccache is used when building LLVM #ccache = false @@ -285,7 +285,7 @@ optimize = true # "maximally debuggable" environment (notably libstd) takes # hours to build. # -debug = true +debug = false # Number of codegen units to use for each compiler invocation. A value of 0 # means "the number of cores on this machine", and 1+ is passed through to the @@ -298,7 +298,7 @@ debug = true # Whether or not debug assertions are enabled for the compiler and standard # library. -debug-assertions = true +debug-assertions = false # Whether or not debuginfo is emitted #debuginfo = false From fe5552e283c17efc466d91e3d04b03b13a343124 Mon Sep 17 00:00:00 2001 From: Jack May Date: Wed, 27 Feb 2019 15:29:16 -0800 Subject: [PATCH 015/103] [SOL] Add BPF as a built-in target --- build.sh | 5 +- .../src/spec/bpfel_unknown_unknown.rs | 52 +++++++++++++++++++ compiler/rustc_target/src/spec/mod.rs | 1 + config.toml | 2 +- .../host-x86_64/dist-various-1/Dockerfile | 1 + src/tools/build-manifest/src/main.rs | 1 + 6 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs diff --git a/build.sh b/build.sh index b821637ea79ca..deaa2664bca47 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -x +set -ex if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then echo "--llvm to rebuild llvm"; @@ -11,3 +11,6 @@ if [ "$1" == "--llvm" ]; then rm build/x86_64-apple-darwin/llvm/llvm-finished-building; fi ./x.py build --stage 1 + +# Needed by xargo +mkdir build/x86_64-apple-darwin/stage1/lib/rustlib/x86_64-apple-darwin/bin \ No newline at end of file diff --git a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs new file mode 100644 index 0000000000000..49d452508dbb9 --- /dev/null +++ b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs @@ -0,0 +1,52 @@ +use crate::spec::abi::Abi; +use crate::spec::{LinkerFlavor, LldFlavor, PanicStrategy, + Target, TargetOptions, TargetResult}; + +// All the calling conventions trigger an assertion(Unsupported calling +// convention) in llvm on BPF +pub fn abi_blacklist() -> Vec { + vec![ + Abi::Cdecl, + Abi::Stdcall, + Abi::Fastcall, + Abi::Vectorcall, + Abi::Thiscall, + Abi::Aapcs, + Abi::Win64, + Abi::SysV64, + Abi::PtxKernel, + Abi::Msp430Interrupt, + Abi::X86Interrupt, + Abi::AmdGpuKernel, + ] +} + +pub fn target() -> TargetResult { + Ok(Target { + llvm_target: "bpf".to_string(), + data_layout: "e-m:e-p:64:64-i64:64-n32:64-S128".to_string(), + target_endian: "little".to_string(), + target_pointer_width: "64".to_string(), + target_c_int_width: "64".to_string(), + target_os: "linux".to_string(), // TODO unknown? + target_env: String::new(), + target_vendor: "unknown".to_string(), + arch: "bpf".to_string(), + linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), + + options: TargetOptions { + atomic_cas: false, + executables: true, + dll_prefix: "".to_string(), + dynamic_linking: true, + i128_lowering: true, + no_builtins: true, + no_default_libraries: true, + panic_strategy: PanicStrategy::Abort, + position_independent_executables: true, + singlethread: true, + abi_blacklist: abi_blacklist(), + .. Default::default() + }, + }) +} diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index f04799482c831..4507f829c3059 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1691,6 +1691,7 @@ supported_targets! { ("bpfeb-unknown-none", bpfeb_unknown_none), ("bpfel-unknown-none", bpfel_unknown_none), + ("bpfel-unknown-unknown", bpfel_unknown_unknown), ("armv6k-nintendo-3ds", armv6k_nintendo_3ds), diff --git a/config.toml b/config.toml index b2d4cc9583a09..e87a258fff53f 100644 --- a/config.toml +++ b/config.toml @@ -67,7 +67,7 @@ assertions = false # the same format as above, but since these targets are experimental, they are # not built by default and the experimental Rust compilation targets that depend # on them will not work unless the user opts in to building them. By default the -# `WebAssembly` and `RISCV` targets are enabled when compiling LLVM from scratch. +# `WebAssembly`, `RISCV`, and `BPF` targets are enabled when compiling LLVM from scratch. experimental-targets = "WebAssembly;BPF" # Cap the number of parallel linker invocations when compiling LLVM. diff --git a/src/ci/docker/host-x86_64/dist-various-1/Dockerfile b/src/ci/docker/host-x86_64/dist-various-1/Dockerfile index 3372baed999ac..bafde50c41635 100644 --- a/src/ci/docker/host-x86_64/dist-various-1/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-various-1/Dockerfile @@ -104,6 +104,7 @@ ENV TARGETS=$TARGETS,armv7r-none-eabi ENV TARGETS=$TARGETS,armv7r-none-eabihf ENV TARGETS=$TARGETS,thumbv7neon-unknown-linux-gnueabihf ENV TARGETS=$TARGETS,armv7a-none-eabi +ENV TARGETS=$TARGETS,bpfel-unknown-unknown # riscv targets currently do not need a C compiler, as compiler_builtins # doesn't currently have it enabled, and the riscv gcc compiler is not diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs index aed6796fa13c4..d675c9082e554 100644 --- a/src/tools/build-manifest/src/main.rs +++ b/src/tools/build-manifest/src/main.rs @@ -85,6 +85,7 @@ static TARGETS: &[&str] = &[ "asmjs-unknown-emscripten", "bpfeb-unknown-none", "bpfel-unknown-none", + "bpfel-unknown-unknown", "i386-apple-ios", "i586-pc-windows-msvc", "i586-unknown-linux-gnu", From 658124437b093ac262169f81a7ec76228c1b61c7 Mon Sep 17 00:00:00 2001 From: Jack May Date: Wed, 27 Feb 2019 17:16:27 -0800 Subject: [PATCH 016/103] [SOL] Add bin dir later --- build.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/build.sh b/build.sh index deaa2664bca47..438e6fc1d2a29 100755 --- a/build.sh +++ b/build.sh @@ -11,6 +11,3 @@ if [ "$1" == "--llvm" ]; then rm build/x86_64-apple-darwin/llvm/llvm-finished-building; fi ./x.py build --stage 1 - -# Needed by xargo -mkdir build/x86_64-apple-darwin/stage1/lib/rustlib/x86_64-apple-darwin/bin \ No newline at end of file From d2c967493fcbb7fa25924c5e9bbc8e9a9a109b8a Mon Sep 17 00:00:00 2001 From: Jack May Date: Fri, 1 Mar 2019 16:58:06 -0800 Subject: [PATCH 017/103] [SOL] Update README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fb7ab6ebb902f..9ffd72e2e23c9 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,10 @@ # Fork of the Rust Programming Language that supports Berkley Packet Filter (BPF) targets +This fork of Rust contains changes that enables rustc to build BPF modules. It depends on a customized [fork](https://github.com/solana-labs/llvm-project) of Rust's LLVM fork. -This fork of Rust contains changes that enables rustc to build BPF modules. It depends on a customized [fork](https://github.com/solana-labs/llvm-project) of Rust's LLVM fork +Solana SDK does not depend directly on this repo. Instread [rust-bpf-builder] builds and releases binary packages that the Solana SDK pulls in. + +BPF modules are built using target triple `bpfel-unknown-unknown` which represents the little endian version of BPF. There is no support for big endian at this time. --- From e6e81d96b5517110913605f12911a5c374d74111 Mon Sep 17 00:00:00 2001 From: Jack May Date: Tue, 4 Jun 2019 13:41:26 -0700 Subject: [PATCH 018/103] [SOL] Script nit --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 438e6fc1d2a29..dc4da61d396b3 100755 --- a/build.sh +++ b/build.sh @@ -8,6 +8,6 @@ if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then fi if [ "$1" == "--llvm" ]; then - rm build/x86_64-apple-darwin/llvm/llvm-finished-building; + rm -f build/x86_64-apple-darwin/llvm/llvm-finished-building; fi ./x.py build --stage 1 From 9e1748e930b94283db08c7fabdcedad205df295a Mon Sep 17 00:00:00 2001 From: Jack May Date: Thu, 19 Sep 2019 16:39:05 -0700 Subject: [PATCH 019/103] [SOL] BPF Spec use os=unknown --- compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs index 49d452508dbb9..ecacbbf82b215 100644 --- a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs +++ b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs @@ -28,7 +28,7 @@ pub fn target() -> TargetResult { target_endian: "little".to_string(), target_pointer_width: "64".to_string(), target_c_int_width: "64".to_string(), - target_os: "linux".to_string(), // TODO unknown? + target_os: "unknown".to_string(), target_env: String::new(), target_vendor: "unknown".to_string(), arch: "bpf".to_string(), From 64421ad0b89e4913dcca6ef2c777b7b918854ffd Mon Sep 17 00:00:00 2001 From: Jack May Date: Wed, 25 Sep 2019 16:25:23 -0700 Subject: [PATCH 020/103] [SOL] Rust libstd requires atomic cas support --- compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs index ecacbbf82b215..18bd01250be90 100644 --- a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs +++ b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs @@ -35,7 +35,6 @@ pub fn target() -> TargetResult { linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), options: TargetOptions { - atomic_cas: false, executables: true, dll_prefix: "".to_string(), dynamic_linking: true, @@ -45,6 +44,7 @@ pub fn target() -> TargetResult { panic_strategy: PanicStrategy::Abort, position_independent_executables: true, singlethread: true, + max_atomic_width: Some(64), abi_blacklist: abi_blacklist(), .. Default::default() }, From 2d98f9038e1bdc219167b999bb71056797f7f0fc Mon Sep 17 00:00:00 2001 From: Jack May Date: Mon, 9 Dec 2019 23:51:18 -0800 Subject: [PATCH 021/103] [SOL] Updates from latest config.example.toml --- config.toml | 67 ++++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/config.toml b/config.toml index e87a258fff53f..20e65e37468a1 100644 --- a/config.toml +++ b/config.toml @@ -14,10 +14,6 @@ # ============================================================================= [llvm] -# Indicates whether rustc will support compilation with LLVM -# note: rustc does not compile without LLVM at the moment -#enabled = true - # Indicates whether the LLVM build is a Release or Debug build optimize = true @@ -61,14 +57,14 @@ assertions = false # support. You'll need to write a target specification at least, and most # likely, teach rustc about the C ABI of the target. Get in touch with the # Rust team and file an issue if you need assistance in porting! -#targets = "X86;ARM;AArch64;Mips;PowerPC;SystemZ;JSBackend;MSP430;Sparc;NVPTX;Hexagon" +#targets = "AArch64;ARM;Hexagon;MSP430;Mips;NVPTX;PowerPC;RISCV;Sparc;SystemZ;WebAssembly;X86" # LLVM experimental targets to build support for. These targets are specified in # the same format as above, but since these targets are experimental, they are # not built by default and the experimental Rust compilation targets that depend # on them will not work unless the user opts in to building them. By default the # `WebAssembly`, `RISCV`, and `BPF` targets are enabled when compiling LLVM from scratch. -experimental-targets = "WebAssembly;BPF" +experimental-targets = "BPF" # Cap the number of parallel linker invocations when compiling LLVM. # This can be useful when building LLVM with debug info, which significantly @@ -104,6 +100,8 @@ experimental-targets = "WebAssembly;BPF" # The value specified here will be passed as `-DLLVM_USE_LINKER` to CMake. #use-linker = "lld" +# Whether or not to specify `-DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=YES` +#allow-old-toolchain = false # ============================================================================= # General build configuration options @@ -144,10 +142,10 @@ docs = false # library and facade crates. #compiler-docs = false -# Indicate whether submodules are managed and updated automatically. +# Indicate whether git submodules are managed and updated automatically. #submodules = true -# Update submodules only when the checked out commit in the submodules differs +# Update git submodules only when the checked out commit in the submodules differs # from what is committed in the main rustc repo. #fast-submodules = true @@ -162,6 +160,9 @@ docs = false # Python interpreter to use for various tasks throughout the build, notably # rustdoc tests, the lldb python interpreter, and some dist bits and pieces. # Note that Python 2 is currently required. +# +# Defaults to python2.7, then python2. If neither executable can be found, then +# it defaults to the Python interpreter used to execute x.py. #python = "python2.7" # Force Cargo to check that Cargo.lock describes the precise dependency @@ -184,7 +185,7 @@ docs = false # default. #extended = false -# Installs chosen set of extended tools if enables. By default builds all. +# Installs chosen set of extended tools if enabled. By default builds all. # If chosen tool failed to build the installation fails. #tools = ["cargo", "rls", "clippy", "rustfmt", "analysis", "src"] @@ -300,20 +301,27 @@ debug = false # library. debug-assertions = false -# Whether or not debuginfo is emitted -#debuginfo = false +# Debuginfo level for most of Rust code, corresponds to the `-C debuginfo=N` option of `rustc`. +# `0` - no debug info +# `1` - line tables only +# `2` - full debug info with variable and type information +# Can be overriden for specific subsets of Rust code (rustc, std or tools). +# Debuginfo for tests run with compiletest is not controlled by this option +# and needs to be enabled separately with `debuginfo-level-tests`. +#debuginfo-level = if debug { 2 } else { 0 } -# Whether or not line number debug information is emitted -#debuginfo-lines = false +# Debuginfo level for the compiler. +#debuginfo-level-rustc = debuginfo-level -# Whether or not to only build debuginfo for the standard library if enabled. -# If enabled, this will not compile the compiler with debuginfo, just the -# standard library. -#debuginfo-only-std = false +# Debuginfo level for the standard library. +#debuginfo-level-std = debuginfo-level -# Enable debuginfo for the extended tools: cargo, rls, rustfmt -# Adding debuginfo makes them several times larger. -#debuginfo-tools = false +# Debuginfo level for the tools. +#debuginfo-level-tools = debuginfo-level + +# Debuginfo level for the test suites run with compiletest. +# FIXME(#61117): Some tests fail when this option is enabled. +#debuginfo-level-tests = 0 # Whether or not `panic!`s generate backtraces (RUST_BACKTRACE) #backtrace = true @@ -344,10 +352,8 @@ debug-assertions = false # harness are debuggable just from logfiles. #verbose-tests = false -# Flag indicating whether tests are compiled with optimizations (the -O flag) or -# with debuginfo (the -g flag) +# Flag indicating whether tests are compiled with optimizations (the -O flag). #optimize-tests = true -#debuginfo-tests = true # Flag indicating whether codegen tests will be run or not. If you get an error # saying that the FileCheck executable is missing, you may want to disable this. @@ -363,10 +369,6 @@ debug-assertions = false # When creating source tarballs whether or not to create a source tarball. #dist-src = false -# Whether to also run the Miri tests suite when running tests. -# As a side-effect also generates MIR for all libraries. -#test-miri = false - # After building or testing extended tools (e.g. clippy and rustfmt), append the # result (broken, compiling, testing) into this JSON file. #save-toolstates = "/path/to/toolstates.json" @@ -381,11 +383,6 @@ debug-assertions = false # This is the name of the directory in which codegen backends will get installed #codegen-backends-dir = "codegen-backends" -# Flag indicating whether `libstd` calls an imported function to handle basic IO -# when targeting WebAssembly. Enable this to debug tests for the `wasm32-unknown-unknown` -# target, as without this option the test output will not be captured. -#wasm-syscall = false - # Indicates whether LLD will be compiled and made available in the sysroot for # rustc to execute. #lld = false @@ -420,6 +417,9 @@ debug-assertions = false # development of NLL #test-compare-mode = false +# Use LLVM libunwind as the implementation for Rust's unwinder. +#llvm-libunwind = false + # ============================================================================= # Options for specific targets # @@ -476,6 +476,9 @@ debug-assertions = false # linked binaries #musl-root = "..." +# The root location of the `wasm32-wasi` sysroot. +#wasi-root = "..." + # Used in testing for configuring where the QEMU images are located, you # probably don't want to use this. #qemu-rootfs = "..." From 3a68e3d001ed698b96435c3bdfe457e278d93316 Mon Sep 17 00:00:00 2001 From: Jack May Date: Mon, 9 Dec 2019 23:54:19 -0800 Subject: [PATCH 022/103] [SOL] Updates from rust 1.39 --- compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs index 18bd01250be90..d8fea34eb35dd 100644 --- a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs +++ b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs @@ -38,7 +38,6 @@ pub fn target() -> TargetResult { executables: true, dll_prefix: "".to_string(), dynamic_linking: true, - i128_lowering: true, no_builtins: true, no_default_libraries: true, panic_strategy: PanicStrategy::Abort, From 9a45ecd295294461e2254364194ca556e02d4886 Mon Sep 17 00:00:00 2001 From: Jack May Date: Tue, 28 Apr 2020 12:00:38 -0700 Subject: [PATCH 023/103] [SOL] Allow all nightly options to help interactions with newer Cargo --- compiler/rustc_session/src/config.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index f745bc390cadc..12196197cd955 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -2977,9 +2977,10 @@ pub mod nightly_options { use crate::EarlyErrorHandler; use rustc_feature::UnstableFeatures; - pub fn is_unstable_enabled(matches: &getopts::Matches) -> bool { - match_is_nightly_build(matches) - && matches.opt_strs("Z").iter().any(|x| *x == "unstable-options") + pub fn is_unstable_enabled(_matches: &getopts::Matches) -> bool { + // Newer versions of Cargo might pass options that used to be nightly only + // Allow all nightly options on the Rust BPF compiler + true } pub fn match_is_nightly_build(matches: &getopts::Matches) -> bool { From df47a166e22b8a4f06baf4363857c82b3de81667 Mon Sep 17 00:00:00 2001 From: Tom Zakrajsek Date: Sat, 25 Jul 2020 21:39:05 -0700 Subject: [PATCH 024/103] [SOL] Update README.md Fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9ffd72e2e23c9..4ed6bd7ccac7e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ This fork of Rust contains changes that enables rustc to build BPF modules. It depends on a customized [fork](https://github.com/solana-labs/llvm-project) of Rust's LLVM fork. -Solana SDK does not depend directly on this repo. Instread [rust-bpf-builder] builds and releases binary packages that the Solana SDK pulls in. +Solana SDK does not depend directly on this repo. Instead [rust-bpf-builder] builds and releases binary packages that the Solana SDK pulls in. BPF modules are built using target triple `bpfel-unknown-unknown` which represents the little endian version of BPF. There is no support for big endian at this time. From 5e1e60d231eb7b2474bf0ffbc2abb6032c3da7a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Mon, 7 Sep 2020 13:30:15 +0200 Subject: [PATCH 025/103] [SOL] Renames to match the upstream changes - d4d11118ef55501a73d423651e45c0102afd0209 "The target configuration option `abi_blacklist` has been renamed to `unsupported_abis`." - 6567154ede38d9bb65413942845bf9739d830a20 "rustc_target: rename {Fn,Arg}Type to {Fn,Arg}Abi." --- compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs index d8fea34eb35dd..da13c21569179 100644 --- a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs +++ b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs @@ -44,7 +44,7 @@ pub fn target() -> TargetResult { position_independent_executables: true, singlethread: true, max_atomic_width: Some(64), - abi_blacklist: abi_blacklist(), + unsupported_abis: abi_blacklist(), .. Default::default() }, }) From 24ce202d849554055ce2ce9a72cb864adb8e734a Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Wed, 10 Feb 2021 09:57:37 -0800 Subject: [PATCH 026/103] [SOL] Disable eh_frame_hdr linker option --- compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs index da13c21569179..729964834dc1f 100644 --- a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs +++ b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs @@ -45,6 +45,7 @@ pub fn target() -> TargetResult { singlethread: true, max_atomic_width: Some(64), unsupported_abis: abi_blacklist(), + eh_frame_header: false, .. Default::default() }, }) From 9f94fb5b2bfa0d6ac1e7391f1f37d1d96044ae21 Mon Sep 17 00:00:00 2001 From: Jack May Date: Tue, 16 Feb 2021 12:14:30 -0800 Subject: [PATCH 027/103] [SOL] Build llvm tools from llvm-project --- config.toml | 3 +++ src/bootstrap/src/core/build_steps/llvm.rs | 6 ++++++ src/bootstrap/src/core/config/config.rs | 3 +++ 3 files changed, 12 insertions(+) diff --git a/config.toml b/config.toml index 20e65e37468a1..8d798245e2be4 100644 --- a/config.toml +++ b/config.toml @@ -103,6 +103,9 @@ experimental-targets = "BPF" # Whether or not to specify `-DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=YES` #allow-old-toolchain = false +# Which LLVM projects to build along with the LLVM base libraries/tools +enable-projects = "clang;lld" + # ============================================================================= # General build configuration options # ============================================================================= diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index f76bed4890065..857328186d36f 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -429,6 +429,12 @@ impl Step for Llvm { enabled_llvm_projects.push("clang"); } + if let Some(projects) = &builder.config.llvm_enable_projects { + for p in projects.split(';') { + enabled_llvm_projects.push(p); + } + } + // We want libxml to be disabled. // See https://github.com/rust-lang/rust/pull/50104 cfg.define("LLVM_ENABLE_LIBXML2", "OFF"); diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index 0a9175aa3ea5c..3b44270f729e0 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -197,6 +197,7 @@ pub struct Config { pub llvm_enable_warnings: bool, pub llvm_from_ci: bool, pub llvm_build_config: HashMap, + pub llvm_enable_projects: Option, pub use_lld: bool, pub lld_enabled: bool, @@ -847,6 +848,7 @@ define_config! { enable_warnings: Option = "enable-warnings", download_ci_llvm: Option = "download-ci-llvm", build_config: Option> = "build-config", + enable_projects: Option = "enable-projects", } } @@ -1520,6 +1522,7 @@ impl Config { config.llvm_link_jobs = llvm.link_jobs; config.llvm_version_suffix = llvm.version_suffix.clone(); config.llvm_clang_cl = llvm.clang_cl.clone(); + config.llvm_enable_projects = llvm.enable_projects.clone(); config.llvm_cflags = llvm.cflags.clone(); config.llvm_cxxflags = llvm.cxxflags.clone(); From 888bb9af60588cbcd2124eb8a53987192dc1b988 Mon Sep 17 00:00:00 2001 From: Jack May Date: Wed, 17 Feb 2021 10:22:14 -0800 Subject: [PATCH 028/103] [SOL] Link llvm tools statically --- config.toml | 3 ++- src/bootstrap/src/core/build_steps/llvm.rs | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/config.toml b/config.toml index 8d798245e2be4..a15b163ffe544 100644 --- a/config.toml +++ b/config.toml @@ -58,6 +58,7 @@ assertions = false # likely, teach rustc about the C ABI of the target. Get in touch with the # Rust team and file an issue if you need assistance in porting! #targets = "AArch64;ARM;Hexagon;MSP430;Mips;NVPTX;PowerPC;RISCV;Sparc;SystemZ;WebAssembly;X86" +targets = "X86" # LLVM experimental targets to build support for. These targets are specified in # the same format as above, but since these targets are experimental, they are @@ -76,7 +77,7 @@ experimental-targets = "BPF" # When invoking `llvm-config` this configures whether the `--shared` argument is # passed to prefer linking to shared libraries. -#link-shared = false +link-shared = false # When building llvm, this configures what is being appended to the version. # If absent, we let the version as-is. diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index 857328186d36f..d37299548c5c8 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -379,6 +379,11 @@ impl Step for Llvm { // equally well everywhere. if builder.llvm_link_shared() { cfg.define("LLVM_LINK_LLVM_DYLIB", "ON"); + } else { + cfg.define("LIBCLANG_BUILD_STATIC", "ON"); + cfg.define("CLANG_LINK_CLANG_DYLIB", "OFF"); + cfg.define("LLVM_BUILD_LLVM_DYLIB", "OFF"); + cfg.define("LLVM_LINK_LLVM_DYLIB", "OFF"); } if (target.starts_with("riscv") || target.starts_with("csky")) From fa8962ab8021a098b8834881a04610145a39fdf2 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Wed, 17 Feb 2021 21:02:51 +0100 Subject: [PATCH 029/103] [SOL] Do not disable all builtins for BPF target --- compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs index 729964834dc1f..4925c5880db71 100644 --- a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs +++ b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs @@ -38,7 +38,6 @@ pub fn target() -> TargetResult { executables: true, dll_prefix: "".to_string(), dynamic_linking: true, - no_builtins: true, no_default_libraries: true, panic_strategy: PanicStrategy::Abort, position_independent_executables: true, From a74652847e5485cf4dab35312b2cc69a76e69ff4 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Fri, 26 Feb 2021 12:02:21 +0100 Subject: [PATCH 030/103] [SOL] Adjust ABI implementation to pass 128-bit arguments by value --- compiler/rustc_target/src/abi/call/bpf.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_target/src/abi/call/bpf.rs b/compiler/rustc_target/src/abi/call/bpf.rs index fe2757b0a56e7..d762c7fae9734 100644 --- a/compiler/rustc_target/src/abi/call/bpf.rs +++ b/compiler/rustc_target/src/abi/call/bpf.rs @@ -3,7 +3,9 @@ use crate::abi::call::{ArgAbi, FnAbi}; fn classify_ret(ret: &mut ArgAbi<'_, Ty>) { if ret.layout.is_aggregate() || ret.layout.size.bits() > 64 { - ret.make_indirect(); + if ret.layout.size.bits() != 128 { + ret.make_indirect(); + } } else { ret.extend_integer_width_to(64); } @@ -11,7 +13,9 @@ fn classify_ret(ret: &mut ArgAbi<'_, Ty>) { fn classify_arg(arg: &mut ArgAbi<'_, Ty>) { if arg.layout.is_aggregate() || arg.layout.size.bits() > 64 { - arg.make_indirect(); + if arg.layout.size.bits() != 128 { + arg.make_indirect(); + } } else { arg.extend_integer_width_to(64); } From d66363681837b9ba036a18b320dc428bca3c4941 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Sun, 28 Feb 2021 08:16:34 +0100 Subject: [PATCH 031/103] [SOL] Adjust BPF target spec to upstream changes --- .../src/spec/bpfel_unknown_unknown.rs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs index 4925c5880db71..13267d935c08d 100644 --- a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs +++ b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs @@ -1,6 +1,6 @@ use crate::spec::abi::Abi; use crate::spec::{LinkerFlavor, LldFlavor, PanicStrategy, - Target, TargetOptions, TargetResult}; + Target, TargetOptions}; // All the calling conventions trigger an assertion(Unsupported calling // convention) in llvm on BPF @@ -21,20 +21,20 @@ pub fn abi_blacklist() -> Vec { ] } -pub fn target() -> TargetResult { - Ok(Target { +pub fn target() -> Target { + Target { llvm_target: "bpf".to_string(), - data_layout: "e-m:e-p:64:64-i64:64-n32:64-S128".to_string(), - target_endian: "little".to_string(), - target_pointer_width: "64".to_string(), - target_c_int_width: "64".to_string(), - target_os: "unknown".to_string(), - target_env: String::new(), - target_vendor: "unknown".to_string(), + pointer_width: 64, arch: "bpf".to_string(), - linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), + data_layout: "e-m:e-p:64:64-i64:64-n32:64-S128".to_string(), options: TargetOptions { + endian: "little".to_string(), + c_int_width: "64".to_string(), + os: "unknown".to_string(), + env: String::new(), + vendor: "unknown".to_string(), + linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), executables: true, dll_prefix: "".to_string(), dynamic_linking: true, @@ -47,5 +47,5 @@ pub fn target() -> TargetResult { eh_frame_header: false, .. Default::default() }, - }) + } } From beb6b9b083c409dc6ce18e2adf157a56ceaf771d Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Fri, 2 Apr 2021 15:17:29 +0200 Subject: [PATCH 032/103] [SOL] Adjust for building in tree the bpf target with std library --- Cargo.lock | 5 + Cargo.toml | 1 + .../src/spec/bpfel_unknown_unknown.rs | 1 + config.toml | 1 + library/core/src/fmt/mod.rs | 2 + library/core/src/fmt/num.rs | 8 +- library/proc_macro/src/lib.rs | 1 + library/std/Cargo.toml | 1 - library/std/build.rs | 1 + library/std/src/alloc.rs | 26 +- library/std/src/error.rs | 1 + library/std/src/io/mod.rs | 1 + library/std/src/io/stdio.rs | 41 +- library/std/src/lib.rs | 3 + library/std/src/macros.rs | 16 + library/std/src/panic.rs | 14 + library/std/src/panicking.rs | 104 ++++- library/std/src/process.rs | 4 + library/std/src/rt.rs | 2 + library/std/src/sync/once.rs | 1 + library/std/src/sync/remutex.rs | 2 + library/std/src/sys/bpf/alloc.rs | 37 ++ library/std/src/sys/bpf/args.rs | 44 +++ library/std/src/sys/bpf/backtrace.rs | 27 ++ library/std/src/sys/bpf/cmath.rs | 29 ++ library/std/src/sys/bpf/condvar.rs | 35 ++ library/std/src/sys/bpf/condvar_atomics.rs | 48 +++ library/std/src/sys/bpf/env.rs | 9 + library/std/src/sys/bpf/fs.rs | 312 +++++++++++++++ library/std/src/sys/bpf/io.rs | 48 +++ library/std/src/sys/bpf/memchr.rs | 1 + library/std/src/sys/bpf/mod.rs | 100 +++++ library/std/src/sys/bpf/mutex.rs | 55 +++ library/std/src/sys/bpf/mutex_atomics.rs | 92 +++++ library/std/src/sys/bpf/net.rs | 368 ++++++++++++++++++ library/std/src/sys/bpf/os.rs | 98 +++++ library/std/src/sys/bpf/path.rs | 19 + library/std/src/sys/bpf/pipe.rs | 44 +++ library/std/src/sys/bpf/process.rs | 204 ++++++++++ library/std/src/sys/bpf/rwlock.rs | 72 ++++ library/std/src/sys/bpf/rwlock_atomics.rs | 151 +++++++ library/std/src/sys/bpf/stdio.rs | 54 +++ library/std/src/sys/bpf/thread.rs | 36 ++ .../std/src/sys/bpf/thread_local_atomics.rs | 61 +++ library/std/src/sys/bpf/thread_local_dtor.rs | 7 + library/std/src/sys/bpf/thread_local_key.rs | 40 ++ library/std/src/sys/bpf/time.rs | 55 +++ library/std/src/sys/mod.rs | 3 + library/std/src/sys_common/backtrace.rs | 2 + library/std/src/sys_common/mod.rs | 2 + library/std/src/sys_common/thread.rs | 9 + library/std/src/thread/mod.rs | 52 +++ library/test/src/lib.rs | 1 + src/bootstrap/src/core/sanity.rs | 4 +- src/bootstrap/src/lib.rs | 11 + src/bootstrap/src/utils/cc_detect.rs | 10 + 56 files changed, 2357 insertions(+), 19 deletions(-) create mode 100644 library/std/src/sys/bpf/alloc.rs create mode 100644 library/std/src/sys/bpf/args.rs create mode 100644 library/std/src/sys/bpf/backtrace.rs create mode 100644 library/std/src/sys/bpf/cmath.rs create mode 100644 library/std/src/sys/bpf/condvar.rs create mode 100644 library/std/src/sys/bpf/condvar_atomics.rs create mode 100644 library/std/src/sys/bpf/env.rs create mode 100644 library/std/src/sys/bpf/fs.rs create mode 100644 library/std/src/sys/bpf/io.rs create mode 100644 library/std/src/sys/bpf/memchr.rs create mode 100644 library/std/src/sys/bpf/mod.rs create mode 100644 library/std/src/sys/bpf/mutex.rs create mode 100644 library/std/src/sys/bpf/mutex_atomics.rs create mode 100644 library/std/src/sys/bpf/net.rs create mode 100644 library/std/src/sys/bpf/os.rs create mode 100644 library/std/src/sys/bpf/path.rs create mode 100644 library/std/src/sys/bpf/pipe.rs create mode 100644 library/std/src/sys/bpf/process.rs create mode 100644 library/std/src/sys/bpf/rwlock.rs create mode 100644 library/std/src/sys/bpf/rwlock_atomics.rs create mode 100644 library/std/src/sys/bpf/stdio.rs create mode 100644 library/std/src/sys/bpf/thread.rs create mode 100644 library/std/src/sys/bpf/thread_local_atomics.rs create mode 100644 library/std/src/sys/bpf/thread_local_dtor.rs create mode 100644 library/std/src/sys/bpf/thread_local_key.rs create mode 100644 library/std/src/sys/bpf/time.rs diff --git a/Cargo.lock b/Cargo.lock index d3ecadf6e172f..a92430a13ca3c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6438,3 +6438,8 @@ dependencies = [ "crossbeam-utils", "flate2", ] + +[[patch.unused]] +name = "compiler_builtins" +version = "0.1.76" +source = "git+https://github.com/solana-labs/compiler-builtins#2044d7e16a99d951853ce362e384027dec4c5b92" diff --git a/Cargo.toml b/Cargo.toml index 9b11ae8744b4f..c735a5b648c8f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -105,6 +105,7 @@ miniz_oxide.debug = 0 object.debug = 0 [patch.crates-io] +compiler_builtins = { git = "https://github.com/solana-labs/compiler-builtins" } # See comments in `library/rustc-std-workspace-core/README.md` for what's going on # here rustc-std-workspace-core = { path = 'library/rustc-std-workspace-core' } diff --git a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs index 13267d935c08d..5908f4bf6870d 100644 --- a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs +++ b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs @@ -38,6 +38,7 @@ pub fn target() -> Target { executables: true, dll_prefix: "".to_string(), dynamic_linking: true, + only_cdylib: true, no_default_libraries: true, panic_strategy: PanicStrategy::Abort, position_independent_executables: true, diff --git a/config.toml b/config.toml index a15b163ffe544..68842b458a1fa 100644 --- a/config.toml +++ b/config.toml @@ -1,3 +1,4 @@ +changelog-seen = 2 # Sample TOML configuration file for building Rust. # # To configure rustbuild, copy this file to the directory from which you will be diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index e1b7b46a1ed2f..8da494a749d07 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -5,6 +5,8 @@ use crate::cell::{Cell, Ref, RefCell, RefMut, SyncUnsafeCell, UnsafeCell}; use crate::char::EscapeDebugExtArgs; use crate::iter; +#[cfg(target_arch = "bpf")] +use crate::intrinsics::abort; use crate::marker::PhantomData; use crate::mem; use crate::num::fmt as numfmt; diff --git a/library/core/src/fmt/num.rs b/library/core/src/fmt/num.rs index 4f42f73ebbaff..2dac024d696c9 100644 --- a/library/core/src/fmt/num.rs +++ b/library/core/src/fmt/num.rs @@ -2,6 +2,7 @@ use crate::fmt; use crate::mem::MaybeUninit; +#[cfg(not(target_arch = "bpf"))] use crate::num::fmt as numfmt; use crate::ops::{Div, Rem, Sub}; use crate::ptr; @@ -294,6 +295,7 @@ macro_rules! impl_Display { }; } +#[cfg(not(target_arch = "bpf"))] macro_rules! impl_Exp { ($($t:ident),* as $u:ident via $conv_fn:ident named $name:ident) => { fn $name( @@ -467,13 +469,15 @@ mod imp { i8, u8, i16, u16, i32, u32, i64, u64, usize, isize as u64 via to_u64 named fmt_u64 ); + + #[cfg(not(target_arch = "bpf"))] impl_Exp!( i8, u8, i16, u16, i32, u32, i64, u64, usize, isize as u64 via to_u64 named exp_u64 ); } -#[cfg(not(any(target_pointer_width = "64", target_arch = "wasm32")))] +#[cfg(not(any(target_pointer_width = "64", target_arch = "wasm32", target_arch = "bpf")))] mod imp { use super::*; impl_Display!(i8, u8, i16, u16, i32, u32, isize, usize as u32 via to_u32 named fmt_u32); @@ -481,6 +485,8 @@ mod imp { impl_Exp!(i8, u8, i16, u16, i32, u32, isize, usize as u32 via to_u32 named exp_u32); impl_Exp!(i64, u64 as u64 via to_u64 named exp_u64); } + +#[cfg(not(target_arch = "bpf"))] impl_Exp!(i128, u128 as u128 via to_u128 named exp_u128); /// Helper function for writing a u64 into `buf` going from last to first, with `curr`. diff --git a/library/proc_macro/src/lib.rs b/library/proc_macro/src/lib.rs index 991fdb1256de3..cddde30fa2489 100644 --- a/library/proc_macro/src/lib.rs +++ b/library/proc_macro/src/lib.rs @@ -9,6 +9,7 @@ //! //! [the book]: ../book/ch19-06-macros.html#procedural-macros-for-generating-code-from-attributes +#![cfg(not(target_arch = "bpf"))] #![stable(feature = "proc_macro_lib", since = "1.15.0")] #![deny(missing_docs)] #![doc( diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index f666b18887cb1..cf7fbcbfdee64 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -14,7 +14,6 @@ crate-type = ["dylib", "rlib"] [dependencies] alloc = { path = "../alloc", public = true } cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] } -panic_unwind = { path = "../panic_unwind", optional = true } panic_abort = { path = "../panic_abort" } core = { path = "../core", public = true } libc = { version = "0.2.150", default-features = false, features = ['rustc-dep-of-std'], public = true } diff --git a/library/std/build.rs b/library/std/build.rs index ad0a82eab8ca1..2da5a866553d3 100644 --- a/library/std/build.rs +++ b/library/std/build.rs @@ -35,6 +35,7 @@ fn main() { || target.contains("xous") || target.contains("hurd") || target.contains("uefi") + || target.contains("bpf") // See src/bootstrap/synthetic_targets.rs || env::var("RUSTC_BOOTSTRAP_SYNTHETIC_TARGET").is_ok() { diff --git a/library/std/src/alloc.rs b/library/std/src/alloc.rs index bb786bd59dc84..56767d3e40b39 100644 --- a/library/std/src/alloc.rs +++ b/library/std/src/alloc.rs @@ -58,8 +58,11 @@ use core::intrinsics; use core::ptr::NonNull; +#[cfg(not(target_arch = "bpf"))] use core::sync::atomic::{AtomicPtr, Ordering}; -use core::{mem, ptr}; +#[cfg(not(target_arch = "bpf"))] +use core::mem; +use core::ptr; #[stable(feature = "alloc_module", since = "1.28.0")] #[doc(inline)] @@ -286,6 +289,7 @@ unsafe impl Allocator for System { } } +#[cfg(not(target_arch = "bpf"))] static HOOK: AtomicPtr<()> = AtomicPtr::new(ptr::null_mut()); /// Registers a custom allocation error hook, replacing any that was previously registered. @@ -328,6 +332,7 @@ static HOOK: AtomicPtr<()> = AtomicPtr::new(ptr::null_mut()); /// set_alloc_error_hook(custom_alloc_error_hook); /// ``` #[unstable(feature = "alloc_error_hook", issue = "51245")] +#[cfg(not(target_arch = "bpf"))] pub fn set_alloc_error_hook(hook: fn(Layout)) { HOOK.store(hook as *mut (), Ordering::SeqCst); } @@ -338,11 +343,13 @@ pub fn set_alloc_error_hook(hook: fn(Layout)) { /// /// If no custom hook is registered, the default hook will be returned. #[unstable(feature = "alloc_error_hook", issue = "51245")] +#[cfg(not(target_arch = "bpf"))] pub fn take_alloc_error_hook() -> fn(Layout) { let hook = HOOK.swap(ptr::null_mut(), Ordering::SeqCst); if hook.is_null() { default_alloc_error_hook } else { unsafe { mem::transmute(hook) } } } +#[cfg(not(target_arch = "bpf"))] fn default_alloc_error_hook(layout: Layout) { extern "Rust" { // This symbol is emitted by rustc next to __rust_alloc_error_handler. @@ -361,11 +368,18 @@ fn default_alloc_error_hook(layout: Layout) { #[doc(hidden)] #[alloc_error_handler] #[unstable(feature = "alloc_internals", issue = "none")] -pub fn rust_oom(layout: Layout) -> ! { - let hook = HOOK.load(Ordering::SeqCst); - let hook: fn(Layout) = - if hook.is_null() { default_alloc_error_hook } else { unsafe { mem::transmute(hook) } }; - hook(layout); +pub fn rust_oom(_layout: Layout) -> ! { + #[cfg(not(target_arch = "bpf"))] + { + let hook = HOOK.load(Ordering::SeqCst); + let hook: fn(Layout) = + if hook.is_null() { default_alloc_error_hook } else { unsafe { mem::transmute(hook) } }; + hook(_layout); + } + #[cfg(target_arch = "bpf")] + { + crate::sys::sol_log("Error: memory allocation failed, out of memory"); + } crate::process::abort() } diff --git a/library/std/src/error.rs b/library/std/src/error.rs index 375ff2d245044..7c0d889199584 100644 --- a/library/std/src/error.rs +++ b/library/std/src/error.rs @@ -4,6 +4,7 @@ #[cfg(test)] mod tests; +#[cfg(not(target_os = "solana"))] use crate::backtrace::Backtrace; use crate::fmt::{self, Write}; diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index 7d70a0bac24fd..d79f9df9e890b 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -313,6 +313,7 @@ pub use self::error::RawOsError; pub(crate) use self::stdio::attempt_print_to_stderr; #[unstable(feature = "internal_output_capture", issue = "none")] #[doc(no_inline, hidden)] +#[cfg(not(target_arch = "bpf"))] pub use self::stdio::set_output_capture; #[stable(feature = "is_terminal", since = "1.70.0")] pub use self::stdio::IsTerminal; diff --git a/library/std/src/io/stdio.rs b/library/std/src/io/stdio.rs index 05b21eeb40f71..30f286a9cc254 100644 --- a/library/std/src/io/stdio.rs +++ b/library/std/src/io/stdio.rs @@ -5,16 +5,22 @@ mod tests; use crate::io::prelude::*; -use crate::cell::{Cell, RefCell}; +#[cfg(not(target_arch = "bpf"))] +use crate::cell::Cell; +use crate::cell::RefCell; use crate::fmt; use crate::fs::File; use crate::io::{self, BorrowedCursor, BufReader, IoSlice, IoSliceMut, LineWriter, Lines}; use crate::sync::atomic::{AtomicBool, Ordering}; -use crate::sync::{Arc, Mutex, MutexGuard, OnceLock, ReentrantMutex, ReentrantMutexGuard}; +#[cfg(not(target_os = "solana"))] +use crate::sync::Arc; +use crate::sync::{Mutex, MutexGuard, OnceLock, ReentrantMutex, ReentrantMutexGuard}; use crate::sys::stdio; +#[cfg(not(target_arch = "bpf"))] type LocalStream = Arc>>; +#[cfg(not(target_arch = "bpf"))] thread_local! { /// Used by the test crate to capture the output of the print macros and panics. static OUTPUT_CAPTURE: Cell> = { @@ -34,6 +40,7 @@ thread_local! { /// have a consistent order between set_output_capture and print_to *within /// the same thread*. Within the same thread, things always have a perfectly /// consistent order. So Ordering::Relaxed is fine. +#[cfg(not(target_arch = "bpf"))] static OUTPUT_CAPTURE_USED: AtomicBool = AtomicBool::new(false); /// A handle to a raw instance of the standard input stream of this process. @@ -62,6 +69,7 @@ struct StderrRaw(stdio::Stderr); /// /// The returned handle has no external synchronization or buffering. #[unstable(feature = "libstd_sys_internals", issue = "none")] +#[cfg(not(target_arch = "bpf"))] const fn stdin_raw() -> StdinRaw { StdinRaw(stdio::Stdin::new()) } @@ -76,6 +84,7 @@ const fn stdin_raw() -> StdinRaw { /// The returned handle has no external synchronization or buffering layered on /// top. #[unstable(feature = "libstd_sys_internals", issue = "none")] +#[cfg(not(target_arch = "bpf"))] const fn stdout_raw() -> StdoutRaw { StdoutRaw(stdio::Stdout::new()) } @@ -88,6 +97,7 @@ const fn stdout_raw() -> StdoutRaw { /// The returned handle has no external synchronization or buffering layered on /// top. #[unstable(feature = "libstd_sys_internals", issue = "none")] +#[cfg(not(target_arch = "bpf"))] const fn stderr_raw() -> StderrRaw { StderrRaw(stdio::Stderr::new()) } @@ -319,6 +329,7 @@ pub struct StdinLock<'a> { /// ``` #[must_use] #[stable(feature = "rust1", since = "1.0.0")] +#[cfg(not(target_arch = "bpf"))] pub fn stdin() -> Stdin { static INSTANCE: OnceLock>> = OnceLock::new(); Stdin { @@ -612,6 +623,7 @@ static STDOUT: OnceLock>>> = OnceLo #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "io_stdout")] +#[cfg(not(target_arch = "bpf"))] pub fn stdout() -> Stdout { Stdout { inner: STDOUT @@ -849,6 +861,7 @@ pub struct StderrLock<'a> { #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "io_stderr")] +#[cfg(not(target_arch = "bpf"))] pub fn stderr() -> Stderr { // Note that unlike `stdout()` we don't use `at_exit` here to register a // destructor. Stderr is not buffered, so there's no need to run a @@ -986,6 +999,7 @@ impl fmt::Debug for StderrLock<'_> { issue = "none" )] #[doc(hidden)] +#[cfg(not(target_arch = "bpf"))] pub fn set_output_capture(sink: Option) -> Option { if sink.is_none() && !OUTPUT_CAPTURE_USED.load(Ordering::Relaxed) { // OUTPUT_CAPTURE is definitely None since OUTPUT_CAPTURE_USED is false. @@ -1008,6 +1022,7 @@ pub fn set_output_capture(sink: Option) -> Option { /// /// Writing to non-blocking stdout/stderr can cause an error, which will lead /// this function to panic. +#[cfg(not(target_arch = "bpf"))] fn print_to(args: fmt::Arguments<'_>, global_s: fn() -> T, label: &str) where T: Write, @@ -1093,10 +1108,21 @@ impl_is_terminal!(File, Stdin, StdinLock<'_>, Stdout, StdoutLock<'_>, Stderr, St )] #[doc(hidden)] #[cfg(not(test))] +#[cfg(not(target_arch = "bpf"))] pub fn _print(args: fmt::Arguments<'_>) { print_to(args, stdout, "stdout"); } +#[unstable( + feature = "print_internals", + reason = "implementation detail which may disappear or be replaced at any time", + issue = "none")] +#[doc(hidden)] +#[cfg(not(test))] +#[cfg(target_arch = "bpf")] +pub fn _print(_args: fmt::Arguments<'_>) { +} + #[unstable( feature = "print_internals", reason = "implementation detail which may disappear or be replaced at any time", @@ -1104,9 +1130,20 @@ pub fn _print(args: fmt::Arguments<'_>) { )] #[doc(hidden)] #[cfg(not(test))] +#[cfg(not(target_arch = "bpf"))] pub fn _eprint(args: fmt::Arguments<'_>) { print_to(args, stderr, "stderr"); } +#[unstable( + feature = "print_internals", + reason = "implementation detail which may disappear or be replaced at any time", + issue = "none")] +#[doc(hidden)] +#[cfg(not(test))] +#[cfg(target_arch = "bpf")] +pub fn _eprint(_args: fmt::Arguments<'_>) { +} + #[cfg(test)] pub use realstd::io::{_eprint, _print}; diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 425890122577f..10c5ed0c95be4 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -421,6 +421,7 @@ extern crate libc; // We always need an unwinder currently for backtraces #[doc(masked)] #[allow(unused_extern_crates)] +#[cfg(not(target_arch = "bpf"))] extern crate unwind; // FIXME: #94122 this extern crate definition only exist here to stop @@ -559,6 +560,7 @@ pub mod f64; #[macro_use] pub mod thread; pub mod ascii; +#[cfg(not(target_arch = "bpf"))] pub mod backtrace; pub mod collections; pub mod env; @@ -640,6 +642,7 @@ pub mod alloc; // Private support modules mod panicking; +#[cfg(not(target_arch = "bpf"))] #[path = "../../backtrace/src/lib.rs"] #[allow(dead_code, unused_attributes, fuzzy_provenance_casts)] mod backtrace_rs; diff --git a/library/std/src/macros.rs b/library/std/src/macros.rs index 34b8b6b97b505..bae96dedda080 100644 --- a/library/std/src/macros.rs +++ b/library/std/src/macros.rs @@ -11,6 +11,7 @@ #[stable(feature = "rust1", since = "1.0.0")] #[allow_internal_unstable(edition_panic)] #[cfg_attr(not(test), rustc_diagnostic_item = "std_panic_macro")] +#[cfg(not(target_arch = "bpf"))] macro_rules! panic { // Expands to either `$crate::panic::panic_2015` or `$crate::panic::panic_2021` // depending on the edition of the caller. @@ -19,6 +20,21 @@ macro_rules! panic { }; } +#[doc(include = "../../core/src/macros/panic.md")] +#[macro_export] +#[stable(feature = "rust1", since = "1.0.0")] +#[allow_internal_unstable(libstd_sys_internals)] +#[cfg_attr(not(any(bootstrap, test)), rustc_diagnostic_item = "std_panic_macro")] +#[cfg(target_arch = "bpf")] +macro_rules! panic { + () => ({ $crate::panic!("explicit panic") }); + ($msg:expr $(,)?) => ({ $crate::panic!("{}", $msg) }); + ($fmt:expr, $($arg:tt)+) => ({ + $crate::rt::begin_panic_fmt(&$crate::format_args!($fmt, $($arg)+), + &($crate::file!(), $crate::line!(), $crate::column!())) + }); +} + /// Prints to the standard output. /// /// Equivalent to the [`println!`] macro except that a newline is not printed at diff --git a/library/std/src/panic.rs b/library/std/src/panic.rs index 69a6f3e6d5ac4..78b83557913e1 100644 --- a/library/std/src/panic.rs +++ b/library/std/src/panic.rs @@ -7,6 +7,7 @@ use crate::collections; use crate::panicking; use crate::sync::atomic::{AtomicUsize, Ordering}; use crate::sync::{Mutex, RwLock}; +#[cfg(not(target_arch = "bpf"))] use crate::thread::Result; #[doc(hidden)] @@ -37,6 +38,7 @@ pub macro panic_2015 { pub use core::panic::panic_2021; #[stable(feature = "panic_hooks", since = "1.10.0")] +#[cfg(not(target_arch = "bpf"))] pub use crate::panicking::{set_hook, take_hook}; #[unstable(feature = "panic_update_hook", issue = "92649")] @@ -56,6 +58,7 @@ pub use core::panic::{AssertUnwindSafe, RefUnwindSafe, UnwindSafe}; /// accessed later using [`PanicInfo::payload`]. /// /// See the [`panic!`] macro for more information about panicking. +#[cfg(not(target_arch = "bpf"))] #[stable(feature = "panic_any", since = "1.51.0")] #[inline] #[track_caller] @@ -138,6 +141,7 @@ where /// assert!(result.is_err()); /// ``` #[stable(feature = "catch_unwind", since = "1.9.0")] +#[cfg(not(target_arch = "bpf"))] pub fn catch_unwind R + UnwindSafe, R>(f: F) -> Result { unsafe { panicking::r#try(f) } } @@ -168,10 +172,20 @@ pub fn catch_unwind R + UnwindSafe, R>(f: F) -> Result { /// } /// ``` #[stable(feature = "resume_unwind", since = "1.9.0")] +#[cfg(not(target_arch = "bpf"))] pub fn resume_unwind(payload: Box) -> ! { panicking::rust_panic_without_hook(payload) } +/// BPF version of resume_unwind +#[stable(feature = "resume_unwind", since = "1.9.0")] +#[cfg(target_arch = "bpf")] +pub fn resume_unwind(_payload: Box) -> ! { + // Only used by thread, redirect to plain old panic + panicking::begin_panic_fmt(&format_args!("unwind"), + &(file!(), line!(), column!())) +} + /// Make all future panics abort directly without running the panic hook or unwinding. /// /// There is no way to undo this; the effect lasts until the process exits or diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index 55f4917a93705..2fd081869ec17 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -10,25 +10,36 @@ #![deny(unsafe_op_in_unsafe_fn)] use crate::panic::BacktraceStyle; -use core::panic::{Location, PanicInfo, PanicPayload}; +#[cfg(not(target_arch = "bpf"))] +use core::panic::{PanicPayload}; +use core::panic::{Location, PanicInfo}; +#[cfg(not(target_arch = "bpf"))] use crate::any::Any; use crate::fmt; +#[cfg(not(target_arch = "bpf"))] use crate::intrinsics; +#[cfg(not(target_arch = "bpf"))] use crate::mem::{self, ManuallyDrop}; +#[cfg(not(target_arch = "bpf"))] use crate::process; +#[cfg(not(target_arch = "bpf"))] use crate::sync::atomic::{AtomicBool, Ordering}; use crate::sync::{PoisonError, RwLock}; +#[cfg(not(target_arch = "bpf"))] use crate::sys::stdio::panic_output; +#[cfg(not(target_arch = "bpf"))] use crate::sys_common::backtrace; +#[cfg(not(target_arch = "bpf"))] use crate::sys_common::thread_info; +#[cfg(not(target_arch = "bpf"))] use crate::thread; -#[cfg(not(test))] +#[cfg(all(not(test), not(target_arch = "bpf")))] use crate::io::set_output_capture; // make sure to use the stderr output configured // by libtest in the real copy of std -#[cfg(test)] +#[cfg(all(test, not(target_arch = "bpf")))] use realstd::io::set_output_capture; // Binary interface to the panic runtime that the standard library depends on. @@ -42,6 +53,7 @@ use realstd::io::set_output_capture; // One day this may look a little less ad-hoc with the compiler helping out to // hook up these functions, but it is not this day! #[allow(improper_ctypes)] +#[cfg(not(target_arch = "bpf"))] extern "C" { fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any + Send + 'static); } @@ -55,7 +67,7 @@ extern "Rust" { /// This function is called by the panic runtime if FFI code catches a Rust /// panic but doesn't rethrow it. We don't support this case since it messes /// with our panic count. -#[cfg(not(test))] +#[cfg(all(not(test), not(target_arch = "bpf")))] #[rustc_std_internal_symbol] extern "C" fn __rust_drop_panic() -> ! { rtabort!("Rust panics must be rethrown"); @@ -63,17 +75,19 @@ extern "C" fn __rust_drop_panic() -> ! { /// This function is called by the panic runtime if it catches an exception /// object which does not correspond to a Rust panic. -#[cfg(not(test))] +#[cfg(all(not(test), not(target_arch = "bpf")))] #[rustc_std_internal_symbol] extern "C" fn __rust_foreign_exception() -> ! { rtabort!("Rust cannot catch foreign exceptions"); } +#[cfg(not(target_arch = "bpf"))] enum Hook { Default, Custom(Box) + 'static + Sync + Send>), } +#[cfg(not(target_os = "solana"))] impl Hook { #[inline] fn into_box(self) -> Box) + 'static + Sync + Send> { @@ -84,6 +98,7 @@ impl Hook { } } +#[cfg(not(target_os = "solana"))] impl Default for Hook { #[inline] fn default() -> Hook { @@ -91,6 +106,7 @@ impl Default for Hook { } } +#[cfg(not(target_os = "solana"))] static HOOK: RwLock = RwLock::new(Hook::Default); /// Registers a custom panic hook, replacing the previously registered hook. @@ -129,6 +145,7 @@ static HOOK: RwLock = RwLock::new(Hook::Default); /// /// panic!("Normal panic"); /// ``` +#[cfg(not(target_arch = "bpf"))] #[stable(feature = "panic_hooks", since = "1.10.0")] pub fn set_hook(hook: Box) + 'static + Sync + Send>) { if thread::panicking() { @@ -173,6 +190,7 @@ pub fn set_hook(hook: Box) + 'static + Sync + Send>) { /// panic!("Normal panic"); /// ``` #[must_use] +#[cfg(not(target_arch = "bpf"))] #[stable(feature = "panic_hooks", since = "1.10.0")] pub fn take_hook() -> Box) + 'static + Sync + Send> { if thread::panicking() { @@ -235,6 +253,7 @@ where } /// The default panic handler. +#[cfg(not(target_arch = "bpf"))] fn default_hook(info: &PanicInfo<'_>) { // If this is a double panic, make sure that we print a backtrace // for this panic. Otherwise only print it if logging is enabled. @@ -293,7 +312,7 @@ fn default_hook(info: &PanicInfo<'_>) { } } -#[cfg(not(test))] +#[cfg(all(not(test), not(target_arch = "bpf")))] #[doc(hidden)] #[cfg(feature = "panic_immediate_abort")] #[unstable(feature = "update_panic_count", issue = "none")] @@ -458,17 +477,19 @@ pub mod panic_count { } } -#[cfg(test)] +#[cfg(all(test, not(target_arch = "bpf")))] pub use realstd::rt::panic_count; /// Invoke a closure, capturing the cause of an unwinding panic if one occurs. #[cfg(feature = "panic_immediate_abort")] +#[cfg(not(target_arch = "bpf"))] pub unsafe fn r#try R>(f: F) -> Result> { Ok(f()) } /// Invoke a closure, capturing the cause of an unwinding panic if one occurs. #[cfg(not(feature = "panic_immediate_abort"))] +#[cfg(not(target_arch = "bpf"))] pub unsafe fn r#try R>(f: F) -> Result> { union Data { f: ManuallyDrop, @@ -582,13 +603,14 @@ pub unsafe fn r#try R>(f: F) -> Result> } /// Determines whether the current thread is unwinding because of panic. +#[cfg(not(target_arch = "bpf"))] #[inline] pub fn panicking() -> bool { !panic_count::count_is_zero() } /// Entry point of panics from the core crate (`panic_impl` lang item). -#[cfg(not(test))] +#[cfg(not(any(test, target_os = "solana")))] #[panic_handler] pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! { struct FormatStringPayload<'a> { @@ -668,6 +690,7 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! { /// This is the entry point of panicking for the non-format-string variants of /// panic!() and assert!(). In particular, this is the only entry point that supports /// arbitrary payloads, not just format strings. +#[cfg(not(target_arch = "bpf"))] #[unstable(feature = "libstd_sys_internals", reason = "used by the panic! macro", issue = "none")] #[cfg_attr(not(test), lang = "begin_panic")] // lang item for CTFE panic support @@ -731,6 +754,7 @@ pub const fn begin_panic(msg: M) -> ! { /// Executes the primary logic for a panic, including checking for recursive /// panics, panic hooks, and finally dispatching to the panic runtime to either /// abort or unwind. +#[cfg(not(target_arch = "bpf"))] fn rust_panic_with_hook( payload: &mut dyn PanicPayload, message: Option<&fmt::Arguments<'_>>, @@ -804,6 +828,7 @@ fn rust_panic_with_hook( /// This is the entry point for `resume_unwind`. /// It just forwards the payload to the panic runtime. #[cfg_attr(feature = "panic_immediate_abort", inline)] +#[cfg(not(target_arch = "bpf"))] pub fn rust_panic_without_hook(payload: Box) -> ! { panic_count::increase(false); @@ -824,6 +849,7 @@ pub fn rust_panic_without_hook(payload: Box) -> ! { /// An unmangled function (through `rustc_std_internal_symbol`) on which to slap /// yer breakpoints. +#[cfg(not(target_arch = "bpf"))] #[inline(never)] #[cfg_attr(not(test), rustc_std_internal_symbol)] #[cfg(not(feature = "panic_immediate_abort"))] @@ -838,4 +864,66 @@ fn rust_panic(_: &mut dyn PanicPayload) -> ! { unsafe { crate::intrinsics::abort(); } + +// Note: The panicking functions have been stripped and rewritten +// in order to save space in BPF programs. Panic messages +// are not supported, just file, line, column. + +/// This function is called by the panic runtime if it catches an exception +/// object which does not correspond to a Rust panic. +#[cfg(all(not(test), target_arch = "bpf"))] +#[rustc_std_internal_symbol] +extern "C" fn __rust_foreign_exception() -> ! { + rtabort!("Rust cannot catch foreign exceptions"); +} + +/// Determines whether the current thread is unwinding because of panic. +#[cfg(target_arch = "bpf")] +pub fn panicking() -> bool { + true +} + +/// Entry point of panic from the libcore crate. +#[cfg(all(not(test), target_arch = "bpf"))] +#[panic_handler] +#[unwind(allowed)] +pub fn rust_begin_panic(info: &PanicInfo<'_>) -> ! { + crate::sys::sol_log("libstd rust_begin_panic"); + crate::sys::panic(info); +} + +/// The entry point for panicking with a formatted message. +/// +/// This is designed to reduce the amount of code required at the call +/// site as much as possible (so that `panic!()` has as low an impact +/// on (e.g.) the inlining of other functions as possible), by moving +/// the actual formatting into this shared place. +#[cfg(target_arch = "bpf")] +#[unstable(feature = "libstd_sys_internals", reason = "used by the panic! macro", issue = "none")] +#[cold] +// If panic_immediate_abort, inline the abort call, +// otherwise avoid inlining because of it is cold path. +#[cfg_attr(not(feature="panic_immediate_abort"),inline(never))] +#[cfg_attr( feature="panic_immediate_abort" ,inline)] +pub fn begin_panic_fmt(msg: &fmt::Arguments<'_>, + file_line_col: &(&'static str, u32, u32)) -> ! { + begin_panic(msg, file_line_col); +} + +/// Entry point of panicking for panic!() and assert!(). +#[cfg(target_arch = "bpf")] +#[unstable(feature = "libstd_sys_internals", reason = "used by the panic! macro", issue = "none")] +#[cfg_attr(not(test), lang = "begin_panic")] +// never inline unless panic_immediate_abort to avoid code +// bloat at the call sites as much as possible +#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))] +#[cold] +pub fn begin_panic(msg: &fmt::Arguments<'_>, file_line_col: &(&'static str, u32, u32)) -> ! { + let (file, line, col) = *file_line_col; + let location = Location::internal_constructor(file, line, col); + let info = PanicInfo::internal_constructor( + Some(msg), + &location, + ); + crate::sys::panic(&info); } diff --git a/library/std/src/process.rs b/library/std/src/process.rs index af6bef1a76e69..d6141bbd71109 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -2206,6 +2206,7 @@ impl Child { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "process_exit")] +#[cfg(not(target_arch = "bpf"))] pub fn exit(code: i32) -> ! { crate::rt::cleanup(); crate::sys::os::exit(code) @@ -2276,7 +2277,10 @@ pub fn exit(code: i32) -> ! { #[stable(feature = "process_abort", since = "1.17.0")] #[cold] pub fn abort() -> ! { + #[cfg(not(target_arch = "bpf"))] crate::sys::abort_internal(); + #[cfg(target_arch = "bpf")] + unsafe { crate::sys::abort_internal(); } } /// Returns the OS-assigned process identifier associated with this process. diff --git a/library/std/src/rt.rs b/library/std/src/rt.rs index 5c83f72f3c1a1..42092c492d4a8 100644 --- a/library/std/src/rt.rs +++ b/library/std/src/rt.rs @@ -122,6 +122,7 @@ pub(crate) fn cleanup() { // To reduce the generated code of the new `lang_start`, this function is doing // the real work. #[cfg(not(test))] +#[cfg(not(target_arch = "bpf"))] fn lang_start_internal( main: &(dyn Fn() -> i32 + Sync + crate::panic::RefUnwindSafe), argc: isize, @@ -156,6 +157,7 @@ fn lang_start_internal( #[cfg(not(test))] #[inline(never)] +#[cfg(not(target_arch = "bpf"))] #[lang = "start"] fn lang_start( main: fn() -> T, diff --git a/library/std/src/sync/once.rs b/library/std/src/sync/once.rs index 2bb4f3f9e0383..255a9fa64ecdb 100644 --- a/library/std/src/sync/once.rs +++ b/library/std/src/sync/once.rs @@ -316,6 +316,7 @@ impl OnceState { /// Poison the associated [`Once`] without explicitly panicking. // NOTE: This is currently only exposed for `OnceLock`. + #[cfg(not(target_os = "solana"))] #[inline] pub(crate) fn poison(&self) { self.inner.poison(); diff --git a/library/std/src/sync/remutex.rs b/library/std/src/sync/remutex.rs index 0ced48d10b7c6..cf7166094b21c 100644 --- a/library/std/src/sync/remutex.rs +++ b/library/std/src/sync/remutex.rs @@ -72,6 +72,7 @@ impl !Send for ReentrantMutexGuard<'_, T> {} impl ReentrantMutex { /// Creates a new reentrant mutex in an unlocked state. + #[cfg(not(target_arch = "bpf"))] pub const fn new(t: T) -> ReentrantMutex { ReentrantMutex { mutex: sys::Mutex::new(), @@ -121,6 +122,7 @@ impl ReentrantMutex { /// If another user of this mutex panicked while holding the mutex, then /// this call will return failure if the mutex would otherwise be /// acquired. + #[cfg(not(target_arch = "bpf"))] pub fn try_lock(&self) -> Option> { let this_thread = current_thread_unique_ptr(); // Safety: We only touch lock_count when we own the lock. diff --git a/library/std/src/sys/bpf/alloc.rs b/library/std/src/sys/bpf/alloc.rs new file mode 100644 index 0000000000000..23e3d4e21af15 --- /dev/null +++ b/library/std/src/sys/bpf/alloc.rs @@ -0,0 +1,37 @@ +//! This is an implementation of a global allocator on the BPF platform. +//! In that situation there's no actual runtime for us +//! to lean on for allocation, so instead we provide our own! +//! +//! The crate itself provides a global allocator which on BPF has no +//! synchronization as there are no threads! + +use crate::alloc::{GlobalAlloc, Layout, System}; + +#[stable(feature = "alloc_system_type", since = "1.28.0")] +unsafe impl GlobalAlloc for System { + #[inline] + unsafe fn alloc(&self, layout: Layout) -> *mut u8 { + sol_alloc_free_(layout.size() as u64, 0) + // 0 as *mut u8 + } + + #[inline] + unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { + sol_alloc_free_(layout.size() as u64, 0) + // 0 as *mut u8 + } + + #[inline] + unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { + sol_alloc_free_(layout.size() as u64, ptr as u64); + } + + // #[inline] + // unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { + // sol_alloc_free_(layout.size() as u64, 0) + // // 0 as *mut u8 + // } +} +extern "C" { + fn sol_alloc_free_(size: u64, ptr: u64) -> *mut u8; +} diff --git a/library/std/src/sys/bpf/args.rs b/library/std/src/sys/bpf/args.rs new file mode 100644 index 0000000000000..eeaac8a48e29d --- /dev/null +++ b/library/std/src/sys/bpf/args.rs @@ -0,0 +1,44 @@ +use crate::ffi::OsString; +use crate::marker::PhantomData; +use crate::vec; + +pub fn args() -> Args { + panic!(); +} + +pub struct Args { + iter: vec::IntoIter, + _dont_send_or_sync_me: PhantomData<*mut ()>, +} + +impl Args { + pub fn inner_debug(&self) -> &[OsString] { + self.iter.as_slice() + } +} + +impl Iterator for Args { + type Item = OsString; + fn next(&mut self) -> Option { + self.iter.next() + } + fn size_hint(&self) -> (usize, Option) { + self.iter.size_hint() + } + #[inline] + fn last(mut self) -> Option { + self.next_back() + } +} + +impl ExactSizeIterator for Args { + fn len(&self) -> usize { + self.iter.len() + } +} + +impl DoubleEndedIterator for Args { + fn next_back(&mut self) -> Option { + self.iter.next_back() + } +} diff --git a/library/std/src/sys/bpf/backtrace.rs b/library/std/src/sys/bpf/backtrace.rs new file mode 100644 index 0000000000000..7d56b298997aa --- /dev/null +++ b/library/std/src/sys/bpf/backtrace.rs @@ -0,0 +1,27 @@ +use crate::io; +use crate::sys::unsupported; +use crate::sys_common::backtrace::Frame; + +pub struct BacktraceContext; + +pub fn unwind_backtrace(_frames: &mut [Frame]) + -> io::Result<(usize, BacktraceContext)> +{ + unsupported() +} + +pub fn resolve_symname(_frame: Frame, + _callback: F, + _: &BacktraceContext) -> io::Result<()> + where F: FnOnce(Option<&str>) -> io::Result<()> +{ + unsupported() +} + +pub fn foreach_symbol_fileline(_: Frame, + _: F, + _: &BacktraceContext) -> io::Result + where F: FnMut(&[u8], u32) -> io::Result<()> +{ + unsupported() +} diff --git a/library/std/src/sys/bpf/cmath.rs b/library/std/src/sys/bpf/cmath.rs new file mode 100644 index 0000000000000..fa7783122c2e9 --- /dev/null +++ b/library/std/src/sys/bpf/cmath.rs @@ -0,0 +1,29 @@ +// These symbols are all defined in `compiler-builtins` +extern { + pub fn acos(n: f64) -> f64; + pub fn acosf(n: f32) -> f32; + pub fn asin(n: f64) -> f64; + pub fn asinf(n: f32) -> f32; + pub fn atan(n: f64) -> f64; + pub fn atan2(a: f64, b: f64) -> f64; + pub fn atan2f(a: f32, b: f32) -> f32; + pub fn atanf(n: f32) -> f32; + pub fn cbrt(n: f64) -> f64; + pub fn cbrtf(n: f32) -> f32; + pub fn cosh(n: f64) -> f64; + pub fn coshf(n: f32) -> f32; + pub fn expm1(n: f64) -> f64; + pub fn expm1f(n: f32) -> f32; + pub fn fdim(a: f64, b: f64) -> f64; + pub fn fdimf(a: f32, b: f32) -> f32; + pub fn hypot(x: f64, y: f64) -> f64; + pub fn hypotf(x: f32, y: f32) -> f32; + pub fn log1p(n: f64) -> f64; + pub fn log1pf(n: f32) -> f32; + pub fn sinh(n: f64) -> f64; + pub fn sinhf(n: f32) -> f32; + pub fn tan(n: f64) -> f64; + pub fn tanf(n: f32) -> f32; + pub fn tanh(n: f64) -> f64; + pub fn tanhf(n: f32) -> f32; +} diff --git a/library/std/src/sys/bpf/condvar.rs b/library/std/src/sys/bpf/condvar.rs new file mode 100644 index 0000000000000..792330a6eb551 --- /dev/null +++ b/library/std/src/sys/bpf/condvar.rs @@ -0,0 +1,35 @@ +use crate::sys::mutex::Mutex; +use crate::time::Duration; + +pub struct Condvar { } + +pub type MovableCondvar = Box; + +impl Condvar { + pub const fn new() -> Condvar { + Condvar { } + } + + #[inline] + pub unsafe fn init(&mut self) {} + + #[inline] + pub unsafe fn notify_one(&self) { + } + + #[inline] + pub unsafe fn notify_all(&self) { + } + + pub unsafe fn wait(&self, _mutex: &Mutex) { + panic!("can't block with web assembly") + } + + pub unsafe fn wait_timeout(&self, _mutex: &Mutex, _dur: Duration) -> bool { + panic!("can't block with web assembly"); + } + + #[inline] + pub unsafe fn destroy(&self) { + } +} diff --git a/library/std/src/sys/bpf/condvar_atomics.rs b/library/std/src/sys/bpf/condvar_atomics.rs new file mode 100644 index 0000000000000..a9adf01ef89e8 --- /dev/null +++ b/library/std/src/sys/bpf/condvar_atomics.rs @@ -0,0 +1,48 @@ +use crate::cmp; +use crate::mem; +use crate::sync::atomic::{AtomicUsize, Ordering::SeqCst}; +use crate::sys::mutex::Mutex; +use crate::time::Duration; + +pub struct Condvar { + cnt: AtomicUsize, +} + +impl Condvar { + pub const fn new() -> Condvar { + Condvar { cnt: AtomicUsize::new(0) } + } + + #[inline] + pub unsafe fn init(&mut self) { + // nothing to do... + } + + pub unsafe fn notify_one(&self) { + // nothing to do... + } + + #[inline] + pub unsafe fn notify_all(&self) { + // nothing to do... + } + + pub unsafe fn wait(&self, mutex: &Mutex) { + // nothing to do... + } + + pub unsafe fn wait_timeout(&self, mutex: &Mutex, dur: Duration) -> bool { + true + } + + #[inline] + pub unsafe fn destroy(&self) { + // nothing to do + } + + #[inline] + fn ptr(&self) -> *mut i32 { + assert_eq!(mem::size_of::(), mem::size_of::()); + &self.cnt as *const AtomicUsize as *mut i32 + } +} diff --git a/library/std/src/sys/bpf/env.rs b/library/std/src/sys/bpf/env.rs new file mode 100644 index 0000000000000..277aa067da2fd --- /dev/null +++ b/library/std/src/sys/bpf/env.rs @@ -0,0 +1,9 @@ +pub mod os { + pub const FAMILY: &str = ""; + pub const OS: &str = ""; + pub const DLL_PREFIX: &str = ""; + pub const DLL_SUFFIX: &str = ".so"; + pub const DLL_EXTENSION: &str = "so"; + pub const EXE_SUFFIX: &str = ".so"; + pub const EXE_EXTENSION: &str = "so"; +} diff --git a/library/std/src/sys/bpf/fs.rs b/library/std/src/sys/bpf/fs.rs new file mode 100644 index 0000000000000..59fe2f9aacc1a --- /dev/null +++ b/library/std/src/sys/bpf/fs.rs @@ -0,0 +1,312 @@ +use crate::ffi::OsString; +use crate::fmt; +use crate::hash::{Hash, Hasher}; +use crate::io::{self, SeekFrom, IoSlice, IoSliceMut}; +use crate::path::{Path, PathBuf}; +use crate::sys::time::SystemTime; +use crate::sys::{unsupported, Void}; + +pub struct File(Void); + +pub struct FileAttr(Void); + +pub struct ReadDir(Void); + +pub struct DirEntry(Void); + +#[derive(Clone, Debug)] +pub struct OpenOptions { } + +pub struct FilePermissions(Void); + +pub struct FileType(Void); + +#[derive(Debug)] +pub struct DirBuilder { } + +impl FileAttr { + pub fn size(&self) -> u64 { + match self.0 {} + } + + pub fn perm(&self) -> FilePermissions { + match self.0 {} + } + + pub fn file_type(&self) -> FileType { + match self.0 {} + } + + pub fn modified(&self) -> io::Result { + match self.0 {} + } + + pub fn accessed(&self) -> io::Result { + match self.0 {} + } + + pub fn created(&self) -> io::Result { + match self.0 {} + } +} + +impl Clone for FileAttr { + fn clone(&self) -> FileAttr { + match self.0 {} + } +} + +impl FilePermissions { + pub fn readonly(&self) -> bool { + match self.0 {} + } + + pub fn set_readonly(&mut self, _readonly: bool) { + match self.0 {} + } +} + +impl Clone for FilePermissions { + fn clone(&self) -> FilePermissions { + match self.0 {} + } +} + +impl PartialEq for FilePermissions { + fn eq(&self, _other: &FilePermissions) -> bool { + match self.0 {} + } +} + +impl Eq for FilePermissions { +} + +impl fmt::Debug for FilePermissions { + fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self.0 {} + } +} + +impl FileType { + pub fn is_dir(&self) -> bool { + match self.0 {} + } + + pub fn is_file(&self) -> bool { + match self.0 {} + } + + pub fn is_symlink(&self) -> bool { + match self.0 {} + } +} + +impl Clone for FileType { + fn clone(&self) -> FileType { + match self.0 {} + } +} + +impl Copy for FileType {} + +impl PartialEq for FileType { + fn eq(&self, _other: &FileType) -> bool { + match self.0 {} + } +} + +impl Eq for FileType { +} + +impl Hash for FileType { + fn hash(&self, _h: &mut H) { + match self.0 {} + } +} + +impl fmt::Debug for FileType { + fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self.0 {} + } +} + +impl fmt::Debug for ReadDir { + fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self.0 {} + } +} + +impl Iterator for ReadDir { + type Item = io::Result; + + fn next(&mut self) -> Option> { + match self.0 {} + } +} + +impl DirEntry { + pub fn path(&self) -> PathBuf { + match self.0 {} + } + + pub fn file_name(&self) -> OsString { + match self.0 {} + } + + pub fn metadata(&self) -> io::Result { + match self.0 {} + } + + pub fn file_type(&self) -> io::Result { + match self.0 {} + } +} + +impl OpenOptions { + pub fn new() -> OpenOptions { + OpenOptions { } + } + + pub fn read(&mut self, _read: bool) { } + pub fn write(&mut self, _write: bool) { } + pub fn append(&mut self, _append: bool) { } + pub fn truncate(&mut self, _truncate: bool) { } + pub fn create(&mut self, _create: bool) { } + pub fn create_new(&mut self, _create_new: bool) { } +} + +impl File { + pub fn open(_path: &Path, _opts: &OpenOptions) -> io::Result { + unsupported() + } + + pub fn file_attr(&self) -> io::Result { + match self.0 {} + } + + pub fn fsync(&self) -> io::Result<()> { + match self.0 {} + } + + pub fn datasync(&self) -> io::Result<()> { + match self.0 {} + } + + pub fn truncate(&self, _size: u64) -> io::Result<()> { + match self.0 {} + } + + pub fn read(&self, _buf: &mut [u8]) -> io::Result { + match self.0 {} + } + + pub fn read_vectored(&self, _bufs: &mut [IoSliceMut<'_>]) -> io::Result { + match self.0 {} + } + + #[inline] + pub fn is_read_vectored(&self) -> bool { + false + } + + pub fn write(&self, _buf: &[u8]) -> io::Result { + match self.0 {} + } + + pub fn write_vectored(&self, _bufs: &[IoSlice<'_>]) -> io::Result { + match self.0 {} + } + + #[inline] + pub fn is_write_vectored(&self) -> bool { + false + } + + pub fn flush(&self) -> io::Result<()> { + match self.0 {} + } + + pub fn seek(&self, _pos: SeekFrom) -> io::Result { + match self.0 {} + } + + pub fn duplicate(&self) -> io::Result { + match self.0 {} + } + + pub fn set_permissions(&self, _perm: FilePermissions) -> io::Result<()> { + match self.0 {} + } + + pub fn diverge(&self) -> ! { + match self.0 {} + } +} + +impl DirBuilder { + pub fn new() -> DirBuilder { + DirBuilder { } + } + + pub fn mkdir(&self, _p: &Path) -> io::Result<()> { + unsupported() + } +} + +impl fmt::Debug for File { + fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self.0 {} + } +} + +pub fn readdir(_p: &Path) -> io::Result { + unsupported() +} + +pub fn unlink(_p: &Path) -> io::Result<()> { + unsupported() +} + +pub fn rename(_old: &Path, _new: &Path) -> io::Result<()> { + unsupported() +} + +pub fn set_perm(_p: &Path, perm: FilePermissions) -> io::Result<()> { + match perm.0 {} +} + +pub fn rmdir(_p: &Path) -> io::Result<()> { + unsupported() +} + +pub fn remove_dir_all(_path: &Path) -> io::Result<()> { + unsupported() +} + +pub fn readlink(_p: &Path) -> io::Result { + unsupported() +} + +pub fn symlink(_src: &Path, _dst: &Path) -> io::Result<()> { + unsupported() +} + +pub fn link(_src: &Path, _dst: &Path) -> io::Result<()> { + unsupported() +} + +pub fn stat(_p: &Path) -> io::Result { + unsupported() +} + +pub fn lstat(_p: &Path) -> io::Result { + unsupported() +} + +pub fn canonicalize(_p: &Path) -> io::Result { + unsupported() +} + +pub fn copy(_from: &Path, _to: &Path) -> io::Result { + unsupported() +} diff --git a/library/std/src/sys/bpf/io.rs b/library/std/src/sys/bpf/io.rs new file mode 100644 index 0000000000000..84f13532f308b --- /dev/null +++ b/library/std/src/sys/bpf/io.rs @@ -0,0 +1,48 @@ +use crate::mem; + +#[derive(Copy, Clone)] +#[repr(transparent)] +pub struct IoSlice<'a>(&'a [u8]); + +impl<'a> IoSlice<'a> { + #[inline] + pub fn new(buf: &'a [u8]) -> IoSlice<'a> { + IoSlice(buf) + } + + #[inline] + pub fn advance(&mut self, n: usize) { + self.0 = &self.0[n..] + } + + #[inline] + pub fn as_slice(&self) -> &[u8] { + self.0 + } +} + +pub struct IoSliceMut<'a>(&'a mut [u8]); + +impl<'a> IoSliceMut<'a> { + #[inline] + pub fn new(buf: &'a mut [u8]) -> IoSliceMut<'a> { + IoSliceMut(buf) + } + + #[inline] + pub fn advance(&mut self, n: usize) { + let slice = mem::replace(&mut self.0, &mut []); + let (_, remaining) = slice.split_at_mut(n); + self.0 = remaining; + } + + #[inline] + pub fn as_slice(&self) -> &[u8] { + self.0 + } + + #[inline] + pub fn as_mut_slice(&mut self) -> &mut [u8] { + self.0 + } +} diff --git a/library/std/src/sys/bpf/memchr.rs b/library/std/src/sys/bpf/memchr.rs new file mode 100644 index 0000000000000..9967482197eb3 --- /dev/null +++ b/library/std/src/sys/bpf/memchr.rs @@ -0,0 +1 @@ +pub use core::slice::memchr::{memchr, memrchr}; diff --git a/library/std/src/sys/bpf/mod.rs b/library/std/src/sys/bpf/mod.rs new file mode 100644 index 0000000000000..91e763ebe37ec --- /dev/null +++ b/library/std/src/sys/bpf/mod.rs @@ -0,0 +1,100 @@ +//! System bindings for the BPF platform +//! +//! This module contains the facade (aka platform-specific) implementations of +//! OS level functionality for BPF +//! +//! This is all super highly experimental and not actually intended for +//! wide/production use yet, it's still all in the experimental category. This +//! will likely change over time. +//! +//! Currently all functions here are basically stubs that immediately return +//! errors. The hope is that with a portability lint we can turn actually just +//! remove all this and just omit parts of the standard library if we're +//! compiling for BPF. That way it's a compile time error for something that's +//! guaranteed to be a runtime error! + +use crate::os::raw::c_char; + +pub mod alloc; +pub mod args; +//#[cfg(feature = "backtrace")] +//pub mod backtrace; +pub mod cmath; +pub mod env; +pub mod fs; +pub mod io; +pub mod memchr; +pub mod net; +pub mod os; +pub mod path; +pub mod pipe; +pub mod process; +pub mod thread; +pub mod time; +pub mod stdio; + +pub mod condvar; +pub mod mutex; +pub mod rwlock; +pub mod thread_local_dtor; +pub mod thread_local_key; + +pub use crate::sys_common::os_str_bytes as os_str; + +extern "C" { + fn abort() -> !; + #[allow(improper_ctypes)] + fn custom_panic(info: &core::panic::PanicInfo<'_>); + fn sol_log_(message: *const u8, length: u64); +} + +pub fn sol_log(message: &str) { + unsafe { + sol_log_(message.as_ptr(), message.len() as u64); + } +} + +pub fn panic(info: &core::panic::PanicInfo<'_>) -> ! { + unsafe { custom_panic(info); } + unsafe { abort(); } +} + +pub fn unsupported() -> crate::io::Result { + Err(unsupported_err()) +} + +pub fn unsupported_err() -> crate::io::Error { + crate::io::Error::new(crate::io::ErrorKind::Other, + "operation not supported on BPF yet") +} + +pub fn decode_error_kind(_code: i32) -> crate::io::ErrorKind { + crate::io::ErrorKind::Other +} + +// This enum is used as the storage for a bunch of types which can't actually +// exist. +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] +pub enum Void {} + +pub unsafe fn strlen(mut s: *const c_char) -> usize { + let mut n = 0; + while *s != 0 { + n += 1; + s = s.offset(1); + } + return n +} + +pub unsafe fn abort_internal() -> ! { + abort() +} + +// We don't have randomness yet, but I totally used a random number generator to +// generate these numbers. +// +// More seriously though this is just for DOS protection in hash maps. It's ok +// if we don't do that on BPF just yet. +pub fn hashmap_random_keys() -> (u64, u64) { + (1, 2) +} diff --git a/library/std/src/sys/bpf/mutex.rs b/library/std/src/sys/bpf/mutex.rs new file mode 100644 index 0000000000000..4411b0a9c4236 --- /dev/null +++ b/library/std/src/sys/bpf/mutex.rs @@ -0,0 +1,55 @@ +use crate::cell::UnsafeCell; + +pub struct Mutex { + inner: UnsafeCell, +} + +pub type MovableMutex = Box; + +unsafe impl Send for Mutex {} +unsafe impl Sync for Mutex {} // no threads on BPF + +#[allow(dead_code)] // sys isn't exported yet +impl Mutex { + pub const fn new() -> Mutex { + Mutex { inner: UnsafeCell::new(false) } + } + #[inline] + pub unsafe fn init(&self) {} + #[inline] + pub unsafe fn lock(&self) { + let locked = self.inner.get(); + assert!(!*locked, "cannot recursively acquire mutex"); + *locked = true; + } + #[inline] + pub unsafe fn unlock(&self) { + *self.inner.get() = false; + } + #[inline] + pub unsafe fn try_lock(&self) -> bool { + let locked = self.inner.get(); + if *locked { + false + } else { + *locked = true; + true + } + } + #[inline] + pub unsafe fn destroy(&self) { + } +} + +// All empty stubs because BPF has no threads, lock acquisition always +// succeeds. +pub struct ReentrantMutex { + pub inner: UnsafeCell, +} + +impl ReentrantMutex { + // pub unsafe fn init(&self) {} + pub unsafe fn lock(&self) {} + pub unsafe fn unlock(&self) {} + pub unsafe fn destroy(&self) {} +} diff --git a/library/std/src/sys/bpf/mutex_atomics.rs b/library/std/src/sys/bpf/mutex_atomics.rs new file mode 100644 index 0000000000000..abe7a91541cce --- /dev/null +++ b/library/std/src/sys/bpf/mutex_atomics.rs @@ -0,0 +1,92 @@ +// use crate::arch::BPF; +use crate::cell::UnsafeCell; +use crate::mem; +use crate::sync::atomic::{AtomicUsize, AtomicU32, Ordering::SeqCst}; +use crate::sys::thread; + +pub struct Mutex { + locked: AtomicUsize, +} + +impl Mutex { + pub const fn new() -> Mutex { + Mutex { locked: AtomicUsize::new(0) } + } + + #[inline] + pub unsafe fn init(&mut self) { + // nothing to do + } + + pub unsafe fn lock(&self) { + // nothing to do... + } + + pub unsafe fn unlock(&self) { + // nothing to do... + } + + #[inline] + pub unsafe fn try_lock(&self) -> bool { + true + } + + #[inline] + pub unsafe fn destroy(&self) { + // nothing to do + } + + #[inline] + fn ptr(&self) -> *mut i32 { + assert_eq!(mem::size_of::(), mem::size_of::()); + &self.locked as *const AtomicUsize as *mut isize as *mut i32 + } +} + +pub struct ReentrantMutex { + owner: AtomicU32, + recursions: UnsafeCell, +} + +unsafe impl Send for ReentrantMutex {} +unsafe impl Sync for ReentrantMutex {} + +impl ReentrantMutex { + pub unsafe fn uninitialized() -> ReentrantMutex { + ReentrantMutex { + owner: AtomicU32::new(0), + recursions: UnsafeCell::new(0), + } + } + + pub unsafe fn init(&mut self) { + // nothing to do... + } + + pub unsafe fn lock(&self) { + // nothing to do... + } + + #[inline] + pub unsafe fn try_lock(&self) -> bool { + // nothing to do... + } + + #[inline] + unsafe fn _try_lock(&self, id: u32) -> Result<(), u32> { + Ok(()) + } + + pub unsafe fn unlock(&self) { + // nothing to do... + } + + pub unsafe fn destroy(&self) { + // nothing to do... + } + + #[inline] + fn ptr(&self) -> *mut i32 { + &self.owner as *const AtomicU32 as *mut i32 + } +} diff --git a/library/std/src/sys/bpf/net.rs b/library/std/src/sys/bpf/net.rs new file mode 100644 index 0000000000000..53001f5166730 --- /dev/null +++ b/library/std/src/sys/bpf/net.rs @@ -0,0 +1,368 @@ +use crate::fmt; +use crate::io::{self, IoSlice, IoSliceMut}; +use crate::net::{SocketAddr, Shutdown, Ipv4Addr, Ipv6Addr}; +use crate::time::Duration; +use crate::sys::{unsupported, Void}; +use crate::convert::TryFrom; + +pub struct TcpStream(Void); + +impl TcpStream { + pub fn connect(_: io::Result<&SocketAddr>) -> io::Result { + unsupported() + } + + pub fn connect_timeout(_: &SocketAddr, _: Duration) -> io::Result { + unsupported() + } + + pub fn set_read_timeout(&self, _: Option) -> io::Result<()> { + match self.0 {} + } + + pub fn set_write_timeout(&self, _: Option) -> io::Result<()> { + match self.0 {} + } + + pub fn read_timeout(&self) -> io::Result> { + match self.0 {} + } + + pub fn write_timeout(&self) -> io::Result> { + match self.0 {} + } + + #[inline] + pub fn is_write_vectored(&self) -> bool { + false + } + + pub fn peek(&self, _: &mut [u8]) -> io::Result { + match self.0 {} + } + + pub fn read(&self, _: &mut [u8]) -> io::Result { + match self.0 {} + } + + pub fn read_vectored(&self, _: &mut [IoSliceMut<'_>]) -> io::Result { + match self.0 {} + } + + #[inline] + pub fn is_read_vectored(&self) -> bool { + false + } + + pub fn write(&self, _: &[u8]) -> io::Result { + match self.0 {} + } + + pub fn write_vectored(&self, _: &[IoSlice<'_>]) -> io::Result { + match self.0 {} + } + + pub fn peer_addr(&self) -> io::Result { + match self.0 {} + } + + pub fn socket_addr(&self) -> io::Result { + match self.0 {} + } + + pub fn shutdown(&self, _: Shutdown) -> io::Result<()> { + match self.0 {} + } + + pub fn duplicate(&self) -> io::Result { + match self.0 {} + } + + pub fn set_nodelay(&self, _: bool) -> io::Result<()> { + match self.0 {} + } + + pub fn nodelay(&self) -> io::Result { + match self.0 {} + } + + pub fn set_ttl(&self, _: u32) -> io::Result<()> { + match self.0 {} + } + + pub fn ttl(&self) -> io::Result { + match self.0 {} + } + + pub fn take_error(&self) -> io::Result> { + match self.0 {} + } + + pub fn set_nonblocking(&self, _: bool) -> io::Result<()> { + match self.0 {} + } +} + +impl fmt::Debug for TcpStream { + fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self.0 {} + } +} + +pub struct TcpListener(Void); + +impl TcpListener { + pub fn bind(_: io::Result<&SocketAddr>) -> io::Result { + unsupported() + } + + pub fn socket_addr(&self) -> io::Result { + match self.0 {} + } + + pub fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> { + match self.0 {} + } + + pub fn duplicate(&self) -> io::Result { + match self.0 {} + } + + pub fn set_ttl(&self, _: u32) -> io::Result<()> { + match self.0 {} + } + + pub fn ttl(&self) -> io::Result { + match self.0 {} + } + + pub fn set_only_v6(&self, _: bool) -> io::Result<()> { + match self.0 {} + } + + pub fn only_v6(&self) -> io::Result { + match self.0 {} + } + + pub fn take_error(&self) -> io::Result> { + match self.0 {} + } + + pub fn set_nonblocking(&self, _: bool) -> io::Result<()> { + match self.0 {} + } +} + +impl fmt::Debug for TcpListener { + fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self.0 {} + } +} + +pub struct UdpSocket(Void); + +impl UdpSocket { + pub fn bind(_: io::Result<&SocketAddr>) -> io::Result { + unsupported() + } + + pub fn peer_addr(&self) -> io::Result { + match self.0 {} + } + + pub fn socket_addr(&self) -> io::Result { + match self.0 {} + } + + pub fn recv_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> { + match self.0 {} + } + + pub fn peek_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> { + match self.0 {} + } + + pub fn send_to(&self, _: &[u8], _: &SocketAddr) -> io::Result { + match self.0 {} + } + + pub fn duplicate(&self) -> io::Result { + match self.0 {} + } + + pub fn set_read_timeout(&self, _: Option) -> io::Result<()> { + match self.0 {} + } + + pub fn set_write_timeout(&self, _: Option) -> io::Result<()> { + match self.0 {} + } + + pub fn read_timeout(&self) -> io::Result> { + match self.0 {} + } + + pub fn write_timeout(&self) -> io::Result> { + match self.0 {} + } + + pub fn set_broadcast(&self, _: bool) -> io::Result<()> { + match self.0 {} + } + + pub fn broadcast(&self) -> io::Result { + match self.0 {} + } + + pub fn set_multicast_loop_v4(&self, _: bool) -> io::Result<()> { + match self.0 {} + } + + pub fn multicast_loop_v4(&self) -> io::Result { + match self.0 {} + } + + pub fn set_multicast_ttl_v4(&self, _: u32) -> io::Result<()> { + match self.0 {} + } + + pub fn multicast_ttl_v4(&self) -> io::Result { + match self.0 {} + } + + pub fn set_multicast_loop_v6(&self, _: bool) -> io::Result<()> { + match self.0 {} + } + + pub fn multicast_loop_v6(&self) -> io::Result { + match self.0 {} + } + + pub fn join_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr) + -> io::Result<()> { + match self.0 {} + } + + pub fn join_multicast_v6(&self, _: &Ipv6Addr, _: u32) + -> io::Result<()> { + match self.0 {} + } + + pub fn leave_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr) + -> io::Result<()> { + match self.0 {} + } + + pub fn leave_multicast_v6(&self, _: &Ipv6Addr, _: u32) + -> io::Result<()> { + match self.0 {} + } + + pub fn set_ttl(&self, _: u32) -> io::Result<()> { + match self.0 {} + } + + pub fn ttl(&self) -> io::Result { + match self.0 {} + } + + pub fn take_error(&self) -> io::Result> { + match self.0 {} + } + + pub fn set_nonblocking(&self, _: bool) -> io::Result<()> { + match self.0 {} + } + + pub fn recv(&self, _: &mut [u8]) -> io::Result { + match self.0 {} + } + + pub fn peek(&self, _: &mut [u8]) -> io::Result { + match self.0 {} + } + + pub fn send(&self, _: &[u8]) -> io::Result { + match self.0 {} + } + + pub fn connect(&self, _: io::Result<&SocketAddr>) -> io::Result<()> { + match self.0 {} + } +} + +impl fmt::Debug for UdpSocket { + fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self.0 {} + } +} + +pub struct LookupHost(Void); + +impl LookupHost { + pub fn port(&self) -> u16 { + match self.0 {} + } +} + +impl Iterator for LookupHost { + type Item = SocketAddr; + fn next(&mut self) -> Option { + match self.0 {} + } +} + +impl TryFrom<&str> for LookupHost { + type Error = io::Error; + + fn try_from(_v: &str) -> io::Result { + unsupported() + } +} + +impl<'a> TryFrom<(&'a str, u16)> for LookupHost { + type Error = io::Error; + + fn try_from(_v: (&'a str, u16)) -> io::Result { + unsupported() + } +} + +#[allow(nonstandard_style)] +pub mod netc { + pub const AF_INET: u8 = 0; + pub const AF_INET6: u8 = 1; + pub type sa_family_t = u8; + + #[derive(Copy, Clone)] + pub struct in_addr { + pub s_addr: u32, + } + + #[derive(Copy, Clone)] + pub struct sockaddr_in { + pub sin_family: sa_family_t, + pub sin_port: u16, + pub sin_addr: in_addr, + } + + #[derive(Copy, Clone)] + pub struct in6_addr { + pub s6_addr: [u8; 16], + } + + #[derive(Copy, Clone)] + pub struct sockaddr_in6 { + pub sin6_family: sa_family_t, + pub sin6_port: u16, + pub sin6_addr: in6_addr, + pub sin6_flowinfo: u32, + pub sin6_scope_id: u32, + } + + #[derive(Copy, Clone)] + pub struct sockaddr { + } + + pub type socklen_t = usize; +} diff --git a/library/std/src/sys/bpf/os.rs b/library/std/src/sys/bpf/os.rs new file mode 100644 index 0000000000000..2718bb0b7a0c5 --- /dev/null +++ b/library/std/src/sys/bpf/os.rs @@ -0,0 +1,98 @@ +use crate::error::Error as StdError; +use crate::ffi::{OsString, OsStr}; +use crate::fmt; +use crate::io; +use crate::path::{self, PathBuf}; +use crate::str; +use crate::sys::{unsupported, Void}; + +pub fn errno() -> i32 { + 0 +} + +pub fn error_string(_errno: i32) -> String { + "operation successful".to_string() +} + +pub fn getcwd() -> io::Result { + unsupported() +} + +pub fn chdir(_: &path::Path) -> io::Result<()> { + unsupported() +} + +pub struct SplitPaths<'a>(&'a Void); + +pub fn split_paths(_unparsed: &OsStr) -> SplitPaths<'_> { + panic!(); +} + +impl<'a> Iterator for SplitPaths<'a> { + type Item = PathBuf; + fn next(&mut self) -> Option { + match *self.0 {} + } +} + +#[derive(Debug)] +pub struct JoinPathsError; + +pub fn join_paths(_paths: I) -> Result + where I: Iterator, T: AsRef +{ + Err(JoinPathsError) +} + +impl fmt::Display for JoinPathsError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + "not supported on BPF yet".fmt(f) + } +} + +impl StdError for JoinPathsError { + fn description(&self) -> &str { + "not supported on BPF yet" + } +} + +pub fn current_exe() -> io::Result { + unsupported() +} + +pub struct Env(Void); + +impl Iterator for Env { + type Item = (OsString, OsString); + fn next(&mut self) -> Option<(OsString, OsString)> { + match self.0 {} + } +} + +pub fn env() -> Env { + panic!(); +} + +pub fn getenv(_k: &OsStr) -> io::Result> { + unsupported() +} + +pub fn setenv(_k: &OsStr, _v: &OsStr) -> io::Result<()> { + unsupported() +} + +pub fn unsetenv(_k: &OsStr) -> io::Result<()> { + unsupported() +} + +pub fn temp_dir() -> PathBuf { + panic!(); +} + +pub fn home_dir() -> Option { + None +} + +pub fn getpid() -> u32 { + 0 +} diff --git a/library/std/src/sys/bpf/path.rs b/library/std/src/sys/bpf/path.rs new file mode 100644 index 0000000000000..7a18395610785 --- /dev/null +++ b/library/std/src/sys/bpf/path.rs @@ -0,0 +1,19 @@ +use crate::path::Prefix; +use crate::ffi::OsStr; + +#[inline] +pub fn is_sep_byte(b: u8) -> bool { + b == b'/' +} + +#[inline] +pub fn is_verbatim_sep(b: u8) -> bool { + b == b'/' +} + +pub fn parse_prefix(_: &OsStr) -> Option> { + None +} + +pub const MAIN_SEP_STR: &str = "/"; +pub const MAIN_SEP: char = '/'; diff --git a/library/std/src/sys/bpf/pipe.rs b/library/std/src/sys/bpf/pipe.rs new file mode 100644 index 0000000000000..d455c28715df2 --- /dev/null +++ b/library/std/src/sys/bpf/pipe.rs @@ -0,0 +1,44 @@ +use crate::io::{self, IoSlice, IoSliceMut}; +use crate::sys::Void; + +pub struct AnonPipe(Void); + +impl AnonPipe { + pub fn read(&self, _buf: &mut [u8]) -> io::Result { + match self.0 {} + } + + + pub fn read_vectored(&self, _bufs: &mut [IoSliceMut<'_>]) -> io::Result { + match self.0 {} + } + + #[inline] + pub fn is_read_vectored(&self) -> bool { + false + } + + pub fn write(&self, _buf: &[u8]) -> io::Result { + match self.0 {} + } + + pub fn write_vectored(&self, _bufs: &[IoSlice<'_>]) -> io::Result { + match self.0 {} + } + + #[inline] + pub fn is_write_vectored(&self) -> bool { + false + } + + pub fn diverge(&self) -> ! { + match self.0 {} + } +} + +pub fn read2(p1: AnonPipe, + _v1: &mut Vec, + _p2: AnonPipe, + _v2: &mut Vec) -> io::Result<()> { + match p1.0 {} +} diff --git a/library/std/src/sys/bpf/process.rs b/library/std/src/sys/bpf/process.rs new file mode 100644 index 0000000000000..0abc112e9fa8d --- /dev/null +++ b/library/std/src/sys/bpf/process.rs @@ -0,0 +1,204 @@ +use crate::ffi::{CString, OsStr}; +use crate::fmt; +use crate::io; +use crate::path::Path; +use crate::sys::fs::File; +use crate::sys::pipe::AnonPipe; +use crate::sys::{unsupported, Void}; +use crate::sys_common::process::{CommandEnv, CommandEnvs}; + +pub use crate::ffi::OsString as EnvKey; + +//////////////////////////////////////////////////////////////////////////////// +// Command +//////////////////////////////////////////////////////////////////////////////// + +pub struct Command { + env: CommandEnv, + args: Vec, +} + +// passed back to std::process with the pipes connected to the child, if any +// were requested +pub struct StdioPipes { + pub stdin: Option, + pub stdout: Option, + pub stderr: Option, +} + +pub enum Stdio { + Inherit, + Null, + MakePipe, +} + +impl Command { + pub fn new(_program: &OsStr) -> Command { + Command { + env: Default::default(), + args: vec![CString::new("").unwrap()] + } + } + + pub fn arg(&mut self, _arg: &OsStr) { + } + + pub fn env_mut(&mut self) -> &mut CommandEnv { + &mut self.env + } + + pub fn cwd(&mut self, _dir: &OsStr) { + } + + pub fn stdin(&mut self, _stdin: Stdio) { + } + + pub fn stdout(&mut self, _stdout: Stdio) { + } + + pub fn stderr(&mut self, _stderr: Stdio) { + } + + pub fn spawn(&mut self, _default: Stdio, _needs_stdin: bool) + -> io::Result<(Process, StdioPipes)> { + unsupported() + } + + pub fn get_args(&self) -> CommandArgs<'_> { + let mut iter = self.args.iter(); + iter.next(); + CommandArgs { iter } + } + + pub fn get_envs(&self) -> CommandEnvs<'_> { + self.env.iter() + } + + pub fn get_current_dir(&self) -> Option<&Path> { + Some(Path::new(OsStr::new(""))) + } + + pub fn get_program(&self) -> &OsStr { + OsStr::new("") + } +} + +impl From for Stdio { + fn from(pipe: AnonPipe) -> Stdio { + pipe.diverge() + } +} + +impl From for Stdio { + fn from(file: File) -> Stdio { + file.diverge() + } +} + +impl fmt::Debug for Command { + fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { + Ok(()) + } +} + +pub struct ExitStatus(Void); + +impl ExitStatus { + pub fn success(&self) -> bool { + match self.0 {} + } + + pub fn code(&self) -> Option { + match self.0 {} + } +} + +impl Clone for ExitStatus { + fn clone(&self) -> ExitStatus { + match self.0 {} + } +} + +impl Copy for ExitStatus {} + +impl PartialEq for ExitStatus { + fn eq(&self, _other: &ExitStatus) -> bool { + match self.0 {} + } +} + +impl Eq for ExitStatus { +} + +impl fmt::Debug for ExitStatus { + fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self.0 {} + } +} + +impl fmt::Display for ExitStatus { + fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self.0 {} + } +} + +#[derive(PartialEq, Eq, Clone, Copy, Debug)] +pub struct ExitCode(bool); + +impl ExitCode { + pub const SUCCESS: ExitCode = ExitCode(false); + pub const FAILURE: ExitCode = ExitCode(true); + + pub fn as_i32(&self) -> i32 { + self.0 as i32 + } +} + +pub struct Process(Void); + +impl Process { + pub fn id(&self) -> u32 { + match self.0 {} + } + + pub fn kill(&mut self) -> io::Result<()> { + match self.0 {} + } + + pub fn wait(&mut self) -> io::Result { + match self.0 {} + } + + pub fn try_wait(&mut self) -> io::Result> { + match self.0 {} + } +} + +pub struct CommandArgs<'a> { + iter: crate::slice::Iter<'a, CString>, +} + +impl<'a> Iterator for CommandArgs<'a> { + type Item = &'a OsStr; + fn next(&mut self) -> Option<&'a OsStr> { + self.iter.next().map(|_| OsStr::new("")) + } + fn size_hint(&self) -> (usize, Option) { + self.iter.size_hint() + } +} + +impl<'a> ExactSizeIterator for CommandArgs<'a> { + fn len(&self) -> usize { + self.iter.len() + } + fn is_empty(&self) -> bool { + self.iter.is_empty() + } +} + +impl<'a> fmt::Debug for CommandArgs<'a> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_list().entries(self.iter.clone()).finish() + } +} diff --git a/library/std/src/sys/bpf/rwlock.rs b/library/std/src/sys/bpf/rwlock.rs new file mode 100644 index 0000000000000..fd407a1d5f66e --- /dev/null +++ b/library/std/src/sys/bpf/rwlock.rs @@ -0,0 +1,72 @@ +use crate::cell::UnsafeCell; + +pub struct RWLock { + mode: UnsafeCell, +} + +unsafe impl Send for RWLock {} +unsafe impl Sync for RWLock {} // no threads on BPF + +impl RWLock { + pub const fn new() -> RWLock { + RWLock { + mode: UnsafeCell::new(0), + } + } + + #[inline] + pub unsafe fn read(&self) { + let mode = self.mode.get(); + if *mode >= 0 { + *mode += 1; + } else { + rtabort!("rwlock locked for writing"); + } + } + + #[inline] + pub unsafe fn try_read(&self) -> bool { + let mode = self.mode.get(); + if *mode >= 0 { + *mode += 1; + true + } else { + false + } + } + + #[inline] + pub unsafe fn write(&self) { + let mode = self.mode.get(); + if *mode == 0 { + *mode = -1; + } else { + rtabort!("rwlock locked for reading") + } + } + + #[inline] + pub unsafe fn try_write(&self) -> bool { + let mode = self.mode.get(); + if *mode == 0 { + *mode = -1; + true + } else { + false + } + } + + #[inline] + pub unsafe fn read_unlock(&self) { + *self.mode.get() -= 1; + } + + #[inline] + pub unsafe fn write_unlock(&self) { + *self.mode.get() += 1; + } + + #[inline] + pub unsafe fn destroy(&self) { + } +} diff --git a/library/std/src/sys/bpf/rwlock_atomics.rs b/library/std/src/sys/bpf/rwlock_atomics.rs new file mode 100644 index 0000000000000..c705568cec992 --- /dev/null +++ b/library/std/src/sys/bpf/rwlock_atomics.rs @@ -0,0 +1,151 @@ +use crate::cell::UnsafeCell; +use crate::sys::mutex::Mutex; +use crate::sys::condvar::Condvar; + +pub struct RWLock { + lock: Mutex, + cond: Condvar, + state: UnsafeCell, +} + +enum State { + Unlocked, + Reading(usize), + Writing, +} + +unsafe impl Send for RWLock {} +unsafe impl Sync for RWLock {} + +// This rwlock implementation is a relatively simple implementation which has a +// condition variable for readers/writers as well as a mutex protecting the +// internal state of the lock. A current downside of the implementation is that +// unlocking the lock will notify *all* waiters rather than just readers or just +// writers. This can cause lots of "thundering stampede" problems. While +// hopefully correct this implementation is very likely to want to be changed in +// the future. + +impl RWLock { + pub const fn new() -> RWLock { + RWLock { + lock: Mutex::new(), + cond: Condvar::new(), + state: UnsafeCell::new(State::Unlocked), + } + } + + #[inline] + pub unsafe fn read(&self) { + self.lock.lock(); + while !(*self.state.get()).inc_readers() { + self.cond.wait(&self.lock); + } + self.lock.unlock(); + } + + #[inline] + pub unsafe fn try_read(&self) -> bool { + self.lock.lock(); + let ok = (*self.state.get()).inc_readers(); + self.lock.unlock(); + return ok + } + + #[inline] + pub unsafe fn write(&self) { + self.lock.lock(); + while !(*self.state.get()).inc_writers() { + self.cond.wait(&self.lock); + } + self.lock.unlock(); + } + + #[inline] + pub unsafe fn try_write(&self) -> bool { + self.lock.lock(); + let ok = (*self.state.get()).inc_writers(); + self.lock.unlock(); + return ok + } + + #[inline] + pub unsafe fn read_unlock(&self) { + self.lock.lock(); + let notify = (*self.state.get()).dec_readers(); + self.lock.unlock(); + if notify { + // FIXME: should only wake up one of these some of the time + self.cond.notify_all(); + } + } + + #[inline] + pub unsafe fn write_unlock(&self) { + self.lock.lock(); + (*self.state.get()).dec_writers(); + self.lock.unlock(); + // FIXME: should only wake up one of these some of the time + self.cond.notify_all(); + } + + #[inline] + pub unsafe fn destroy(&self) { + self.lock.destroy(); + self.cond.destroy(); + } +} + +impl State { + fn inc_readers(&mut self) -> bool { + match *self { + State::Unlocked => { + *self = State::Reading(1); + true + } + State::Reading(ref mut cnt) => { + *cnt += 1; + true + } + State::Writing => false + } + } + + fn inc_writers(&mut self) -> bool { + match *self { + State::Unlocked => { + *self = State::Writing; + true + } + State::Reading(_) | + State::Writing => false + } + } + + fn dec_readers(&mut self) -> bool { + let zero = match *self { + State::Reading(ref mut cnt) => { + *cnt -= 1; + *cnt == 0 + } + State::Unlocked | + State::Writing => invalid(), + }; + if zero { + *self = State::Unlocked; + } + zero + } + + fn dec_writers(&mut self) { + match *self { + State::Writing => {} + State::Unlocked | + State::Reading(_) => invalid(), + } + *self = State::Unlocked; + } +} + +fn invalid() -> ! { + panic!("inconsistent rwlock"); +} diff --git a/library/std/src/sys/bpf/stdio.rs b/library/std/src/sys/bpf/stdio.rs new file mode 100644 index 0000000000000..c157eb66dbcde --- /dev/null +++ b/library/std/src/sys/bpf/stdio.rs @@ -0,0 +1,54 @@ +use crate::io; + +pub struct Stdin; +pub struct Stdout; +pub struct Stderr; + +impl Stdin { +} + +impl io::Read for Stdin { + fn read(&mut self, _buf: &mut [u8]) -> io::Result { + Ok(0) + } +} + +impl Stdout { +} + +impl io::Write for Stdout { + fn write(&mut self, buf: &[u8]) -> io::Result { + unsafe { + crate::sys::sol_log(core::str::from_utf8_unchecked(buf)); + } + Ok(buf.len()) + } + + fn flush(&mut self) -> io::Result<()> { + Ok(()) + } +} + +impl Stderr { +} + +impl io::Write for Stderr { + fn write(&mut self, buf: &[u8]) -> io::Result { + unsafe { + crate::sys::sol_log(core::str::from_utf8_unchecked(buf)); + } + Ok(buf.len()) + } + + fn flush(&mut self) -> io::Result<()> { + Ok(()) + } +} + +pub fn is_ebadf(_err: &io::Error) -> bool { + true +} + +pub fn panic_output() -> Option { + None::> +} diff --git a/library/std/src/sys/bpf/thread.rs b/library/std/src/sys/bpf/thread.rs new file mode 100644 index 0000000000000..5791ba291b0e7 --- /dev/null +++ b/library/std/src/sys/bpf/thread.rs @@ -0,0 +1,36 @@ +use crate::ffi::CStr; +use crate::io; +use crate::sys::{unsupported, Void}; +use crate::time::Duration; + +pub struct Thread(Void); + +impl Thread { + // unsafe: see thread::Builder::spawn_unchecked for safety requirements + pub unsafe fn new(_stack: usize, _p: Box) + -> io::Result + { + unsupported() + } + + pub fn yield_now() { + // do nothing + } + + pub fn set_name(_name: &CStr) { + // nope + } + + pub fn sleep(_dur: Duration) { + panic!("can't sleep"); + } + + pub fn join(self) { + match self.0 {} + } +} + +pub mod guard { + pub type Guard = !; + pub unsafe fn current() -> Option { None } +} diff --git a/library/std/src/sys/bpf/thread_local_atomics.rs b/library/std/src/sys/bpf/thread_local_atomics.rs new file mode 100644 index 0000000000000..b408ad0d5c1f8 --- /dev/null +++ b/library/std/src/sys/bpf/thread_local_atomics.rs @@ -0,0 +1,61 @@ +use crate::sys::thread; +use crate::sync::atomic::{AtomicUsize, Ordering::SeqCst}; + +const MAX_KEYS: usize = 128; +static NEXT_KEY: AtomicUsize = AtomicUsize::new(0); + +struct ThreadControlBlock { + keys: [*mut u8; MAX_KEYS], +} + +impl ThreadControlBlock { + fn new() -> ThreadControlBlock { + ThreadControlBlock { + keys: [0 as *mut u8; MAX_KEYS], + } + } + + fn get() -> *mut ThreadControlBlock { + let ptr = thread::tcb_get(); + if !ptr.is_null() { + return ptr as *mut ThreadControlBlock + } + let tcb = Box::into_raw(Box::new(ThreadControlBlock::new())); + thread::tcb_set(tcb as *mut u8); + tcb + } +} + +pub type Key = usize; + +pub unsafe fn create(dtor: Option) -> Key { + drop(dtor); // FIXME: need to figure out how to hook thread exit to run this + let key = NEXT_KEY.fetch_add(1, SeqCst); + if key >= MAX_KEYS { + NEXT_KEY.store(MAX_KEYS, SeqCst); + panic!("cannot allocate space for more TLS keys"); + } + // offset by 1 so we never hand out 0. This is currently required by + // `sys_common/thread_local.rs` where it can't cope with keys of value 0 + // because it messes up the atomic management. + return key + 1 +} + +pub unsafe fn set(key: Key, value: *mut u8) { + (*ThreadControlBlock::get()).keys[key - 1] = value; +} + +pub unsafe fn get(key: Key) -> *mut u8 { + (*ThreadControlBlock::get()).keys[key - 1] +} + +pub unsafe fn destroy(_key: Key) { + // FIXME: should implement this somehow, this isn't typically called but it + // can be called if two threads race to initialize a TLS slot and one ends + // up not being needed. +} + +#[inline] +pub fn requires_synchronized_create() -> bool { + false +} diff --git a/library/std/src/sys/bpf/thread_local_dtor.rs b/library/std/src/sys/bpf/thread_local_dtor.rs new file mode 100644 index 0000000000000..5391ed83ebc36 --- /dev/null +++ b/library/std/src/sys/bpf/thread_local_dtor.rs @@ -0,0 +1,7 @@ +#![cfg(target_thread_local)] +#![unstable(feature = "thread_local_internals", issue = "none")] + +pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) { + use crate::sys_common::thread_local_dtor::register_dtor_fallback; + register_dtor_fallback(t, dtor); +} diff --git a/library/std/src/sys/bpf/thread_local_key.rs b/library/std/src/sys/bpf/thread_local_key.rs new file mode 100644 index 0000000000000..29e9854bcfccb --- /dev/null +++ b/library/std/src/sys/bpf/thread_local_key.rs @@ -0,0 +1,40 @@ +use crate::boxed::Box; +use crate::ptr; + +pub type Key = usize; + +struct Allocated { + value: *mut u8, + dtor: Option, +} + +#[inline] +pub unsafe fn create(dtor: Option) -> Key { + Box::into_raw(Box::new(Allocated { + value: ptr::null_mut(), + dtor, + })) as usize +} + +#[inline] +pub unsafe fn set(key: Key, value: *mut u8) { + (*(key as *mut Allocated)).value = value; +} + +#[inline] +pub unsafe fn get(key: Key) -> *mut u8 { + (*(key as *mut Allocated)).value +} + +#[inline] +pub unsafe fn destroy(key: Key) { + let key = Box::from_raw(key as *mut Allocated); + if let Some(f) = key.dtor { + f(key.value); + } +} + +#[inline] +pub fn requires_synchronized_create() -> bool { + false +} diff --git a/library/std/src/sys/bpf/time.rs b/library/std/src/sys/bpf/time.rs new file mode 100644 index 0000000000000..6d0532d9ea5ed --- /dev/null +++ b/library/std/src/sys/bpf/time.rs @@ -0,0 +1,55 @@ +use crate::time::Duration; +// use crate::sys::{TimeSysCall, TimeClock}; + +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] +pub struct Instant(Duration); + +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] +pub struct SystemTime(Duration); + +pub const UNIX_EPOCH: SystemTime = SystemTime(Duration::from_secs(0)); + +impl Instant { + pub fn now() -> Instant { + panic!(); + } + + pub const fn zero() -> Instant { + Instant(Duration::from_secs(0)) + } + + pub fn actually_monotonic() -> bool { + false + } + + pub fn checked_sub_instant(&self, other: &Instant) -> Option { + self.0.checked_sub(other.0) + } + + pub fn checked_add_duration(&self, other: &Duration) -> Option { + Some(Instant(self.0.checked_add(*other)?)) + } + + pub fn checked_sub_duration(&self, other: &Duration) -> Option { + Some(Instant(self.0.checked_sub(*other)?)) + } +} + +impl SystemTime { + pub fn now() -> SystemTime { + panic!(); + } + + pub fn sub_time(&self, other: &SystemTime) + -> Result { + self.0.checked_sub(other.0).ok_or_else(|| other.0 - self.0) + } + + pub fn checked_add_duration(&self, other: &Duration) -> Option { + Some(SystemTime(self.0.checked_add(*other)?)) + } + + pub fn checked_sub_duration(&self, other: &Duration) -> Option { + Some(SystemTime(self.0.checked_sub(*other)?)) + } +} diff --git a/library/std/src/sys/mod.rs b/library/std/src/sys/mod.rs index 159ffe7ac9635..acb10cc3235bb 100644 --- a/library/std/src/sys/mod.rs +++ b/library/std/src/sys/mod.rs @@ -35,6 +35,9 @@ cfg_if::cfg_if! { } else if #[cfg(target_os = "solid_asp3")] { mod solid; pub use self::solid::*; + } else if #[cfg(target_arch = "bpf")] { + mod bpf; + pub use self::bpf::*; } else if #[cfg(target_os = "hermit")] { mod hermit; pub use self::hermit::*; diff --git a/library/std/src/sys_common/backtrace.rs b/library/std/src/sys_common/backtrace.rs index 84e2c5d8d7f70..0e795099d954a 100644 --- a/library/std/src/sys_common/backtrace.rs +++ b/library/std/src/sys_common/backtrace.rs @@ -1,3 +1,5 @@ +#![cfg(not(target_arch = "bpf"))] + use crate::backtrace_rs::{self, BacktraceFmt, BytesOrWideString, PrintFmt}; use crate::borrow::Cow; /// Common code for printing the backtrace in the same way across the different diff --git a/library/std/src/sys_common/mod.rs b/library/std/src/sys_common/mod.rs index e18638f2a5f54..a03694b435fb5 100644 --- a/library/std/src/sys_common/mod.rs +++ b/library/std/src/sys_common/mod.rs @@ -20,6 +20,7 @@ #[cfg(test)] mod tests; +#[cfg(feature = "backtrace")] pub mod backtrace; pub mod fs; pub mod io; @@ -45,6 +46,7 @@ cfg_if::cfg_if! { cfg_if::cfg_if! { if #[cfg(any(target_os = "l4re", target_os = "uefi", + target_arch = "bpf", feature = "restricted-std", all(target_family = "wasm", not(target_os = "emscripten")), target_os = "xous", diff --git a/library/std/src/sys_common/thread.rs b/library/std/src/sys_common/thread.rs index 76466b2b37beb..e1cbf9ea88ff3 100644 --- a/library/std/src/sys_common/thread.rs +++ b/library/std/src/sys_common/thread.rs @@ -1,7 +1,11 @@ +#[cfg(not(target_arch = "bpf"))] use crate::env; +#[cfg(not(target_arch = "bpf"))] use crate::sync::atomic::{self, Ordering}; +#[cfg(not(target_arch = "bpf"))] use crate::sys::thread as imp; +#[cfg(not(target_arch = "bpf"))] pub fn min_stack() -> usize { static MIN: atomic::AtomicUsize = atomic::AtomicUsize::new(0); match MIN.load(Ordering::Relaxed) { @@ -16,3 +20,8 @@ pub fn min_stack() -> usize { MIN.store(amt + 1, Ordering::Relaxed); amt } + +#[cfg(target_arch = "bpf")] +pub fn min_stack() -> usize { + 0 +} diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index 4097eb5549efe..e1315c24712a0 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -448,6 +448,7 @@ impl Builder { /// /// [`io::Result`]: crate::io::Result #[unstable(feature = "thread_spawn_unchecked", issue = "55132")] + #[cfg(not(target_arch = "bpf"))] pub unsafe fn spawn_unchecked<'a, F, T>(self, f: F) -> io::Result> where F: FnOnce() -> T, @@ -573,6 +574,57 @@ impl Builder { packet: my_packet, }) } + + /// BPF version of spawn_unchecked + #[unstable(feature = "thread_spawn_unchecked", issue = "55132")] + #[cfg(target_arch = "bpf")] + pub unsafe fn spawn_unchecked<'a, F, T>(self, _f: F) -> io::Result> + where + F: FnOnce() -> T, + F: Send + 'a, + T: Send + 'a, + { + let Builder { name, stack_size } = self; + let stack_size = stack_size.unwrap_or_else(thread::min_stack); + let my_thread = Thread::new(name); + let their_thread = my_thread.clone(); + let my_packet: Arc>>> = Arc::new(UnsafeCell::new(None)); + let main = move || { + if let Some(name) = their_thread.cname() { + imp::Thread::set_name(name); + } + // SAFETY: the stack guard passed is the one for the current thread. + // This means the current thread's stack and the new thread's stack + // are properly set and protected from each other. + thread_info::set(unsafe { imp::guard::current() }, their_thread); + }; + + Ok(JoinHandle(JoinInner { + // SAFETY: + // + // `imp::Thread::new` takes a closure with a `'static` lifetime, since it's passed + // through FFI or otherwise used with low-level threading primitives that have no + // notion of or way to enforce lifetimes. + // + // As mentioned in the `Safety` section of this function's documentation, the caller of + // this function needs to guarantee that the passed-in lifetime is sufficiently long + // for the lifetime of the thread. + // + // Similarly, the `sys` implementation must guarantee that no references to the closure + // exist after the thread has terminated, which is signaled by `Thread::join` + // returning. + native: unsafe { + Some(imp::Thread::new( + stack_size, + mem::transmute::, Box>( + Box::new(main), + ), + )?) + }, + thread: my_thread, + packet: Packet(my_packet), + })) + } } //////////////////////////////////////////////////////////////////////////////// diff --git a/library/test/src/lib.rs b/library/test/src/lib.rs index bddf75dffbb62..ad7fec8f07874 100644 --- a/library/test/src/lib.rs +++ b/library/test/src/lib.rs @@ -14,6 +14,7 @@ // running tests while providing a base that other test frameworks may // build off of. +#![cfg(not(target_arch = "bpf"))] #![unstable(feature = "test", issue = "50297")] #![doc(test(attr(deny(warnings))))] #![cfg_attr(not(bootstrap), doc(rust_logo))] diff --git a/src/bootstrap/src/core/sanity.rs b/src/bootstrap/src/core/sanity.rs index eec3be66a1281..2caee2dba7572 100644 --- a/src/bootstrap/src/core/sanity.rs +++ b/src/bootstrap/src/core/sanity.rs @@ -172,7 +172,9 @@ than building it. continue; } - if !build.config.dry_run() { + // bpf target relies on in-tree built llvm, + // which doesn't exist when this check runs + if !build.config.dry_run() && !target.contains("sbf") && !target.contains("bpf") { cmd_finder.must_have(build.cc(*target)); if let Some(ar) = build.ar(*target) { cmd_finder.must_have(ar); diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 33b8f1a7ce720..935b61e832975 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -846,6 +846,17 @@ impl Build { } } + /// Returns the path to llvm/bin + fn llvm_bin(&self, target: TargetSelection) -> PathBuf { + let target_config = self.config.target_config.get(&target); + if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) { + let llvm_bindir = output(Command::new(s).arg("--bindir")); + PathBuf::from(llvm_bindir.trim()) + } else { + self.llvm_out(self.config.build).join("bin") + } + } + /// Returns the path to `FileCheck` binary for the specified target fn llvm_filecheck(&self, target: TargetSelection) -> PathBuf { let target_config = self.config.target_config.get(&target); diff --git a/src/bootstrap/src/utils/cc_detect.rs b/src/bootstrap/src/utils/cc_detect.rs index 52b36ce75f343..c2c6c8b0c8d9f 100644 --- a/src/bootstrap/src/utils/cc_detect.rs +++ b/src/bootstrap/src/utils/cc_detect.rs @@ -39,6 +39,10 @@ fn cc2ar(cc: &Path, target: TargetSelection) -> Option { Some(PathBuf::from(ar)) } else if let Some(ar) = env::var_os("AR") { Some(PathBuf::from(ar)) + } else if target.contains("bpf") { + let parent = cc.parent().unwrap(); + let file = PathBuf::from("llvm-ar"); + Some(parent.join(file)) } else if target.contains("msvc") { None } else if target.contains("musl") { @@ -134,6 +138,9 @@ pub fn find_target(build: &Build, target: TargetSelection) { { cfg.compiler(cxx); true + } else if &*target.triple == "bpfel-unknown-unknown" { + set_compiler(&mut cfg, Language::CPlusPlus, target, config, build); + true } else { // Use an auto-detected compiler (or one configured via `CXX_target_triple` env vars). cfg.try_get_compiler().is_ok() @@ -215,6 +222,9 @@ fn default_compiler( None } } + "bpfel-unknown-unknown" => { + cfg.compiler(build.llvm_bin(target).join(compiler.clang())); + } t if t.contains("musl") && compiler == Language::C => { if let Some(root) = build.musl_root(target) { From c331c8117ace4fd7a52018bee56e027f2ce5cd93 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Fri, 2 Apr 2021 18:28:33 +0200 Subject: [PATCH 033/103] [SOL] Update build script to automatically build for correct targets --- build.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/build.sh b/build.sh index dc4da61d396b3..6dcddf682d06e 100755 --- a/build.sh +++ b/build.sh @@ -7,7 +7,13 @@ if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then exit; fi +if [ "$(uname)" == "Darwin" ]; then + HOST_TRIPLE=x86_64-apple-darwin +else + HOST_TRIPLE=x86_64-unknown-linux-gnu +fi + if [ "$1" == "--llvm" ]; then rm -f build/x86_64-apple-darwin/llvm/llvm-finished-building; fi -./x.py build --stage 1 +./x.py build --stage 1 --target ${HOST_TRIPLE},bpfel-unknown-unknown From 1c1137dbcc672d993d97eef20f6820dc41d059dd Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Mon, 12 Apr 2021 08:39:34 +0200 Subject: [PATCH 034/103] [SOL] Use +solana feature when compiling for BPF target --- compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs | 1 + src/bootstrap/src/lib.rs | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs index 5908f4bf6870d..b6a4c1b204689 100644 --- a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs +++ b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs @@ -33,6 +33,7 @@ pub fn target() -> Target { c_int_width: "64".to_string(), os: "unknown".to_string(), env: String::new(), + features: "+solana".to_string(), vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), executables: true, diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 935b61e832975..4647202bd9275 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -1223,6 +1223,13 @@ impl Build { base.push("-fno-omit-frame-pointer".into()); } + if &*target.triple == "bpfel-unknown-unknown" { + base.push("-Xclang".into()); + base.push("-target-feature".into()); + base.push("-Xclang".into()); + base.push("+solana".into()); + } + if let Some(map_to) = self.debuginfo_map_to(which) { let map = format!("{}={}", self.src.display(), map_to); let cc = self.cc(target); From 8d20de35b11e8804f08dfe363f32b5d833fa8fb2 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Mon, 12 Apr 2021 12:58:51 +0200 Subject: [PATCH 035/103] [SOL] Document source tree upgrade and bpf-tools release process --- README.md | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4ed6bd7ccac7e..4f9520707f37a 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,47 @@ # Fork of the Rust Programming Language that supports Berkley Packet Filter (BPF) targets -This fork of Rust contains changes that enables rustc to build BPF modules. It depends on a customized [fork](https://github.com/solana-labs/llvm-project) of Rust's LLVM fork. - -Solana SDK does not depend directly on this repo. Instead [rust-bpf-builder] builds and releases binary packages that the Solana SDK pulls in. - -BPF modules are built using target triple `bpfel-unknown-unknown` which represents the little endian version of BPF. There is no support for big endian at this time. +This fork of Rust contains changes that enable rustc to build BPF +modules. It depends on a customized +[fork](https://github.com/solana-labs/llvm-project) of Rust's LLVM +fork. + +Solana SDK does not depend directly on this repo. Instead [bpf-tools] +builds and releases binary packages that the Solana SDK pulls in. + +[bpf-tools]: https://github.com/solana-labs/bpf-tools + +BPF modules are built using target triple `bpfel-unknown-unknown` +which represents the little endian version of BPF. There is no +support for big endian at this time. + +Upgrading the compiler and standard library source tree +------------------------------------------------------- + +The source tree has two external dependencies +1. [compiler-builtins] +2. [llvm-project] + +If any of the depencies is changed or this repository is updated to +make a new release of the bpf-tools, tag the dependencies, and this +repository with a new bpf-tools-v1.x tag, so that all components of +the released bpf-tools have the same tag, e.g. bpf-tools-v1.6. Thus, +release of every version of the bpf-tools is fully specified by the +release version. + +The [llvm-project] is a submodule of this repository, therefore its +version is explicitly committed in this repository. However, +[compiler-builtins] is pulled in as a cargo package. Therefore, it is +necessary to update the `[patch.crates-io]` subsection of the +top-level `Cargo.toml` file, and specify which tag must be used to +pull the correct version of [compiler-builtins]. + +After this repository is tagged for a new release, update the +`bpf-tools/build.sh` in [bpf-tools] repository to pull the correct +version of the rust repository and make a new release tag in +[bpf-tools] repository. + +[compiler-builtins]: https://github.com/solana-labs/compiler-builtins +[llvm-project]: https://github.com/solana-labs/llvm-project --- From 7a81ac94278cea22f92e44d2d54b1447d2bb3d95 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Fri, 7 May 2021 16:51:59 +0200 Subject: [PATCH 036/103] [SOL] Enable test harness for BPF programs --- compiler/rustc_codegen_ssa/src/base.rs | 16 +- compiler/rustc_interface/src/util.rs | 3 + compiler/rustc_monomorphize/src/collector.rs | 4 +- compiler/rustc_passes/src/entry.rs | 4 +- .../src/spec/bpfel_unknown_unknown.rs | 1 + library/std/Cargo.toml | 2 + library/std/src/io/mod.rs | 1 - library/std/src/io/stdio.rs | 259 +++++++++++++++++- library/std/src/lib.rs | 1 - library/std/src/panic.rs | 2 - library/std/src/panicking.rs | 31 ++- library/std/src/process.rs | 2 +- library/std/src/sync/remutex.rs | 1 + library/std/src/sys/bpf/mutex.rs | 3 - library/std/src/sys/bpf/os.rs | 5 + library/std/src/sys/bpf/time.rs | 4 +- library/test/src/cli.rs | 37 +++ library/test/src/console.rs | 3 + library/test/src/helpers/concurrency.rs | 7 + library/test/src/lib.rs | 8 + 20 files changed, 366 insertions(+), 28 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 198e5696357af..2f13463f655c3 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -422,6 +422,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( ) -> Bx::Function { // The entry function is either `int main(void)` or `int main(int argc, char **argv)`, or // `usize efi_main(void *handle, void *system_table)` depending on the target. + let is_bpf = cx.sess().target.arch == "bpf" && cx.sess().opts.test; let llfty = if cx.sess().target.os.contains("uefi") { cx.type_func(&[cx.type_ptr(), cx.type_ptr()], cx.type_isize()) } else if cx.sess().target.main_needs_argc_argv { @@ -456,13 +457,15 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( let llbb = Bx::append_block(&cx, llfn, "top"); let mut bx = Bx::build(&cx, llbb); - bx.insert_reference_to_gdb_debug_scripts_section_global(); + if !is_bpf { + bx.insert_reference_to_gdb_debug_scripts_section_global(); + } let isize_ty = cx.type_isize(); let ptr_ty = cx.type_ptr(); let (arg_argc, arg_argv) = get_argc_argv(cx, &mut bx); - let (start_fn, start_ty, args) = if let EntryFnType::Main { sigpipe } = entry_type { + let (start_fn, start_ty, args) = if !is_bpf && let EntryFnType::Main { sigpipe } = entry_type { let start_def_id = cx.tcx().require_lang_item(LangItem::Start, None); let start_fn = cx.get_fn_addr( ty::Instance::resolve( @@ -486,7 +489,14 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( (rust_main, start_ty, vec![arg_argc, arg_argv]) }; - let result = bx.call(start_ty, None, None, start_fn, &args, None); + let result = if is_bpf { + let args = Vec::new(); + bx.call(start_ty, None, None, start_fn, &args, None); + bx.const_i32(0) + } else { + bx.call(start_ty, None, None, start_fn, &args, None) + }; + if cx.sess().target.os.contains("uefi") { bx.ret(result); } else { diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index 22d12793464a8..fc2cbe7d32b7a 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -404,6 +404,9 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec, mode: MonoItemCollectionMode) -> Vec { } fn entry_fn(tcx: TyCtxt<'_>, (): ()) -> Option<(DefId, EntryFnType)> { + + let exe_only = tcx.sess.target.arch != "bpf" || !tcx.sess.opts.test; let any_exe = tcx.crate_types().iter().any(|ty| *ty == CrateType::Executable); - if !any_exe { + if !any_exe && exe_only { // No need to find a main function. return None; } diff --git a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs index b6a4c1b204689..9c8fcf62568b7 100644 --- a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs +++ b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs @@ -47,6 +47,7 @@ pub fn target() -> Target { max_atomic_width: Some(64), unsupported_abis: abi_blacklist(), eh_frame_header: false, + main_needs_argc_argv: false, .. Default::default() }, } diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index cf7fbcbfdee64..d9f1a781235ff 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -24,6 +24,8 @@ hashbrown = { version = "0.14", default-features = false, features = ['rustc-dep std_detect = { path = "../stdarch/crates/std_detect", default-features = false, features = ['rustc-dep-of-std'] } # Dependencies of the `backtrace` crate +[target.'cfg(not(target_arch = "bpf"))'.dependencies] +addr2line = { version = "0.21.0", optional = true, default-features = false } rustc-demangle = { version = "0.1.21", features = ['rustc-dep-of-std'] } [target.'cfg(not(all(windows, target_env = "msvc", not(target_vendor = "uwp"))))'.dependencies] diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index d79f9df9e890b..7d70a0bac24fd 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -313,7 +313,6 @@ pub use self::error::RawOsError; pub(crate) use self::stdio::attempt_print_to_stderr; #[unstable(feature = "internal_output_capture", issue = "none")] #[doc(no_inline, hidden)] -#[cfg(not(target_arch = "bpf"))] pub use self::stdio::set_output_capture; #[stable(feature = "is_terminal", since = "1.70.0")] pub use self::stdio::IsTerminal; diff --git a/library/std/src/io/stdio.rs b/library/std/src/io/stdio.rs index 30f286a9cc254..7f972d3ebfa73 100644 --- a/library/std/src/io/stdio.rs +++ b/library/std/src/io/stdio.rs @@ -6,18 +6,14 @@ mod tests; use crate::io::prelude::*; #[cfg(not(target_arch = "bpf"))] -use crate::cell::Cell; -use crate::cell::RefCell; +use crate::cell::{Cell, RefCell}; use crate::fmt; use crate::fs::File; use crate::io::{self, BorrowedCursor, BufReader, IoSlice, IoSliceMut, LineWriter, Lines}; use crate::sync::atomic::{AtomicBool, Ordering}; -#[cfg(not(target_os = "solana"))] -use crate::sync::Arc; -use crate::sync::{Mutex, MutexGuard, OnceLock, ReentrantMutex, ReentrantMutexGuard}; +use crate::sync::{Arc, Mutex, MutexGuard, OnceLock, ReentrantMutex, ReentrantMutexGuard}; use crate::sys::stdio; -#[cfg(not(target_arch = "bpf"))] type LocalStream = Arc>>; #[cfg(not(target_arch = "bpf"))] @@ -240,6 +236,7 @@ fn handle_ebadf(r: io::Result, default: T) -> io::Result { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub struct Stdin { + #[cfg(not(target_arch = "bpf"))] inner: &'static Mutex>, } @@ -339,6 +336,56 @@ pub fn stdin() -> Stdin { } } +/// BPF dummy +#[stable(feature = "rust1", since = "1.0.0")] +#[cfg(target_arch = "bpf")] +pub fn stdin() -> Stdin { + Stdin {} +} + +/// Constructs a new locked handle to the standard input of the current +/// process. +/// +/// Each handle returned is a guard granting locked access to a shared +/// global buffer whose access is synchronized via a mutex. If you need +/// more explicit control over locking, for example, in a multi-threaded +/// program, use the [`io::stdin`] function to obtain an unlocked handle, +/// along with the [`Stdin::lock`] method. +/// +/// The lock is released when the returned guard goes out of scope. The +/// returned guard also implements the [`Read`] and [`BufRead`] traits for +/// accessing the underlying data. +/// +/// **Note**: The mutex locked by this handle is not reentrant. Even in a +/// single-threaded program, calling other code that accesses [`Stdin`] +/// could cause a deadlock or panic, if this locked handle is held across +/// that call. +/// +/// ### Note: Windows Portability Consideration +/// When operating in a console, the Windows implementation of this stream does not support +/// non-UTF-8 byte sequences. Attempting to read bytes that are not valid UTF-8 will return +/// an error. +/// +/// # Examples +/// +/// ```no_run +/// #![feature(stdio_locked)] +/// use std::io::{self, BufRead}; +/// +/// fn main() -> io::Result<()> { +/// let mut buffer = String::new(); +/// let mut handle = io::stdin_locked(); +/// +/// handle.read_line(&mut buffer)?; +/// Ok(()) +/// } +/// ``` +#[unstable(feature = "stdio_locked", issue = "86845")] +#[cfg(not(target_arch = "bpf"))] +pub fn stdin_locked() -> StdinLock<'static> { + stdin().into_locked() +} + impl Stdin { /// Locks this handle to the standard input stream, returning a readable /// guard. @@ -362,6 +409,7 @@ impl Stdin { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(not(target_arch = "bpf"))] pub fn lock(&self) -> StdinLock<'static> { // Locks this handle with 'static lifetime. This depends on the // implementation detail that the underlying `Mutex` is static. @@ -395,6 +443,7 @@ impl Stdin { /// in which case it will wait for the Enter key to be pressed before /// continuing #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(not(target_arch = "bpf"))] pub fn read_line(&self, buf: &mut String) -> io::Result { self.lock().read_line(buf) } @@ -429,6 +478,7 @@ impl fmt::Debug for Stdin { } #[stable(feature = "rust1", since = "1.0.0")] +#[cfg(not(target_arch = "bpf"))] impl Read for Stdin { fn read(&mut self, buf: &mut [u8]) -> io::Result { self.lock().read(buf) @@ -454,6 +504,34 @@ impl Read for Stdin { } } +#[stable(feature = "rust1", since = "1.0.0")] +#[cfg(target_arch = "bpf")] +impl Read for Stdin { + fn read(&mut self, _buf: &mut [u8]) -> io::Result { + Ok(0) + } + fn read_vectored(&mut self, _bufs: &mut [IoSliceMut<'_>]) -> io::Result { + Ok(0) + } + #[inline] + fn is_read_vectored(&self) -> bool { + false + } + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::nop() + } + fn read_to_end(&mut self, _buf: &mut Vec) -> io::Result { + Ok(0) + } + fn read_to_string(&mut self, _buf: &mut String) -> io::Result { + Ok(0) + } + fn read_exact(&mut self, _buf: &mut [u8]) -> io::Result<()> { + Ok(()) + } +} + // only used by platform-dependent io::copy specializations, i.e. unused on some platforms #[cfg(any(target_os = "linux", target_os = "android"))] impl StdinLock<'_> { @@ -547,6 +625,7 @@ pub struct Stdout { // FIXME: this should be LineWriter or BufWriter depending on the state of // stdout (tty or not). Note that if this is not line buffered it // should also flush-on-panic or some form of flush-on-abort. + #[cfg(not(target_arch = "bpf"))] inner: &'static ReentrantMutex>>, } @@ -568,10 +647,18 @@ pub struct Stdout { /// standard library or via raw Windows API calls, will fail. #[must_use = "if unused stdout will immediately unlock"] #[stable(feature = "rust1", since = "1.0.0")] +#[cfg(not(target_arch = "bpf"))] pub struct StdoutLock<'a> { inner: ReentrantMutexGuard<'a, RefCell>>, } +/// BPF dummy +#[stable(feature = "rust1", since = "1.0.0")] +#[cfg(target_arch = "bpf")] +pub struct StdoutLock { +} + +#[cfg(not(target_arch = "bpf"))] static STDOUT: OnceLock>>> = OnceLock::new(); /// Constructs a new handle to the standard output of the current process. @@ -631,9 +718,17 @@ pub fn stdout() -> Stdout { } } +/// Dummy stdout for BPF target +#[stable(feature = "rust1", since = "1.0.0")] +#[cfg(target_arch = "bpf")] +pub fn stdout() -> Stdout { + Stdout {} +} + // Flush the data and disable buffering during shutdown // by replacing the line writer by one with zero // buffering capacity. +#[cfg(not(target_arch = "bpf"))] pub fn cleanup() { let mut initialized = false; let stdout = STDOUT.get_or_init(|| { @@ -673,6 +768,7 @@ impl Stdout { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(not(target_arch = "bpf"))] pub fn lock(&self) -> StdoutLock<'static> { // Locks this handle with 'static lifetime. This depends on the // implementation detail that the underlying `ReentrantMutex` is @@ -689,6 +785,7 @@ impl fmt::Debug for Stdout { } #[stable(feature = "rust1", since = "1.0.0")] +#[cfg(not(target_arch = "bpf"))] impl Write for Stdout { fn write(&mut self, buf: &[u8]) -> io::Result { (&*self).write(buf) @@ -714,7 +811,41 @@ impl Write for Stdout { } } +#[stable(feature = "rust1", since = "1.0.0")] +#[cfg(target_arch = "bpf")] +impl Write for Stdout { + fn write(&mut self, buf: &[u8]) -> io::Result { + unsafe { + crate::sys::sol_log(core::str::from_utf8_unchecked(buf)); + } + Ok(buf.len()) + } + fn write_vectored(&mut self, _bufs: &[IoSlice<'_>]) -> io::Result { + Ok(0) + } + #[inline] + fn is_write_vectored(&self) -> bool { + false + } + fn flush(&mut self) -> io::Result<()> { + Ok(()) + } + fn write_all(&mut self, buf: &[u8]) -> io::Result<()> { + unsafe { + crate::sys::sol_log(core::str::from_utf8_unchecked(buf)); + } + Ok(()) + } + fn write_all_vectored(&mut self, _bufs: &mut [IoSlice<'_>]) -> io::Result<()> { + Ok(()) + } + fn write_fmt(&mut self, _args: fmt::Arguments<'_>) -> io::Result<()> { + Ok(()) + } +} + #[stable(feature = "write_mt", since = "1.48.0")] +#[cfg(not(target_arch = "bpf"))] impl Write for &Stdout { fn write(&mut self, buf: &[u8]) -> io::Result { self.lock().write(buf) @@ -741,6 +872,7 @@ impl Write for &Stdout { } #[stable(feature = "rust1", since = "1.0.0")] +#[cfg(not(target_arch = "bpf"))] impl Write for StdoutLock<'_> { fn write(&mut self, buf: &[u8]) -> io::Result { self.inner.borrow_mut().write(buf) @@ -764,12 +896,21 @@ impl Write for StdoutLock<'_> { } #[stable(feature = "std_debug", since = "1.16.0")] +#[cfg(not(target_arch = "bpf"))] impl fmt::Debug for StdoutLock<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("StdoutLock").finish_non_exhaustive() } } +#[stable(feature = "std_debug", since = "1.16.0")] +#[cfg(target_arch = "bpf")] +impl fmt::Debug for StdoutLock { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.pad("StdoutLock { .. }") + } +} + /// A handle to the standard error stream of a process. /// /// For more information, see the [`io::stderr`] method. @@ -789,6 +930,7 @@ impl fmt::Debug for StdoutLock<'_> { /// standard library or via raw Windows API calls, will fail. #[stable(feature = "rust1", since = "1.0.0")] pub struct Stderr { + #[cfg(not(target_arch = "bpf"))] inner: &'static ReentrantMutex>, } @@ -810,10 +952,17 @@ pub struct Stderr { /// standard library or via raw Windows API calls, will fail. #[must_use = "if unused stderr will immediately unlock"] #[stable(feature = "rust1", since = "1.0.0")] +#[cfg(not(target_arch = "bpf"))] pub struct StderrLock<'a> { inner: ReentrantMutexGuard<'a, RefCell>, } +/// BPF dummy +#[stable(feature = "rust1", since = "1.0.0")] +#[cfg(target_arch = "bpf")] +pub struct StderrLock { +} + /// Constructs a new handle to the standard error of the current process. /// /// This handle is not buffered. @@ -872,6 +1021,43 @@ pub fn stderr() -> Stderr { Stderr { inner: &INSTANCE } } +/// BPF dummy +#[stable(feature = "rust1", since = "1.0.0")] +#[cfg(target_arch = "bpf")] +pub fn stderr() -> Stderr { + Stderr {} +} + +/// Constructs a new locked handle to the standard error of the current +/// process. +/// +/// This handle is not buffered. +/// +/// ### Note: Windows Portability Consideration +/// When operating in a console, the Windows implementation of this stream does not support +/// non-UTF-8 byte sequences. Attempting to write bytes that are not valid UTF-8 will return +/// an error. +/// +/// # Example +/// +/// ```no_run +/// #![feature(stdio_locked)] +/// use std::io::{self, Write}; +/// +/// fn main() -> io::Result<()> { +/// let mut handle = io::stderr_locked(); +/// +/// handle.write_all(b"hello world")?; +/// +/// Ok(()) +/// } +/// ``` +#[unstable(feature = "stdio_locked", issue = "86845")] +#[cfg(not(target_arch = "bpf"))] +pub fn stderr_locked() -> StderrLock<'static> { + stderr().into_locked() +} + impl Stderr { /// Locks this handle to the standard error stream, returning a writable /// guard. @@ -894,6 +1080,7 @@ impl Stderr { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(not(target_arch = "bpf"))] pub fn lock(&self) -> StderrLock<'static> { // Locks this handle with 'static lifetime. This depends on the // implementation detail that the underlying `ReentrantMutex` is @@ -910,6 +1097,7 @@ impl fmt::Debug for Stderr { } #[stable(feature = "rust1", since = "1.0.0")] +#[cfg(not(target_arch = "bpf"))] impl Write for Stderr { fn write(&mut self, buf: &[u8]) -> io::Result { (&*self).write(buf) @@ -935,7 +1123,41 @@ impl Write for Stderr { } } +#[stable(feature = "rust1", since = "1.0.0")] +#[cfg(target_arch = "bpf")] +impl Write for Stderr { + fn write(&mut self, buf: &[u8]) -> io::Result { + unsafe { + crate::sys::sol_log(core::str::from_utf8_unchecked(buf)); + } + Ok(buf.len()) + } + fn write_vectored(&mut self, _bufs: &[IoSlice<'_>]) -> io::Result { + Ok(0) + } + #[inline] + fn is_write_vectored(&self) -> bool { + false + } + fn flush(&mut self) -> io::Result<()> { + Ok(()) + } + fn write_all(&mut self, buf: &[u8]) -> io::Result<()> { + unsafe { + crate::sys::sol_log(core::str::from_utf8_unchecked(buf)); + } + Ok(()) + } + fn write_all_vectored(&mut self, _bufs: &mut [IoSlice<'_>]) -> io::Result<()> { + Ok(()) + } + fn write_fmt(&mut self, _args: fmt::Arguments<'_>) -> io::Result<()> { + Ok(()) + } +} + #[stable(feature = "write_mt", since = "1.48.0")] +#[cfg(not(target_arch = "bpf"))] impl Write for &Stderr { fn write(&mut self, buf: &[u8]) -> io::Result { self.lock().write(buf) @@ -962,6 +1184,7 @@ impl Write for &Stderr { } #[stable(feature = "rust1", since = "1.0.0")] +#[cfg(not(target_arch = "bpf"))] impl Write for StderrLock<'_> { fn write(&mut self, buf: &[u8]) -> io::Result { self.inner.borrow_mut().write(buf) @@ -985,13 +1208,23 @@ impl Write for StderrLock<'_> { } #[stable(feature = "std_debug", since = "1.16.0")] +#[cfg(not(target_arch = "bpf"))] impl fmt::Debug for StderrLock<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("StderrLock").finish_non_exhaustive() } } +#[stable(feature = "std_debug", since = "1.16.0")] +#[cfg(target_arch = "bpf")] +impl fmt::Debug for StderrLock { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.pad("StderrLock { .. }") + } +} + /// Sets the thread-local output capture buffer and returns the old one. +#[cfg(not(target_arch = "bpf"))] #[unstable( feature = "internal_output_capture", reason = "this function is meant for use in the test crate \ @@ -999,7 +1232,6 @@ impl fmt::Debug for StderrLock<'_> { issue = "none" )] #[doc(hidden)] -#[cfg(not(target_arch = "bpf"))] pub fn set_output_capture(sink: Option) -> Option { if sink.is_none() && !OUTPUT_CAPTURE_USED.load(Ordering::Relaxed) { // OUTPUT_CAPTURE is definitely None since OUTPUT_CAPTURE_USED is false. @@ -1009,6 +1241,19 @@ pub fn set_output_capture(sink: Option) -> Option { OUTPUT_CAPTURE.with(move |slot| slot.replace(sink)) } +/// Dummy version for satisfying test library dependencies when building the BPF target. +#[cfg(target_arch = "bpf")] +#[unstable( + feature = "internal_output_capture", + reason = "this function is meant for use in the test crate \ + and may disappear in the future", + issue = "none" +)] +#[doc(hidden)] +pub fn set_output_capture(_sink: Option) -> Option { + None +} + /// Write `args` to the capture buffer if enabled and possible, or `global_s` /// otherwise. `label` identifies the stream in a panic message. /// diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 10c5ed0c95be4..4d287484b005f 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -421,7 +421,6 @@ extern crate libc; // We always need an unwinder currently for backtraces #[doc(masked)] #[allow(unused_extern_crates)] -#[cfg(not(target_arch = "bpf"))] extern crate unwind; // FIXME: #94122 this extern crate definition only exist here to stop diff --git a/library/std/src/panic.rs b/library/std/src/panic.rs index 78b83557913e1..675791dd465fe 100644 --- a/library/std/src/panic.rs +++ b/library/std/src/panic.rs @@ -38,7 +38,6 @@ pub macro panic_2015 { pub use core::panic::panic_2021; #[stable(feature = "panic_hooks", since = "1.10.0")] -#[cfg(not(target_arch = "bpf"))] pub use crate::panicking::{set_hook, take_hook}; #[unstable(feature = "panic_update_hook", issue = "92649")] @@ -141,7 +140,6 @@ where /// assert!(result.is_err()); /// ``` #[stable(feature = "catch_unwind", since = "1.9.0")] -#[cfg(not(target_arch = "bpf"))] pub fn catch_unwind R + UnwindSafe, R>(f: F) -> Result { unsafe { panicking::r#try(f) } } diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index 2fd081869ec17..462fc15dab123 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -14,13 +14,12 @@ use crate::panic::BacktraceStyle; use core::panic::{PanicPayload}; use core::panic::{Location, PanicInfo}; -#[cfg(not(target_arch = "bpf"))] use crate::any::Any; use crate::fmt; -#[cfg(not(target_arch = "bpf"))] use crate::intrinsics; +use crate::mem::ManuallyDrop; #[cfg(not(target_arch = "bpf"))] -use crate::mem::{self, ManuallyDrop}; +use crate::mem; #[cfg(not(target_arch = "bpf"))] use crate::process; #[cfg(not(target_arch = "bpf"))] @@ -53,7 +52,6 @@ use realstd::io::set_output_capture; // One day this may look a little less ad-hoc with the compiler helping out to // hook up these functions, but it is not this day! #[allow(improper_ctypes)] -#[cfg(not(target_arch = "bpf"))] extern "C" { fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any + Send + 'static); } @@ -161,6 +159,12 @@ pub fn set_hook(hook: Box) + 'static + Sync + Send>) { drop(old); } +/// Dummy version for satisfying library/test dependencies for BPF target +#[cfg(target_arch = "bpf")] +#[stable(feature = "panic_hooks", since = "1.10.0")] +pub fn set_hook(_hook: Box) + 'static + Sync + Send>) { +} + /// Unregisters the current panic hook and returns it, registering the default hook /// in its place. /// @@ -252,6 +256,13 @@ where *hook = Hook::Custom(Box::new(move |info| hook_fn(&prev, info))); } +/// Dummy version for satisfying library/test dependencies for BPF target +#[cfg(target_arch = "bpf")] +#[stable(feature = "panic_hooks", since = "1.10.0")] +pub fn take_hook() -> Box) + 'static + Sync + Send> { + Box::new(default_hook) +} + /// The default panic handler. #[cfg(not(target_arch = "bpf"))] fn default_hook(info: &PanicInfo<'_>) { @@ -312,7 +323,11 @@ fn default_hook(info: &PanicInfo<'_>) { } } -#[cfg(all(not(test), not(target_arch = "bpf")))] +#[cfg(target_arch = "bpf")] +fn default_hook(_info: &PanicInfo<'_>) { +} + +#[cfg(not(test))] #[doc(hidden)] #[cfg(feature = "panic_immediate_abort")] #[unstable(feature = "update_panic_count", issue = "none")] @@ -407,6 +422,7 @@ pub mod panic_count { // // This also updates thread-local state to keep track of whether a panic // hook is currently executing. + #[cfg(not(target_arch = "bpf"))] pub fn increase(run_panic_hook: bool) -> Option { let global_count = GLOBAL_PANIC_COUNT.fetch_add(1, Ordering::Relaxed); if global_count & ALWAYS_ABORT_FLAG != 0 { @@ -444,12 +460,14 @@ pub mod panic_count { // Disregards ALWAYS_ABORT_FLAG #[must_use] + #[cfg(not(target_arch = "bpf"))] pub fn get_count() -> usize { LOCAL_PANIC_COUNT.with(|c| c.get().0) } // Disregards ALWAYS_ABORT_FLAG #[must_use] + #[cfg(not(target_arch = "bpf"))] #[inline] pub fn count_is_zero() -> bool { if GLOBAL_PANIC_COUNT.load(Ordering::Relaxed) & !ALWAYS_ABORT_FLAG == 0 { @@ -470,6 +488,7 @@ pub mod panic_count { // Slow path is in a separate function to reduce the amount of code // inlined from `count_is_zero`. + #[cfg(not(target_arch = "bpf"))] #[inline(never)] #[cold] fn is_zero_slow_path() -> bool { @@ -477,7 +496,7 @@ pub mod panic_count { } } -#[cfg(all(test, not(target_arch = "bpf")))] +#[cfg(test)] pub use realstd::rt::panic_count; /// Invoke a closure, capturing the cause of an unwinding panic if one occurs. diff --git a/library/std/src/process.rs b/library/std/src/process.rs index d6141bbd71109..18d816f65834c 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -2206,8 +2206,8 @@ impl Child { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "process_exit")] -#[cfg(not(target_arch = "bpf"))] pub fn exit(code: i32) -> ! { + #[cfg(not(target_arch = "bpf"))] crate::rt::cleanup(); crate::sys::os::exit(code) } diff --git a/library/std/src/sync/remutex.rs b/library/std/src/sync/remutex.rs index cf7166094b21c..df0c871ba18b8 100644 --- a/library/std/src/sync/remutex.rs +++ b/library/std/src/sync/remutex.rs @@ -94,6 +94,7 @@ impl ReentrantMutex { /// If another user of this mutex panicked while holding the mutex, then /// this call will return failure if the mutex would otherwise be /// acquired. + #[cfg(not(target_arch = "bpf"))] pub fn lock(&self) -> ReentrantMutexGuard<'_, T> { let this_thread = current_thread_unique_ptr(); // Safety: We only touch lock_count when we own the lock. diff --git a/library/std/src/sys/bpf/mutex.rs b/library/std/src/sys/bpf/mutex.rs index 4411b0a9c4236..97b523930b857 100644 --- a/library/std/src/sys/bpf/mutex.rs +++ b/library/std/src/sys/bpf/mutex.rs @@ -44,12 +44,9 @@ impl Mutex { // All empty stubs because BPF has no threads, lock acquisition always // succeeds. pub struct ReentrantMutex { - pub inner: UnsafeCell, } impl ReentrantMutex { - // pub unsafe fn init(&self) {} - pub unsafe fn lock(&self) {} pub unsafe fn unlock(&self) {} pub unsafe fn destroy(&self) {} } diff --git a/library/std/src/sys/bpf/os.rs b/library/std/src/sys/bpf/os.rs index 2718bb0b7a0c5..65bc578c32456 100644 --- a/library/std/src/sys/bpf/os.rs +++ b/library/std/src/sys/bpf/os.rs @@ -1,6 +1,7 @@ use crate::error::Error as StdError; use crate::ffi::{OsString, OsStr}; use crate::fmt; +use crate::intrinsics; use crate::io; use crate::path::{self, PathBuf}; use crate::str; @@ -93,6 +94,10 @@ pub fn home_dir() -> Option { None } +pub fn exit(_code: i32) -> ! { + intrinsics::abort() +} + pub fn getpid() -> u32 { 0 } diff --git a/library/std/src/sys/bpf/time.rs b/library/std/src/sys/bpf/time.rs index 6d0532d9ea5ed..bce067a244f6e 100644 --- a/library/std/src/sys/bpf/time.rs +++ b/library/std/src/sys/bpf/time.rs @@ -11,7 +11,7 @@ pub const UNIX_EPOCH: SystemTime = SystemTime(Duration::from_secs(0)); impl Instant { pub fn now() -> Instant { - panic!(); + Instant(Duration::from_secs(0)) } pub const fn zero() -> Instant { @@ -19,7 +19,7 @@ impl Instant { } pub fn actually_monotonic() -> bool { - false + true } pub fn checked_sub_instant(&self, other: &Instant) -> Option { diff --git a/library/test/src/cli.rs b/library/test/src/cli.rs index 6ac3b3eaa797b..62720a6a36c57 100644 --- a/library/test/src/cli.rs +++ b/library/test/src/cli.rs @@ -1,5 +1,6 @@ //! Module converting command-line arguments into test configuration. +#[cfg(not(target_arch = "bpf"))] use std::env; use std::path::PathBuf; @@ -46,6 +47,7 @@ impl TestOpts { /// Result of parsing the options. pub type OptRes = Result; /// Result of parsing the option part. +#[cfg(not(target_arch = "bpf"))] type OptPartRes = Result; fn optgroups() -> getopts::Options { @@ -221,6 +223,7 @@ pub fn parse_opts(args: &[String]) -> Option { } // Gets the option value and checks if unstable features are enabled. +#[cfg(not(target_arch = "bpf"))] macro_rules! unstable_optflag { ($matches:ident, $allow_unstable:ident, $option_name:literal) => {{ let opt = $matches.opt_present($option_name); @@ -252,6 +255,7 @@ macro_rules! unstable_optopt { // Implementation of `parse_opts` that doesn't care about help message // and returns a `Result`. +#[cfg(not(target_arch = "bpf"))] fn parse_opts_impl(matches: getopts::Matches) -> OptRes { let allow_unstable = get_allow_unstable(&matches)?; @@ -306,7 +310,32 @@ fn parse_opts_impl(matches: getopts::Matches) -> OptRes { Ok(test_opts) } +#[cfg(target_arch = "bpf")] +fn parse_opts_impl(_matches: getopts::Matches) -> OptRes { + let test_opts = TestOpts { + list: false, + filter: None, + filter_exact: false, + force_run_in_process: false, + exclude_should_panic: false, + run_ignored: RunIgnored::No, + run_tests: true, + bench_benchmarks: true, + logfile: None, + nocapture: true, + color: ColorConfig::NeverColor, + format: OutputFormat::Pretty, + test_threads: Some(1), + skip: Vec::new(), + time_options: None, + options: Options::new(), + }; + + Ok(test_opts) +} + // FIXME: Copied from librustc_ast until linkage errors are resolved. Issue #47566 +#[cfg(not(target_arch = "bpf"))] fn is_nightly() -> bool { // Whether this is a feature-staged build, i.e., on the beta or stable channel let disable_unstable_features = @@ -318,6 +347,7 @@ fn is_nightly() -> bool { } // Gets the CLI options associated with `report-time` feature. +#[cfg(not(target_arch = "bpf"))] fn get_time_options( matches: &getopts::Matches, allow_unstable: bool, @@ -375,6 +405,7 @@ fn get_shuffle_seed(matches: &getopts::Matches, allow_unstable: bool) -> OptPart Ok(shuffle_seed) } +#[cfg(not(target_arch = "bpf"))] fn get_test_threads(matches: &getopts::Matches) -> OptPartRes> { let test_threads = match matches.opt_str("test-threads") { Some(n_str) => match n_str.parse::() { @@ -393,6 +424,7 @@ fn get_test_threads(matches: &getopts::Matches) -> OptPartRes> { Ok(test_threads) } +#[cfg(not(target_arch = "bpf"))] fn get_format( matches: &getopts::Matches, quiet: bool, @@ -425,6 +457,7 @@ fn get_format( Ok(format) } +#[cfg(not(target_arch = "bpf"))] fn get_color_config(matches: &getopts::Matches) -> OptPartRes { let color = match matches.opt_str("color").as_deref() { Some("auto") | None => ColorConfig::AutoColor, @@ -442,6 +475,7 @@ fn get_color_config(matches: &getopts::Matches) -> OptPartRes { Ok(color) } +#[cfg(not(target_arch = "bpf"))] fn get_nocapture(matches: &getopts::Matches) -> OptPartRes { let mut nocapture = matches.opt_present("nocapture"); if !nocapture { @@ -454,6 +488,7 @@ fn get_nocapture(matches: &getopts::Matches) -> OptPartRes { Ok(nocapture) } +#[cfg(not(target_arch = "bpf"))] fn get_run_ignored(matches: &getopts::Matches, include_ignored: bool) -> OptPartRes { let run_ignored = match (include_ignored, matches.opt_present("ignored")) { (true, true) => { @@ -467,6 +502,7 @@ fn get_run_ignored(matches: &getopts::Matches, include_ignored: bool) -> OptPart Ok(run_ignored) } +#[cfg(not(target_arch = "bpf"))] fn get_allow_unstable(matches: &getopts::Matches) -> OptPartRes { let mut allow_unstable = false; @@ -488,6 +524,7 @@ fn get_allow_unstable(matches: &getopts::Matches) -> OptPartRes { Ok(allow_unstable) } +#[cfg(not(target_arch = "bpf"))] fn get_log_file(matches: &getopts::Matches) -> OptPartRes> { let logfile = matches.opt_str("logfile").map(|s| PathBuf::from(&s)); diff --git a/library/test/src/console.rs b/library/test/src/console.rs index bbeb944e8b11b..5eaac0e1356da 100644 --- a/library/test/src/console.rs +++ b/library/test/src/console.rs @@ -291,10 +291,13 @@ fn on_test_event( /// A simple console test runner. /// Runs provided tests reporting process and results to the stdout. pub fn run_tests_console(opts: &TestOpts, tests: Vec) -> io::Result { + #[cfg(not(target_arch = "bpf"))] let output = match term::stdout() { None => OutputLocation::Raw(io::stdout()), Some(t) => OutputLocation::Pretty(t), }; + #[cfg(target_arch = "bpf")] + let output = OutputLocation::Raw(io::stdout()); let max_name_len = tests .iter() diff --git a/library/test/src/helpers/concurrency.rs b/library/test/src/helpers/concurrency.rs index eb211157371b5..ee5f117db8333 100644 --- a/library/test/src/helpers/concurrency.rs +++ b/library/test/src/helpers/concurrency.rs @@ -1,7 +1,9 @@ //! Helper module which helps to determine amount of threads to be used //! during tests execution. +#[cfg(not(target_arch = "bpf"))] use std::{env, num::NonZeroUsize, thread}; +#[cfg(not(target_arch = "bpf"))] pub fn get_concurrency() -> usize { if let Ok(value) = env::var("RUST_TEST_THREADS") { match value.parse::().ok() { @@ -12,3 +14,8 @@ pub fn get_concurrency() -> usize { thread::available_parallelism().map(|n| n.get()).unwrap_or(1) } } + +#[cfg(target_arch = "bpf")] +pub fn get_concurrency() -> usize { + 1 +} diff --git a/library/test/src/lib.rs b/library/test/src/lib.rs index ad7fec8f07874..076a235d42bc7 100644 --- a/library/test/src/lib.rs +++ b/library/test/src/lib.rs @@ -15,6 +15,11 @@ // build off of. #![cfg(not(target_arch = "bpf"))] +// N.B., this is also specified in this crate's Cargo.toml, but librustc_ast contains logic specific to +// this crate, which relies on this attribute (rather than the value of `--crate-name` passed by +// cargo) to detect this crate. + +#![crate_name = "test"] #![unstable(feature = "test", issue = "50297")] #![doc(test(attr(deny(warnings))))] #![cfg_attr(not(bootstrap), doc(rust_logo))] @@ -158,7 +163,10 @@ pub fn test_main(args: &[String], tests: Vec, options: Option>(); + #[cfg(target_arch = "bpf")] + let args: [String; 0] = []; let owned_tests: Vec<_> = tests.iter().map(make_owned_test).collect(); test_main(&args, owned_tests, None) } From 5f8055b17a6f13f9d838603bb72df458a0157674 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Tue, 11 May 2021 13:51:54 +0200 Subject: [PATCH 037/103] [SOL] Fix github actions configuration --- compiler/rustc_target/src/spec/tests/tests_impl.rs | 1 + src/bootstrap/Cargo.toml | 8 ++++---- src/doc/rustc/src/platform-support.md | 1 + src/tools/tidy/src/extdeps.rs | 3 ++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_target/src/spec/tests/tests_impl.rs b/compiler/rustc_target/src/spec/tests/tests_impl.rs index 257867b1b807b..9dbce47b55a6e 100644 --- a/compiler/rustc_target/src/spec/tests/tests_impl.rs +++ b/compiler/rustc_target/src/spec/tests/tests_impl.rs @@ -154,6 +154,7 @@ impl Target { fn can_use_os_unknown(&self) -> bool { self.llvm_target == "wasm32-unknown-unknown" || self.llvm_target == "wasm64-unknown-unknown" + || self.llvm_target == "bpf" || (self.env == "sgx" && self.vendor == "fortanix") } } diff --git a/src/bootstrap/Cargo.toml b/src/bootstrap/Cargo.toml index e0c8f434dbf85..b1a21dff79525 100644 --- a/src/bootstrap/Cargo.toml +++ b/src/bootstrap/Cargo.toml @@ -22,10 +22,10 @@ name = "rustc" path = "src/bin/rustc.rs" test = false -#[[bin]] -#name = "rustdoc" -#path = "bin/rustdoc.rs" -#test = false +[[bin]] +name = "rustdoc" +path = "bin/rustdoc.rs" +test = false [[bin]] name = "sccache-plus-cl" diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index 907e9c59f316c..876c6c969fb35 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -263,6 +263,7 @@ target | std | host | notes `bpfel-unknown-none` | * | | BPF (little endian) `csky-unknown-linux-gnuabiv2` | ✓ | | C-SKY abiv2 Linux (little endian) `csky-unknown-linux-gnuabiv2hf` | ✓ | | C-SKY abiv2 Linux, hardfloat (little endian) +`bpfel-unknown-unknown` | ✓ | | BPF `hexagon-unknown-linux-musl` | ? | | `i386-apple-ios` | ✓ | | 32-bit x86 iOS [^x86_32-floats-return-ABI] [`i586-pc-nto-qnx700`](platform-support/nto-qnx.md) | * | | 32-bit x86 QNX Neutrino 7.0 RTOS [^x86_32-floats-return-ABI] diff --git a/src/tools/tidy/src/extdeps.rs b/src/tools/tidy/src/extdeps.rs index ff71ca537256f..6b4792018dea8 100644 --- a/src/tools/tidy/src/extdeps.rs +++ b/src/tools/tidy/src/extdeps.rs @@ -4,7 +4,8 @@ use std::fs; use std::path::Path; /// List of allowed sources for packages. -const ALLOWED_SOURCES: &[&str] = &["\"registry+https://github.com/rust-lang/crates.io-index\""]; +const ALLOWED_SOURCES: &[&str] = &["\"registry+https://github.com/rust-lang/crates.io-index\"", +"\"git+https://github.com/solana-labs/compiler-builtins?tag=bpf-tools-v1.7#875087b410b77e0561b653882b431c84515eb044\""]; /// Checks for external package sources. `root` is the path to the directory that contains the /// workspace `Cargo.toml`. From 3cfbaa8f5973ff9d8f97ca4836c7c1146ad2c5ef Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Thu, 13 May 2021 14:31:28 +0200 Subject: [PATCH 038/103] [SOL] Add linker script and command line options to BPF target spec --- .../src/spec/bpfel_unknown_unknown.rs | 78 ++++++++++++++++++- 1 file changed, 74 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs index 9c8fcf62568b7..14fc45bf6df9b 100644 --- a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs +++ b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs @@ -1,6 +1,6 @@ -use crate::spec::abi::Abi; -use crate::spec::{LinkerFlavor, LldFlavor, PanicStrategy, - Target, TargetOptions}; +use super::abi::Abi; +use super::{LinkerFlavor, PanicStrategy, Target, TargetOptions}; +use std::{collections::BTreeMap, env, path::Path}; // All the calling conventions trigger an assertion(Unsupported calling // convention) in llvm on BPF @@ -22,6 +22,32 @@ pub fn abi_blacklist() -> Vec { } pub fn target() -> Target { + let linker_script = r" +PHDRS +{ + text PT_LOAD ; + rodata PT_LOAD ; + dynamic PT_DYNAMIC ; +} + +SECTIONS +{ + . = SIZEOF_HEADERS; + .text : { *(.text*) } :text + .rodata : { *(.rodata*) } :rodata + .data.rel.ro : { *(.data.rel.ro*) } :rodata + .dynamic : { *(.dynamic) } :dynamic +} +"; + let mut lld_args = Vec::new(); + lld_args.push("--Bdynamic".to_string()); + lld_args.push("--entry=entrypoint".to_string()); + lld_args.push("--threads=1".to_string()); + lld_args.push("-z".to_string()); + lld_args.push("notext".to_string()); + let mut pre_link_args = BTreeMap::new(); + pre_link_args.insert(LinkerFlavor::Ld, lld_args); + Target { llvm_target: "bpf".to_string(), pointer_width: 64, @@ -35,7 +61,11 @@ pub fn target() -> Target { env: String::new(), features: "+solana".to_string(), vendor: "unknown".to_string(), - linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), + linker_flavor: LinkerFlavor::Ld, + linker_is_gnu: true, + linker: find_linker(), + link_script: Some(linker_script.to_string()), + pre_link_args, executables: true, dll_prefix: "".to_string(), dynamic_linking: true, @@ -52,3 +82,43 @@ pub fn target() -> Target { }, } } + +fn find_linker() -> Option { + fn construct_linker_path(path: &Path) -> Option { + if let Some(base) = path.parent() { + let path = base + .join("llvm") + .join("bin") + .join("ld.lld"); + if path.exists() { + if let Some(ld_str) = path.to_str() { + return Some(ld_str.to_string()); + } + } + } + None + } + + if let Ok(path) = env::current_exe() { + let mut ancestors = path.ancestors(); + // ~/.rustup/bpf/bin/rustc + let base = ancestors.next(); + if base == None { + return None; + } + // ~/.rustup/bpf/bin + let base = ancestors.next(); + if base == None { + return None; + } + // ~/.rustup/bpf + if let Some(base) = ancestors.next() { + if let Ok(link) = base.read_link() { + return construct_linker_path(&link); + } else { + return construct_linker_path(&base); + } + } + } + None +} From 8fe60f50275f91a1d57b503cbb2421e656b91a40 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Mon, 17 May 2021 16:51:22 +0200 Subject: [PATCH 039/103] [SOL] Fix BPF target spec after upgrade to rust 1.52.1 --- compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs index 14fc45bf6df9b..8f0ae8f095666 100644 --- a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs +++ b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs @@ -1,3 +1,4 @@ +use crate::abi::Endian; use super::abi::Abi; use super::{LinkerFlavor, PanicStrategy, Target, TargetOptions}; use std::{collections::BTreeMap, env, path::Path}; @@ -7,10 +8,10 @@ use std::{collections::BTreeMap, env, path::Path}; pub fn abi_blacklist() -> Vec { vec![ Abi::Cdecl, - Abi::Stdcall, + Abi::Stdcall { unwind: false }, Abi::Fastcall, Abi::Vectorcall, - Abi::Thiscall, + Abi::Thiscall { unwind: false }, Abi::Aapcs, Abi::Win64, Abi::SysV64, @@ -55,7 +56,7 @@ SECTIONS data_layout: "e-m:e-p:64:64-i64:64-n32:64-S128".to_string(), options: TargetOptions { - endian: "little".to_string(), + endian: Endian::Little, c_int_width: "64".to_string(), os: "unknown".to_string(), env: String::new(), From e1328e682e490d5db7add9709c5dfb2121e8f921 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Tue, 18 May 2021 11:22:31 +0200 Subject: [PATCH 040/103] [SOL] Adjust BPF customization after upgrading to rust 1.52.1 --- library/std/src/macros.rs | 7 ++++--- library/std/src/panic.rs | 3 +-- library/std/src/panicking.rs | 34 +++++++++++++++++----------------- library/test/src/cli.rs | 2 +- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/library/std/src/macros.rs b/library/std/src/macros.rs index bae96dedda080..f22a4575e7c09 100644 --- a/library/std/src/macros.rs +++ b/library/std/src/macros.rs @@ -20,11 +20,12 @@ macro_rules! panic { }; } -#[doc(include = "../../core/src/macros/panic.md")] +#[doc = include_str!("../../core/src/macros/panic.md")] #[macro_export] +#[rustc_builtin_macro = "std_panic"] #[stable(feature = "rust1", since = "1.0.0")] -#[allow_internal_unstable(libstd_sys_internals)] -#[cfg_attr(not(any(bootstrap, test)), rustc_diagnostic_item = "std_panic_macro")] +#[allow_internal_unstable(edition_panic)] +#[cfg_attr(not(test), rustc_diagnostic_item = "std_panic_macro")] #[cfg(target_arch = "bpf")] macro_rules! panic { () => ({ $crate::panic!("explicit panic") }); diff --git a/library/std/src/panic.rs b/library/std/src/panic.rs index 675791dd465fe..269425496d1fe 100644 --- a/library/std/src/panic.rs +++ b/library/std/src/panic.rs @@ -180,8 +180,7 @@ pub fn resume_unwind(payload: Box) -> ! { #[cfg(target_arch = "bpf")] pub fn resume_unwind(_payload: Box) -> ! { // Only used by thread, redirect to plain old panic - panicking::begin_panic_fmt(&format_args!("unwind"), - &(file!(), line!(), column!())) + panicking::begin_panic_fmt(&format_args!("unwind")) } /// Make all future panics abort directly without running the panic hook or unwinding. diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index 462fc15dab123..6d55c968f8053 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -59,6 +59,7 @@ extern "C" { extern "Rust" { /// `PanicPayload` lazily performs allocation only when needed (this avoids /// allocations when using the "abort" panic runtime). + #[cfg(not(target_arch = "bpf"))] fn __rust_start_panic(payload: &mut dyn PanicPayload) -> u32; } @@ -911,38 +912,37 @@ pub fn rust_begin_panic(info: &PanicInfo<'_>) -> ! { crate::sys::panic(info); } -/// The entry point for panicking with a formatted message. -/// -/// This is designed to reduce the amount of code required at the call -/// site as much as possible (so that `panic!()` has as low an impact -/// on (e.g.) the inlining of other functions as possible), by moving -/// the actual formatting into this shared place. +/// The entry point for panicking with a formatted message BPF version. #[cfg(target_arch = "bpf")] #[unstable(feature = "libstd_sys_internals", reason = "used by the panic! macro", issue = "none")] #[cold] // If panic_immediate_abort, inline the abort call, // otherwise avoid inlining because of it is cold path. -#[cfg_attr(not(feature="panic_immediate_abort"),inline(never))] -#[cfg_attr( feature="panic_immediate_abort" ,inline)] -pub fn begin_panic_fmt(msg: &fmt::Arguments<'_>, - file_line_col: &(&'static str, u32, u32)) -> ! { - begin_panic(msg, file_line_col); +#[cfg_attr(not(feature = "panic_immediate_abort"), track_caller)] +#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))] +#[cfg_attr(feature = "panic_immediate_abort", inline)] +pub fn begin_panic_fmt(msg: &fmt::Arguments<'_>) -> ! { + let info = PanicInfo::internal_constructor( + Some(msg), + Location::caller(), + ); + crate::sys::panic(&info); } -/// Entry point of panicking for panic!() and assert!(). +/// Entry point of panicking for panic!() and assert!() BPF version. #[cfg(target_arch = "bpf")] #[unstable(feature = "libstd_sys_internals", reason = "used by the panic! macro", issue = "none")] #[cfg_attr(not(test), lang = "begin_panic")] +// lang item for CTFE panic support // never inline unless panic_immediate_abort to avoid code // bloat at the call sites as much as possible #[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))] #[cold] -pub fn begin_panic(msg: &fmt::Arguments<'_>, file_line_col: &(&'static str, u32, u32)) -> ! { - let (file, line, col) = *file_line_col; - let location = Location::internal_constructor(file, line, col); +#[track_caller] +pub fn begin_panic(_msg: M) -> ! { let info = PanicInfo::internal_constructor( - Some(msg), - &location, + None, + Location::caller(), ); crate::sys::panic(&info); } diff --git a/library/test/src/cli.rs b/library/test/src/cli.rs index 62720a6a36c57..314408593c158 100644 --- a/library/test/src/cli.rs +++ b/library/test/src/cli.rs @@ -314,7 +314,7 @@ fn parse_opts_impl(matches: getopts::Matches) -> OptRes { fn parse_opts_impl(_matches: getopts::Matches) -> OptRes { let test_opts = TestOpts { list: false, - filter: None, + filters: Vec::new(), filter_exact: false, force_run_in_process: false, exclude_should_panic: false, From 42274766db7acbd1b810b5c4b88553973a776d62 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Thu, 17 Jun 2021 11:53:35 -0700 Subject: [PATCH 041/103] [SOL] Strip full paths from source filenames referred in messages Prevent including users local paths in generated binary files. --- compiler/rustc_codegen_ssa/src/mir/block.rs | 1 + compiler/rustc_middle/src/mir/consts.rs | 24 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index 3d2d8f8b50990..5df26d3eae988 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -23,6 +23,7 @@ use rustc_target::abi::{self, HasDataLayout, WrappingRange}; use rustc_target::spec::abi::Abi; use std::cmp; +use std::path::{Path, PathBuf}; // Indicates if we are in the middle of merging a BB's successor into it. This // can happen when BB jumps directly to its successor and the successor has no diff --git a/compiler/rustc_middle/src/mir/consts.rs b/compiler/rustc_middle/src/mir/consts.rs index a9d09709e8427..bc4fe7f0276c6 100644 --- a/compiler/rustc_middle/src/mir/consts.rs +++ b/compiler/rustc_middle/src/mir/consts.rs @@ -590,10 +590,30 @@ impl<'tcx> TyCtxt<'tcx> { pub fn span_as_caller_location(self, span: Span) -> ConstValue<'tcx> { let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span); let caller = self.sess.source_map().lookup_char_pos(topmost.lo()); - self.const_caller_location( + let file_name = if self.sess.target.arch == "bpf" { + let file_name = caller.file.name.prefer_remapped().to_string_lossy(); + let mut path = Path::new(&file_name); + let components = path.components().collect::>(); + let len = components.len(); + let mut buf = PathBuf::new(); + if len > 3 { + buf.push(components[len - 3].as_os_str()); + buf.push(components[len - 2].as_os_str()); + buf.push(components[len - 1].as_os_str()); + path = buf.as_path(); + } + if let Some(path_str) = path.to_str() { + rustc_span::symbol::Symbol::intern(&path_str) + } else { + rustc_span::symbol::Symbol::intern(&file_name) + } + } else { rustc_span::symbol::Symbol::intern( &caller.file.name.for_codegen(&self.sess).to_string_lossy(), - ), + ) + }; + self.const_caller_location( + file_name, caller.line as u32, caller.col_display as u32 + 1, ) From 5e4de603557f6c8acb779eff893c9bc07cfae761 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Sun, 4 Jul 2021 16:42:31 -0700 Subject: [PATCH 042/103] [SOL] Adjust BPF customization after upgrading to rust 1.53.0 --- library/std/src/sys/bpf/args.rs | 10 +++++++--- library/std/src/sys/bpf/thread.rs | 4 +++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/library/std/src/sys/bpf/args.rs b/library/std/src/sys/bpf/args.rs index eeaac8a48e29d..eaa943769e7dd 100644 --- a/library/std/src/sys/bpf/args.rs +++ b/library/std/src/sys/bpf/args.rs @@ -1,5 +1,6 @@ use crate::ffi::OsString; use crate::marker::PhantomData; +use crate::fmt; use crate::vec; pub fn args() -> Args { @@ -11,9 +12,12 @@ pub struct Args { _dont_send_or_sync_me: PhantomData<*mut ()>, } -impl Args { - pub fn inner_debug(&self) -> &[OsString] { - self.iter.as_slice() +impl !Send for Args {} +impl !Sync for Args {} + +impl fmt::Debug for Args { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.iter.as_slice().fmt(f) } } diff --git a/library/std/src/sys/bpf/thread.rs b/library/std/src/sys/bpf/thread.rs index 5791ba291b0e7..a1f49a43ba1db 100644 --- a/library/std/src/sys/bpf/thread.rs +++ b/library/std/src/sys/bpf/thread.rs @@ -32,5 +32,7 @@ impl Thread { pub mod guard { pub type Guard = !; - pub unsafe fn current() -> Option { None } + pub unsafe fn current() -> Option { + None + } } From d53a8b98def6d252e90ab9346ba801a07f7c67a4 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Sun, 4 Jul 2021 20:12:11 -0700 Subject: [PATCH 043/103] [SOL] Make adjustments to work around CI failures --- library/std/src/panicking.rs | 1 - src/tools/tidy/src/pal.rs | 21 +++++++++++++++++-- .../run-make/unstable-flag-required/Makefile | 2 ++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index 6d55c968f8053..2c3a296c881c5 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -908,7 +908,6 @@ pub fn panicking() -> bool { #[panic_handler] #[unwind(allowed)] pub fn rust_begin_panic(info: &PanicInfo<'_>) -> ! { - crate::sys::sol_log("libstd rust_begin_panic"); crate::sys::panic(info); } diff --git a/src/tools/tidy/src/pal.rs b/src/tools/tidy/src/pal.rs index 5f6b63a67fda7..d1c3abef34b7c 100644 --- a/src/tools/tidy/src/pal.rs +++ b/src/tools/tidy/src/pal.rs @@ -38,8 +38,25 @@ const EXCEPTION_PATHS: &[&str] = &[ "library/panic_abort", "library/panic_unwind", "library/unwind", - "library/rtstartup", // Not sure what to do about this. magic stuff for mingw - "library/test", // Probably should defer to unstable `std::sys` APIs. + "library/std/src/sys/", // Platform-specific code for std lives here. + // This has the trailing slash so that sys_common is not excepted. + "library/std/src/os", // Platform-specific public interfaces + "library/rtstartup", // Not sure what to do about this. magic stuff for mingw + // Integration test for platform-specific run-time feature detection: + "library/std/tests/run-time-detect.rs", + "library/std/src/net/test.rs", + "library/std/src/net/addr", + "library/std/src/net/udp", + "library/std/src/sys_common/backtrace.rs", + "library/std/src/sys_common/remutex.rs", + "library/std/src/sync/mutex.rs", + "library/std/src/sync/rwlock.rs", + "library/term", // Not sure how to make this crate portable, but test crate needs it. + "library/test", // Probably should defer to unstable `std::sys` APIs. + // std testing crates, okay for now at least + "library/core/tests", + "library/alloc/tests/lib.rs", + "library/alloc/benches/lib.rs", // The `VaList` implementation must have platform specific code. // The Windows implementation of a `va_list` is always a character // pointer regardless of the target architecture. As a result, diff --git a/tests/run-make/unstable-flag-required/Makefile b/tests/run-make/unstable-flag-required/Makefile index 17dd15b079c62..c95ec74a55d3a 100644 --- a/tests/run-make/unstable-flag-required/Makefile +++ b/tests/run-make/unstable-flag-required/Makefile @@ -1,4 +1,6 @@ include ../tools.mk +# only-thumb + all: $(RUSTDOC) --output-format=json x.html 2>&1 | diff - output-format-json.stderr From 93885ef3ed1d4ac099911fc6965f22a2044f75ee Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Thu, 5 Aug 2021 19:14:38 +0200 Subject: [PATCH 044/103] [SOL] Adjust BPF customization after upgrading to rust 1.54.0 --- compiler/rustc_codegen_ssa/src/mir/block.rs | 1 - compiler/rustc_middle/src/mir/consts.rs | 24 ++----------------- .../src/spec/bpfel_unknown_unknown.rs | 7 +++--- library/std/src/process.rs | 3 --- library/std/src/sys/bpf/fs.rs | 4 ++++ library/std/src/sys/bpf/mod.rs | 4 ++-- library/std/src/sys/bpf/process.rs | 18 +++++++++++++- library/std/src/sys/bpf/rwlock.rs | 2 ++ 8 files changed, 31 insertions(+), 32 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index 5df26d3eae988..3d2d8f8b50990 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -23,7 +23,6 @@ use rustc_target::abi::{self, HasDataLayout, WrappingRange}; use rustc_target::spec::abi::Abi; use std::cmp; -use std::path::{Path, PathBuf}; // Indicates if we are in the middle of merging a BB's successor into it. This // can happen when BB jumps directly to its successor and the successor has no diff --git a/compiler/rustc_middle/src/mir/consts.rs b/compiler/rustc_middle/src/mir/consts.rs index bc4fe7f0276c6..a9d09709e8427 100644 --- a/compiler/rustc_middle/src/mir/consts.rs +++ b/compiler/rustc_middle/src/mir/consts.rs @@ -590,30 +590,10 @@ impl<'tcx> TyCtxt<'tcx> { pub fn span_as_caller_location(self, span: Span) -> ConstValue<'tcx> { let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span); let caller = self.sess.source_map().lookup_char_pos(topmost.lo()); - let file_name = if self.sess.target.arch == "bpf" { - let file_name = caller.file.name.prefer_remapped().to_string_lossy(); - let mut path = Path::new(&file_name); - let components = path.components().collect::>(); - let len = components.len(); - let mut buf = PathBuf::new(); - if len > 3 { - buf.push(components[len - 3].as_os_str()); - buf.push(components[len - 2].as_os_str()); - buf.push(components[len - 1].as_os_str()); - path = buf.as_path(); - } - if let Some(path_str) = path.to_str() { - rustc_span::symbol::Symbol::intern(&path_str) - } else { - rustc_span::symbol::Symbol::intern(&file_name) - } - } else { + self.const_caller_location( rustc_span::symbol::Symbol::intern( &caller.file.name.for_codegen(&self.sess).to_string_lossy(), - ) - }; - self.const_caller_location( - file_name, + ), caller.line as u32, caller.col_display as u32 + 1, ) diff --git a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs index 8f0ae8f095666..6356facdf5355 100644 --- a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs +++ b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs @@ -50,18 +50,18 @@ SECTIONS pre_link_args.insert(LinkerFlavor::Ld, lld_args); Target { - llvm_target: "bpf".to_string(), + llvm_target: "bpfel".to_string(), pointer_width: 64, arch: "bpf".to_string(), data_layout: "e-m:e-p:64:64-i64:64-n32:64-S128".to_string(), options: TargetOptions { + allow_asm: true, endian: Endian::Little, c_int_width: "64".to_string(), - os: "unknown".to_string(), env: String::new(), features: "+solana".to_string(), - vendor: "unknown".to_string(), + vendor: "solana".to_string(), linker_flavor: LinkerFlavor::Ld, linker_is_gnu: true, linker: find_linker(), @@ -74,6 +74,7 @@ SECTIONS no_default_libraries: true, panic_strategy: PanicStrategy::Abort, position_independent_executables: true, + requires_lto: false, singlethread: true, max_atomic_width: Some(64), unsupported_abis: abi_blacklist(), diff --git a/library/std/src/process.rs b/library/std/src/process.rs index 18d816f65834c..db0bc1ca94002 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -2277,10 +2277,7 @@ pub fn exit(code: i32) -> ! { #[stable(feature = "process_abort", since = "1.17.0")] #[cold] pub fn abort() -> ! { - #[cfg(not(target_arch = "bpf"))] crate::sys::abort_internal(); - #[cfg(target_arch = "bpf")] - unsafe { crate::sys::abort_internal(); } } /// Returns the OS-assigned process identifier associated with this process. diff --git a/library/std/src/sys/bpf/fs.rs b/library/std/src/sys/bpf/fs.rs index 59fe2f9aacc1a..fe3197377ba64 100644 --- a/library/std/src/sys/bpf/fs.rs +++ b/library/std/src/sys/bpf/fs.rs @@ -283,6 +283,10 @@ pub fn remove_dir_all(_path: &Path) -> io::Result<()> { unsupported() } +pub fn try_exists(_path: &Path) -> io::Result { + unsupported() +} + pub fn readlink(_p: &Path) -> io::Result { unsupported() } diff --git a/library/std/src/sys/bpf/mod.rs b/library/std/src/sys/bpf/mod.rs index 91e763ebe37ec..daf8610b15635 100644 --- a/library/std/src/sys/bpf/mod.rs +++ b/library/std/src/sys/bpf/mod.rs @@ -86,8 +86,8 @@ pub unsafe fn strlen(mut s: *const c_char) -> usize { return n } -pub unsafe fn abort_internal() -> ! { - abort() +pub fn abort_internal() -> ! { + unsafe { abort() } } // We don't have randomness yet, but I totally used a random number generator to diff --git a/library/std/src/sys/bpf/process.rs b/library/std/src/sys/bpf/process.rs index 0abc112e9fa8d..a45409ddb90d6 100644 --- a/library/std/src/sys/bpf/process.rs +++ b/library/std/src/sys/bpf/process.rs @@ -1,6 +1,7 @@ use crate::ffi::{CString, OsStr}; use crate::fmt; use crate::io; +use crate::num::NonZeroI32; use crate::path::Path; use crate::sys::fs::File; use crate::sys::pipe::AnonPipe; @@ -104,7 +105,7 @@ impl fmt::Debug for Command { pub struct ExitStatus(Void); impl ExitStatus { - pub fn success(&self) -> bool { + pub fn exit_ok(&self) -> Result<(), ExitStatusError> { match self.0 {} } @@ -142,6 +143,21 @@ impl fmt::Display for ExitStatus { } } +#[derive(PartialEq, Eq, Clone, Copy, Debug)] +pub struct ExitStatusError(ExitStatus); + +impl Into for ExitStatusError { + fn into(self) -> ExitStatus { + match self.0 {} + } +} + +impl ExitStatusError { + pub fn code(self) -> Option { + match self.0 {} + } +} + #[derive(PartialEq, Eq, Clone, Copy, Debug)] pub struct ExitCode(bool); diff --git a/library/std/src/sys/bpf/rwlock.rs b/library/std/src/sys/bpf/rwlock.rs index fd407a1d5f66e..2e9f4e9a87b94 100644 --- a/library/std/src/sys/bpf/rwlock.rs +++ b/library/std/src/sys/bpf/rwlock.rs @@ -4,6 +4,8 @@ pub struct RWLock { mode: UnsafeCell, } +pub type MovableRWLock = RWLock; + unsafe impl Send for RWLock {} unsafe impl Sync for RWLock {} // no threads on BPF From ffede79cad97f867854d8406c88804cd6430afd0 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Sat, 7 Aug 2021 18:44:32 +0200 Subject: [PATCH 045/103] [SOL] Disable channel check in CI as we use different branch names --- src/ci/github-actions/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml index da29ffb8e5f9b..807c567efba00 100644 --- a/src/ci/github-actions/ci.yml +++ b/src/ci/github-actions/ci.yml @@ -145,9 +145,9 @@ x--expand-yaml-anchors--remove: run: src/ci/scripts/should-skip-this.sh <<: *step - - name: ensure the channel matches the target branch - run: src/ci/scripts/verify-channel.sh - <<: *step +# - name: ensure the channel matches the target branch +# run: src/ci/scripts/verify-channel.sh +# <<: *step - name: collect CPU statistics run: src/ci/scripts/collect-cpu-stats.sh From aa02f0a68dbb4b808d46c768022583a9aea65e7d Mon Sep 17 00:00:00 2001 From: Jon Cinque Date: Mon, 27 Sep 2021 13:31:37 +0200 Subject: [PATCH 046/103] [SOL] Add support for windows in build script --- build.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/build.sh b/build.sh index 6dcddf682d06e..060c1b4a1f4f3 100755 --- a/build.sh +++ b/build.sh @@ -7,13 +7,15 @@ if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then exit; fi -if [ "$(uname)" == "Darwin" ]; then - HOST_TRIPLE=x86_64-apple-darwin -else - HOST_TRIPLE=x86_64-unknown-linux-gnu -fi +unameOut="$(uname -s)" +case "${unameOut}" in + Linux*) HOST_TRIPLE=x86_64-unknown-linux-gnu;; + Darwin*) HOST_TRIPLE=x86_64-apple-darwin;; + MINGW*) HOST_TRIPLE=x86_64-pc-windows-msvc;; + *) HOST_TRIPLE=x86_64-unknown-linux-gnu +esac if [ "$1" == "--llvm" ]; then - rm -f build/x86_64-apple-darwin/llvm/llvm-finished-building; + rm -f build/${HOST_TRIPLE}/llvm/llvm-finished-building; fi ./x.py build --stage 1 --target ${HOST_TRIPLE},bpfel-unknown-unknown From 4df64254b0d8f82343fa7b0dd22b1760e7aaa616 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Tue, 2 Nov 2021 19:44:44 -0700 Subject: [PATCH 047/103] [SOL] Adjust BPF customization after upgrading to rust 1.56.0 --- .../src/spec/bpfel_unknown_unknown.rs | 21 --- library/std/src/io/stdio.rs | 139 ++++++++++++++++++ library/std/src/macros.rs | 17 --- library/std/src/panic.rs | 1 - library/std/src/panicking.rs | 16 +- library/std/src/sys/bpf/mod.rs | 5 +- library/std/src/sys/bpf/net.rs | 8 + library/std/src/sys/bpf/os.rs | 4 +- library/std/src/sys/bpf/thread.rs | 5 + 9 files changed, 172 insertions(+), 44 deletions(-) diff --git a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs index 6356facdf5355..301210aea0ea4 100644 --- a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs +++ b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs @@ -1,27 +1,7 @@ use crate::abi::Endian; -use super::abi::Abi; use super::{LinkerFlavor, PanicStrategy, Target, TargetOptions}; use std::{collections::BTreeMap, env, path::Path}; -// All the calling conventions trigger an assertion(Unsupported calling -// convention) in llvm on BPF -pub fn abi_blacklist() -> Vec { - vec![ - Abi::Cdecl, - Abi::Stdcall { unwind: false }, - Abi::Fastcall, - Abi::Vectorcall, - Abi::Thiscall { unwind: false }, - Abi::Aapcs, - Abi::Win64, - Abi::SysV64, - Abi::PtxKernel, - Abi::Msp430Interrupt, - Abi::X86Interrupt, - Abi::AmdGpuKernel, - ] -} - pub fn target() -> Target { let linker_script = r" PHDRS @@ -77,7 +57,6 @@ SECTIONS requires_lto: false, singlethread: true, max_atomic_width: Some(64), - unsupported_abis: abi_blacklist(), eh_frame_header: false, main_needs_argc_argv: false, .. Default::default() diff --git a/library/std/src/io/stdio.rs b/library/std/src/io/stdio.rs index 7f972d3ebfa73..740f4877cf793 100644 --- a/library/std/src/io/stdio.rs +++ b/library/std/src/io/stdio.rs @@ -448,6 +448,45 @@ impl Stdin { self.lock().read_line(buf) } + // Locks this handle with any lifetime. This depends on the + // implementation detail that the underlying `Mutex` is static. + #[cfg(not(target_arch = "bpf"))] + fn lock_any<'a>(&self) -> StdinLock<'a> { + StdinLock { inner: self.inner.lock().unwrap_or_else(|e| e.into_inner()) } + } + + /// Consumes this handle to the standard input stream, locking the + /// shared global buffer associated with the stream and returning a + /// readable guard. + /// + /// The lock is released when the returned guard goes out of scope. The + /// returned guard also implements the [`Read`] and [`BufRead`] traits + /// for accessing the underlying data. + /// + /// It is often simpler to directly get a locked handle using the + /// [`stdin_locked`] function instead, unless nearby code also needs to + /// use an unlocked handle. + /// + /// # Examples + /// + /// ```no_run + /// #![feature(stdio_locked)] + /// use std::io::{self, BufRead}; + /// + /// fn main() -> io::Result<()> { + /// let mut buffer = String::new(); + /// let mut handle = io::stdin().into_locked(); + /// + /// handle.read_line(&mut buffer)?; + /// Ok(()) + /// } + /// ``` + #[unstable(feature = "stdio_locked", issue = "86845")] + #[cfg(not(target_arch = "bpf"))] + pub fn into_locked(self) -> StdinLock<'static> { + self.lock_any() + } + /// Consumes this handle and returns an iterator over input lines. /// /// For detailed semantics of this method, see the documentation on @@ -465,9 +504,34 @@ impl Stdin { /// ``` #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "stdin_forwarders", since = "1.62.0")] + #[cfg(not(target_arch = "bpf"))] pub fn lines(self) -> Lines> { self.lock().lines() } + + /// Consumes this handle and returns an iterator over input bytes, + /// split at the specified byte value. + /// + /// For detailed semantics of this method, see the documentation on + /// [`BufRead::split`]. + /// + /// # Examples + /// + /// ```no_run + /// #![feature(stdin_forwarders)] + /// use std::io; + /// + /// let splits = io::stdin().split(b'-'); + /// for split in splits { + /// println!("got a chunk: {}", String::from_utf8_lossy(&split.unwrap())); + /// } + /// ``` + #[must_use = "`self` will be dropped if the result is not used"] + #[unstable(feature = "stdin_forwarders", issue = "87096")] + #[cfg(not(target_arch = "bpf"))] + pub fn split(self, byte: u8) -> Split> { + self.into_locked().split(byte) + } } #[stable(feature = "std_debug", since = "1.16.0")] @@ -775,6 +839,45 @@ impl Stdout { // static. StdoutLock { inner: self.inner.lock() } } + + // Locks this handle with any lifetime. This depends on the + // implementation detail that the underlying `ReentrantMutex` is + // static. + #[cfg(not(target_arch = "bpf"))] + fn lock_any<'a>(&self) -> StdoutLock<'a> { + StdoutLock { inner: self.inner.lock() } + } + + /// Consumes this handle to the standard output stream, locking the + /// shared global buffer associated with the stream and returning a + /// writable guard. + /// + /// The lock is released when the returned lock goes out of scope. The + /// returned guard also implements the [`Write`] trait for writing data. + /// + /// It is often simpler to directly get a locked handle using the + /// [`io::stdout_locked`] function instead, unless nearby code also + /// needs to use an unlocked handle. + /// + /// # Examples + /// + /// ```no_run + /// #![feature(stdio_locked)] + /// use std::io::{self, Write}; + /// + /// fn main() -> io::Result<()> { + /// let mut handle = io::stdout().into_locked(); + /// + /// handle.write_all(b"hello world")?; + /// + /// Ok(()) + /// } + /// ``` + #[unstable(feature = "stdio_locked", issue = "86845")] + #[cfg(not(target_arch = "bpf"))] + pub fn into_locked(self) -> StdoutLock<'static> { + self.lock_any() + } } #[stable(feature = "std_debug", since = "1.16.0")] @@ -1087,6 +1190,42 @@ impl Stderr { // static. StderrLock { inner: self.inner.lock() } } + + // Locks this handle with any lifetime. This depends on the + // implementation detail that the underlying `ReentrantMutex` is + // static. + #[cfg(not(target_arch = "bpf"))] + fn lock_any<'a>(&self) -> StderrLock<'a> { + StderrLock { inner: self.inner.lock() } + } + + /// Locks and consumes this handle to the standard error stream, + /// returning a writable guard. + /// + /// The lock is released when the returned guard goes out of scope. The + /// returned guard also implements the [`Write`] trait for writing + /// data. + /// + /// # Examples + /// + /// ``` + /// #![feature(stdio_locked)] + /// use std::io::{self, Write}; + /// + /// fn foo() -> io::Result<()> { + /// let stderr = io::stderr(); + /// let mut handle = stderr.into_locked(); + /// + /// handle.write_all(b"hello world")?; + /// + /// Ok(()) + /// } + /// ``` + #[unstable(feature = "stdio_locked", issue = "86845")] + #[cfg(not(target_arch = "bpf"))] + pub fn into_locked(self) -> StderrLock<'static> { + self.lock_any() + } } #[stable(feature = "std_debug", since = "1.16.0")] diff --git a/library/std/src/macros.rs b/library/std/src/macros.rs index f22a4575e7c09..34b8b6b97b505 100644 --- a/library/std/src/macros.rs +++ b/library/std/src/macros.rs @@ -11,7 +11,6 @@ #[stable(feature = "rust1", since = "1.0.0")] #[allow_internal_unstable(edition_panic)] #[cfg_attr(not(test), rustc_diagnostic_item = "std_panic_macro")] -#[cfg(not(target_arch = "bpf"))] macro_rules! panic { // Expands to either `$crate::panic::panic_2015` or `$crate::panic::panic_2021` // depending on the edition of the caller. @@ -20,22 +19,6 @@ macro_rules! panic { }; } -#[doc = include_str!("../../core/src/macros/panic.md")] -#[macro_export] -#[rustc_builtin_macro = "std_panic"] -#[stable(feature = "rust1", since = "1.0.0")] -#[allow_internal_unstable(edition_panic)] -#[cfg_attr(not(test), rustc_diagnostic_item = "std_panic_macro")] -#[cfg(target_arch = "bpf")] -macro_rules! panic { - () => ({ $crate::panic!("explicit panic") }); - ($msg:expr $(,)?) => ({ $crate::panic!("{}", $msg) }); - ($fmt:expr, $($arg:tt)+) => ({ - $crate::rt::begin_panic_fmt(&$crate::format_args!($fmt, $($arg)+), - &($crate::file!(), $crate::line!(), $crate::column!())) - }); -} - /// Prints to the standard output. /// /// Equivalent to the [`println!`] macro except that a newline is not printed at diff --git a/library/std/src/panic.rs b/library/std/src/panic.rs index 269425496d1fe..2aedc1bdff348 100644 --- a/library/std/src/panic.rs +++ b/library/std/src/panic.rs @@ -7,7 +7,6 @@ use crate::collections; use crate::panicking; use crate::sync::atomic::{AtomicUsize, Ordering}; use crate::sync::{Mutex, RwLock}; -#[cfg(not(target_arch = "bpf"))] use crate::thread::Result; #[doc(hidden)] diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index 2c3a296c881c5..76c66eafff78d 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -373,6 +373,7 @@ pub mod panic_count { #[cfg(not(feature = "panic_immediate_abort"))] #[unstable(feature = "update_panic_count", issue = "none")] pub mod panic_count { + #[cfg(not(target_arch = "bpf"))] use crate::cell::Cell; use crate::sync::atomic::{AtomicUsize, Ordering}; @@ -387,6 +388,7 @@ pub mod panic_count { // Panic count for the current thread and whether a panic hook is currently // being executed.. + #[cfg(not(target_arch = "bpf"))] thread_local! { static LOCAL_PANIC_COUNT: Cell<(usize, bool)> = const { Cell::new((0, false)) } } @@ -447,6 +449,7 @@ pub mod panic_count { }); } + #[cfg(not(target_arch = "bpf"))] pub fn decrease() { GLOBAL_PANIC_COUNT.fetch_sub(1, Ordering::Relaxed); LOCAL_PANIC_COUNT.with(|c| { @@ -566,6 +569,7 @@ pub unsafe fn r#try R>(f: F) -> Result> // optimizer (in most cases this function is not inlined even as a normal, // non-cold function, though, as of the writing of this comment). #[cold] + #[cfg(not(target_arch = "bpf"))] unsafe fn cleanup(payload: *mut u8) -> Box { // SAFETY: The whole unsafe block hinges on a correct implementation of // the panic handler `__rust_panic_cleanup`. As such we can only @@ -576,6 +580,17 @@ pub unsafe fn r#try R>(f: F) -> Result> obj } + #[cold] + #[cfg(target_arch = "bpf")] + unsafe fn cleanup(payload: *mut u8) -> Box { + // SAFETY: The whole unsafe block hinges on a correct implementation of + // the panic handler `__rust_panic_cleanup`. As such we can only + // assume it returns the correct thing for `Box::from_raw` to work + // without undefined behavior. + let obj = unsafe { Box::from_raw(__rust_panic_cleanup(payload)) }; + obj + } + // SAFETY: // data must be non-NUL, correctly aligned, and a pointer to a `Data` // Its must contains a valid `f` (type: F) value that can be use to fill @@ -906,7 +921,6 @@ pub fn panicking() -> bool { /// Entry point of panic from the libcore crate. #[cfg(all(not(test), target_arch = "bpf"))] #[panic_handler] -#[unwind(allowed)] pub fn rust_begin_panic(info: &PanicInfo<'_>) -> ! { crate::sys::panic(info); } diff --git a/library/std/src/sys/bpf/mod.rs b/library/std/src/sys/bpf/mod.rs index daf8610b15635..ed1d0e7bc23cc 100644 --- a/library/std/src/sys/bpf/mod.rs +++ b/library/std/src/sys/bpf/mod.rs @@ -33,14 +33,15 @@ pub mod thread; pub mod time; pub mod stdio; +#[path = "../unix/os_str.rs"] +pub mod os_str; + pub mod condvar; pub mod mutex; pub mod rwlock; pub mod thread_local_dtor; pub mod thread_local_key; -pub use crate::sys_common::os_str_bytes as os_str; - extern "C" { fn abort() -> !; #[allow(improper_ctypes)] diff --git a/library/std/src/sys/bpf/net.rs b/library/std/src/sys/bpf/net.rs index 53001f5166730..88d0c76a59056 100644 --- a/library/std/src/sys/bpf/net.rs +++ b/library/std/src/sys/bpf/net.rs @@ -78,6 +78,14 @@ impl TcpStream { match self.0 {} } + pub fn set_linger(&self, _: Option) -> io::Result<()> { + unsupported() + } + + pub fn linger(&self) -> io::Result> { + unsupported() + } + pub fn set_nodelay(&self, _: bool) -> io::Result<()> { match self.0 {} } diff --git a/library/std/src/sys/bpf/os.rs b/library/std/src/sys/bpf/os.rs index 65bc578c32456..b31aefd270c96 100644 --- a/library/std/src/sys/bpf/os.rs +++ b/library/std/src/sys/bpf/os.rs @@ -74,8 +74,8 @@ pub fn env() -> Env { panic!(); } -pub fn getenv(_k: &OsStr) -> io::Result> { - unsupported() +pub fn getenv(_k: &OsStr) -> Option { + None } pub fn setenv(_k: &OsStr, _v: &OsStr) -> io::Result<()> { diff --git a/library/std/src/sys/bpf/thread.rs b/library/std/src/sys/bpf/thread.rs index a1f49a43ba1db..3efd493aa336f 100644 --- a/library/std/src/sys/bpf/thread.rs +++ b/library/std/src/sys/bpf/thread.rs @@ -1,5 +1,6 @@ use crate::ffi::CStr; use crate::io; +use crate::num::NonZeroUsize; use crate::sys::{unsupported, Void}; use crate::time::Duration; @@ -30,6 +31,10 @@ impl Thread { } } +pub fn available_concurrency() -> io::Result { + unsupported() +} + pub mod guard { pub type Guard = !; pub unsafe fn current() -> Option { From 1f448d3f27ad5ee967d38b29336d87523609bef4 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Wed, 10 Nov 2021 11:53:30 -0800 Subject: [PATCH 048/103] [SOL] Enable build on apple silicon --- build.sh | 11 ++++++----- config.toml | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/build.sh b/build.sh index 060c1b4a1f4f3..13ad72449caa6 100755 --- a/build.sh +++ b/build.sh @@ -7,12 +7,13 @@ if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then exit; fi -unameOut="$(uname -s)" +unameOut="$(uname -s)-$(uname -m)" case "${unameOut}" in - Linux*) HOST_TRIPLE=x86_64-unknown-linux-gnu;; - Darwin*) HOST_TRIPLE=x86_64-apple-darwin;; - MINGW*) HOST_TRIPLE=x86_64-pc-windows-msvc;; - *) HOST_TRIPLE=x86_64-unknown-linux-gnu + Linux*) HOST_TRIPLE=x86_64-unknown-linux-gnu;; + Darwin-x86_64*) HOST_TRIPLE=x86_64-apple-darwin;; + Darwin-arm64*) HOST_TRIPLE=aarch64-apple-darwin;; + MINGW*) HOST_TRIPLE=x86_64-pc-windows-msvc;; + *) HOST_TRIPLE=x86_64-unknown-linux-gnu esac if [ "$1" == "--llvm" ]; then diff --git a/config.toml b/config.toml index 68842b458a1fa..e57333abfca8b 100644 --- a/config.toml +++ b/config.toml @@ -59,7 +59,7 @@ assertions = false # likely, teach rustc about the C ABI of the target. Get in touch with the # Rust team and file an issue if you need assistance in porting! #targets = "AArch64;ARM;Hexagon;MSP430;Mips;NVPTX;PowerPC;RISCV;Sparc;SystemZ;WebAssembly;X86" -targets = "X86" +targets = "AArch64;X86" # LLVM experimental targets to build support for. These targets are specified in # the same format as above, but since these targets are experimental, they are From 099824cbf766afe33c31c7f030b3d57049a75bab Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Wed, 17 Nov 2021 17:20:08 -0800 Subject: [PATCH 049/103] [SOL] Adjust test harness entrypoint function generation The generated entrypoint function calls the tested module's main function, which has type void (), and returns 0. The adjustment is to correct the type of the called main function. --- compiler/rustc_codegen_llvm/src/type_.rs | 4 ++++ compiler/rustc_codegen_ssa/src/base.rs | 9 +++++++-- compiler/rustc_codegen_ssa/src/traits/type_.rs | 2 ++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/type_.rs b/compiler/rustc_codegen_llvm/src/type_.rs index 06b7703672fe8..124fca73d34c3 100644 --- a/compiler/rustc_codegen_llvm/src/type_.rs +++ b/compiler/rustc_codegen_llvm/src/type_.rs @@ -164,6 +164,10 @@ impl<'ll, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> { unsafe { llvm::LLVMDoubleTypeInContext(self.llcx) } } + fn type_void(&self) -> &'ll Type { + unsafe { llvm::LLVMVoidTypeInContext(self.llcx) } + } + fn type_func(&self, args: &[&'ll Type], ret: &'ll Type) -> &'ll Type { unsafe { llvm::LLVMFunctionType(ret, args.as_ptr(), args.len() as c_uint, False) } } diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 2f13463f655c3..d5b85c9104d54 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -485,8 +485,13 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( (start_fn, start_ty, vec![rust_main, arg_argc, arg_argv, arg_sigpipe]) } else { debug!("using user-defined start fn"); - let start_ty = cx.type_func(&[isize_ty, ptr_ty], isize_ty); - (rust_main, start_ty, vec![arg_argc, arg_argv]) + if is_bpf { + let start_ty = cx.type_func(&[], cx.type_void()); + (rust_main, start_ty, Vec::new()) + } else { + let start_ty = cx.type_func(&[isize_ty, ptr_ty], isize_ty); + (rust_main, start_ty, vec![arg_argc, arg_argv]) + } }; let result = if is_bpf { diff --git a/compiler/rustc_codegen_ssa/src/traits/type_.rs b/compiler/rustc_codegen_ssa/src/traits/type_.rs index b1fde8e4d8638..d3d2e5a69d217 100644 --- a/compiler/rustc_codegen_ssa/src/traits/type_.rs +++ b/compiler/rustc_codegen_ssa/src/traits/type_.rs @@ -23,6 +23,8 @@ pub trait BaseTypeMethods<'tcx>: Backend<'tcx> { fn type_f64(&self) -> Self::Type; fn type_array(&self, ty: Self::Type, len: u64) -> Self::Type; + fn type_void(&self) -> Self::Type; + fn type_func(&self, args: &[Self::Type], ret: Self::Type) -> Self::Type; fn type_struct(&self, els: &[Self::Type], packed: bool) -> Self::Type; fn type_kind(&self, ty: Self::Type) -> TypeKind; From a360c6024bd5f48d1d8372f06f5e21df4b0c7459 Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Fri, 26 Nov 2021 11:05:15 +1100 Subject: [PATCH 050/103] [SOL] rework test harness codegen a bit This change reworks the way we generate the test harness, it removes most bpf-only changes, implements a custom start entry for the bpf arch, and tweaks the link stage to set the correct entry point depending on whether we're compiling a library or tests. With this change, artifacts produced by rustc --test can be loaded in rbpf like any other library. --- compiler/rustc_codegen_ssa/src/back/linker.rs | 6 ++++ compiler/rustc_codegen_ssa/src/base.rs | 31 +++++++------------ compiler/rustc_monomorphize/src/collector.rs | 4 +-- .../src/spec/bpfel_unknown_unknown.rs | 3 +- library/std/src/rt.rs | 11 +++++++ 5 files changed, 31 insertions(+), 24 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index 09434513e31e9..7f0bc9f379a60 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -354,6 +354,12 @@ impl<'a> GccLinker<'a> { self.linker_arg(&format!("--out-implib={}", (*implib).to_str().unwrap())); } } + } else if self.sess.target.arch == "bpf" { + if self.sess.opts.test { + self.linker_arg("--entry=main"); + } else { + self.linker_arg("--entry=entrypoint"); + } } } } diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index d5b85c9104d54..cbdc82e5b7add 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -420,6 +420,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( rust_main_def_id: DefId, entry_type: EntryFnType, ) -> Bx::Function { +<<<<<<< HEAD // The entry function is either `int main(void)` or `int main(int argc, char **argv)`, or // `usize efi_main(void *handle, void *system_table)` depending on the target. let is_bpf = cx.sess().target.arch == "bpf" && cx.sess().opts.test; @@ -427,6 +428,12 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( cx.type_func(&[cx.type_ptr(), cx.type_ptr()], cx.type_isize()) } else if cx.sess().target.main_needs_argc_argv { cx.type_func(&[cx.type_int(), cx.type_ptr()], cx.type_int()) +======= + // The entry function is either `int main(void)` or `int main(int argc, char **argv)`, + // depending on whether the target needs `argc` and `argv` to be passed in. + let llfty = if cx.sess().target.main_needs_argc_argv { + cx.type_func(&[cx.type_int(), cx.type_ptr_to(cx.type_i8p())], cx.type_int()) +>>>>>>> e5c32090239 ([SOL] rework test harness codegen a bit) } else { cx.type_func(&[], cx.type_int()) }; @@ -457,15 +464,13 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( let llbb = Bx::append_block(&cx, llfn, "top"); let mut bx = Bx::build(&cx, llbb); - if !is_bpf { - bx.insert_reference_to_gdb_debug_scripts_section_global(); - } + bx.insert_reference_to_gdb_debug_scripts_section_global(); let isize_ty = cx.type_isize(); let ptr_ty = cx.type_ptr(); let (arg_argc, arg_argv) = get_argc_argv(cx, &mut bx); - let (start_fn, start_ty, args) = if !is_bpf && let EntryFnType::Main { sigpipe } = entry_type { + let (start_fn, start_ty, args) = if let EntryFnType::Main { sigpipe } = entry_type { let start_def_id = cx.tcx().require_lang_item(LangItem::Start, None); let start_fn = cx.get_fn_addr( ty::Instance::resolve( @@ -485,23 +490,11 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( (start_fn, start_ty, vec![rust_main, arg_argc, arg_argv, arg_sigpipe]) } else { debug!("using user-defined start fn"); - if is_bpf { - let start_ty = cx.type_func(&[], cx.type_void()); - (rust_main, start_ty, Vec::new()) - } else { - let start_ty = cx.type_func(&[isize_ty, ptr_ty], isize_ty); - (rust_main, start_ty, vec![arg_argc, arg_argv]) - } - }; - - let result = if is_bpf { - let args = Vec::new(); - bx.call(start_ty, None, None, start_fn, &args, None); - bx.const_i32(0) - } else { - bx.call(start_ty, None, None, start_fn, &args, None) + let start_ty = cx.type_func(&[isize_ty, ptr_ty], isize_ty); + (rust_main, start_ty, vec![arg_argc, arg_argv]) }; + let result = bx.call(start_ty, None, start_fn, &args, None); if cx.sess().target.os.contains("uefi") { bx.ret(result); } else { diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index c42ccbed21cc5..65bdcf1076225 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -314,9 +314,7 @@ fn collect_roots(tcx: TyCtxt<'_>, mode: MonoItemCollectionMode) -> Vec( ); v } + +#[cfg(not(test))] +#[cfg(target_arch = "bpf")] +#[lang = "start"] +fn lang_start( + main: fn() -> T, + _argc: isize, + _argv: *const *const u8, +) -> isize { + main().report() as isize +} From 7568b46581bebff619af996a29250eb7e44d11c0 Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Fri, 26 Nov 2021 11:37:01 +1100 Subject: [PATCH 051/103] [SOL] libtest: disable should_panic tests and benchmarks --- library/test/src/cli.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/test/src/cli.rs b/library/test/src/cli.rs index 314408593c158..60f294682b8b0 100644 --- a/library/test/src/cli.rs +++ b/library/test/src/cli.rs @@ -317,10 +317,10 @@ fn parse_opts_impl(_matches: getopts::Matches) -> OptRes { filters: Vec::new(), filter_exact: false, force_run_in_process: false, - exclude_should_panic: false, + exclude_should_panic: true, run_ignored: RunIgnored::No, run_tests: true, - bench_benchmarks: true, + bench_benchmarks: false, logfile: None, nocapture: true, color: ColorConfig::NeverColor, From ce2927888106d1711f26154468bf2c00fd42befd Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Fri, 26 Nov 2021 12:17:31 +1100 Subject: [PATCH 052/103] [SOL] tests: core: depend on dummy getrandom --- Cargo.lock | 3 ++- library/core/Cargo.toml | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index a92430a13ca3c..9a8935920b745 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -781,7 +781,8 @@ checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" name = "core" version = "0.0.0" dependencies = [ - "rand", + "getrandom 0.1.14", + "rand 0.7.3", "rand_xorshift", ] diff --git a/library/core/Cargo.toml b/library/core/Cargo.toml index 3dc8c84e0bfde..6b74372a23ba5 100644 --- a/library/core/Cargo.toml +++ b/library/core/Cargo.toml @@ -27,6 +27,9 @@ test = true rand = { version = "0.8.5", default-features = false } rand_xorshift = { version = "0.3.0", default-features = false } +[target.bpfel-unknown-unknown.dev-dependencies] +getrandom = { version = "0.1.14", features = ["dummy"] } + [features] # Make panics and failed asserts immediately abort without formatting any message panic_immediate_abort = [] From 6dfab123b925dd7ccc3507e3574215f95ede6367 Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Fri, 26 Nov 2021 12:23:58 +1100 Subject: [PATCH 053/103] [SOL] tests: disable failing core tests --- library/core/tests/lib.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 168b47dc99cc6..33276edcfc318 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -124,6 +124,7 @@ mod any; mod array; mod ascii; mod asserting; +#[cfg(not(target_arch = "bpf"))] mod atomic; mod bool; mod cell; @@ -132,12 +133,15 @@ mod clone; mod cmp; mod const_ptr; mod convert; +#[cfg(not(target_arch = "bpf"))] mod fmt; mod future; +#[cfg(not(target_arch = "bpf"))] mod hash; mod intrinsics; mod io; mod iter; +#[cfg(not(target_arch = "bpf"))] mod lazy; #[cfg(test)] mod macros; @@ -145,6 +149,7 @@ mod manually_drop; mod mem; mod net; mod nonzero; +#[cfg(not(target_arch = "bpf"))] mod num; mod ops; mod option; @@ -152,9 +157,11 @@ mod panic; mod pattern; mod pin; mod pin_macro; +#[cfg(not(target_arch = "bpf"))] mod ptr; mod result; mod simd; +#[cfg(not(target_arch = "bpf"))] mod slice; mod str; mod str_lossy; From c1f86489f41c9b9c3daf3dcb6de174b8b6134837 Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Thu, 2 Dec 2021 10:23:24 +1100 Subject: [PATCH 054/103] [SOL] link using rust-lld Link using rust-lld instead of manually looking up ld.lld in the llvm dist folder. rust-lld is guaranteed to be in the rustc sysroot. --- .../src/spec/bpfel_unknown_unknown.rs | 50 ++----------------- config.toml | 2 +- 2 files changed, 6 insertions(+), 46 deletions(-) diff --git a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs index e7583daecf23a..3e49e131bf602 100644 --- a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs +++ b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs @@ -1,6 +1,6 @@ use crate::abi::Endian; -use super::{LinkerFlavor, PanicStrategy, Target, TargetOptions}; -use std::{collections::BTreeMap, env, path::Path}; +use super::{LinkerFlavor, PanicStrategy, Target, TargetOptions, LldFlavor}; +use std::{collections::BTreeMap}; pub fn target() -> Target { let linker_script = r" @@ -25,7 +25,7 @@ SECTIONS lld_args.push("-z".to_string()); lld_args.push("notext".to_string()); let mut pre_link_args = BTreeMap::new(); - pre_link_args.insert(LinkerFlavor::Ld, lld_args); + pre_link_args.insert(LinkerFlavor::Lld(LldFlavor::Ld), lld_args); Target { llvm_target: "bpfel".to_string(), @@ -40,9 +40,9 @@ SECTIONS env: String::new(), features: "+solana".to_string(), vendor: "solana".to_string(), - linker_flavor: LinkerFlavor::Ld, + linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), linker_is_gnu: true, - linker: find_linker(), + linker: Some("rust-lld".to_owned()), link_script: Some(linker_script.to_string()), pre_link_args, executables: true, @@ -62,43 +62,3 @@ SECTIONS }, } } - -fn find_linker() -> Option { - fn construct_linker_path(path: &Path) -> Option { - if let Some(base) = path.parent() { - let path = base - .join("llvm") - .join("bin") - .join("ld.lld"); - if path.exists() { - if let Some(ld_str) = path.to_str() { - return Some(ld_str.to_string()); - } - } - } - None - } - - if let Ok(path) = env::current_exe() { - let mut ancestors = path.ancestors(); - // ~/.rustup/bpf/bin/rustc - let base = ancestors.next(); - if base == None { - return None; - } - // ~/.rustup/bpf/bin - let base = ancestors.next(); - if base == None { - return None; - } - // ~/.rustup/bpf - if let Some(base) = ancestors.next() { - if let Ok(link) = base.read_link() { - return construct_linker_path(&link); - } else { - return construct_linker_path(&base); - } - } - } - None -} diff --git a/config.toml b/config.toml index e57333abfca8b..ca45653597f37 100644 --- a/config.toml +++ b/config.toml @@ -390,7 +390,7 @@ debug-assertions = false # Indicates whether LLD will be compiled and made available in the sysroot for # rustc to execute. -#lld = false +lld = true # Indicates whether some LLVM tools, like llvm-objdump, will be made available in the # sysroot. From 9d4ae58b8b471c5bbe6b92f091a622349cf2f53b Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Wed, 1 Dec 2021 20:07:01 +1100 Subject: [PATCH 055/103] [SOL] CI: run tests for the bpfel-unknown-unknown target --- .github/workflows/ci.yml | 4 ++ .../bpfel-unknown-unknown/Dockerfile | 37 +++++++++++++++++++ src/ci/github-actions/ci.yml | 9 +++-- 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 src/ci/docker/host-x86_64/bpfel-unknown-unknown/Dockerfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5f659a1c3060c..da8de0d5dc9b5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,6 +60,10 @@ jobs: env: ENABLE_GCC_CODEGEN: "1" os: ubuntu-20.04-16core-64gb + env: {} + - name: bpfel-unknown-unknown + os: ubuntu-latest + env: {} - name: x86_64-gnu-tools os: ubuntu-20.04-16core-64gb env: {} diff --git a/src/ci/docker/host-x86_64/bpfel-unknown-unknown/Dockerfile b/src/ci/docker/host-x86_64/bpfel-unknown-unknown/Dockerfile new file mode 100644 index 0000000000000..990c2c0ab4d3e --- /dev/null +++ b/src/ci/docker/host-x86_64/bpfel-unknown-unknown/Dockerfile @@ -0,0 +1,37 @@ +FROM ubuntu:20.04 + +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + g++ \ + make \ + ninja-build \ + file \ + curl \ + ca-certificates \ + python3 \ + git \ + cmake \ + sudo \ + gdb \ + libssl-dev \ + pkg-config \ + xz-utils \ + git \ + cargo + +RUN git clone https://github.com/solana-labs/cargo-run-bpf-tests +WORKDIR /cargo-run-bpf-tests +RUN cargo build +RUN cp target/debug/cargo-run-bpf-tests /usr/local/bin +WORKDIR / + +COPY scripts/sccache.sh /scripts/ +RUN sh /scripts/sccache.sh + +ENV RUST_CONFIGURE_ARGS \ + --set rust.lld \ + --set llvm.clang + +ENV SCRIPT CARGO_TARGET_BPFEL_UNKNOWN_UNKNOWN_RUNNER=cargo-run-bpf-tests \ + LLVM_HOME=/checkout/obj/build/x86_64-unknown-linux-gnu/llvm \ + python3 /checkout/x.py --stage 1 test --host='' --target bpfel-unknown-unknown \ + library/core diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml index 807c567efba00..f332a22eddb9c 100644 --- a/src/ci/github-actions/ci.yml +++ b/src/ci/github-actions/ci.yml @@ -145,9 +145,9 @@ x--expand-yaml-anchors--remove: run: src/ci/scripts/should-skip-this.sh <<: *step -# - name: ensure the channel matches the target branch -# run: src/ci/scripts/verify-channel.sh -# <<: *step + # - name: ensure the channel matches the target branch + # run: src/ci/scripts/verify-channel.sh + # <<: *step - name: collect CPU statistics run: src/ci/scripts/collect-cpu-stats.sh @@ -339,6 +339,9 @@ jobs: ENABLE_GCC_CODEGEN: "1" <<: *job-linux-16c + - name: bpfel-unknown-unknown + <<: *job-linux-xl + - name: x86_64-gnu-tools <<: *job-linux-16c From 777d8dd950bc611183e813d21060593bb6af705b Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Mon, 6 Dec 2021 15:24:53 +1100 Subject: [PATCH 056/103] [SOL] CI: run tests on push and improve run times Run tests on push to master in addition to running them on pull requests and setup S3 caching to improve run times. Docker images for for the jobs are cached in s3://cached-ci-artifacts/docker and LLVM/lld build artifacts are cached through sccache. A custom sccache fork is used. The custom fork is needed to workaround https://github.com/mozilla/sccache/issues/633 happening with our S3 bucket, which only supports the v4 signature scheme. --- .github/workflows/ci.yml | 138 +++++++++++++++++- .../bpfel-unknown-unknown/Dockerfile | 1 + src/ci/docker/scripts/sccache.sh | 2 +- src/ci/github-actions/ci.yml | 31 +++- 4 files changed, 158 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index da8de0d5dc9b5..2303fa9b53188 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,7 +44,7 @@ jobs: HEAD_SHA: "${{ github.event.pull_request.head.sha || github.sha }}" SCCACHE_BUCKET: rust-lang-ci-sccache2 TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate" - CACHE_DOMAIN: ci-caches.rust-lang.org + CACHE_DOMAIN: cached-ci-artifacts.s3.us-east-2.amazonaws.com if: "github.event_name == 'pull_request'" continue-on-error: "${{ matrix.name == 'mingw-check-tidy' }}" strategy: @@ -169,6 +169,125 @@ jobs: env: AWS_ACCESS_KEY_ID: "${{ env.ARTIFACTS_AWS_ACCESS_KEY_ID }}" AWS_SECRET_ACCESS_KEY: "${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.ARTIFACTS_AWS_ACCESS_KEY_ID)] }}" + SKIP_JOB: 1 + if: "success() && !env.SKIP_JOB && (github.event_name == 'push' || env.DEPLOY == '1' || env.DEPLOY_ALT == '1')" + push: + name: push + env: + CI_JOB_NAME: "${{ matrix.name }}" + SCCACHE_BUCKET: cached-ci-artifacts + SCCACHE_REGION: us-east-2 + DEPLOY_BUCKET: rust-lang-ci2 + TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate" + TOOLSTATE_ISSUES_API_URL: "https://api.github.com/repos/rust-lang/rust/issues" + TOOLSTATE_PUBLISH: 0 + CACHES_AWS_ACCESS_KEY_ID: AKIASSXOBJJGY5HRQO4U + ARTIFACTS_AWS_ACCESS_KEY_ID: AKIA46X5W6CZN24CBO55 + CACHE_DOMAIN: cached-ci-artifacts.s3.us-east-2.amazonaws.com + if: "github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'solana-labs/rust'" + strategy: + matrix: + include: + - name: mingw-check + os: ubuntu-latest + env: {} + - name: x86_64-gnu-llvm-10 + os: ubuntu-latest + env: {} + - name: bpfel-unknown-unknown + os: ubuntu-latest + env: {} + timeout-minutes: 600 + runs-on: "${{ matrix.os }}" + steps: + - name: disable git crlf conversion + run: git config --global core.autocrlf false + - name: checkout the source code + uses: actions/checkout@v2 + with: + fetch-depth: 2 + - name: configure the PR in which the error message will be posted + run: "echo \"[CI_PR_NUMBER=$num]\"" + env: + num: "${{ github.event.number }}" + if: "success() && !env.SKIP_JOB && github.event_name == 'pull_request'" + - name: add extra environment variables + run: src/ci/scripts/setup-environment.sh + env: + EXTRA_VARIABLES: "${{ toJson(matrix.env) }}" + if: success() && !env.SKIP_JOB + - name: decide whether to skip this job + run: src/ci/scripts/should-skip-this.sh + if: success() && !env.SKIP_JOB + - name: configure GitHub Actions to kill the build when outdated + uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master + with: + github_token: "${{ secrets.github_token }}" + if: "success() && !env.SKIP_JOB && github.ref != 'refs/heads/try'" + - name: collect CPU statistics + run: src/ci/scripts/collect-cpu-stats.sh + if: success() && !env.SKIP_JOB + - name: show the current environment + run: src/ci/scripts/dump-environment.sh + if: success() && !env.SKIP_JOB + - name: install awscli + run: src/ci/scripts/install-awscli.sh + if: success() && !env.SKIP_JOB + - name: install sccache + run: src/ci/scripts/install-sccache.sh + if: success() && !env.SKIP_JOB + - name: select Xcode + run: src/ci/scripts/select-xcode.sh + if: success() && !env.SKIP_JOB + - name: install clang + run: src/ci/scripts/install-clang.sh + if: success() && !env.SKIP_JOB + - name: install WIX + run: src/ci/scripts/install-wix.sh + if: success() && !env.SKIP_JOB + - name: ensure the build happens on a partition with enough space + run: src/ci/scripts/symlink-build-dir.sh + if: success() && !env.SKIP_JOB + - name: disable git crlf conversion + run: src/ci/scripts/disable-git-crlf-conversion.sh + if: success() && !env.SKIP_JOB + - name: install MSYS2 + run: src/ci/scripts/install-msys2.sh + if: success() && !env.SKIP_JOB + - name: install MinGW + run: src/ci/scripts/install-mingw.sh + if: success() && !env.SKIP_JOB + - name: install ninja + run: src/ci/scripts/install-ninja.sh + if: success() && !env.SKIP_JOB + - name: enable ipv6 on Docker + run: src/ci/scripts/enable-docker-ipv6.sh + if: success() && !env.SKIP_JOB + - name: disable git crlf conversion + run: src/ci/scripts/disable-git-crlf-conversion.sh + if: success() && !env.SKIP_JOB + - name: checkout submodules + run: src/ci/scripts/checkout-submodules.sh + if: success() && !env.SKIP_JOB + - name: ensure line endings are correct + run: src/ci/scripts/verify-line-endings.sh + if: success() && !env.SKIP_JOB + - name: ensure backported commits are in upstream branches + run: src/ci/scripts/verify-backported-commits.sh + if: success() && !env.SKIP_JOB + - name: run the build + run: src/ci/scripts/run-build-from-ci.sh + env: + AWS_ACCESS_KEY_ID: "${{ env.CACHES_AWS_ACCESS_KEY_ID }}" + AWS_SECRET_ACCESS_KEY: "${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.CACHES_AWS_ACCESS_KEY_ID)] }}" + TOOLSTATE_REPO_ACCESS_TOKEN: "${{ secrets.TOOLSTATE_REPO_ACCESS_TOKEN }}" + if: success() && !env.SKIP_JOB + - name: upload artifacts to S3 + run: src/ci/scripts/upload-artifacts.sh + env: + AWS_ACCESS_KEY_ID: "${{ env.ARTIFACTS_AWS_ACCESS_KEY_ID }}" + AWS_SECRET_ACCESS_KEY: "${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.ARTIFACTS_AWS_ACCESS_KEY_ID)] }}" + SKIP_JOB: 1 if: "success() && !env.SKIP_JOB && (github.event_name == 'push' || env.DEPLOY == '1' || env.DEPLOY_ALT == '1')" auto: name: "auto - ${{ matrix.name }}" @@ -180,8 +299,8 @@ jobs: DEPLOY_BUCKET: rust-lang-ci2 TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate" TOOLSTATE_ISSUES_API_URL: "https://api.github.com/repos/rust-lang/rust/issues" - TOOLSTATE_PUBLISH: 1 - CACHES_AWS_ACCESS_KEY_ID: AKIA46X5W6CZI5DHEBFL + TOOLSTATE_PUBLISH: 0 + CACHES_AWS_ACCESS_KEY_ID: AKIASSXOBJJGY5HRQO4U ARTIFACTS_AWS_ACCESS_KEY_ID: AKIA46X5W6CZN24CBO55 AWS_REGION: us-west-1 CACHE_DOMAIN: ci-caches.rust-lang.org @@ -562,6 +681,7 @@ jobs: env: AWS_ACCESS_KEY_ID: "${{ env.ARTIFACTS_AWS_ACCESS_KEY_ID }}" AWS_SECRET_ACCESS_KEY: "${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.ARTIFACTS_AWS_ACCESS_KEY_ID)] }}" + SKIP_JOB: 1 if: "success() && !env.SKIP_JOB && (github.event_name == 'push' || env.DEPLOY == '1' || env.DEPLOY_ALT == '1')" try: name: "try - ${{ matrix.name }}" @@ -574,8 +694,8 @@ jobs: DEPLOY_BUCKET: rust-lang-ci2 TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate" TOOLSTATE_ISSUES_API_URL: "https://api.github.com/repos/rust-lang/rust/issues" - TOOLSTATE_PUBLISH: 1 - CACHES_AWS_ACCESS_KEY_ID: AKIA46X5W6CZI5DHEBFL + TOOLSTATE_PUBLISH: 0 + CACHES_AWS_ACCESS_KEY_ID: AKIASSXOBJJGY5HRQO4U ARTIFACTS_AWS_ACCESS_KEY_ID: AKIA46X5W6CZN24CBO55 AWS_REGION: us-west-1 CACHE_DOMAIN: ci-caches.rust-lang.org @@ -689,17 +809,19 @@ jobs: env: AWS_ACCESS_KEY_ID: "${{ env.ARTIFACTS_AWS_ACCESS_KEY_ID }}" AWS_SECRET_ACCESS_KEY: "${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.ARTIFACTS_AWS_ACCESS_KEY_ID)] }}" + SKIP_JOB: 1 if: "success() && !env.SKIP_JOB && (github.event_name == 'push' || env.DEPLOY == '1' || env.DEPLOY_ALT == '1')" master: name: master runs-on: ubuntu-latest env: - SCCACHE_BUCKET: rust-lang-ci-sccache2 + SCCACHE_BUCKET: cached-ci-artifacts + SCCACHE_REGION: us-east-2 DEPLOY_BUCKET: rust-lang-ci2 TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate" TOOLSTATE_ISSUES_API_URL: "https://api.github.com/repos/rust-lang/rust/issues" - TOOLSTATE_PUBLISH: 1 - CACHES_AWS_ACCESS_KEY_ID: AKIA46X5W6CZI5DHEBFL + TOOLSTATE_PUBLISH: 0 + CACHES_AWS_ACCESS_KEY_ID: AKIASSXOBJJGY5HRQO4U ARTIFACTS_AWS_ACCESS_KEY_ID: AKIA46X5W6CZN24CBO55 AWS_REGION: us-west-1 CACHE_DOMAIN: ci-caches.rust-lang.org diff --git a/src/ci/docker/host-x86_64/bpfel-unknown-unknown/Dockerfile b/src/ci/docker/host-x86_64/bpfel-unknown-unknown/Dockerfile index 990c2c0ab4d3e..504cf5d647880 100644 --- a/src/ci/docker/host-x86_64/bpfel-unknown-unknown/Dockerfile +++ b/src/ci/docker/host-x86_64/bpfel-unknown-unknown/Dockerfile @@ -22,6 +22,7 @@ RUN git clone https://github.com/solana-labs/cargo-run-bpf-tests WORKDIR /cargo-run-bpf-tests RUN cargo build RUN cp target/debug/cargo-run-bpf-tests /usr/local/bin +RUN rm -rf target WORKDIR / COPY scripts/sccache.sh /scripts/ diff --git a/src/ci/docker/scripts/sccache.sh b/src/ci/docker/scripts/sccache.sh index 6c713e1f8611f..626279efc8e45 100644 --- a/src/ci/docker/scripts/sccache.sh +++ b/src/ci/docker/scripts/sccache.sh @@ -6,7 +6,7 @@ set -ex case "$(uname -m)" in x86_64) - url="https://ci-mirrors.rust-lang.org/rustc/2021-08-24-sccache-v0.2.15-x86_64-unknown-linux-musl" + url="https://cached-ci-artifacts.s3.us-east-2.amazonaws.com/sccache-bc014e0-x86_64-unknown-linux-musl" ;; aarch64) url="https://ci-mirrors.rust-lang.org/rustc/2021-08-25-sccache-v0.2.15-aarch64-unknown-linux-musl" diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml index f332a22eddb9c..462216d13fa34 100644 --- a/src/ci/github-actions/ci.yml +++ b/src/ci/github-actions/ci.yml @@ -36,22 +36,24 @@ x--expand-yaml-anchors--remove: HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }} - &public-variables - SCCACHE_BUCKET: rust-lang-ci-sccache2 + SCCACHE_BUCKET: cached-ci-artifacts + SCCACHE_REGION: us-east-2 TOOLSTATE_REPO: https://github.com/rust-lang-nursery/rust-toolstate - CACHE_DOMAIN: ci-caches.rust-lang.org + CACHE_DOMAIN: cached-ci-artifacts.s3.us-east-2.amazonaws.com - &prod-variables - SCCACHE_BUCKET: rust-lang-ci-sccache2 + SCCACHE_BUCKET: cached-ci-artifacts + SCCACHE_REGION: us-east-2 DEPLOY_BUCKET: rust-lang-ci2 TOOLSTATE_REPO: https://github.com/rust-lang-nursery/rust-toolstate TOOLSTATE_ISSUES_API_URL: https://api.github.com/repos/rust-lang/rust/issues - TOOLSTATE_PUBLISH: 1 + TOOLSTATE_PUBLISH: 0 # AWS_SECRET_ACCESS_KEYs are stored in GitHub's secrets storage, named # AWS_SECRET_ACCESS_KEY_. Including the key id in the name allows to # rotate them in a single branch while keeping the old key in another # branch, which wouldn't be possible if the key was named with the kind # (caches, artifacts...). - CACHES_AWS_ACCESS_KEY_ID: AKIA46X5W6CZI5DHEBFL + CACHES_AWS_ACCESS_KEY_ID: AKIASSXOBJJGY5HRQO4U ARTIFACTS_AWS_ACCESS_KEY_ID: AKIA46X5W6CZN24CBO55 AWS_REGION: us-west-1 CACHE_DOMAIN: ci-caches.rust-lang.org @@ -253,6 +255,7 @@ x--expand-yaml-anchors--remove: env: AWS_ACCESS_KEY_ID: ${{ env.ARTIFACTS_AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.ARTIFACTS_AWS_ACCESS_KEY_ID)] }} + SKIP_JOB: 1 # Adding a condition on DEPLOY=1 or DEPLOY_ALT=1 is not needed as all deploy # builders *should* have the AWS credentials available. Still, explicitly # adding the condition is helpful as this way CI will not silently skip @@ -345,6 +348,24 @@ jobs: - name: x86_64-gnu-tools <<: *job-linux-16c + push: + <<: *base-ci-job + name: push + env: + <<: [*shared-ci-variables, *prod-variables] + if: github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'solana-labs/rust' + strategy: + matrix: + include: + - name: mingw-check + <<: *job-linux-xl + + - name: x86_64-gnu-llvm-10 + <<: *job-linux-xl + + - name: bpfel-unknown-unknown + <<: *job-linux-xl + auto: <<: *base-ci-job name: auto - ${{ matrix.name }} From 8a918d3534c0661568f65c94dfd634c47ffa6638 Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Wed, 8 Dec 2021 14:31:02 +1100 Subject: [PATCH 057/103] [SOL] CI: run push job on solana-* branches instead of master --- .github/workflows/ci.yml | 3 ++- src/ci/github-actions/ci.yml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2303fa9b53188..99117659c9967 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,7 @@ name: CI - try-perf - automation/bors/try - master + - solana-** pull_request: branches: - "**" @@ -184,7 +185,7 @@ jobs: CACHES_AWS_ACCESS_KEY_ID: AKIASSXOBJJGY5HRQO4U ARTIFACTS_AWS_ACCESS_KEY_ID: AKIA46X5W6CZN24CBO55 CACHE_DOMAIN: cached-ci-artifacts.s3.us-east-2.amazonaws.com - if: "github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'solana-labs/rust'" + if: "github.event_name == 'push' && startsWith(github.ref, 'refs/heads/solana-') && github.repository == 'solana-labs/rust'" strategy: matrix: include: diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml index 462216d13fa34..a754fbf538497 100644 --- a/src/ci/github-actions/ci.yml +++ b/src/ci/github-actions/ci.yml @@ -298,6 +298,7 @@ on: - try-perf - automation/bors/try - master + - solana-** pull_request: branches: - "**" @@ -353,7 +354,7 @@ jobs: name: push env: <<: [*shared-ci-variables, *prod-variables] - if: github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'solana-labs/rust' + if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/solana-') && github.repository == 'solana-labs/rust' strategy: matrix: include: From 4e9523f45b6463fe199809c278858e432209f559 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Thu, 9 Dec 2021 15:53:27 -0800 Subject: [PATCH 058/103] [SOL] Install rustup and use more recent cargo and rustc The ubuntu cargo package fails to parse solana Cargo.toml files. More recent version of cargo is needed to build cargo-run-bpf-tests dependencies. These changes install current version of cargo in docker used to run bpfel-unknown-unknown tests. --- .../bpfel-unknown-unknown/Dockerfile | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/ci/docker/host-x86_64/bpfel-unknown-unknown/Dockerfile b/src/ci/docker/host-x86_64/bpfel-unknown-unknown/Dockerfile index 504cf5d647880..d7468f6a9532f 100644 --- a/src/ci/docker/host-x86_64/bpfel-unknown-unknown/Dockerfile +++ b/src/ci/docker/host-x86_64/bpfel-unknown-unknown/Dockerfile @@ -14,16 +14,14 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-ins gdb \ libssl-dev \ pkg-config \ - xz-utils \ - git \ - cargo + xz-utils + +ENV RUSTUP_INIT_SKIP_PATH_CHECK="yes" +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y -RUN git clone https://github.com/solana-labs/cargo-run-bpf-tests -WORKDIR /cargo-run-bpf-tests -RUN cargo build -RUN cp target/debug/cargo-run-bpf-tests /usr/local/bin -RUN rm -rf target -WORKDIR / +RUN PATH="${HOME}/.cargo/bin:${PATH}" \ + cargo install --git https://github.com/solana-labs/cargo-run-bpf-tests.git \ + --bin cargo-run-bpf-tests --root /usr/local COPY scripts/sccache.sh /scripts/ RUN sh /scripts/sccache.sh @@ -34,5 +32,6 @@ ENV RUST_CONFIGURE_ARGS \ ENV SCRIPT CARGO_TARGET_BPFEL_UNKNOWN_UNKNOWN_RUNNER=cargo-run-bpf-tests \ LLVM_HOME=/checkout/obj/build/x86_64-unknown-linux-gnu/llvm \ + PATH="${HOME}/.cargo/bin:${PATH}" \ python3 /checkout/x.py --stage 1 test --host='' --target bpfel-unknown-unknown \ library/core From 189a73dc1a62ec008eecb97a23d0effb56110344 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Thu, 9 Dec 2021 12:58:07 -0800 Subject: [PATCH 059/103] [SOL] Rename bpf target to sbf --- .../rustc_codegen_ssa/src/target_features.rs | 3 +- compiler/rustc_feature/src/unstable.rs | 1 + compiler/rustc_interface/src/util.rs | 2 +- compiler/rustc_llvm/build.rs | 1 + compiler/rustc_llvm/src/lib.rs | 8 ++ compiler/rustc_passes/src/entry.rs | 3 +- compiler/rustc_span/src/symbol.rs | 1 + compiler/rustc_target/src/abi/call/mod.rs | 2 + compiler/rustc_target/src/abi/call/sbf.rs | 35 +++++ compiler/rustc_target/src/asm/mod.rs | 3 +- .../src/spec/bpfel_unknown_unknown.rs | 58 +------- compiler/rustc_target/src/spec/mod.rs | 1 + compiler/rustc_target/src/spec/sbf_base.rs | 57 ++++++++ .../src/spec/sbf_solana_solana.rs | 12 ++ library/core/src/fmt/mod.rs | 2 +- library/core/src/fmt/num.rs | 10 +- library/proc_macro/src/lib.rs | 2 +- library/std/Cargo.toml | 2 +- library/std/build.rs | 1 + library/std/src/alloc.rs | 16 +-- library/std/src/io/stdio.rs | 128 +++++++++--------- library/std/src/lib.rs | 4 +- library/std/src/panic.rs | 8 +- library/std/src/panicking.rs | 88 ++++++------ library/std/src/process.rs | 2 +- library/std/src/rt.rs | 6 +- library/std/src/sync/remutex.rs | 6 +- library/std/src/sys/mod.rs | 6 +- library/std/src/sys/{bpf => sbf}/alloc.rs | 4 +- library/std/src/sys/{bpf => sbf}/args.rs | 0 library/std/src/sys/{bpf => sbf}/backtrace.rs | 0 library/std/src/sys/{bpf => sbf}/cmath.rs | 0 library/std/src/sys/{bpf => sbf}/condvar.rs | 0 .../src/sys/{bpf => sbf}/condvar_atomics.rs | 0 library/std/src/sys/{bpf => sbf}/env.rs | 0 library/std/src/sys/{bpf => sbf}/fs.rs | 0 library/std/src/sys/{bpf => sbf}/io.rs | 0 library/std/src/sys/{bpf => sbf}/memchr.rs | 0 library/std/src/sys/{bpf => sbf}/mod.rs | 10 +- library/std/src/sys/{bpf => sbf}/mutex.rs | 4 +- .../std/src/sys/{bpf => sbf}/mutex_atomics.rs | 2 +- library/std/src/sys/{bpf => sbf}/net.rs | 0 library/std/src/sys/{bpf => sbf}/os.rs | 4 +- library/std/src/sys/{bpf => sbf}/path.rs | 0 library/std/src/sys/{bpf => sbf}/pipe.rs | 0 library/std/src/sys/{bpf => sbf}/process.rs | 0 library/std/src/sys/{bpf => sbf}/rwlock.rs | 2 +- .../src/sys/{bpf => sbf}/rwlock_atomics.rs | 0 library/std/src/sys/{bpf => sbf}/stdio.rs | 0 library/std/src/sys/{bpf => sbf}/thread.rs | 0 .../sys/{bpf => sbf}/thread_local_atomics.rs | 0 .../src/sys/{bpf => sbf}/thread_local_dtor.rs | 0 .../src/sys/{bpf => sbf}/thread_local_key.rs | 0 library/std/src/sys/{bpf => sbf}/time.rs | 0 library/std/src/sys_common/backtrace.rs | 2 +- library/std/src/sys_common/mod.rs | 1 + library/std/src/sys_common/thread.rs | 10 +- library/std/src/thread/mod.rs | 6 +- library/test/src/cli.rs | 28 ++-- library/test/src/console.rs | 4 +- library/test/src/helpers/concurrency.rs | 6 +- library/test/src/lib.rs | 4 +- src/bootstrap/src/core/build_steps/compile.rs | 2 +- src/bootstrap/src/core/sanity.rs | 2 +- src/bootstrap/src/utils/cc_detect.rs | 7 +- src/bootstrap/src/utils/helpers.rs | 1 + src/doc/rustc/src/platform-support.md | 1 + src/tools/build-manifest/src/main.rs | 1 + src/tools/compiletest/src/runtest.rs | 3 +- tests/codegen/sbf-alu32.rs | 11 ++ tests/ui/target-feature/gate.rs | 1 + tests/ui/target-feature/gate.stderr | 2 +- 72 files changed, 340 insertions(+), 246 deletions(-) create mode 100644 compiler/rustc_target/src/abi/call/sbf.rs create mode 100644 compiler/rustc_target/src/spec/sbf_base.rs create mode 100644 compiler/rustc_target/src/spec/sbf_solana_solana.rs rename library/std/src/sys/{bpf => sbf}/alloc.rs (89%) rename library/std/src/sys/{bpf => sbf}/args.rs (100%) rename library/std/src/sys/{bpf => sbf}/backtrace.rs (100%) rename library/std/src/sys/{bpf => sbf}/cmath.rs (100%) rename library/std/src/sys/{bpf => sbf}/condvar.rs (100%) rename library/std/src/sys/{bpf => sbf}/condvar_atomics.rs (100%) rename library/std/src/sys/{bpf => sbf}/env.rs (100%) rename library/std/src/sys/{bpf => sbf}/fs.rs (100%) rename library/std/src/sys/{bpf => sbf}/io.rs (100%) rename library/std/src/sys/{bpf => sbf}/memchr.rs (100%) rename library/std/src/sys/{bpf => sbf}/mod.rs (90%) rename library/std/src/sys/{bpf => sbf}/mutex.rs (89%) rename library/std/src/sys/{bpf => sbf}/mutex_atomics.rs (98%) rename library/std/src/sys/{bpf => sbf}/net.rs (100%) rename library/std/src/sys/{bpf => sbf}/os.rs (95%) rename library/std/src/sys/{bpf => sbf}/path.rs (100%) rename library/std/src/sys/{bpf => sbf}/pipe.rs (100%) rename library/std/src/sys/{bpf => sbf}/process.rs (100%) rename library/std/src/sys/{bpf => sbf}/rwlock.rs (96%) rename library/std/src/sys/{bpf => sbf}/rwlock_atomics.rs (100%) rename library/std/src/sys/{bpf => sbf}/stdio.rs (100%) rename library/std/src/sys/{bpf => sbf}/thread.rs (100%) rename library/std/src/sys/{bpf => sbf}/thread_local_atomics.rs (100%) rename library/std/src/sys/{bpf => sbf}/thread_local_dtor.rs (100%) rename library/std/src/sys/{bpf => sbf}/thread_local_key.rs (100%) rename library/std/src/sys/{bpf => sbf}/time.rs (100%) create mode 100644 tests/codegen/sbf-alu32.rs diff --git a/compiler/rustc_codegen_ssa/src/target_features.rs b/compiler/rustc_codegen_ssa/src/target_features.rs index 2936f1de3cbf8..760b7bbee723b 100644 --- a/compiler/rustc_codegen_ssa/src/target_features.rs +++ b/compiler/rustc_codegen_ssa/src/target_features.rs @@ -394,9 +394,10 @@ pub fn supported_target_features(sess: &Session) -> &'static [(&'static str, Opt "powerpc" | "powerpc64" => POWERPC_ALLOWED_FEATURES, "riscv32" | "riscv64" => RISCV_ALLOWED_FEATURES, "wasm32" | "wasm64" => WASM_ALLOWED_FEATURES, - "bpf" => BPF_ALLOWED_FEATURES, "csky" => CSKY_ALLOWED_FEATURES, "loongarch64" => LOONGARCH_ALLOWED_FEATURES, + "bpf" => BPF_ALLOWED_FEATURES, + "sbf" => BPF_ALLOWED_FEATURES, _ => &[], } } diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index b11b190bdedad..4cd32b9ef4910 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -293,6 +293,7 @@ declare_features! ( (unstable, powerpc_target_feature, "1.27.0", Some(44839), None), (unstable, riscv_target_feature, "1.45.0", Some(44839), None), (unstable, rtm_target_feature, "1.35.0", Some(44839), None), + (unstable, sbf_target_feature, "1.54.0", Some(44839), None), (unstable, sse4a_target_feature, "1.27.0", Some(44839), None), (unstable, tbm_target_feature, "1.27.0", Some(44839), None), (unstable, wasm_target_feature, "1.30.0", Some(44839), None), diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index fc2cbe7d32b7a..5dfcd6fc1ab78 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -404,7 +404,7 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec { } fn entry_fn(tcx: TyCtxt<'_>, (): ()) -> Option<(DefId, EntryFnType)> { - - let exe_only = tcx.sess.target.arch != "bpf" || !tcx.sess.opts.test; + let exe_only = (tcx.sess.target.arch != "bpf" && tcx.sess.target.arch != "sbf") || !tcx.sess.opts.test; let any_exe = tcx.crate_types().iter().any(|ty| *ty == CrateType::Executable); if !any_exe && exe_only { // No need to find a main function. diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index f287862cc23c5..f2ce9ef742ef5 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1447,6 +1447,7 @@ symbols! { saturating_add, saturating_div, saturating_sub, + sbf_target_feature, self_in_typedefs, self_struct_ctor, semitransparent, diff --git a/compiler/rustc_target/src/abi/call/mod.rs b/compiler/rustc_target/src/abi/call/mod.rs index 5efd171b9dd76..084da59568a3a 100644 --- a/compiler/rustc_target/src/abi/call/mod.rs +++ b/compiler/rustc_target/src/abi/call/mod.rs @@ -22,6 +22,7 @@ mod powerpc; mod powerpc64; mod riscv; mod s390x; +mod sbf; mod sparc; mod sparc64; mod wasm; @@ -838,6 +839,7 @@ impl<'a, Ty> FnAbi<'a, Ty> { } "asmjs" => wasm::compute_c_abi_info(cx, self), "bpf" => bpf::compute_abi_info(self), + "sbf" => sbf::compute_abi_info(self), arch => { return Err(AdjustForForeignAbiError::Unsupported { arch: Symbol::intern(arch), diff --git a/compiler/rustc_target/src/abi/call/sbf.rs b/compiler/rustc_target/src/abi/call/sbf.rs new file mode 100644 index 0000000000000..b60c33b22fa47 --- /dev/null +++ b/compiler/rustc_target/src/abi/call/sbf.rs @@ -0,0 +1,35 @@ +// see https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/BPF/BPFCallingConv.td +use crate::abi::call::{ArgAbi, FnAbi}; + +fn classify_ret(ret: &mut ArgAbi<'_, Ty>) { + if ret.layout.is_aggregate() || ret.layout.size.bits() > 64 { + if ret.layout.size.bits() != 128 { + ret.make_indirect(); + } + } else { + ret.extend_integer_width_to(64); + } +} + +fn classify_arg(arg: &mut ArgAbi<'_, Ty>) { + if arg.layout.is_aggregate() || arg.layout.size.bits() > 64 { + if arg.layout.size.bits() != 128 { + arg.make_indirect(); + } + } else { + arg.extend_integer_width_to(64); + } +} + +pub fn compute_abi_info(fn_abi: &mut FnAbi<'_, Ty>) { + if !fn_abi.ret.is_ignore() { + classify_ret(&mut fn_abi.ret); + } + + for arg in &mut fn_abi.args { + if arg.is_ignore() { + continue; + } + classify_arg(arg); + } +} diff --git a/compiler/rustc_target/src/asm/mod.rs b/compiler/rustc_target/src/asm/mod.rs index a11884bea268f..ce06a0040fe77 100644 --- a/compiler/rustc_target/src/asm/mod.rs +++ b/compiler/rustc_target/src/asm/mod.rs @@ -247,11 +247,12 @@ impl FromStr for InlineAsmArch { "spirv" => Ok(Self::SpirV), "wasm32" => Ok(Self::Wasm32), "wasm64" => Ok(Self::Wasm64), - "bpf" => Ok(Self::Bpf), "avr" => Ok(Self::Avr), "msp430" => Ok(Self::Msp430), "m68k" => Ok(Self::M68k), "csky" => Ok(Self::CSKY), + "bpf" => Ok(Self::Bpf), + "sbf" => Ok(Self::Bpf), _ => Err(()), } } diff --git a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs index 3e49e131bf602..bb13b79f770b9 100644 --- a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs +++ b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs @@ -1,64 +1,12 @@ -use crate::abi::Endian; -use super::{LinkerFlavor, PanicStrategy, Target, TargetOptions, LldFlavor}; -use std::{collections::BTreeMap}; +use crate::spec::Target; +use crate::spec::sbf_base; pub fn target() -> Target { - let linker_script = r" -PHDRS -{ - text PT_LOAD ; - rodata PT_LOAD ; - dynamic PT_DYNAMIC ; -} - -SECTIONS -{ - . = SIZEOF_HEADERS; - .text : { *(.text*) } :text - .rodata : { *(.rodata*) } :rodata - .data.rel.ro : { *(.data.rel.ro*) } :rodata - .dynamic : { *(.dynamic) } :dynamic -} -"; - let mut lld_args = Vec::new(); - lld_args.push("--threads=1".to_string()); - lld_args.push("-z".to_string()); - lld_args.push("notext".to_string()); - let mut pre_link_args = BTreeMap::new(); - pre_link_args.insert(LinkerFlavor::Lld(LldFlavor::Ld), lld_args); - Target { llvm_target: "bpfel".to_string(), pointer_width: 64, arch: "bpf".to_string(), data_layout: "e-m:e-p:64:64-i64:64-n32:64-S128".to_string(), - - options: TargetOptions { - allow_asm: true, - endian: Endian::Little, - c_int_width: "64".to_string(), - env: String::new(), - features: "+solana".to_string(), - vendor: "solana".to_string(), - linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), - linker_is_gnu: true, - linker: Some("rust-lld".to_owned()), - link_script: Some(linker_script.to_string()), - pre_link_args, - executables: true, - dll_prefix: "".to_string(), - dynamic_linking: true, - only_cdylib: true, - no_default_libraries: true, - panic_strategy: PanicStrategy::Abort, - position_independent_executables: true, - requires_lto: false, - singlethread: true, - max_atomic_width: Some(64), - eh_frame_header: false, - main_needs_argc_argv: false, - emit_debug_gdb_scripts: false, - .. Default::default() - }, + options: sbf_base::opts(), } } diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 4507f829c3059..bae5f1af122c9 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1692,6 +1692,7 @@ supported_targets! { ("bpfeb-unknown-none", bpfeb_unknown_none), ("bpfel-unknown-none", bpfel_unknown_none), ("bpfel-unknown-unknown", bpfel_unknown_unknown), + ("sbf-solana-solana", sbf_solana_solana), ("armv6k-nintendo-3ds", armv6k_nintendo_3ds), diff --git a/compiler/rustc_target/src/spec/sbf_base.rs b/compiler/rustc_target/src/spec/sbf_base.rs new file mode 100644 index 0000000000000..bbd7f6205da88 --- /dev/null +++ b/compiler/rustc_target/src/spec/sbf_base.rs @@ -0,0 +1,57 @@ +use crate::abi::Endian; +use super::{LinkerFlavor, PanicStrategy, TargetOptions, LldFlavor}; +use std::{collections::BTreeMap}; + +pub fn opts() -> TargetOptions { + let linker_script = r" +PHDRS +{ + text PT_LOAD ; + rodata PT_LOAD ; + dynamic PT_DYNAMIC ; +} + +SECTIONS +{ + . = SIZEOF_HEADERS; + .text : { *(.text*) } :text + .rodata : { *(.rodata*) } :rodata + .data.rel.ro : { *(.data.rel.ro*) } :rodata + .dynamic : { *(.dynamic) } :dynamic +} +"; + let mut lld_args = Vec::new(); + lld_args.push("--threads=1".to_string()); + lld_args.push("-z".to_string()); + lld_args.push("notext".to_string()); + let mut pre_link_args = BTreeMap::new(); + pre_link_args.insert(LinkerFlavor::Lld(LldFlavor::Ld), lld_args); + + TargetOptions { + allow_asm: true, + endian: Endian::Little, + c_int_width: "64".to_string(), + env: String::new(), + features: "+solana".to_string(), + vendor: "solana".to_string(), + linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), + linker_is_gnu: true, + linker: Some("rust-lld".to_owned()), + link_script: Some(linker_script.to_string()), + pre_link_args, + executables: true, + dll_prefix: "".to_string(), + dynamic_linking: true, + only_cdylib: true, + no_default_libraries: true, + panic_strategy: PanicStrategy::Abort, + position_independent_executables: true, + requires_lto: false, + singlethread: true, + max_atomic_width: Some(64), + eh_frame_header: false, + main_needs_argc_argv: false, + emit_debug_gdb_scripts: false, + .. Default::default() + } +} diff --git a/compiler/rustc_target/src/spec/sbf_solana_solana.rs b/compiler/rustc_target/src/spec/sbf_solana_solana.rs new file mode 100644 index 0000000000000..79783600a8151 --- /dev/null +++ b/compiler/rustc_target/src/spec/sbf_solana_solana.rs @@ -0,0 +1,12 @@ +use crate::spec::Target; +use crate::spec::sbf_base; + +pub fn target() -> Target { + Target { + llvm_target: "sbf".to_string(), + pointer_width: 64, + arch: "sbf".to_string(), + data_layout: "e-m:e-p:64:64-i64:64-n32:64-S128".to_string(), + options: sbf_base::opts(), + } +} diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index 8da494a749d07..c54f7408205fc 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -5,7 +5,7 @@ use crate::cell::{Cell, Ref, RefCell, RefMut, SyncUnsafeCell, UnsafeCell}; use crate::char::EscapeDebugExtArgs; use crate::iter; -#[cfg(target_arch = "bpf")] +#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] use crate::intrinsics::abort; use crate::marker::PhantomData; use crate::mem; diff --git a/library/core/src/fmt/num.rs b/library/core/src/fmt/num.rs index 2dac024d696c9..34cf989de0895 100644 --- a/library/core/src/fmt/num.rs +++ b/library/core/src/fmt/num.rs @@ -2,7 +2,7 @@ use crate::fmt; use crate::mem::MaybeUninit; -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] use crate::num::fmt as numfmt; use crate::ops::{Div, Rem, Sub}; use crate::ptr; @@ -295,7 +295,7 @@ macro_rules! impl_Display { }; } -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] macro_rules! impl_Exp { ($($t:ident),* as $u:ident via $conv_fn:ident named $name:ident) => { fn $name( @@ -470,14 +470,14 @@ mod imp { as u64 via to_u64 named fmt_u64 ); - #[cfg(not(target_arch = "bpf"))] + #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] impl_Exp!( i8, u8, i16, u16, i32, u32, i64, u64, usize, isize as u64 via to_u64 named exp_u64 ); } -#[cfg(not(any(target_pointer_width = "64", target_arch = "wasm32", target_arch = "bpf")))] +#[cfg(not(any(target_pointer_width = "64", target_arch = "wasm32", target_arch = "bpf", target_arch = "sbf")))] mod imp { use super::*; impl_Display!(i8, u8, i16, u16, i32, u32, isize, usize as u32 via to_u32 named fmt_u32); @@ -486,7 +486,7 @@ mod imp { impl_Exp!(i64, u64 as u64 via to_u64 named exp_u64); } -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] impl_Exp!(i128, u128 as u128 via to_u128 named exp_u128); /// Helper function for writing a u64 into `buf` going from last to first, with `curr`. diff --git a/library/proc_macro/src/lib.rs b/library/proc_macro/src/lib.rs index cddde30fa2489..a6e7e95070cd5 100644 --- a/library/proc_macro/src/lib.rs +++ b/library/proc_macro/src/lib.rs @@ -9,7 +9,7 @@ //! //! [the book]: ../book/ch19-06-macros.html#procedural-macros-for-generating-code-from-attributes -#![cfg(not(target_arch = "bpf"))] +#![cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] #![stable(feature = "proc_macro_lib", since = "1.15.0")] #![deny(missing_docs)] #![doc( diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index d9f1a781235ff..8fb54e9906269 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -24,7 +24,7 @@ hashbrown = { version = "0.14", default-features = false, features = ['rustc-dep std_detect = { path = "../stdarch/crates/std_detect", default-features = false, features = ['rustc-dep-of-std'] } # Dependencies of the `backtrace` crate -[target.'cfg(not(target_arch = "bpf"))'.dependencies] +[target.'cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))'.dependencies] addr2line = { version = "0.21.0", optional = true, default-features = false } rustc-demangle = { version = "0.1.21", features = ['rustc-dep-of-std'] } diff --git a/library/std/build.rs b/library/std/build.rs index 2da5a866553d3..cf2600039cc1a 100644 --- a/library/std/build.rs +++ b/library/std/build.rs @@ -36,6 +36,7 @@ fn main() { || target.contains("hurd") || target.contains("uefi") || target.contains("bpf") + || target.contains("sbf") // See src/bootstrap/synthetic_targets.rs || env::var("RUSTC_BOOTSTRAP_SYNTHETIC_TARGET").is_ok() { diff --git a/library/std/src/alloc.rs b/library/std/src/alloc.rs index 56767d3e40b39..fb5f69c10ced6 100644 --- a/library/std/src/alloc.rs +++ b/library/std/src/alloc.rs @@ -58,9 +58,9 @@ use core::intrinsics; use core::ptr::NonNull; -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] use core::sync::atomic::{AtomicPtr, Ordering}; -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] use core::mem; use core::ptr; @@ -289,7 +289,7 @@ unsafe impl Allocator for System { } } -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] static HOOK: AtomicPtr<()> = AtomicPtr::new(ptr::null_mut()); /// Registers a custom allocation error hook, replacing any that was previously registered. @@ -332,7 +332,7 @@ static HOOK: AtomicPtr<()> = AtomicPtr::new(ptr::null_mut()); /// set_alloc_error_hook(custom_alloc_error_hook); /// ``` #[unstable(feature = "alloc_error_hook", issue = "51245")] -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub fn set_alloc_error_hook(hook: fn(Layout)) { HOOK.store(hook as *mut (), Ordering::SeqCst); } @@ -343,13 +343,13 @@ pub fn set_alloc_error_hook(hook: fn(Layout)) { /// /// If no custom hook is registered, the default hook will be returned. #[unstable(feature = "alloc_error_hook", issue = "51245")] -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub fn take_alloc_error_hook() -> fn(Layout) { let hook = HOOK.swap(ptr::null_mut(), Ordering::SeqCst); if hook.is_null() { default_alloc_error_hook } else { unsafe { mem::transmute(hook) } } } -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] fn default_alloc_error_hook(layout: Layout) { extern "Rust" { // This symbol is emitted by rustc next to __rust_alloc_error_handler. @@ -369,14 +369,14 @@ fn default_alloc_error_hook(layout: Layout) { #[alloc_error_handler] #[unstable(feature = "alloc_internals", issue = "none")] pub fn rust_oom(_layout: Layout) -> ! { - #[cfg(not(target_arch = "bpf"))] + #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] { let hook = HOOK.load(Ordering::SeqCst); let hook: fn(Layout) = if hook.is_null() { default_alloc_error_hook } else { unsafe { mem::transmute(hook) } }; hook(_layout); } - #[cfg(target_arch = "bpf")] + #[cfg(any(target_arch = "bpf", target_arch = "sbf"))] { crate::sys::sol_log("Error: memory allocation failed, out of memory"); } diff --git a/library/std/src/io/stdio.rs b/library/std/src/io/stdio.rs index 740f4877cf793..ad5b8fd1397e3 100644 --- a/library/std/src/io/stdio.rs +++ b/library/std/src/io/stdio.rs @@ -5,18 +5,22 @@ mod tests; use crate::io::prelude::*; -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] use crate::cell::{Cell, RefCell}; use crate::fmt; use crate::fs::File; +#[cfg(not(target_os = "solana"))] use crate::io::{self, BorrowedCursor, BufReader, IoSlice, IoSliceMut, LineWriter, Lines}; +#[cfg(target_os = "solana")] +use crate::io::{self, BufReader, IoSlice, IoSliceMut}; +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] use crate::sync::atomic::{AtomicBool, Ordering}; use crate::sync::{Arc, Mutex, MutexGuard, OnceLock, ReentrantMutex, ReentrantMutexGuard}; use crate::sys::stdio; type LocalStream = Arc>>; -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] thread_local! { /// Used by the test crate to capture the output of the print macros and panics. static OUTPUT_CAPTURE: Cell> = { @@ -36,7 +40,7 @@ thread_local! { /// have a consistent order between set_output_capture and print_to *within /// the same thread*. Within the same thread, things always have a perfectly /// consistent order. So Ordering::Relaxed is fine. -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] static OUTPUT_CAPTURE_USED: AtomicBool = AtomicBool::new(false); /// A handle to a raw instance of the standard input stream of this process. @@ -65,7 +69,7 @@ struct StderrRaw(stdio::Stderr); /// /// The returned handle has no external synchronization or buffering. #[unstable(feature = "libstd_sys_internals", issue = "none")] -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] const fn stdin_raw() -> StdinRaw { StdinRaw(stdio::Stdin::new()) } @@ -80,7 +84,7 @@ const fn stdin_raw() -> StdinRaw { /// The returned handle has no external synchronization or buffering layered on /// top. #[unstable(feature = "libstd_sys_internals", issue = "none")] -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] const fn stdout_raw() -> StdoutRaw { StdoutRaw(stdio::Stdout::new()) } @@ -93,7 +97,7 @@ const fn stdout_raw() -> StdoutRaw { /// The returned handle has no external synchronization or buffering layered on /// top. #[unstable(feature = "libstd_sys_internals", issue = "none")] -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] const fn stderr_raw() -> StderrRaw { StderrRaw(stdio::Stderr::new()) } @@ -236,7 +240,7 @@ fn handle_ebadf(r: io::Result, default: T) -> io::Result { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub struct Stdin { - #[cfg(not(target_arch = "bpf"))] + #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] inner: &'static Mutex>, } @@ -326,7 +330,7 @@ pub struct StdinLock<'a> { /// ``` #[must_use] #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub fn stdin() -> Stdin { static INSTANCE: OnceLock>> = OnceLock::new(); Stdin { @@ -336,9 +340,9 @@ pub fn stdin() -> Stdin { } } -/// BPF dummy +/// SBF dummy #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(target_arch = "bpf")] +#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] pub fn stdin() -> Stdin { Stdin {} } @@ -381,7 +385,7 @@ pub fn stdin() -> Stdin { /// } /// ``` #[unstable(feature = "stdio_locked", issue = "86845")] -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub fn stdin_locked() -> StdinLock<'static> { stdin().into_locked() } @@ -409,7 +413,7 @@ impl Stdin { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[cfg(not(target_arch = "bpf"))] + #[cfg(not(target_os = "solana"))] pub fn lock(&self) -> StdinLock<'static> { // Locks this handle with 'static lifetime. This depends on the // implementation detail that the underlying `Mutex` is static. @@ -443,14 +447,14 @@ impl Stdin { /// in which case it will wait for the Enter key to be pressed before /// continuing #[stable(feature = "rust1", since = "1.0.0")] - #[cfg(not(target_arch = "bpf"))] + #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub fn read_line(&self, buf: &mut String) -> io::Result { self.lock().read_line(buf) } // Locks this handle with any lifetime. This depends on the // implementation detail that the underlying `Mutex` is static. - #[cfg(not(target_arch = "bpf"))] + #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] fn lock_any<'a>(&self) -> StdinLock<'a> { StdinLock { inner: self.inner.lock().unwrap_or_else(|e| e.into_inner()) } } @@ -482,7 +486,7 @@ impl Stdin { /// } /// ``` #[unstable(feature = "stdio_locked", issue = "86845")] - #[cfg(not(target_arch = "bpf"))] + #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub fn into_locked(self) -> StdinLock<'static> { self.lock_any() } @@ -504,7 +508,7 @@ impl Stdin { /// ``` #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "stdin_forwarders", since = "1.62.0")] - #[cfg(not(target_arch = "bpf"))] + #[cfg(not(target_os = "solana"))] pub fn lines(self) -> Lines> { self.lock().lines() } @@ -528,7 +532,7 @@ impl Stdin { /// ``` #[must_use = "`self` will be dropped if the result is not used"] #[unstable(feature = "stdin_forwarders", issue = "87096")] - #[cfg(not(target_arch = "bpf"))] + #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub fn split(self, byte: u8) -> Split> { self.into_locked().split(byte) } @@ -542,7 +546,7 @@ impl fmt::Debug for Stdin { } #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] impl Read for Stdin { fn read(&mut self, buf: &mut [u8]) -> io::Result { self.lock().read(buf) @@ -569,7 +573,7 @@ impl Read for Stdin { } #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(target_arch = "bpf")] +#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] impl Read for Stdin { fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) @@ -689,7 +693,7 @@ pub struct Stdout { // FIXME: this should be LineWriter or BufWriter depending on the state of // stdout (tty or not). Note that if this is not line buffered it // should also flush-on-panic or some form of flush-on-abort. - #[cfg(not(target_arch = "bpf"))] + #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] inner: &'static ReentrantMutex>>, } @@ -711,18 +715,18 @@ pub struct Stdout { /// standard library or via raw Windows API calls, will fail. #[must_use = "if unused stdout will immediately unlock"] #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub struct StdoutLock<'a> { inner: ReentrantMutexGuard<'a, RefCell>>, } -/// BPF dummy +/// SBF dummy #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(target_arch = "bpf")] +#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] pub struct StdoutLock { } -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] static STDOUT: OnceLock>>> = OnceLock::new(); /// Constructs a new handle to the standard output of the current process. @@ -774,7 +778,7 @@ static STDOUT: OnceLock>>> = OnceLo #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "io_stdout")] -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub fn stdout() -> Stdout { Stdout { inner: STDOUT @@ -782,9 +786,9 @@ pub fn stdout() -> Stdout { } } -/// Dummy stdout for BPF target +/// Dummy stdout for SBF target #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(target_arch = "bpf")] +#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] pub fn stdout() -> Stdout { Stdout {} } @@ -792,7 +796,7 @@ pub fn stdout() -> Stdout { // Flush the data and disable buffering during shutdown // by replacing the line writer by one with zero // buffering capacity. -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub fn cleanup() { let mut initialized = false; let stdout = STDOUT.get_or_init(|| { @@ -832,7 +836,7 @@ impl Stdout { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[cfg(not(target_arch = "bpf"))] + #[cfg(not(target_os = "solana"))] pub fn lock(&self) -> StdoutLock<'static> { // Locks this handle with 'static lifetime. This depends on the // implementation detail that the underlying `ReentrantMutex` is @@ -843,7 +847,7 @@ impl Stdout { // Locks this handle with any lifetime. This depends on the // implementation detail that the underlying `ReentrantMutex` is // static. - #[cfg(not(target_arch = "bpf"))] + #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] fn lock_any<'a>(&self) -> StdoutLock<'a> { StdoutLock { inner: self.inner.lock() } } @@ -874,7 +878,7 @@ impl Stdout { /// } /// ``` #[unstable(feature = "stdio_locked", issue = "86845")] - #[cfg(not(target_arch = "bpf"))] + #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub fn into_locked(self) -> StdoutLock<'static> { self.lock_any() } @@ -888,7 +892,7 @@ impl fmt::Debug for Stdout { } #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] impl Write for Stdout { fn write(&mut self, buf: &[u8]) -> io::Result { (&*self).write(buf) @@ -915,7 +919,7 @@ impl Write for Stdout { } #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(target_arch = "bpf")] +#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] impl Write for Stdout { fn write(&mut self, buf: &[u8]) -> io::Result { unsafe { @@ -948,7 +952,7 @@ impl Write for Stdout { } #[stable(feature = "write_mt", since = "1.48.0")] -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] impl Write for &Stdout { fn write(&mut self, buf: &[u8]) -> io::Result { self.lock().write(buf) @@ -975,7 +979,7 @@ impl Write for &Stdout { } #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] impl Write for StdoutLock<'_> { fn write(&mut self, buf: &[u8]) -> io::Result { self.inner.borrow_mut().write(buf) @@ -999,7 +1003,7 @@ impl Write for StdoutLock<'_> { } #[stable(feature = "std_debug", since = "1.16.0")] -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] impl fmt::Debug for StdoutLock<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("StdoutLock").finish_non_exhaustive() @@ -1007,7 +1011,7 @@ impl fmt::Debug for StdoutLock<'_> { } #[stable(feature = "std_debug", since = "1.16.0")] -#[cfg(target_arch = "bpf")] +#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] impl fmt::Debug for StdoutLock { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("StdoutLock { .. }") @@ -1033,7 +1037,7 @@ impl fmt::Debug for StdoutLock { /// standard library or via raw Windows API calls, will fail. #[stable(feature = "rust1", since = "1.0.0")] pub struct Stderr { - #[cfg(not(target_arch = "bpf"))] + #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] inner: &'static ReentrantMutex>, } @@ -1055,14 +1059,14 @@ pub struct Stderr { /// standard library or via raw Windows API calls, will fail. #[must_use = "if unused stderr will immediately unlock"] #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub struct StderrLock<'a> { inner: ReentrantMutexGuard<'a, RefCell>, } -/// BPF dummy +/// SBF dummy #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(target_arch = "bpf")] +#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] pub struct StderrLock { } @@ -1113,7 +1117,7 @@ pub struct StderrLock { #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "io_stderr")] -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub fn stderr() -> Stderr { // Note that unlike `stdout()` we don't use `at_exit` here to register a // destructor. Stderr is not buffered, so there's no need to run a @@ -1124,9 +1128,9 @@ pub fn stderr() -> Stderr { Stderr { inner: &INSTANCE } } -/// BPF dummy +/// SBF dummy #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(target_arch = "bpf")] +#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] pub fn stderr() -> Stderr { Stderr {} } @@ -1156,7 +1160,7 @@ pub fn stderr() -> Stderr { /// } /// ``` #[unstable(feature = "stdio_locked", issue = "86845")] -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub fn stderr_locked() -> StderrLock<'static> { stderr().into_locked() } @@ -1183,7 +1187,7 @@ impl Stderr { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[cfg(not(target_arch = "bpf"))] + #[cfg(not(target_os = "solana"))] pub fn lock(&self) -> StderrLock<'static> { // Locks this handle with 'static lifetime. This depends on the // implementation detail that the underlying `ReentrantMutex` is @@ -1194,7 +1198,7 @@ impl Stderr { // Locks this handle with any lifetime. This depends on the // implementation detail that the underlying `ReentrantMutex` is // static. - #[cfg(not(target_arch = "bpf"))] + #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] fn lock_any<'a>(&self) -> StderrLock<'a> { StderrLock { inner: self.inner.lock() } } @@ -1222,7 +1226,7 @@ impl Stderr { /// } /// ``` #[unstable(feature = "stdio_locked", issue = "86845")] - #[cfg(not(target_arch = "bpf"))] + #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub fn into_locked(self) -> StderrLock<'static> { self.lock_any() } @@ -1236,7 +1240,7 @@ impl fmt::Debug for Stderr { } #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] impl Write for Stderr { fn write(&mut self, buf: &[u8]) -> io::Result { (&*self).write(buf) @@ -1263,7 +1267,7 @@ impl Write for Stderr { } #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(target_arch = "bpf")] +#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] impl Write for Stderr { fn write(&mut self, buf: &[u8]) -> io::Result { unsafe { @@ -1296,7 +1300,7 @@ impl Write for Stderr { } #[stable(feature = "write_mt", since = "1.48.0")] -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] impl Write for &Stderr { fn write(&mut self, buf: &[u8]) -> io::Result { self.lock().write(buf) @@ -1323,7 +1327,7 @@ impl Write for &Stderr { } #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] impl Write for StderrLock<'_> { fn write(&mut self, buf: &[u8]) -> io::Result { self.inner.borrow_mut().write(buf) @@ -1347,7 +1351,7 @@ impl Write for StderrLock<'_> { } #[stable(feature = "std_debug", since = "1.16.0")] -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] impl fmt::Debug for StderrLock<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("StderrLock").finish_non_exhaustive() @@ -1355,7 +1359,7 @@ impl fmt::Debug for StderrLock<'_> { } #[stable(feature = "std_debug", since = "1.16.0")] -#[cfg(target_arch = "bpf")] +#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] impl fmt::Debug for StderrLock { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("StderrLock { .. }") @@ -1363,7 +1367,7 @@ impl fmt::Debug for StderrLock { } /// Sets the thread-local output capture buffer and returns the old one. -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] #[unstable( feature = "internal_output_capture", reason = "this function is meant for use in the test crate \ @@ -1380,8 +1384,8 @@ pub fn set_output_capture(sink: Option) -> Option { OUTPUT_CAPTURE.with(move |slot| slot.replace(sink)) } -/// Dummy version for satisfying test library dependencies when building the BPF target. -#[cfg(target_arch = "bpf")] +/// Dummy version for satisfying test library dependencies when building the SBF target. +#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] #[unstable( feature = "internal_output_capture", reason = "this function is meant for use in the test crate \ @@ -1406,7 +1410,7 @@ pub fn set_output_capture(_sink: Option) -> Option { /// /// Writing to non-blocking stdout/stderr can cause an error, which will lead /// this function to panic. -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] fn print_to(args: fmt::Arguments<'_>, global_s: fn() -> T, label: &str) where T: Write, @@ -1492,7 +1496,7 @@ impl_is_terminal!(File, Stdin, StdinLock<'_>, Stdout, StdoutLock<'_>, Stderr, St )] #[doc(hidden)] #[cfg(not(test))] -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub fn _print(args: fmt::Arguments<'_>) { print_to(args, stdout, "stdout"); } @@ -1503,7 +1507,7 @@ pub fn _print(args: fmt::Arguments<'_>) { issue = "none")] #[doc(hidden)] #[cfg(not(test))] -#[cfg(target_arch = "bpf")] +#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] pub fn _print(_args: fmt::Arguments<'_>) { } @@ -1514,7 +1518,7 @@ pub fn _print(_args: fmt::Arguments<'_>) { )] #[doc(hidden)] #[cfg(not(test))] -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub fn _eprint(args: fmt::Arguments<'_>) { print_to(args, stderr, "stderr"); } @@ -1525,7 +1529,7 @@ pub fn _eprint(args: fmt::Arguments<'_>) { issue = "none")] #[doc(hidden)] #[cfg(not(test))] -#[cfg(target_arch = "bpf")] +#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] pub fn _eprint(_args: fmt::Arguments<'_>) { } diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 4d287484b005f..891ff0d62a209 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -559,7 +559,7 @@ pub mod f64; #[macro_use] pub mod thread; pub mod ascii; -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub mod backtrace; pub mod collections; pub mod env; @@ -641,7 +641,7 @@ pub mod alloc; // Private support modules mod panicking; -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] #[path = "../../backtrace/src/lib.rs"] #[allow(dead_code, unused_attributes, fuzzy_provenance_casts)] mod backtrace_rs; diff --git a/library/std/src/panic.rs b/library/std/src/panic.rs index 2aedc1bdff348..dc2ecc1ed46c0 100644 --- a/library/std/src/panic.rs +++ b/library/std/src/panic.rs @@ -56,7 +56,7 @@ pub use core::panic::{AssertUnwindSafe, RefUnwindSafe, UnwindSafe}; /// accessed later using [`PanicInfo::payload`]. /// /// See the [`panic!`] macro for more information about panicking. -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] #[stable(feature = "panic_any", since = "1.51.0")] #[inline] #[track_caller] @@ -169,14 +169,14 @@ pub fn catch_unwind R + UnwindSafe, R>(f: F) -> Result { /// } /// ``` #[stable(feature = "resume_unwind", since = "1.9.0")] -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub fn resume_unwind(payload: Box) -> ! { panicking::rust_panic_without_hook(payload) } -/// BPF version of resume_unwind +/// SBF version of resume_unwind #[stable(feature = "resume_unwind", since = "1.9.0")] -#[cfg(target_arch = "bpf")] +#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] pub fn resume_unwind(_payload: Box) -> ! { // Only used by thread, redirect to plain old panic panicking::begin_panic_fmt(&format_args!("unwind")) diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index 76c66eafff78d..040b774cacb26 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -10,7 +10,7 @@ #![deny(unsafe_op_in_unsafe_fn)] use crate::panic::BacktraceStyle; -#[cfg(not(target_arch = "bpf"))] +#[cfg(not(target_os = "solana"))] use core::panic::{PanicPayload}; use core::panic::{Location, PanicInfo}; @@ -18,27 +18,29 @@ use crate::any::Any; use crate::fmt; use crate::intrinsics; use crate::mem::ManuallyDrop; -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] use crate::mem; -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] use crate::process; -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] use crate::sync::atomic::{AtomicBool, Ordering}; use crate::sync::{PoisonError, RwLock}; -#[cfg(not(target_arch = "bpf"))] +#[cfg(not(target_os = "solana"))] use crate::sys::stdio::panic_output; -#[cfg(not(target_arch = "bpf"))] +#[cfg(not(target_os = "solana"))] use crate::sys_common::backtrace; -#[cfg(not(target_arch = "bpf"))] +#[cfg(not(target_os = "solana"))] +use crate::sys_common::rwlock::StaticRwLock; +#[cfg(not(target_os = "solana"))] use crate::sys_common::thread_info; -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] use crate::thread; -#[cfg(all(not(test), not(target_arch = "bpf")))] +#[cfg(all(not(test), not(target_arch = "bpf"), not(target_arch = "sbf")))] use crate::io::set_output_capture; // make sure to use the stderr output configured // by libtest in the real copy of std -#[cfg(all(test, not(target_arch = "bpf")))] +#[cfg(all(test, not(target_arch = "bpf"), not(target_arch = "sbf")))] use realstd::io::set_output_capture; // Binary interface to the panic runtime that the standard library depends on. @@ -59,14 +61,14 @@ extern "C" { extern "Rust" { /// `PanicPayload` lazily performs allocation only when needed (this avoids /// allocations when using the "abort" panic runtime). - #[cfg(not(target_arch = "bpf"))] + #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] fn __rust_start_panic(payload: &mut dyn PanicPayload) -> u32; } /// This function is called by the panic runtime if FFI code catches a Rust /// panic but doesn't rethrow it. We don't support this case since it messes /// with our panic count. -#[cfg(all(not(test), not(target_arch = "bpf")))] +#[cfg(all(not(test), not(target_arch = "bpf"), not(target_arch = "sbf")))] #[rustc_std_internal_symbol] extern "C" fn __rust_drop_panic() -> ! { rtabort!("Rust panics must be rethrown"); @@ -74,13 +76,13 @@ extern "C" fn __rust_drop_panic() -> ! { /// This function is called by the panic runtime if it catches an exception /// object which does not correspond to a Rust panic. -#[cfg(all(not(test), not(target_arch = "bpf")))] +#[cfg(all(not(test), not(target_arch = "bpf"), not(target_arch = "sbf")))] #[rustc_std_internal_symbol] extern "C" fn __rust_foreign_exception() -> ! { rtabort!("Rust cannot catch foreign exceptions"); } -#[cfg(not(target_arch = "bpf"))] +#[cfg(not(target_os = "solana"))] enum Hook { Default, Custom(Box) + 'static + Sync + Send>), @@ -144,7 +146,7 @@ static HOOK: RwLock = RwLock::new(Hook::Default); /// /// panic!("Normal panic"); /// ``` -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] #[stable(feature = "panic_hooks", since = "1.10.0")] pub fn set_hook(hook: Box) + 'static + Sync + Send>) { if thread::panicking() { @@ -160,8 +162,8 @@ pub fn set_hook(hook: Box) + 'static + Sync + Send>) { drop(old); } -/// Dummy version for satisfying library/test dependencies for BPF target -#[cfg(target_arch = "bpf")] +/// Dummy version for satisfying library/test dependencies for SBF target +#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] #[stable(feature = "panic_hooks", since = "1.10.0")] pub fn set_hook(_hook: Box) + 'static + Sync + Send>) { } @@ -195,7 +197,7 @@ pub fn set_hook(_hook: Box) + 'static + Sync + Send>) { /// panic!("Normal panic"); /// ``` #[must_use] -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] #[stable(feature = "panic_hooks", since = "1.10.0")] pub fn take_hook() -> Box) + 'static + Sync + Send> { if thread::panicking() { @@ -258,14 +260,14 @@ where } /// Dummy version for satisfying library/test dependencies for BPF target -#[cfg(target_arch = "bpf")] +#[cfg(target_os = "solana")] #[stable(feature = "panic_hooks", since = "1.10.0")] pub fn take_hook() -> Box) + 'static + Sync + Send> { Box::new(default_hook) } /// The default panic handler. -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] fn default_hook(info: &PanicInfo<'_>) { // If this is a double panic, make sure that we print a backtrace // for this panic. Otherwise only print it if logging is enabled. @@ -324,7 +326,7 @@ fn default_hook(info: &PanicInfo<'_>) { } } -#[cfg(target_arch = "bpf")] +#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] fn default_hook(_info: &PanicInfo<'_>) { } @@ -373,7 +375,7 @@ pub mod panic_count { #[cfg(not(feature = "panic_immediate_abort"))] #[unstable(feature = "update_panic_count", issue = "none")] pub mod panic_count { - #[cfg(not(target_arch = "bpf"))] + #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] use crate::cell::Cell; use crate::sync::atomic::{AtomicUsize, Ordering}; @@ -388,7 +390,7 @@ pub mod panic_count { // Panic count for the current thread and whether a panic hook is currently // being executed.. - #[cfg(not(target_arch = "bpf"))] + #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] thread_local! { static LOCAL_PANIC_COUNT: Cell<(usize, bool)> = const { Cell::new((0, false)) } } @@ -425,7 +427,7 @@ pub mod panic_count { // // This also updates thread-local state to keep track of whether a panic // hook is currently executing. - #[cfg(not(target_arch = "bpf"))] + #[cfg(not(target_os = "solana"))] pub fn increase(run_panic_hook: bool) -> Option { let global_count = GLOBAL_PANIC_COUNT.fetch_add(1, Ordering::Relaxed); if global_count & ALWAYS_ABORT_FLAG != 0 { @@ -449,7 +451,7 @@ pub mod panic_count { }); } - #[cfg(not(target_arch = "bpf"))] + #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub fn decrease() { GLOBAL_PANIC_COUNT.fetch_sub(1, Ordering::Relaxed); LOCAL_PANIC_COUNT.with(|c| { @@ -464,14 +466,14 @@ pub mod panic_count { // Disregards ALWAYS_ABORT_FLAG #[must_use] - #[cfg(not(target_arch = "bpf"))] + #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub fn get_count() -> usize { LOCAL_PANIC_COUNT.with(|c| c.get().0) } // Disregards ALWAYS_ABORT_FLAG #[must_use] - #[cfg(not(target_arch = "bpf"))] + #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] #[inline] pub fn count_is_zero() -> bool { if GLOBAL_PANIC_COUNT.load(Ordering::Relaxed) & !ALWAYS_ABORT_FLAG == 0 { @@ -492,7 +494,7 @@ pub mod panic_count { // Slow path is in a separate function to reduce the amount of code // inlined from `count_is_zero`. - #[cfg(not(target_arch = "bpf"))] + #[cfg(not(target_os = "solana"))] #[inline(never)] #[cold] fn is_zero_slow_path() -> bool { @@ -569,7 +571,7 @@ pub unsafe fn r#try R>(f: F) -> Result> // optimizer (in most cases this function is not inlined even as a normal, // non-cold function, though, as of the writing of this comment). #[cold] - #[cfg(not(target_arch = "bpf"))] + #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] unsafe fn cleanup(payload: *mut u8) -> Box { // SAFETY: The whole unsafe block hinges on a correct implementation of // the panic handler `__rust_panic_cleanup`. As such we can only @@ -581,7 +583,7 @@ pub unsafe fn r#try R>(f: F) -> Result> } #[cold] - #[cfg(target_arch = "bpf")] + #[cfg(any(target_arch = "bpf", target_arch = "sbf"))] unsafe fn cleanup(payload: *mut u8) -> Box { // SAFETY: The whole unsafe block hinges on a correct implementation of // the panic handler `__rust_panic_cleanup`. As such we can only @@ -638,7 +640,7 @@ pub unsafe fn r#try R>(f: F) -> Result> } /// Determines whether the current thread is unwinding because of panic. -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] #[inline] pub fn panicking() -> bool { !panic_count::count_is_zero() @@ -725,7 +727,7 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! { /// This is the entry point of panicking for the non-format-string variants of /// panic!() and assert!(). In particular, this is the only entry point that supports /// arbitrary payloads, not just format strings. -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] #[unstable(feature = "libstd_sys_internals", reason = "used by the panic! macro", issue = "none")] #[cfg_attr(not(test), lang = "begin_panic")] // lang item for CTFE panic support @@ -789,7 +791,7 @@ pub const fn begin_panic(msg: M) -> ! { /// Executes the primary logic for a panic, including checking for recursive /// panics, panic hooks, and finally dispatching to the panic runtime to either /// abort or unwind. -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] fn rust_panic_with_hook( payload: &mut dyn PanicPayload, message: Option<&fmt::Arguments<'_>>, @@ -863,7 +865,7 @@ fn rust_panic_with_hook( /// This is the entry point for `resume_unwind`. /// It just forwards the payload to the panic runtime. #[cfg_attr(feature = "panic_immediate_abort", inline)] -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub fn rust_panic_without_hook(payload: Box) -> ! { panic_count::increase(false); @@ -884,7 +886,7 @@ pub fn rust_panic_without_hook(payload: Box) -> ! { /// An unmangled function (through `rustc_std_internal_symbol`) on which to slap /// yer breakpoints. -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] #[inline(never)] #[cfg_attr(not(test), rustc_std_internal_symbol)] #[cfg(not(feature = "panic_immediate_abort"))] @@ -901,32 +903,32 @@ fn rust_panic(_: &mut dyn PanicPayload) -> ! { } // Note: The panicking functions have been stripped and rewritten -// in order to save space in BPF programs. Panic messages +// in order to save space in SBF programs. Panic messages // are not supported, just file, line, column. /// This function is called by the panic runtime if it catches an exception /// object which does not correspond to a Rust panic. -#[cfg(all(not(test), target_arch = "bpf"))] +#[cfg(all(not(test), any(target_arch = "bpf", target_arch = "sbf")))] #[rustc_std_internal_symbol] extern "C" fn __rust_foreign_exception() -> ! { rtabort!("Rust cannot catch foreign exceptions"); } /// Determines whether the current thread is unwinding because of panic. -#[cfg(target_arch = "bpf")] +#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] pub fn panicking() -> bool { true } /// Entry point of panic from the libcore crate. -#[cfg(all(not(test), target_arch = "bpf"))] +#[cfg(all(not(test), any(target_arch = "bpf", target_arch = "sbf")))] #[panic_handler] pub fn rust_begin_panic(info: &PanicInfo<'_>) -> ! { crate::sys::panic(info); } -/// The entry point for panicking with a formatted message BPF version. -#[cfg(target_arch = "bpf")] +/// The entry point for panicking with a formatted message SBF version. +#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] #[unstable(feature = "libstd_sys_internals", reason = "used by the panic! macro", issue = "none")] #[cold] // If panic_immediate_abort, inline the abort call, @@ -942,8 +944,8 @@ pub fn begin_panic_fmt(msg: &fmt::Arguments<'_>) -> ! { crate::sys::panic(&info); } -/// Entry point of panicking for panic!() and assert!() BPF version. -#[cfg(target_arch = "bpf")] +/// Entry point of panicking for panic!() and assert!() SBF version. +#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] #[unstable(feature = "libstd_sys_internals", reason = "used by the panic! macro", issue = "none")] #[cfg_attr(not(test), lang = "begin_panic")] // lang item for CTFE panic support diff --git a/library/std/src/process.rs b/library/std/src/process.rs index db0bc1ca94002..6f802ca943e0c 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -2207,7 +2207,7 @@ impl Child { #[stable(feature = "rust1", since = "1.0.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "process_exit")] pub fn exit(code: i32) -> ! { - #[cfg(not(target_arch = "bpf"))] + #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] crate::rt::cleanup(); crate::sys::os::exit(code) } diff --git a/library/std/src/rt.rs b/library/std/src/rt.rs index 27e4edb79fd12..e98c5773bfebd 100644 --- a/library/std/src/rt.rs +++ b/library/std/src/rt.rs @@ -122,7 +122,7 @@ pub(crate) fn cleanup() { // To reduce the generated code of the new `lang_start`, this function is doing // the real work. #[cfg(not(test))] -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] fn lang_start_internal( main: &(dyn Fn() -> i32 + Sync + crate::panic::RefUnwindSafe), argc: isize, @@ -157,7 +157,7 @@ fn lang_start_internal( #[cfg(not(test))] #[inline(never)] -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] #[lang = "start"] fn lang_start( main: fn() -> T, @@ -175,7 +175,7 @@ fn lang_start( } #[cfg(not(test))] -#[cfg(target_arch = "bpf")] +#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] #[lang = "start"] fn lang_start( main: fn() -> T, diff --git a/library/std/src/sync/remutex.rs b/library/std/src/sync/remutex.rs index df0c871ba18b8..65a1c7fbcc6d3 100644 --- a/library/std/src/sync/remutex.rs +++ b/library/std/src/sync/remutex.rs @@ -72,7 +72,7 @@ impl !Send for ReentrantMutexGuard<'_, T> {} impl ReentrantMutex { /// Creates a new reentrant mutex in an unlocked state. - #[cfg(not(target_arch = "bpf"))] + #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub const fn new(t: T) -> ReentrantMutex { ReentrantMutex { mutex: sys::Mutex::new(), @@ -94,7 +94,7 @@ impl ReentrantMutex { /// If another user of this mutex panicked while holding the mutex, then /// this call will return failure if the mutex would otherwise be /// acquired. - #[cfg(not(target_arch = "bpf"))] + #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub fn lock(&self) -> ReentrantMutexGuard<'_, T> { let this_thread = current_thread_unique_ptr(); // Safety: We only touch lock_count when we own the lock. @@ -123,7 +123,7 @@ impl ReentrantMutex { /// If another user of this mutex panicked while holding the mutex, then /// this call will return failure if the mutex would otherwise be /// acquired. - #[cfg(not(target_arch = "bpf"))] + #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub fn try_lock(&self) -> Option> { let this_thread = current_thread_unique_ptr(); // Safety: We only touch lock_count when we own the lock. diff --git a/library/std/src/sys/mod.rs b/library/std/src/sys/mod.rs index acb10cc3235bb..9dd457f9a65b4 100644 --- a/library/std/src/sys/mod.rs +++ b/library/std/src/sys/mod.rs @@ -35,9 +35,9 @@ cfg_if::cfg_if! { } else if #[cfg(target_os = "solid_asp3")] { mod solid; pub use self::solid::*; - } else if #[cfg(target_arch = "bpf")] { - mod bpf; - pub use self::bpf::*; + } else if #[cfg(any(target_arch = "bpf", target_arch = "sbf"))] { + mod sbf; + pub use self::sbf::*; } else if #[cfg(target_os = "hermit")] { mod hermit; pub use self::hermit::*; diff --git a/library/std/src/sys/bpf/alloc.rs b/library/std/src/sys/sbf/alloc.rs similarity index 89% rename from library/std/src/sys/bpf/alloc.rs rename to library/std/src/sys/sbf/alloc.rs index 23e3d4e21af15..dcf18ead5c036 100644 --- a/library/std/src/sys/bpf/alloc.rs +++ b/library/std/src/sys/sbf/alloc.rs @@ -1,8 +1,8 @@ -//! This is an implementation of a global allocator on the BPF platform. +//! This is an implementation of a global allocator on the SBF platform. //! In that situation there's no actual runtime for us //! to lean on for allocation, so instead we provide our own! //! -//! The crate itself provides a global allocator which on BPF has no +//! The crate itself provides a global allocator which on SBF has no //! synchronization as there are no threads! use crate::alloc::{GlobalAlloc, Layout, System}; diff --git a/library/std/src/sys/bpf/args.rs b/library/std/src/sys/sbf/args.rs similarity index 100% rename from library/std/src/sys/bpf/args.rs rename to library/std/src/sys/sbf/args.rs diff --git a/library/std/src/sys/bpf/backtrace.rs b/library/std/src/sys/sbf/backtrace.rs similarity index 100% rename from library/std/src/sys/bpf/backtrace.rs rename to library/std/src/sys/sbf/backtrace.rs diff --git a/library/std/src/sys/bpf/cmath.rs b/library/std/src/sys/sbf/cmath.rs similarity index 100% rename from library/std/src/sys/bpf/cmath.rs rename to library/std/src/sys/sbf/cmath.rs diff --git a/library/std/src/sys/bpf/condvar.rs b/library/std/src/sys/sbf/condvar.rs similarity index 100% rename from library/std/src/sys/bpf/condvar.rs rename to library/std/src/sys/sbf/condvar.rs diff --git a/library/std/src/sys/bpf/condvar_atomics.rs b/library/std/src/sys/sbf/condvar_atomics.rs similarity index 100% rename from library/std/src/sys/bpf/condvar_atomics.rs rename to library/std/src/sys/sbf/condvar_atomics.rs diff --git a/library/std/src/sys/bpf/env.rs b/library/std/src/sys/sbf/env.rs similarity index 100% rename from library/std/src/sys/bpf/env.rs rename to library/std/src/sys/sbf/env.rs diff --git a/library/std/src/sys/bpf/fs.rs b/library/std/src/sys/sbf/fs.rs similarity index 100% rename from library/std/src/sys/bpf/fs.rs rename to library/std/src/sys/sbf/fs.rs diff --git a/library/std/src/sys/bpf/io.rs b/library/std/src/sys/sbf/io.rs similarity index 100% rename from library/std/src/sys/bpf/io.rs rename to library/std/src/sys/sbf/io.rs diff --git a/library/std/src/sys/bpf/memchr.rs b/library/std/src/sys/sbf/memchr.rs similarity index 100% rename from library/std/src/sys/bpf/memchr.rs rename to library/std/src/sys/sbf/memchr.rs diff --git a/library/std/src/sys/bpf/mod.rs b/library/std/src/sys/sbf/mod.rs similarity index 90% rename from library/std/src/sys/bpf/mod.rs rename to library/std/src/sys/sbf/mod.rs index ed1d0e7bc23cc..ff49c4e3b329d 100644 --- a/library/std/src/sys/bpf/mod.rs +++ b/library/std/src/sys/sbf/mod.rs @@ -1,7 +1,7 @@ -//! System bindings for the BPF platform +//! System bindings for the SBF platform //! //! This module contains the facade (aka platform-specific) implementations of -//! OS level functionality for BPF +//! OS level functionality for SBF //! //! This is all super highly experimental and not actually intended for //! wide/production use yet, it's still all in the experimental category. This @@ -10,7 +10,7 @@ //! Currently all functions here are basically stubs that immediately return //! errors. The hope is that with a portability lint we can turn actually just //! remove all this and just omit parts of the standard library if we're -//! compiling for BPF. That way it's a compile time error for something that's +//! compiling for SBF. That way it's a compile time error for something that's //! guaranteed to be a runtime error! use crate::os::raw::c_char; @@ -66,7 +66,7 @@ pub fn unsupported() -> crate::io::Result { pub fn unsupported_err() -> crate::io::Error { crate::io::Error::new(crate::io::ErrorKind::Other, - "operation not supported on BPF yet") + "operation not supported on SBF yet") } pub fn decode_error_kind(_code: i32) -> crate::io::ErrorKind { @@ -95,7 +95,7 @@ pub fn abort_internal() -> ! { // generate these numbers. // // More seriously though this is just for DOS protection in hash maps. It's ok -// if we don't do that on BPF just yet. +// if we don't do that on SBF just yet. pub fn hashmap_random_keys() -> (u64, u64) { (1, 2) } diff --git a/library/std/src/sys/bpf/mutex.rs b/library/std/src/sys/sbf/mutex.rs similarity index 89% rename from library/std/src/sys/bpf/mutex.rs rename to library/std/src/sys/sbf/mutex.rs index 97b523930b857..c1c336135c98f 100644 --- a/library/std/src/sys/bpf/mutex.rs +++ b/library/std/src/sys/sbf/mutex.rs @@ -7,7 +7,7 @@ pub struct Mutex { pub type MovableMutex = Box; unsafe impl Send for Mutex {} -unsafe impl Sync for Mutex {} // no threads on BPF +unsafe impl Sync for Mutex {} // no threads on SBF #[allow(dead_code)] // sys isn't exported yet impl Mutex { @@ -41,7 +41,7 @@ impl Mutex { } } -// All empty stubs because BPF has no threads, lock acquisition always +// All empty stubs because SBF has no threads, lock acquisition always // succeeds. pub struct ReentrantMutex { } diff --git a/library/std/src/sys/bpf/mutex_atomics.rs b/library/std/src/sys/sbf/mutex_atomics.rs similarity index 98% rename from library/std/src/sys/bpf/mutex_atomics.rs rename to library/std/src/sys/sbf/mutex_atomics.rs index abe7a91541cce..a42da624ee2db 100644 --- a/library/std/src/sys/bpf/mutex_atomics.rs +++ b/library/std/src/sys/sbf/mutex_atomics.rs @@ -1,4 +1,4 @@ -// use crate::arch::BPF; +// use crate::arch::SBF; use crate::cell::UnsafeCell; use crate::mem; use crate::sync::atomic::{AtomicUsize, AtomicU32, Ordering::SeqCst}; diff --git a/library/std/src/sys/bpf/net.rs b/library/std/src/sys/sbf/net.rs similarity index 100% rename from library/std/src/sys/bpf/net.rs rename to library/std/src/sys/sbf/net.rs diff --git a/library/std/src/sys/bpf/os.rs b/library/std/src/sys/sbf/os.rs similarity index 95% rename from library/std/src/sys/bpf/os.rs rename to library/std/src/sys/sbf/os.rs index b31aefd270c96..19190b24060a0 100644 --- a/library/std/src/sys/bpf/os.rs +++ b/library/std/src/sys/sbf/os.rs @@ -47,13 +47,13 @@ pub fn join_paths(_paths: I) -> Result impl fmt::Display for JoinPathsError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - "not supported on BPF yet".fmt(f) + "not supported on SBF yet".fmt(f) } } impl StdError for JoinPathsError { fn description(&self) -> &str { - "not supported on BPF yet" + "not supported on SBF yet" } } diff --git a/library/std/src/sys/bpf/path.rs b/library/std/src/sys/sbf/path.rs similarity index 100% rename from library/std/src/sys/bpf/path.rs rename to library/std/src/sys/sbf/path.rs diff --git a/library/std/src/sys/bpf/pipe.rs b/library/std/src/sys/sbf/pipe.rs similarity index 100% rename from library/std/src/sys/bpf/pipe.rs rename to library/std/src/sys/sbf/pipe.rs diff --git a/library/std/src/sys/bpf/process.rs b/library/std/src/sys/sbf/process.rs similarity index 100% rename from library/std/src/sys/bpf/process.rs rename to library/std/src/sys/sbf/process.rs diff --git a/library/std/src/sys/bpf/rwlock.rs b/library/std/src/sys/sbf/rwlock.rs similarity index 96% rename from library/std/src/sys/bpf/rwlock.rs rename to library/std/src/sys/sbf/rwlock.rs index 2e9f4e9a87b94..66482f4dd8ba0 100644 --- a/library/std/src/sys/bpf/rwlock.rs +++ b/library/std/src/sys/sbf/rwlock.rs @@ -7,7 +7,7 @@ pub struct RWLock { pub type MovableRWLock = RWLock; unsafe impl Send for RWLock {} -unsafe impl Sync for RWLock {} // no threads on BPF +unsafe impl Sync for RWLock {} // no threads on SBF impl RWLock { pub const fn new() -> RWLock { diff --git a/library/std/src/sys/bpf/rwlock_atomics.rs b/library/std/src/sys/sbf/rwlock_atomics.rs similarity index 100% rename from library/std/src/sys/bpf/rwlock_atomics.rs rename to library/std/src/sys/sbf/rwlock_atomics.rs diff --git a/library/std/src/sys/bpf/stdio.rs b/library/std/src/sys/sbf/stdio.rs similarity index 100% rename from library/std/src/sys/bpf/stdio.rs rename to library/std/src/sys/sbf/stdio.rs diff --git a/library/std/src/sys/bpf/thread.rs b/library/std/src/sys/sbf/thread.rs similarity index 100% rename from library/std/src/sys/bpf/thread.rs rename to library/std/src/sys/sbf/thread.rs diff --git a/library/std/src/sys/bpf/thread_local_atomics.rs b/library/std/src/sys/sbf/thread_local_atomics.rs similarity index 100% rename from library/std/src/sys/bpf/thread_local_atomics.rs rename to library/std/src/sys/sbf/thread_local_atomics.rs diff --git a/library/std/src/sys/bpf/thread_local_dtor.rs b/library/std/src/sys/sbf/thread_local_dtor.rs similarity index 100% rename from library/std/src/sys/bpf/thread_local_dtor.rs rename to library/std/src/sys/sbf/thread_local_dtor.rs diff --git a/library/std/src/sys/bpf/thread_local_key.rs b/library/std/src/sys/sbf/thread_local_key.rs similarity index 100% rename from library/std/src/sys/bpf/thread_local_key.rs rename to library/std/src/sys/sbf/thread_local_key.rs diff --git a/library/std/src/sys/bpf/time.rs b/library/std/src/sys/sbf/time.rs similarity index 100% rename from library/std/src/sys/bpf/time.rs rename to library/std/src/sys/sbf/time.rs diff --git a/library/std/src/sys_common/backtrace.rs b/library/std/src/sys_common/backtrace.rs index 0e795099d954a..e1c0aeeafabf2 100644 --- a/library/std/src/sys_common/backtrace.rs +++ b/library/std/src/sys_common/backtrace.rs @@ -1,4 +1,4 @@ -#![cfg(not(target_arch = "bpf"))] +#![cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] use crate::backtrace_rs::{self, BacktraceFmt, BytesOrWideString, PrintFmt}; use crate::borrow::Cow; diff --git a/library/std/src/sys_common/mod.rs b/library/std/src/sys_common/mod.rs index a03694b435fb5..86495e9597ac5 100644 --- a/library/std/src/sys_common/mod.rs +++ b/library/std/src/sys_common/mod.rs @@ -47,6 +47,7 @@ cfg_if::cfg_if! { if #[cfg(any(target_os = "l4re", target_os = "uefi", target_arch = "bpf", + target_arch = "sbf", feature = "restricted-std", all(target_family = "wasm", not(target_os = "emscripten")), target_os = "xous", diff --git a/library/std/src/sys_common/thread.rs b/library/std/src/sys_common/thread.rs index e1cbf9ea88ff3..e8974c220610d 100644 --- a/library/std/src/sys_common/thread.rs +++ b/library/std/src/sys_common/thread.rs @@ -1,11 +1,11 @@ -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] use crate::env; -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] use crate::sync::atomic::{self, Ordering}; -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] use crate::sys::thread as imp; -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub fn min_stack() -> usize { static MIN: atomic::AtomicUsize = atomic::AtomicUsize::new(0); match MIN.load(Ordering::Relaxed) { @@ -21,7 +21,7 @@ pub fn min_stack() -> usize { amt } -#[cfg(target_arch = "bpf")] +#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] pub fn min_stack() -> usize { 0 } diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index e1315c24712a0..be72bb2a9f983 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -448,7 +448,7 @@ impl Builder { /// /// [`io::Result`]: crate::io::Result #[unstable(feature = "thread_spawn_unchecked", issue = "55132")] - #[cfg(not(target_arch = "bpf"))] + #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub unsafe fn spawn_unchecked<'a, F, T>(self, f: F) -> io::Result> where F: FnOnce() -> T, @@ -575,9 +575,9 @@ impl Builder { }) } - /// BPF version of spawn_unchecked + /// SBF version of spawn_unchecked #[unstable(feature = "thread_spawn_unchecked", issue = "55132")] - #[cfg(target_arch = "bpf")] + #[cfg(any(target_arch = "bpf", target_arch = "sbf"))] pub unsafe fn spawn_unchecked<'a, F, T>(self, _f: F) -> io::Result> where F: FnOnce() -> T, diff --git a/library/test/src/cli.rs b/library/test/src/cli.rs index 60f294682b8b0..292f52f72bd10 100644 --- a/library/test/src/cli.rs +++ b/library/test/src/cli.rs @@ -1,6 +1,6 @@ //! Module converting command-line arguments into test configuration. -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] use std::env; use std::path::PathBuf; @@ -47,7 +47,7 @@ impl TestOpts { /// Result of parsing the options. pub type OptRes = Result; /// Result of parsing the option part. -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] type OptPartRes = Result; fn optgroups() -> getopts::Options { @@ -223,7 +223,7 @@ pub fn parse_opts(args: &[String]) -> Option { } // Gets the option value and checks if unstable features are enabled. -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] macro_rules! unstable_optflag { ($matches:ident, $allow_unstable:ident, $option_name:literal) => {{ let opt = $matches.opt_present($option_name); @@ -255,7 +255,7 @@ macro_rules! unstable_optopt { // Implementation of `parse_opts` that doesn't care about help message // and returns a `Result`. -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] fn parse_opts_impl(matches: getopts::Matches) -> OptRes { let allow_unstable = get_allow_unstable(&matches)?; @@ -310,7 +310,7 @@ fn parse_opts_impl(matches: getopts::Matches) -> OptRes { Ok(test_opts) } -#[cfg(target_arch = "bpf")] +#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] fn parse_opts_impl(_matches: getopts::Matches) -> OptRes { let test_opts = TestOpts { list: false, @@ -335,7 +335,7 @@ fn parse_opts_impl(_matches: getopts::Matches) -> OptRes { } // FIXME: Copied from librustc_ast until linkage errors are resolved. Issue #47566 -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] fn is_nightly() -> bool { // Whether this is a feature-staged build, i.e., on the beta or stable channel let disable_unstable_features = @@ -347,7 +347,7 @@ fn is_nightly() -> bool { } // Gets the CLI options associated with `report-time` feature. -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] fn get_time_options( matches: &getopts::Matches, allow_unstable: bool, @@ -405,7 +405,7 @@ fn get_shuffle_seed(matches: &getopts::Matches, allow_unstable: bool) -> OptPart Ok(shuffle_seed) } -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] fn get_test_threads(matches: &getopts::Matches) -> OptPartRes> { let test_threads = match matches.opt_str("test-threads") { Some(n_str) => match n_str.parse::() { @@ -424,7 +424,7 @@ fn get_test_threads(matches: &getopts::Matches) -> OptPartRes> { Ok(test_threads) } -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] fn get_format( matches: &getopts::Matches, quiet: bool, @@ -457,7 +457,7 @@ fn get_format( Ok(format) } -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] fn get_color_config(matches: &getopts::Matches) -> OptPartRes { let color = match matches.opt_str("color").as_deref() { Some("auto") | None => ColorConfig::AutoColor, @@ -475,7 +475,7 @@ fn get_color_config(matches: &getopts::Matches) -> OptPartRes { Ok(color) } -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] fn get_nocapture(matches: &getopts::Matches) -> OptPartRes { let mut nocapture = matches.opt_present("nocapture"); if !nocapture { @@ -488,7 +488,7 @@ fn get_nocapture(matches: &getopts::Matches) -> OptPartRes { Ok(nocapture) } -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] fn get_run_ignored(matches: &getopts::Matches, include_ignored: bool) -> OptPartRes { let run_ignored = match (include_ignored, matches.opt_present("ignored")) { (true, true) => { @@ -502,7 +502,7 @@ fn get_run_ignored(matches: &getopts::Matches, include_ignored: bool) -> OptPart Ok(run_ignored) } -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] fn get_allow_unstable(matches: &getopts::Matches) -> OptPartRes { let mut allow_unstable = false; @@ -524,7 +524,7 @@ fn get_allow_unstable(matches: &getopts::Matches) -> OptPartRes { Ok(allow_unstable) } -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] fn get_log_file(matches: &getopts::Matches) -> OptPartRes> { let logfile = matches.opt_str("logfile").map(|s| PathBuf::from(&s)); diff --git a/library/test/src/console.rs b/library/test/src/console.rs index 5eaac0e1356da..0efbf9e1417d0 100644 --- a/library/test/src/console.rs +++ b/library/test/src/console.rs @@ -291,12 +291,12 @@ fn on_test_event( /// A simple console test runner. /// Runs provided tests reporting process and results to the stdout. pub fn run_tests_console(opts: &TestOpts, tests: Vec) -> io::Result { - #[cfg(not(target_arch = "bpf"))] + #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] let output = match term::stdout() { None => OutputLocation::Raw(io::stdout()), Some(t) => OutputLocation::Pretty(t), }; - #[cfg(target_arch = "bpf")] + #[cfg(any(target_arch = "bpf", target_arch = "sbf"))] let output = OutputLocation::Raw(io::stdout()); let max_name_len = tests diff --git a/library/test/src/helpers/concurrency.rs b/library/test/src/helpers/concurrency.rs index ee5f117db8333..b3b4cea699e81 100644 --- a/library/test/src/helpers/concurrency.rs +++ b/library/test/src/helpers/concurrency.rs @@ -1,9 +1,9 @@ //! Helper module which helps to determine amount of threads to be used //! during tests execution. -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] use std::{env, num::NonZeroUsize, thread}; -#[cfg(not(target_arch = "bpf"))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub fn get_concurrency() -> usize { if let Ok(value) = env::var("RUST_TEST_THREADS") { match value.parse::().ok() { @@ -15,7 +15,7 @@ pub fn get_concurrency() -> usize { } } -#[cfg(target_arch = "bpf")] +#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] pub fn get_concurrency() -> usize { 1 } diff --git a/library/test/src/lib.rs b/library/test/src/lib.rs index 076a235d42bc7..cd0a3bdb60a9c 100644 --- a/library/test/src/lib.rs +++ b/library/test/src/lib.rs @@ -163,9 +163,9 @@ pub fn test_main(args: &[String], tests: Vec, options: Option>(); - #[cfg(target_arch = "bpf")] + #[cfg(any(target_arch = "bpf", target_arch = "sbf"))] let args: [String; 0] = []; let owned_tests: Vec<_> = tests.iter().map(make_owned_test).collect(); test_main(&args, owned_tests, None) diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 7021a9543582d..f5f000d78201f 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -415,7 +415,7 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car if builder.no_std(target) == Some(true) { features += " compiler-builtins-mem"; - if !target.starts_with("bpf") { + if !target.starts_with("sbf") && !target.starts_with("bpf") { features.push_str(compiler_builtins_c_feature); } diff --git a/src/bootstrap/src/core/sanity.rs b/src/bootstrap/src/core/sanity.rs index 2caee2dba7572..83b77b83dd11f 100644 --- a/src/bootstrap/src/core/sanity.rs +++ b/src/bootstrap/src/core/sanity.rs @@ -172,7 +172,7 @@ than building it. continue; } - // bpf target relies on in-tree built llvm, + // sbf target relies on in-tree built llvm, // which doesn't exist when this check runs if !build.config.dry_run() && !target.contains("sbf") && !target.contains("bpf") { cmd_finder.must_have(build.cc(*target)); diff --git a/src/bootstrap/src/utils/cc_detect.rs b/src/bootstrap/src/utils/cc_detect.rs index c2c6c8b0c8d9f..44621d61af3c5 100644 --- a/src/bootstrap/src/utils/cc_detect.rs +++ b/src/bootstrap/src/utils/cc_detect.rs @@ -39,7 +39,7 @@ fn cc2ar(cc: &Path, target: TargetSelection) -> Option { Some(PathBuf::from(ar)) } else if let Some(ar) = env::var_os("AR") { Some(PathBuf::from(ar)) - } else if target.contains("bpf") { + } else if target.contains("sbf") || target.contains("bpf") { let parent = cc.parent().unwrap(); let file = PathBuf::from("llvm-ar"); Some(parent.join(file)) @@ -138,7 +138,7 @@ pub fn find_target(build: &Build, target: TargetSelection) { { cfg.compiler(cxx); true - } else if &*target.triple == "bpfel-unknown-unknown" { + } else if &*target.triple == "sbf-solana-solana" || &*target.triple == "bpfel-unknown-unknown" { set_compiler(&mut cfg, Language::CPlusPlus, target, config, build); true } else { @@ -225,6 +225,9 @@ fn default_compiler( "bpfel-unknown-unknown" => { cfg.compiler(build.llvm_bin(target).join(compiler.clang())); } + "sbf-solana-solana" => { + cfg.compiler(build.llvm_bin(target).join(compiler.clang())); + } t if t.contains("musl") && compiler == Language::C => { if let Some(root) = build.musl_root(target) { diff --git a/src/bootstrap/src/utils/helpers.rs b/src/bootstrap/src/utils/helpers.rs index 5bc81f2d983e8..8334fb10a999f 100644 --- a/src/bootstrap/src/utils/helpers.rs +++ b/src/bootstrap/src/utils/helpers.rs @@ -180,6 +180,7 @@ pub fn use_host_linker(target: TargetSelection) -> bool { || target.contains("fortanix") || target.contains("fuchsia") || target.contains("bpf") + || target.contains("sbf") || target.contains("switch")) } diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index 876c6c969fb35..64ad2aecc64f6 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -326,6 +326,7 @@ target | std | host | notes [`riscv64gc-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | OpenBSD/riscv64 [`riscv64-linux-android`](platform-support/android.md) | | | RISC-V 64-bit Android `s390x-unknown-linux-musl` | | | S390x Linux (kernel 3.2, MUSL) +`sbf-solana-solana` | ✓ | | SBF `sparc-unknown-linux-gnu` | ✓ | | 32-bit SPARC Linux [`sparc-unknown-none-elf`](./platform-support/sparc-unknown-none-elf.md) | * | | Bare 32-bit SPARC V7+ [`sparc64-unknown-netbsd`](platform-support/netbsd.md) | ✓ | ✓ | NetBSD/sparc64 diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs index d675c9082e554..3c37cc6e46aff 100644 --- a/src/tools/build-manifest/src/main.rs +++ b/src/tools/build-manifest/src/main.rs @@ -130,6 +130,7 @@ static TARGETS: &[&str] = &[ "riscv64gc-unknown-none-elf", "riscv64gc-unknown-linux-gnu", "s390x-unknown-linux-gnu", + "sbf-solana-solana", "sparc64-unknown-linux-gnu", "sparcv9-sun-solaris", "sparc-unknown-none-elf", diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 63e8ba7c79f9f..282d8310b8ff8 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2191,9 +2191,10 @@ impl<'test> TestCx<'test> { || self.config.target.contains("wasm32") || self.config.target.contains("nvptx") || self.is_vxworks_pure_static() - || self.config.target.contains("bpf") || !self.config.target_cfg().dynamic_linking || matches!(self.config.mode, CoverageMap | CoverageRun) + || self.config.target.contains("bpf") + || self.config.target.contains("sbf") { // We primarily compile all auxiliary libraries as dynamic libraries // to avoid code size bloat and large binaries as much as possible diff --git a/tests/codegen/sbf-alu32.rs b/tests/codegen/sbf-alu32.rs new file mode 100644 index 0000000000000..47aaeb093dacd --- /dev/null +++ b/tests/codegen/sbf-alu32.rs @@ -0,0 +1,11 @@ +// only-sbf +#![crate_type = "lib"] +#![feature(sbf_target_feature)] +#![no_std] + +#[no_mangle] +#[target_feature(enable = "alu32")] +// CHECK: define i8 @foo(i8 returned %arg) unnamed_addr #0 { +pub unsafe fn foo(arg: u8) -> u8 { + arg +} diff --git a/tests/ui/target-feature/gate.rs b/tests/ui/target-feature/gate.rs index 971a4654b4cec..fb6097551d029 100644 --- a/tests/ui/target-feature/gate.rs +++ b/tests/ui/target-feature/gate.rs @@ -19,6 +19,7 @@ // gate-test-aarch64_ver_target_feature // gate-test-csky_target_feature // gate-test-loongarch_target_feature +// gate-test-sbf_target_feature #[target_feature(enable = "avx512bw")] //~^ ERROR: currently unstable diff --git a/tests/ui/target-feature/gate.stderr b/tests/ui/target-feature/gate.stderr index 0ec7427c3c456..8877b41c65049 100644 --- a/tests/ui/target-feature/gate.stderr +++ b/tests/ui/target-feature/gate.stderr @@ -1,5 +1,5 @@ error[E0658]: the target feature `avx512bw` is currently unstable - --> $DIR/gate.rs:23:18 + --> $DIR/gate.rs:24:18 | LL | #[target_feature(enable = "avx512bw")] | ^^^^^^^^^^^^^^^^^^^ From 430579c5f8436267580a43d1bb43c7175b7898d3 Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Thu, 16 Dec 2021 12:59:44 +1100 Subject: [PATCH 060/103] [SOL] make all core tests (but atomics) pass This makes all the core tests pass. - Removes the use of thread_local!()s. The API can't be implemented without adding rbpf shims, which seems pointless. - Hardcodes ThreadId::new() to return 1, disabling upstream code that creates static muts. - Re-enables UpperExp / LowerExp impls - only float code stays disabled - Reduces stack size in some tests. - Hardcodes a static seed in tests that use the rand crate. --- library/core/src/fmt/num.rs | 4 -- library/core/tests/lazy.rs | 3 ++ library/core/tests/lib.rs | 6 --- library/core/tests/num/mod.rs | 2 + library/core/tests/ptr.rs | 3 ++ library/core/tests/slice.rs | 24 +++++----- library/std/src/collections/hash/map.rs | 45 ++++++++++--------- library/std/src/thread/mod.rs | 7 ++- .../bpfel-unknown-unknown/Dockerfile | 5 ++- 9 files changed, 54 insertions(+), 45 deletions(-) diff --git a/library/core/src/fmt/num.rs b/library/core/src/fmt/num.rs index 34cf989de0895..bc84f662f5c75 100644 --- a/library/core/src/fmt/num.rs +++ b/library/core/src/fmt/num.rs @@ -2,7 +2,6 @@ use crate::fmt; use crate::mem::MaybeUninit; -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] use crate::num::fmt as numfmt; use crate::ops::{Div, Rem, Sub}; use crate::ptr; @@ -295,7 +294,6 @@ macro_rules! impl_Display { }; } -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] macro_rules! impl_Exp { ($($t:ident),* as $u:ident via $conv_fn:ident named $name:ident) => { fn $name( @@ -470,7 +468,6 @@ mod imp { as u64 via to_u64 named fmt_u64 ); - #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] impl_Exp!( i8, u8, i16, u16, i32, u32, i64, u64, usize, isize as u64 via to_u64 named exp_u64 @@ -486,7 +483,6 @@ mod imp { impl_Exp!(i64, u64 as u64 via to_u64 named exp_u64); } -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] impl_Exp!(i128, u128 as u128 via to_u128 named exp_u128); /// Helper function for writing a u64 into `buf` going from last to first, with `curr`. diff --git a/library/core/tests/lazy.rs b/library/core/tests/lazy.rs index 7f7f1f0058801..ba2dc88eaa248 100644 --- a/library/core/tests/lazy.rs +++ b/library/core/tests/lazy.rs @@ -1,3 +1,4 @@ +#![allow(unused_imports)] use core::{ cell::{Cell, LazyCell, OnceCell}, sync::atomic::{AtomicUsize, Ordering::SeqCst}, @@ -23,6 +24,8 @@ fn once_cell_get_mut() { assert_eq!(c.get_mut(), Some(&mut 92)); } +// sbf doesn't have mutable static data +#[cfg(not(any(target_arch = "bpf", target_arg = "sbf")))] #[test] fn once_cell_drop() { static DROP_CNT: AtomicUsize = AtomicUsize::new(0); diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 33276edcfc318..a26e00737cf31 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -133,15 +133,12 @@ mod clone; mod cmp; mod const_ptr; mod convert; -#[cfg(not(target_arch = "bpf"))] mod fmt; mod future; -#[cfg(not(target_arch = "bpf"))] mod hash; mod intrinsics; mod io; mod iter; -#[cfg(not(target_arch = "bpf"))] mod lazy; #[cfg(test)] mod macros; @@ -149,7 +146,6 @@ mod manually_drop; mod mem; mod net; mod nonzero; -#[cfg(not(target_arch = "bpf"))] mod num; mod ops; mod option; @@ -157,11 +153,9 @@ mod panic; mod pattern; mod pin; mod pin_macro; -#[cfg(not(target_arch = "bpf"))] mod ptr; mod result; mod simd; -#[cfg(not(target_arch = "bpf"))] mod slice; mod str; mod str_lossy; diff --git a/library/core/tests/num/mod.rs b/library/core/tests/num/mod.rs index 3f3659ba837d5..bfa9e52e7de6a 100644 --- a/library/core/tests/num/mod.rs +++ b/library/core/tests/num/mod.rs @@ -30,6 +30,8 @@ mod bignum; mod const_from; mod dec2flt; +// sbf doesn't support floats +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] mod flt2dec; mod int_log; mod ops; diff --git a/library/core/tests/ptr.rs b/library/core/tests/ptr.rs index ee885adfeee61..10f20328187cb 100644 --- a/library/core/tests/ptr.rs +++ b/library/core/tests/ptr.rs @@ -1,3 +1,4 @@ +#![allow(unused_imports)] use core::cell::RefCell; use core::mem::{self, MaybeUninit}; use core::num::NonZeroUsize; @@ -320,6 +321,8 @@ pub fn test_variadic_fnptr() { assert_eq!(p.hash(&mut s), q.hash(&mut s)); } +// sbf doesn't support thread locals +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] #[test] fn write_unaligned_drop() { thread_local! { diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs index 666452ead3f5a..1fa0ac9e07a8f 100644 --- a/library/core/tests/slice.rs +++ b/library/core/tests/slice.rs @@ -1735,31 +1735,31 @@ fn test_iter_folds() { #[test] fn test_rotate_left() { const N: usize = 600; - let a: &mut [_] = &mut [0; N]; + let a: &mut [_] = &mut [0u8; N]; for i in 0..N { - a[i] = i; + a[i] = i as u8; } a.rotate_left(42); let k = N - 42; for i in 0..N { - assert_eq!(a[(i + k) % N], i); + assert_eq!(a[(i + k) % N], i as u8); } } #[test] fn test_rotate_right() { const N: usize = 600; - let a: &mut [_] = &mut [0; N]; + let a: &mut [_] = &mut [0u8; N]; for i in 0..N { - a[i] = i; + a[i] = i as u8; } a.rotate_right(42); for i in 0..N { - assert_eq!(a[(i + 42) % N], i); + assert_eq!(a[(i + 42) % N], i as u8); } } @@ -1809,12 +1809,12 @@ fn sort_unstable() { use rand::{seq::SliceRandom, Rng}; // Miri is too slow (but still need to `chain` to make the types match) - let lens = if cfg!(miri) { (2..20).chain(0..0) } else { (2..25).chain(500..510) }; + let lens = if cfg!(miri) { (2..20).chain(0..0) } else { (2..25).chain(200..210) }; let rounds = if cfg!(miri) { 1 } else { 100 }; - let mut v = [0; 600]; - let mut tmp = [0; 600]; - let mut rng = crate::test_rng(); + let mut v = [0; 300]; + let mut tmp = [0; 300]; + let mut rng = StdRng::seed_from_u64(0); for len in lens { let v = &mut v[0..len]; @@ -1883,9 +1883,9 @@ fn select_nth_unstable() { use rand::seq::SliceRandom; use rand::Rng; - let mut rng = crate::test_rng(); + let mut rng = StdRng::seed_from_u64(0); - for len in (2..21).chain(500..501) { + for len in (2..21).chain(200..201) { let mut orig = vec![0; len]; for &modulus in &[5, 10, 1000] { diff --git a/library/std/src/collections/hash/map.rs b/library/std/src/collections/hash/map.rs index 4d109285d1645..5e0df1170b0d8 100644 --- a/library/std/src/collections/hash/map.rs +++ b/library/std/src/collections/hash/map.rs @@ -3111,26 +3111,31 @@ impl RandomState { #[must_use] #[stable(feature = "hashmap_build_hasher", since = "1.7.0")] pub fn new() -> RandomState { - // Historically this function did not cache keys from the OS and instead - // simply always called `rand::thread_rng().gen()` twice. In #31356 it - // was discovered, however, that because we re-seed the thread-local RNG - // from the OS periodically that this can cause excessive slowdown when - // many hash maps are created on a thread. To solve this performance - // trap we cache the first set of randomly generated keys per-thread. - // - // Later in #36481 it was discovered that exposing a deterministic - // iteration order allows a form of DOS attack. To counter that we - // increment one of the seeds on every RandomState creation, giving - // every corresponding HashMap a different iteration order. - thread_local!(static KEYS: Cell<(u64, u64)> = { - Cell::new(sys::hashmap_random_keys()) - }); - - KEYS.with(|keys| { - let (k0, k1) = keys.get(); - keys.set((k0.wrapping_add(1), k1)); - RandomState { k0, k1 } - }) + if cfg!(any(target_arch = "bpf", target_arch = "sbf")) { + // sbf doesn't support thread_local!() + RandomState { k0: 0, k1: 0 } + } else { + // Historically this function did not cache keys from the OS and instead + // simply always called `rand::thread_rng().gen()` twice. In #31356 it + // was discovered, however, that because we re-seed the thread-local RNG + // from the OS periodically that this can cause excessive slowdown when + // many hash maps are created on a thread. To solve this performance + // trap we cache the first set of randomly generated keys per-thread. + // + // Later in #36481 it was discovered that exposing a deterministic + // iteration order allows a form of DOS attack. To counter that we + // increment one of the seeds on every RandomState creation, giving + // every corresponding HashMap a different iteration order. + thread_local!(static KEYS: Cell<(u64, u64)> = { + Cell::new(sys::hashmap_random_keys()) + }); + + KEYS.with(|keys| { + let (k0, k1) = keys.get(); + keys.set((k0.wrapping_add(1), k1)); + RandomState { k0, k1 } + }) + } } } diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index be72bb2a9f983..52c9d1343ed37 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -1249,7 +1249,7 @@ impl ThreadId { Err(id) => last = id, } } - } else { + } else if #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] { use crate::sync::{Mutex, PoisonError}; static COUNTER: Mutex = Mutex::new(0); @@ -1265,6 +1265,11 @@ impl ThreadId { *counter = id; drop(counter); ThreadId(NonZeroU64::new(id).unwrap()) + } else { + // threads are not supported in sbf, so this isn't actually used + // anywhere. This branch of the if is only to avoid creating static + // mutable data. + ThreadId(NonZeroU64::new(1).unwrap()) } } } diff --git a/src/ci/docker/host-x86_64/bpfel-unknown-unknown/Dockerfile b/src/ci/docker/host-x86_64/bpfel-unknown-unknown/Dockerfile index d7468f6a9532f..75ab959f167cc 100644 --- a/src/ci/docker/host-x86_64/bpfel-unknown-unknown/Dockerfile +++ b/src/ci/docker/host-x86_64/bpfel-unknown-unknown/Dockerfile @@ -21,7 +21,8 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y RUN PATH="${HOME}/.cargo/bin:${PATH}" \ cargo install --git https://github.com/solana-labs/cargo-run-bpf-tests.git \ - --bin cargo-run-bpf-tests --root /usr/local + --rev 4cae9c0 \ + --bin cargo-run-bpf-tests --root /usr/local COPY scripts/sccache.sh /scripts/ RUN sh /scripts/sccache.sh @@ -30,7 +31,7 @@ ENV RUST_CONFIGURE_ARGS \ --set rust.lld \ --set llvm.clang -ENV SCRIPT CARGO_TARGET_BPFEL_UNKNOWN_UNKNOWN_RUNNER=cargo-run-bpf-tests \ +ENV SCRIPT CARGO_TARGET_BPFEL_UNKNOWN_UNKNOWN_RUNNER=\"cargo-run-bpf-tests --heap-size 104857600\" \ LLVM_HOME=/checkout/obj/build/x86_64-unknown-linux-gnu/llvm \ PATH="${HOME}/.cargo/bin:${PATH}" \ python3 /checkout/x.py --stage 1 test --host='' --target bpfel-unknown-unknown \ From 5d567f9a33d4e190f410725c6a37c07a69b49a5f Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Wed, 22 Dec 2021 11:48:07 -0800 Subject: [PATCH 061/103] [SOL] Fix missing SBF customizations --- compiler/rustc_codegen_ssa/src/back/linker.rs | 2 +- library/core/tests/lazy.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index 7f0bc9f379a60..333d1297de216 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -354,7 +354,7 @@ impl<'a> GccLinker<'a> { self.linker_arg(&format!("--out-implib={}", (*implib).to_str().unwrap())); } } - } else if self.sess.target.arch == "bpf" { + } else if self.sess.target.arch == "bpf" || self.sess.target.arch == "sbf" { if self.sess.opts.test { self.linker_arg("--entry=main"); } else { diff --git a/library/core/tests/lazy.rs b/library/core/tests/lazy.rs index ba2dc88eaa248..225975b43948e 100644 --- a/library/core/tests/lazy.rs +++ b/library/core/tests/lazy.rs @@ -25,7 +25,7 @@ fn once_cell_get_mut() { } // sbf doesn't have mutable static data -#[cfg(not(any(target_arch = "bpf", target_arg = "sbf")))] +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] #[test] fn once_cell_drop() { static DROP_CNT: AtomicUsize = AtomicUsize::new(0); From d3e1438057b596caf46f7453728e4fb3151e7014 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Tue, 14 Dec 2021 18:42:41 -0800 Subject: [PATCH 062/103] [SOL] CI: build and test sbf target --- .github/workflows/ci.yml | 4 ++-- build.sh | 2 +- library/core/tests/lib.rs | 2 +- src/ci/docker/host-x86_64/dist-various-1/Dockerfile | 2 +- .../{bpfel-unknown-unknown => sbf-solana-solana}/Dockerfile | 3 ++- src/ci/github-actions/ci.yml | 4 ++-- 6 files changed, 9 insertions(+), 8 deletions(-) rename src/ci/docker/host-x86_64/{bpfel-unknown-unknown => sbf-solana-solana}/Dockerfile (88%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 99117659c9967..f68840dd88550 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,7 +62,7 @@ jobs: ENABLE_GCC_CODEGEN: "1" os: ubuntu-20.04-16core-64gb env: {} - - name: bpfel-unknown-unknown + - name: sbf-solana-solana os: ubuntu-latest env: {} - name: x86_64-gnu-tools @@ -195,7 +195,7 @@ jobs: - name: x86_64-gnu-llvm-10 os: ubuntu-latest env: {} - - name: bpfel-unknown-unknown + - name: sbf-solana-solana os: ubuntu-latest env: {} timeout-minutes: 600 diff --git a/build.sh b/build.sh index 13ad72449caa6..03051d7a23c4a 100755 --- a/build.sh +++ b/build.sh @@ -19,4 +19,4 @@ esac if [ "$1" == "--llvm" ]; then rm -f build/${HOST_TRIPLE}/llvm/llvm-finished-building; fi -./x.py build --stage 1 --target ${HOST_TRIPLE},bpfel-unknown-unknown +./x.py build --stage 1 --target ${HOST_TRIPLE},bpfel-unknown-unknown,sbf-solana-solana diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index a26e00737cf31..0acea3a5f6891 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -124,7 +124,7 @@ mod any; mod array; mod ascii; mod asserting; -#[cfg(not(target_arch = "bpf"))] +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] mod atomic; mod bool; mod cell; diff --git a/src/ci/docker/host-x86_64/dist-various-1/Dockerfile b/src/ci/docker/host-x86_64/dist-various-1/Dockerfile index bafde50c41635..68e51873c5381 100644 --- a/src/ci/docker/host-x86_64/dist-various-1/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-various-1/Dockerfile @@ -104,7 +104,7 @@ ENV TARGETS=$TARGETS,armv7r-none-eabi ENV TARGETS=$TARGETS,armv7r-none-eabihf ENV TARGETS=$TARGETS,thumbv7neon-unknown-linux-gnueabihf ENV TARGETS=$TARGETS,armv7a-none-eabi -ENV TARGETS=$TARGETS,bpfel-unknown-unknown +ENV TARGETS=$TARGETS,sbf-solana-solana # riscv targets currently do not need a C compiler, as compiler_builtins # doesn't currently have it enabled, and the riscv gcc compiler is not diff --git a/src/ci/docker/host-x86_64/bpfel-unknown-unknown/Dockerfile b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile similarity index 88% rename from src/ci/docker/host-x86_64/bpfel-unknown-unknown/Dockerfile rename to src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile index 75ab959f167cc..c20a0a6e82e33 100644 --- a/src/ci/docker/host-x86_64/bpfel-unknown-unknown/Dockerfile +++ b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile @@ -32,7 +32,8 @@ ENV RUST_CONFIGURE_ARGS \ --set llvm.clang ENV SCRIPT CARGO_TARGET_BPFEL_UNKNOWN_UNKNOWN_RUNNER=\"cargo-run-bpf-tests --heap-size 104857600\" \ + CARGO_TARGET_SBF_SOLANA_SOLANA_RUNNER=\"cargo-run-bpf-tests --heap-size 104857600\" \ LLVM_HOME=/checkout/obj/build/x86_64-unknown-linux-gnu/llvm \ PATH="${HOME}/.cargo/bin:${PATH}" \ - python3 /checkout/x.py --stage 1 test --host='' --target bpfel-unknown-unknown \ + python3 /checkout/x.py --stage 1 test --host='' --target bpfel-unknown-unknown,sbf-solana-solana \ library/core diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml index a754fbf538497..26deebbaa8af1 100644 --- a/src/ci/github-actions/ci.yml +++ b/src/ci/github-actions/ci.yml @@ -343,7 +343,7 @@ jobs: ENABLE_GCC_CODEGEN: "1" <<: *job-linux-16c - - name: bpfel-unknown-unknown + - name: sbf-solana-solana <<: *job-linux-xl - name: x86_64-gnu-tools @@ -364,7 +364,7 @@ jobs: - name: x86_64-gnu-llvm-10 <<: *job-linux-xl - - name: bpfel-unknown-unknown + - name: sbf-solana-solana <<: *job-linux-xl auto: From 4495cdcd88ef21ccb592e060c49cc0a0669f3e29 Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Mon, 3 Jan 2022 11:55:48 +1100 Subject: [PATCH 063/103] [SOL] CI: speed up PR runs Deploy new sccache with support for SCCACHE_S3_NO_CREDENTIALS --- src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile | 2 +- src/ci/docker/run.sh | 1 + src/ci/docker/scripts/sccache.sh | 2 +- src/ci/github-actions/ci.yml | 1 + 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile index c20a0a6e82e33..146c2a08ebfe8 100644 --- a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile +++ b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile @@ -21,7 +21,7 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y RUN PATH="${HOME}/.cargo/bin:${PATH}" \ cargo install --git https://github.com/solana-labs/cargo-run-bpf-tests.git \ - --rev 4cae9c0 \ + --rev 3d628c7 \ --bin cargo-run-bpf-tests --root /usr/local COPY scripts/sccache.sh /scripts/ diff --git a/src/ci/docker/run.sh b/src/ci/docker/run.sh index cedbc0390f8ff..27cd04b7c11e8 100755 --- a/src/ci/docker/run.sh +++ b/src/ci/docker/run.sh @@ -186,6 +186,7 @@ args= if [ "$SCCACHE_BUCKET" != "" ]; then args="$args --env SCCACHE_BUCKET" args="$args --env SCCACHE_REGION" + args="$args --env SCCACHE_S3_NO_CREDENTIALS" args="$args --env AWS_ACCESS_KEY_ID" args="$args --env AWS_SECRET_ACCESS_KEY" args="$args --env AWS_REGION" diff --git a/src/ci/docker/scripts/sccache.sh b/src/ci/docker/scripts/sccache.sh index 626279efc8e45..4ea5ab6ffa285 100644 --- a/src/ci/docker/scripts/sccache.sh +++ b/src/ci/docker/scripts/sccache.sh @@ -6,7 +6,7 @@ set -ex case "$(uname -m)" in x86_64) - url="https://cached-ci-artifacts.s3.us-east-2.amazonaws.com/sccache-bc014e0-x86_64-unknown-linux-musl" + url="https://cached-ci-artifacts.s3.us-east-2.amazonaws.com/sccache-5d2a373-x86_64-unknown-linux-musl" ;; aarch64) url="https://ci-mirrors.rust-lang.org/rustc/2021-08-25-sccache-v0.2.15-aarch64-unknown-linux-musl" diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml index 26deebbaa8af1..71853fb6ab633 100644 --- a/src/ci/github-actions/ci.yml +++ b/src/ci/github-actions/ci.yml @@ -38,6 +38,7 @@ x--expand-yaml-anchors--remove: - &public-variables SCCACHE_BUCKET: cached-ci-artifacts SCCACHE_REGION: us-east-2 + SCCACHE_S3_NO_CREDENTIALS: 1 TOOLSTATE_REPO: https://github.com/rust-lang-nursery/rust-toolstate CACHE_DOMAIN: cached-ci-artifacts.s3.us-east-2.amazonaws.com From 3c8851309b7cebfca11f4e4ea9a11960adde38af Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Mon, 3 Jan 2022 19:51:11 +1100 Subject: [PATCH 064/103] [SOL] remove stubs for atomics (Pseudo) atomics are now implemented in SBF https://github.com/solana-labs/llvm-project/pull/23 --- library/core/tests/atomic.rs | 100 ++++++++++++++++++----------------- library/core/tests/lib.rs | 1 - 2 files changed, 52 insertions(+), 49 deletions(-) diff --git a/library/core/tests/atomic.rs b/library/core/tests/atomic.rs index a67a842d3407f..bd4ca75a8979e 100644 --- a/library/core/tests/atomic.rs +++ b/library/core/tests/atomic.rs @@ -212,38 +212,42 @@ fn ptr_bitops_tagging() { assert_eq!(atom.load(SeqCst), ptr); } -static S_FALSE: AtomicBool = AtomicBool::new(false); -static S_TRUE: AtomicBool = AtomicBool::new(true); -static S_INT: AtomicIsize = AtomicIsize::new(0); -static S_UINT: AtomicUsize = AtomicUsize::new(0); - -#[test] -fn static_init() { - // Note that we're not really testing the mutability here but it's important - // on Android at the moment (#49775) - assert!(!S_FALSE.swap(true, SeqCst)); - assert!(S_TRUE.swap(false, SeqCst)); - assert!(S_INT.fetch_add(1, SeqCst) == 0); - assert!(S_UINT.fetch_add(1, SeqCst) == 0); +// SBF does not support mustable static data +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +mod statik { + use super::*; + + static S_FALSE: AtomicBool = AtomicBool::new(false); + static S_TRUE: AtomicBool = AtomicBool::new(true); + static S_INT: AtomicIsize = AtomicIsize::new(0); + static S_UINT: AtomicUsize = AtomicUsize::new(0); + + #[test] + fn static_init() { + // Note that we're not really testing the mutability here but it's important + // on Android at the moment (#49775) + assert!(!S_FALSE.swap(true, SeqCst)); + assert!(S_TRUE.swap(false, SeqCst)); + assert!(S_INT.fetch_add(1, SeqCst) == 0); + assert!(S_UINT.fetch_add(1, SeqCst) == 0); + } } #[test] fn atomic_access_bool() { - static mut ATOMIC: AtomicBool = AtomicBool::new(false); - - unsafe { - assert_eq!(*ATOMIC.get_mut(), false); - ATOMIC.store(true, SeqCst); - assert_eq!(*ATOMIC.get_mut(), true); - ATOMIC.fetch_or(false, SeqCst); - assert_eq!(*ATOMIC.get_mut(), true); - ATOMIC.fetch_and(false, SeqCst); - assert_eq!(*ATOMIC.get_mut(), false); - ATOMIC.fetch_nand(true, SeqCst); - assert_eq!(*ATOMIC.get_mut(), true); - ATOMIC.fetch_xor(true, SeqCst); - assert_eq!(*ATOMIC.get_mut(), false); - } + let mut atomic: AtomicBool = AtomicBool::new(false); + + assert_eq!(*atomic.get_mut(), false); + atomic.store(true, SeqCst); + assert_eq!(*atomic.get_mut(), true); + atomic.fetch_or(false, SeqCst); + assert_eq!(*atomic.get_mut(), true); + atomic.fetch_and(false, SeqCst); + assert_eq!(*atomic.get_mut(), false); + atomic.fetch_nand(true, SeqCst); + assert_eq!(*atomic.get_mut(), true); + atomic.fetch_xor(true, SeqCst); + assert_eq!(*atomic.get_mut(), false); } #[test] @@ -284,26 +288,26 @@ fn atomic_alignment() { fn atomic_compare_exchange() { use Ordering::*; - static ATOMIC: AtomicIsize = AtomicIsize::new(0); - - ATOMIC.compare_exchange(0, 1, Relaxed, Relaxed).ok(); - ATOMIC.compare_exchange(0, 1, Acquire, Relaxed).ok(); - ATOMIC.compare_exchange(0, 1, Release, Relaxed).ok(); - ATOMIC.compare_exchange(0, 1, AcqRel, Relaxed).ok(); - ATOMIC.compare_exchange(0, 1, SeqCst, Relaxed).ok(); - ATOMIC.compare_exchange(0, 1, Acquire, Acquire).ok(); - ATOMIC.compare_exchange(0, 1, AcqRel, Acquire).ok(); - ATOMIC.compare_exchange(0, 1, SeqCst, Acquire).ok(); - ATOMIC.compare_exchange(0, 1, SeqCst, SeqCst).ok(); - ATOMIC.compare_exchange_weak(0, 1, Relaxed, Relaxed).ok(); - ATOMIC.compare_exchange_weak(0, 1, Acquire, Relaxed).ok(); - ATOMIC.compare_exchange_weak(0, 1, Release, Relaxed).ok(); - ATOMIC.compare_exchange_weak(0, 1, AcqRel, Relaxed).ok(); - ATOMIC.compare_exchange_weak(0, 1, SeqCst, Relaxed).ok(); - ATOMIC.compare_exchange_weak(0, 1, Acquire, Acquire).ok(); - ATOMIC.compare_exchange_weak(0, 1, AcqRel, Acquire).ok(); - ATOMIC.compare_exchange_weak(0, 1, SeqCst, Acquire).ok(); - ATOMIC.compare_exchange_weak(0, 1, SeqCst, SeqCst).ok(); + let atomic: AtomicIsize = AtomicIsize::new(0); + + atomic.compare_exchange(0, 1, Relaxed, Relaxed).ok(); + atomic.compare_exchange(0, 1, Acquire, Relaxed).ok(); + atomic.compare_exchange(0, 1, Release, Relaxed).ok(); + atomic.compare_exchange(0, 1, AcqRel, Relaxed).ok(); + atomic.compare_exchange(0, 1, SeqCst, Relaxed).ok(); + atomic.compare_exchange(0, 1, Acquire, Acquire).ok(); + atomic.compare_exchange(0, 1, AcqRel, Acquire).ok(); + atomic.compare_exchange(0, 1, SeqCst, Acquire).ok(); + atomic.compare_exchange(0, 1, SeqCst, SeqCst).ok(); + atomic.compare_exchange_weak(0, 1, Relaxed, Relaxed).ok(); + atomic.compare_exchange_weak(0, 1, Acquire, Relaxed).ok(); + atomic.compare_exchange_weak(0, 1, Release, Relaxed).ok(); + atomic.compare_exchange_weak(0, 1, AcqRel, Relaxed).ok(); + atomic.compare_exchange_weak(0, 1, SeqCst, Relaxed).ok(); + atomic.compare_exchange_weak(0, 1, Acquire, Acquire).ok(); + atomic.compare_exchange_weak(0, 1, AcqRel, Acquire).ok(); + atomic.compare_exchange_weak(0, 1, SeqCst, Acquire).ok(); + atomic.compare_exchange_weak(0, 1, SeqCst, SeqCst).ok(); } /* FIXME(#110395) diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 0acea3a5f6891..168b47dc99cc6 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -124,7 +124,6 @@ mod any; mod array; mod ascii; mod asserting; -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] mod atomic; mod bool; mod cell; From e87cbe12e88611ece69fc13de946f5251cf35705 Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Fri, 4 Feb 2022 14:00:54 +1100 Subject: [PATCH 065/103] [SOL] use codegen-units=1 by default for SBF --- compiler/rustc_session/src/session.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 80a549b30f799..4f4b1341c15bd 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -1244,7 +1244,21 @@ impl Session { // As a result 16 was chosen here! Mostly because it was a power of 2 // and most benchmarks agreed it was roughly a local optimum. Not very // scientific. - CodegenUnits::Default(16) + + if self.target.options.vendor == "solana" { + // Default to 1 for SBF programs. It makes a huge difference in + // terms of generated code size for us + // (https://github.com/rust-lang/rust/issues/47745) and compilation + // time isn't a huge concern (programs tend to be small). It's still + // possible to override this from the command line or from cargo + // profiles. + // + // Note that we don't set default_codegen_units in the target + // definition as that would break incremental compilation. + CodegenUnits::Default(1) + } else { + CodegenUnits::Default(16) + } } pub fn teach(&self, code: &DiagnosticId) -> bool { From ad6cca56b43696b3b743ea8d4b5ff95bb809a1d2 Mon Sep 17 00:00:00 2001 From: Kenta Iwasaki Date: Mon, 24 Jan 2022 22:18:28 +0000 Subject: [PATCH 066/103] [SOL] build: add aarch64-linux target Add support for building for the aarch64-linux target. --- build.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 03051d7a23c4a..1dc775ba259d1 100755 --- a/build.sh +++ b/build.sh @@ -9,7 +9,8 @@ fi unameOut="$(uname -s)-$(uname -m)" case "${unameOut}" in - Linux*) HOST_TRIPLE=x86_64-unknown-linux-gnu;; + Linux-x86_64*) HOST_TRIPLE=x86_64-unknown-linux-gnu;; + Linux-aarch64*) HOST_TRIPLE=aarch64-unknown-linux-gnu;; Darwin-x86_64*) HOST_TRIPLE=x86_64-apple-darwin;; Darwin-arm64*) HOST_TRIPLE=aarch64-apple-darwin;; MINGW*) HOST_TRIPLE=x86_64-pc-windows-msvc;; From 42b144849fc1a0ed9bbf9e2db9f2fb066f96ab9e Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Tue, 22 Feb 2022 13:20:14 -0800 Subject: [PATCH 067/103] [SOL] Update run-bpf-tests revision in CI --- src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile index 146c2a08ebfe8..44b8faadf3682 100644 --- a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile +++ b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile @@ -21,7 +21,7 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y RUN PATH="${HOME}/.cargo/bin:${PATH}" \ cargo install --git https://github.com/solana-labs/cargo-run-bpf-tests.git \ - --rev 3d628c7 \ + --rev 5c19a51992e5ed922fbd9f0e97b6d270e153029a \ --bin cargo-run-bpf-tests --root /usr/local COPY scripts/sccache.sh /scripts/ From d726b063f9d903569826348217dd72fef3178c2c Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Tue, 29 Mar 2022 19:28:22 -0700 Subject: [PATCH 068/103] [SOL] Adjust BPF customization after upgrading to rust 1.59.0 --- compiler/rustc_codegen_gcc/src/type_.rs | 8 +++--- library/core/tests/array.rs | 2 ++ library/std/src/io/mod.rs | 1 + library/std/src/io/stdio.rs | 4 --- library/std/src/panicking.rs | 34 +++++++++++------------ library/std/src/rt.rs | 7 +++++ library/std/src/sys/sbf/fs.rs | 6 +++- library/std/src/sys/sbf/thread.rs | 9 +----- library/std/src/sys_common/thread_info.rs | 1 + library/std/src/thread/mod.rs | 19 +++++++++---- library/test/src/cli.rs | 5 ++++ library/test/src/lib.rs | 1 - 12 files changed, 57 insertions(+), 40 deletions(-) diff --git a/compiler/rustc_codegen_gcc/src/type_.rs b/compiler/rustc_codegen_gcc/src/type_.rs index 7a89fe81d3844..d30059eaaf5a8 100644 --- a/compiler/rustc_codegen_gcc/src/type_.rs +++ b/compiler/rustc_codegen_gcc/src/type_.rs @@ -26,10 +26,6 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> { } } - pub fn type_void(&self) -> Type<'gcc> { - self.context.new_type::<()>() - } - pub fn type_size_t(&self) -> Type<'gcc> { self.context.new_type::() } @@ -126,6 +122,10 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> { self.double_type } + fn type_void(&self) -> Type<'gcc> { + self.context.new_type::<()>() + } + fn type_func(&self, params: &[Type<'gcc>], return_type: Type<'gcc>) -> Type<'gcc> { self.context.new_function_pointer_type(None, return_type, params, false) } diff --git a/library/core/tests/array.rs b/library/core/tests/array.rs index 81da75d32a1c9..aca1cccf3a249 100644 --- a/library/core/tests/array.rs +++ b/library/core/tests/array.rs @@ -512,6 +512,7 @@ fn array_rsplit_array_mut_out_of_bounds() { } #[test] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] fn array_intoiter_advance_by() { use std::cell::Cell; struct DropCounter<'a>(usize, &'a Cell); @@ -565,6 +566,7 @@ fn array_intoiter_advance_by() { } #[test] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] fn array_intoiter_advance_back_by() { use std::cell::Cell; struct DropCounter<'a>(usize, &'a Cell); diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index 7d70a0bac24fd..47eec5320c348 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -344,6 +344,7 @@ mod util; const DEFAULT_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE; +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub(crate) use stdio::cleanup; struct Guard<'a> { diff --git a/library/std/src/io/stdio.rs b/library/std/src/io/stdio.rs index ad5b8fd1397e3..4cf3d06b43be2 100644 --- a/library/std/src/io/stdio.rs +++ b/library/std/src/io/stdio.rs @@ -585,10 +585,6 @@ impl Read for Stdin { fn is_read_vectored(&self) -> bool { false } - #[inline] - unsafe fn initializer(&self) -> Initializer { - Initializer::nop() - } fn read_to_end(&mut self, _buf: &mut Vec) -> io::Result { Ok(0) } diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index 040b774cacb26..6ec723562da89 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -927,23 +927,6 @@ pub fn rust_begin_panic(info: &PanicInfo<'_>) -> ! { crate::sys::panic(info); } -/// The entry point for panicking with a formatted message SBF version. -#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] -#[unstable(feature = "libstd_sys_internals", reason = "used by the panic! macro", issue = "none")] -#[cold] -// If panic_immediate_abort, inline the abort call, -// otherwise avoid inlining because of it is cold path. -#[cfg_attr(not(feature = "panic_immediate_abort"), track_caller)] -#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))] -#[cfg_attr(feature = "panic_immediate_abort", inline)] -pub fn begin_panic_fmt(msg: &fmt::Arguments<'_>) -> ! { - let info = PanicInfo::internal_constructor( - Some(msg), - Location::caller(), - ); - crate::sys::panic(&info); -} - /// Entry point of panicking for panic!() and assert!() SBF version. #[cfg(any(target_arch = "bpf", target_arch = "sbf"))] #[unstable(feature = "libstd_sys_internals", reason = "used by the panic! macro", issue = "none")] @@ -961,3 +944,20 @@ pub fn begin_panic(_msg: M) -> ! { ); crate::sys::panic(&info); } + +/// The entry point for panicking with a formatted message SBF version. +#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[unstable(feature = "libstd_sys_internals", reason = "used by the panic! macro", issue = "none")] +#[cold] +// If panic_immediate_abort, inline the abort call, +// otherwise avoid inlining because of it is cold path. +#[cfg_attr(not(feature = "panic_immediate_abort"), track_caller)] +#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))] +#[cfg_attr(feature = "panic_immediate_abort", inline)] +pub fn begin_panic_fmt(msg: &fmt::Arguments<'_>) -> ! { + let info = PanicInfo::internal_constructor( + Some(msg), + Location::caller(), + ); + crate::sys::panic(&info); +} diff --git a/library/std/src/rt.rs b/library/std/src/rt.rs index e98c5773bfebd..7982c44e41893 100644 --- a/library/std/src/rt.rs +++ b/library/std/src/rt.rs @@ -16,15 +16,20 @@ #![deny(unsafe_op_in_unsafe_fn)] #![allow(unused_macros)] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] use crate::ffi::CString; // Re-export some of our utilities which are expected by other crates. pub use crate::panicking::{begin_panic, panic_count}; pub use core::panicking::{panic_display, panic_fmt}; +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] use crate::sync::Once; +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] use crate::sys; +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] use crate::sys_common::thread_info; +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] use crate::thread::Thread; // Prints to the "panic output", depending on the platform this may be: @@ -92,6 +97,7 @@ macro_rules! rtunwrap { // Even though it is an `u8`, it only ever has 4 values. These are documented in // `compiler/rustc_session/src/config/sigpipe.rs`. #[cfg_attr(test, allow(dead_code))] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) { unsafe { sys::init(argc, argv, sigpipe); @@ -109,6 +115,7 @@ unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) { // One-time runtime cleanup. // Runs after `main` or at program exit. // NOTE: this is not guaranteed to run, for example when the program aborts. +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub(crate) fn cleanup() { static CLEANUP: Once = Once::new(); CLEANUP.call_once(|| unsafe { diff --git a/library/std/src/sys/sbf/fs.rs b/library/std/src/sys/sbf/fs.rs index fe3197377ba64..2b9e18532af86 100644 --- a/library/std/src/sys/sbf/fs.rs +++ b/library/std/src/sys/sbf/fs.rs @@ -1,7 +1,7 @@ use crate::ffi::OsString; use crate::fmt; use crate::hash::{Hash, Hasher}; -use crate::io::{self, SeekFrom, IoSlice, IoSliceMut}; +use crate::io::{self, SeekFrom, IoSlice, IoSliceMut, ReadBuf}; use crate::path::{Path, PathBuf}; use crate::sys::time::SystemTime; use crate::sys::{unsupported, Void}; @@ -209,6 +209,10 @@ impl File { false } + pub fn read_buf(&self, _buf: &mut ReadBuf<'_>) -> io::Result<()> { + match self.0 {} + } + pub fn write(&self, _buf: &[u8]) -> io::Result { match self.0 {} } diff --git a/library/std/src/sys/sbf/thread.rs b/library/std/src/sys/sbf/thread.rs index 3efd493aa336f..41dd0ace0920f 100644 --- a/library/std/src/sys/sbf/thread.rs +++ b/library/std/src/sys/sbf/thread.rs @@ -31,13 +31,6 @@ impl Thread { } } -pub fn available_concurrency() -> io::Result { +pub fn available_parallelism() -> io::Result { unsupported() } - -pub mod guard { - pub type Guard = !; - pub unsafe fn current() -> Option { - None - } -} diff --git a/library/std/src/sys_common/thread_info.rs b/library/std/src/sys_common/thread_info.rs index 8d51732e03588..383630a1491a5 100644 --- a/library/std/src/sys_common/thread_info.rs +++ b/library/std/src/sys_common/thread_info.rs @@ -1,3 +1,4 @@ +#![cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] #![allow(dead_code)] // stack_guard isn't used right now on all platforms use crate::cell::OnceCell; diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index 52c9d1343ed37..8256f858481f3 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -175,6 +175,7 @@ use crate::str; use crate::sync::Arc; use crate::sys::thread as imp; use crate::sys_common::thread; +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] use crate::sys_common::thread_info; use crate::sys_common::thread_parking::Parker; use crate::sys_common::{AsInner, IntoInner}; @@ -586,17 +587,15 @@ impl Builder { { let Builder { name, stack_size } = self; let stack_size = stack_size.unwrap_or_else(thread::min_stack); - let my_thread = Thread::new(name); + let my_thread = Thread::new(name.map(|name| { + CString::new(name).expect("thread name may not contain interior null bytes") + })); let their_thread = my_thread.clone(); let my_packet: Arc>>> = Arc::new(UnsafeCell::new(None)); let main = move || { if let Some(name) = their_thread.cname() { imp::Thread::set_name(name); } - // SAFETY: the stack guard passed is the one for the current thread. - // This means the current thread's stack and the new thread's stack - // are properly set and protected from each other. - thread_info::set(unsafe { imp::guard::current() }, their_thread); }; Ok(JoinHandle(JoinInner { @@ -761,6 +760,7 @@ where /// ``` #[must_use] #[stable(feature = "rust1", since = "1.0.0")] +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub fn current() -> Thread { thread_info::current_thread().expect( "use of std::thread::current() is not possible \ @@ -768,6 +768,15 @@ pub fn current() -> Thread { ) } +/// SBF dummy version +/// +#[must_use] +#[stable(feature = "rust1", since = "1.0.0")] +#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +pub fn current() -> Thread { + Thread::new(None) +} + /// Cooperatively gives up a timeslice to the OS scheduler. /// /// This calls the underlying OS scheduler's yield primitive, signaling diff --git a/library/test/src/cli.rs b/library/test/src/cli.rs index 292f52f72bd10..34f73cf758f94 100644 --- a/library/test/src/cli.rs +++ b/library/test/src/cli.rs @@ -239,6 +239,7 @@ macro_rules! unstable_optflag { } // Gets the option value and checks if unstable features are enabled. +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] macro_rules! unstable_optopt { ($matches:ident, $allow_unstable:ident, $option_name:literal) => {{ let opt = $matches.opt_str($option_name); @@ -325,6 +326,8 @@ fn parse_opts_impl(_matches: getopts::Matches) -> OptRes { nocapture: true, color: ColorConfig::NeverColor, format: OutputFormat::Pretty, + shuffle: false, + shuffle_seed: None, test_threads: Some(1), skip: Vec::new(), time_options: None, @@ -366,6 +369,7 @@ fn get_time_options( Ok(options) } +#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] fn get_shuffle(matches: &getopts::Matches, allow_unstable: bool) -> OptPartRes { let mut shuffle = unstable_optflag!(matches, allow_unstable, "shuffle"); if !shuffle && allow_unstable { @@ -378,6 +382,7 @@ fn get_shuffle(matches: &getopts::Matches, allow_unstable: bool) -> OptPartRes OptPartRes> { let mut shuffle_seed = match unstable_optopt!(matches, allow_unstable, "shuffle-seed") { Some(n_str) => match n_str.parse::() { diff --git a/library/test/src/lib.rs b/library/test/src/lib.rs index cd0a3bdb60a9c..b9fcbdda497b8 100644 --- a/library/test/src/lib.rs +++ b/library/test/src/lib.rs @@ -14,7 +14,6 @@ // running tests while providing a base that other test frameworks may // build off of. -#![cfg(not(target_arch = "bpf"))] // N.B., this is also specified in this crate's Cargo.toml, but librustc_ast contains logic specific to // this crate, which relies on this attribute (rather than the value of `--crate-name` passed by // cargo) to detect this crate. From d71b0f97e46b313020fcfff660ae337e1c781bf7 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Fri, 1 Apr 2022 18:13:18 -0700 Subject: [PATCH 069/103] [SOL] Skip 'ensure the stable version number is correct' step in CI --- .github/workflows/ci.yml | 14 +++++++++++--- src/ci/github-actions/ci.yml | 2 ++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f68840dd88550..359801a7e0e8c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -146,6 +146,8 @@ jobs: if: success() && !env.SKIP_JOB - name: ensure the stable version number is correct run: src/ci/scripts/verify-stable-version-number.sh + env: + SKIP_JOB: 1 if: success() && !env.SKIP_JOB - name: run the build run: src/ci/scripts/run-build-from-ci.sh @@ -237,9 +239,6 @@ jobs: - name: install sccache run: src/ci/scripts/install-sccache.sh if: success() && !env.SKIP_JOB - - name: select Xcode - run: src/ci/scripts/select-xcode.sh - if: success() && !env.SKIP_JOB - name: install clang run: src/ci/scripts/install-clang.sh if: success() && !env.SKIP_JOB @@ -276,6 +275,11 @@ jobs: - name: ensure backported commits are in upstream branches run: src/ci/scripts/verify-backported-commits.sh if: success() && !env.SKIP_JOB + - name: ensure the stable version number is correct + run: src/ci/scripts/verify-stable-version-number.sh + env: + SKIP_JOB: 1 + if: success() && !env.SKIP_JOB - name: run the build run: src/ci/scripts/run-build-from-ci.sh env: @@ -658,6 +662,8 @@ jobs: if: success() && !env.SKIP_JOB - name: ensure the stable version number is correct run: src/ci/scripts/verify-stable-version-number.sh + env: + SKIP_JOB: 1 if: success() && !env.SKIP_JOB - name: run the build run: src/ci/scripts/run-build-from-ci.sh @@ -786,6 +792,8 @@ jobs: if: success() && !env.SKIP_JOB - name: ensure the stable version number is correct run: src/ci/scripts/verify-stable-version-number.sh + env: + SKIP_JOB: 1 if: success() && !env.SKIP_JOB - name: run the build run: src/ci/scripts/run-build-from-ci.sh diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml index 71853fb6ab633..58e8060f88074 100644 --- a/src/ci/github-actions/ci.yml +++ b/src/ci/github-actions/ci.yml @@ -227,6 +227,8 @@ x--expand-yaml-anchors--remove: - name: ensure the stable version number is correct run: src/ci/scripts/verify-stable-version-number.sh + env: + SKIP_JOB: 1 <<: *step - name: run the build From d5561adb678501627568f339bfdd7d61e3ae8ae9 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Fri, 1 Apr 2022 18:13:45 -0700 Subject: [PATCH 070/103] [SOL] Update run-bpf-tests revision in CI --- src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile index 44b8faadf3682..381c3cd2f35ea 100644 --- a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile +++ b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile @@ -21,7 +21,7 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y RUN PATH="${HOME}/.cargo/bin:${PATH}" \ cargo install --git https://github.com/solana-labs/cargo-run-bpf-tests.git \ - --rev 5c19a51992e5ed922fbd9f0e97b6d270e153029a \ + --rev 7eb5ae15b1870c3bb41634737d29dd9a395060f8 \ --bin cargo-run-bpf-tests --root /usr/local COPY scripts/sccache.sh /scripts/ From 09ec2c61dff8f00e1663b4d2a300b17add496ba3 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Sat, 2 Apr 2022 10:33:49 -0700 Subject: [PATCH 071/103] [SOL] Temporary disable some failing core tests --- library/core/benches/num/int_log/mod.rs | 1 + library/core/tests/array.rs | 1 + library/core/tests/future.rs | 1 + 3 files changed, 3 insertions(+) diff --git a/library/core/benches/num/int_log/mod.rs b/library/core/benches/num/int_log/mod.rs index bb61224b5baad..050a88f7281b4 100644 --- a/library/core/benches/num/int_log/mod.rs +++ b/library/core/benches/num/int_log/mod.rs @@ -1,3 +1,4 @@ +#![cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] use rand::Rng; use test::{black_box, Bencher}; diff --git a/library/core/tests/array.rs b/library/core/tests/array.rs index aca1cccf3a249..740275fc44764 100644 --- a/library/core/tests/array.rs +++ b/library/core/tests/array.rs @@ -1,3 +1,4 @@ +#![cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] use core::{array, assert_eq}; use core::convert::TryFrom; use core::num::NonZeroUsize; diff --git a/library/core/tests/future.rs b/library/core/tests/future.rs index db417256dd01e..f0549da14e2ab 100644 --- a/library/core/tests/future.rs +++ b/library/core/tests/future.rs @@ -1,3 +1,4 @@ +#![cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] use std::future::{join, Future}; use std::pin::Pin; use std::sync::Arc; From d41d4c0006ea5194b61b15ef41a4c09a4835d02c Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 18 Feb 2022 09:51:20 -0700 Subject: [PATCH 072/103] [SOL] Don't create invalid string slices in stdout/stderr on Solana --- library/std/src/alloc.rs | 2 +- library/std/src/io/stdio.rs | 16 ++++------------ library/std/src/sys/sbf/mod.rs | 2 +- library/std/src/sys/sbf/stdio.rs | 8 ++------ 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/library/std/src/alloc.rs b/library/std/src/alloc.rs index fb5f69c10ced6..b01b8f5300424 100644 --- a/library/std/src/alloc.rs +++ b/library/std/src/alloc.rs @@ -378,7 +378,7 @@ pub fn rust_oom(_layout: Layout) -> ! { } #[cfg(any(target_arch = "bpf", target_arch = "sbf"))] { - crate::sys::sol_log("Error: memory allocation failed, out of memory"); + crate::sys::sol_log(b"Error: memory allocation failed, out of memory"); } crate::process::abort() } diff --git a/library/std/src/io/stdio.rs b/library/std/src/io/stdio.rs index 4cf3d06b43be2..743ace5ce6cea 100644 --- a/library/std/src/io/stdio.rs +++ b/library/std/src/io/stdio.rs @@ -918,9 +918,7 @@ impl Write for Stdout { #[cfg(any(target_arch = "bpf", target_arch = "sbf"))] impl Write for Stdout { fn write(&mut self, buf: &[u8]) -> io::Result { - unsafe { - crate::sys::sol_log(core::str::from_utf8_unchecked(buf)); - } + crate::sys::sol_log(buf); Ok(buf.len()) } fn write_vectored(&mut self, _bufs: &[IoSlice<'_>]) -> io::Result { @@ -934,9 +932,7 @@ impl Write for Stdout { Ok(()) } fn write_all(&mut self, buf: &[u8]) -> io::Result<()> { - unsafe { - crate::sys::sol_log(core::str::from_utf8_unchecked(buf)); - } + crate::sys::sol_log(buf); Ok(()) } fn write_all_vectored(&mut self, _bufs: &mut [IoSlice<'_>]) -> io::Result<()> { @@ -1266,9 +1262,7 @@ impl Write for Stderr { #[cfg(any(target_arch = "bpf", target_arch = "sbf"))] impl Write for Stderr { fn write(&mut self, buf: &[u8]) -> io::Result { - unsafe { - crate::sys::sol_log(core::str::from_utf8_unchecked(buf)); - } + crate::sys::sol_log(buf); Ok(buf.len()) } fn write_vectored(&mut self, _bufs: &[IoSlice<'_>]) -> io::Result { @@ -1282,9 +1276,7 @@ impl Write for Stderr { Ok(()) } fn write_all(&mut self, buf: &[u8]) -> io::Result<()> { - unsafe { - crate::sys::sol_log(core::str::from_utf8_unchecked(buf)); - } + crate::sys::sol_log(buf); Ok(()) } fn write_all_vectored(&mut self, _bufs: &mut [IoSlice<'_>]) -> io::Result<()> { diff --git a/library/std/src/sys/sbf/mod.rs b/library/std/src/sys/sbf/mod.rs index ff49c4e3b329d..f5bf4bd825aad 100644 --- a/library/std/src/sys/sbf/mod.rs +++ b/library/std/src/sys/sbf/mod.rs @@ -49,7 +49,7 @@ extern "C" { fn sol_log_(message: *const u8, length: u64); } -pub fn sol_log(message: &str) { +pub fn sol_log(message: &[u8]) { unsafe { sol_log_(message.as_ptr(), message.len() as u64); } diff --git a/library/std/src/sys/sbf/stdio.rs b/library/std/src/sys/sbf/stdio.rs index c157eb66dbcde..1a66bc8cf6794 100644 --- a/library/std/src/sys/sbf/stdio.rs +++ b/library/std/src/sys/sbf/stdio.rs @@ -18,9 +18,7 @@ impl Stdout { impl io::Write for Stdout { fn write(&mut self, buf: &[u8]) -> io::Result { - unsafe { - crate::sys::sol_log(core::str::from_utf8_unchecked(buf)); - } + crate::sys::sol_log(buf); Ok(buf.len()) } @@ -34,9 +32,7 @@ impl Stderr { impl io::Write for Stderr { fn write(&mut self, buf: &[u8]) -> io::Result { - unsafe { - crate::sys::sol_log(core::str::from_utf8_unchecked(buf)); - } + crate::sys::sol_log(buf); Ok(buf.len()) } From 63579e1e3355116a4ba91acd5e833b0a9bc0d1ba Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Fri, 25 Mar 2022 18:44:21 +1100 Subject: [PATCH 073/103] [SOL] tweak linker script Ensure that all read only sections end up in one segment, and everything else in other segments. Discard .eh_frame, .hash and .gnu.hash since they are unused. --- compiler/rustc_target/src/spec/sbf_base.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/compiler/rustc_target/src/spec/sbf_base.rs b/compiler/rustc_target/src/spec/sbf_base.rs index bbd7f6205da88..1c5c8e61c6b3c 100644 --- a/compiler/rustc_target/src/spec/sbf_base.rs +++ b/compiler/rustc_target/src/spec/sbf_base.rs @@ -8,6 +8,7 @@ PHDRS { text PT_LOAD ; rodata PT_LOAD ; + data PT_LOAD ; dynamic PT_DYNAMIC ; } @@ -18,6 +19,14 @@ SECTIONS .rodata : { *(.rodata*) } :rodata .data.rel.ro : { *(.data.rel.ro*) } :rodata .dynamic : { *(.dynamic) } :dynamic + .dynsym : { *(.dynsym) } :data + .dynstr : { *(.dynstr) } :data + .rel.dyn : { *(.rel.dyn) } :data + /DISCARD/ : { + *(.eh_frame*) + *(.gnu.hash*) + *(.hash*) + } } "; let mut lld_args = Vec::new(); From 83ad57fb21ca816a67533859dfe017d985037ecd Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Wed, 27 Apr 2022 10:58:00 -0700 Subject: [PATCH 074/103] [SOL] Update run-bpf-tests revision in CI --- src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile index 381c3cd2f35ea..21ce98bef8e99 100644 --- a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile +++ b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile @@ -21,7 +21,7 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y RUN PATH="${HOME}/.cargo/bin:${PATH}" \ cargo install --git https://github.com/solana-labs/cargo-run-bpf-tests.git \ - --rev 7eb5ae15b1870c3bb41634737d29dd9a395060f8 \ + --rev f0b78a1be039fdbeec41a21a7226368f197eacbf \ --bin cargo-run-bpf-tests --root /usr/local COPY scripts/sccache.sh /scripts/ From 4419577334f1bffe1a17c3b27161ba5f4700ed79 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Mon, 2 May 2022 10:24:42 -0700 Subject: [PATCH 075/103] [SOL] Update run-bpf-tests revision in CI --- src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile index 21ce98bef8e99..c7b091c0b650a 100644 --- a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile +++ b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile @@ -21,7 +21,7 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y RUN PATH="${HOME}/.cargo/bin:${PATH}" \ cargo install --git https://github.com/solana-labs/cargo-run-bpf-tests.git \ - --rev f0b78a1be039fdbeec41a21a7226368f197eacbf \ + --rev f0201b677976190568b8a04d8ede018fc6ccf053 \ --bin cargo-run-bpf-tests --root /usr/local COPY scripts/sccache.sh /scripts/ From 00b04aa0529fc09e8d088bdb688380509a0bfaa3 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Mon, 2 May 2022 14:45:12 -0700 Subject: [PATCH 076/103] [SOL] Prefer command line supplied linker script over embedded one --- compiler/rustc_codegen_ssa/src/back/link.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index dd9d277fb7757..8aec3df29d9a0 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -1798,7 +1798,7 @@ fn add_pre_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) cmd.args(&sess.opts.unstable_opts.pre_link_args); } -/// Add a link script embedded in the target, if applicable. +/// Add a link script embedded in the target, if applicable and not found in the command line. fn add_link_script(cmd: &mut dyn Linker, sess: &Session, tmpdir: &Path, crate_type: CrateType) { match (crate_type, &sess.target.link_script) { (CrateType::Cdylib | CrateType::Executable, Some(script)) => { @@ -1806,6 +1806,11 @@ fn add_link_script(cmd: &mut dyn Linker, sess: &Session, tmpdir: &Path, crate_ty sess.emit_fatal(errors::LinkScriptUnavailable); } + if sess.opts.cg.link_args.contains(&String::from("--script")) + || sess.opts.cg.link_args.contains(&String::from("-T")) { + return; + } + let file_name = ["rustc", &sess.target.llvm_target, "linkfile.ld"].join("-"); let path = tmpdir.join(file_name); From 09c7774541d9d5199e9744f3692515554ea98217 Mon Sep 17 00:00:00 2001 From: aimeedeer Date: Sat, 26 Mar 2022 11:38:54 -0600 Subject: [PATCH 077/103] [SOL] Enable the std backtrace API --- library/std/src/backtrace.rs | 85 ++++++++++++++++++++++++++++++++++++ library/std/src/lib.rs | 1 - 2 files changed, 85 insertions(+), 1 deletion(-) diff --git a/library/std/src/backtrace.rs b/library/std/src/backtrace.rs index e7110aebdea16..7596d7e41ec40 100644 --- a/library/std/src/backtrace.rs +++ b/library/std/src/backtrace.rs @@ -88,6 +88,7 @@ mod tests; // `Backtrace`, but that's a relatively small price to pay relative to capturing // a backtrace or actually symbolizing it. +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] use crate::backtrace_rs::{self, BytesOrWideString}; use crate::env; use crate::ffi::c_void; @@ -95,6 +96,7 @@ use crate::fmt; use crate::panic::UnwindSafe; use crate::sync::atomic::{AtomicUsize, Ordering::Relaxed}; use crate::sync::LazyLock; +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] use crate::sys_common::backtrace::{lock, output_filename}; use crate::vec::Vec; @@ -155,6 +157,7 @@ pub struct BacktraceFrame { #[derive(Debug)] enum RawFrame { + #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] Actual(backtrace_rs::Frame), #[cfg(test)] Fake, @@ -174,6 +177,7 @@ enum BytesOrWide { #[stable(feature = "backtrace", since = "1.65.0")] impl fmt::Debug for Backtrace { + #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { let capture = match &self.inner { Inner::Unsupported => return fmt.write_str(""), @@ -197,17 +201,29 @@ impl fmt::Debug for Backtrace { dbg.finish() } + + #[cfg(any(target_arch = "bpf", target_arch = "sbf"))] + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(fmt, "") + } } #[unstable(feature = "backtrace_frames", issue = "79676")] impl fmt::Debug for BacktraceFrame { + #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { let mut dbg = fmt.debug_list(); dbg.entries(&self.symbols); dbg.finish() } + + #[cfg(any(target_arch = "bpf", target_arch = "sbf"))] + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(fmt, "") + } } +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] impl fmt::Debug for BacktraceSymbol { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { // FIXME: improve formatting: https://github.com/rust-lang/rust/issues/65280 @@ -234,6 +250,7 @@ impl fmt::Debug for BacktraceSymbol { } } +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] impl fmt::Debug for BytesOrWide { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { output_filename( @@ -251,6 +268,7 @@ impl fmt::Debug for BytesOrWide { impl Backtrace { /// Returns whether backtrace captures are enabled through environment /// variables. + #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] fn enabled() -> bool { // Cache the result of reading the environment variables to make // backtrace captures speedy, because otherwise reading environment @@ -272,6 +290,11 @@ impl Backtrace { enabled } + #[cfg(any(target_arch = "bpf", target_arch = "sbf"))] + fn enabled() -> bool { + false + } + /// Capture a stack backtrace of the current thread. /// /// This function will capture a stack backtrace of the current OS thread of @@ -323,6 +346,7 @@ impl Backtrace { // Capture a backtrace which start just before the function addressed by // `ip` + #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] fn create(ip: usize) -> Backtrace { let _lock = lock(); let mut frames = Vec::new(); @@ -355,6 +379,13 @@ impl Backtrace { Backtrace { inner } } + #[cfg(any(target_arch = "bpf", target_arch = "sbf"))] + fn create(ip: usize) -> Backtrace { + Backtrace { + inner: Inner::Unsupported + } + } + /// Returns the status of this backtrace, indicating whether this backtrace /// request was unsupported, disabled, or a stack trace was actually /// captured. @@ -380,6 +411,7 @@ impl<'a> Backtrace { #[stable(feature = "backtrace", since = "1.65.0")] impl fmt::Display for Backtrace { + #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { let capture = match &self.inner { Inner::Unsupported => return fmt.write_str("unsupported backtrace"), @@ -426,9 +458,52 @@ impl fmt::Display for Backtrace { f.finish()?; Ok(()) } + + #[cfg(any(target_arch = "bpf", target_arch = "sbf"))] + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(fmt, "") + } } +<<<<<<< HEAD type LazyResolve = impl (FnOnce() -> Capture) + Send + Sync + UnwindSafe; +======= +struct LazilyResolvedCapture { + sync: Once, + capture: UnsafeCell, +} + +impl LazilyResolvedCapture { + fn new(capture: Capture) -> Self { + LazilyResolvedCapture { sync: Once::new(), capture: UnsafeCell::new(capture) } + } + + fn force(&self) -> &Capture { + self.sync.call_once(|| { + // SAFETY: This exclusive reference can't overlap with any others + // `Once` guarantees callers will block until this closure returns + // `Once` also guarantees only a single caller will enter this closure + unsafe { &mut *self.capture.get() }.resolve(); + }); + + // SAFETY: This shared reference can't overlap with the exclusive reference above + unsafe { &*self.capture.get() } + } +} + +// SAFETY: Access to the inner value is synchronized using a thread-safe `Once` +// So long as `Capture` is `Sync`, `LazilyResolvedCapture` is too +unsafe impl Sync for LazilyResolvedCapture where Capture: Sync {} + +impl Capture { + #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] + fn resolve(&mut self) { + // If we're already resolved, nothing to do! + if self.resolved { + return; + } + self.resolved = true; +>>>>>>> a2fbab5821e ([SOL] Enable the std backtrace API) fn lazy_resolve(mut capture: Capture) -> LazyResolve { move || { @@ -460,8 +535,18 @@ fn lazy_resolve(mut capture: Capture) -> LazyResolve { capture } + + #[cfg(any(target_arch = "bpf", target_arch = "sbf"))] + fn resolve(&mut self) { + // If we're already resolved, nothing to do! + if self.resolved { + return; + } + self.resolved = true; + } } +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] impl RawFrame { fn ip(&self) -> *mut c_void { match self { diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 891ff0d62a209..680432778b03a 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -559,7 +559,6 @@ pub mod f64; #[macro_use] pub mod thread; pub mod ascii; -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub mod backtrace; pub mod collections; pub mod env; From 6f3a31dd71af33bcecfa59d8b349e3645f8fdf75 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Tue, 10 May 2022 10:09:08 -0700 Subject: [PATCH 078/103] [SOL] Add os field to SBF target specification --- compiler/rustc_target/src/spec/sbf_base.rs | 27 +++++++++++----------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_target/src/spec/sbf_base.rs b/compiler/rustc_target/src/spec/sbf_base.rs index 1c5c8e61c6b3c..0a491f39acdb9 100644 --- a/compiler/rustc_target/src/spec/sbf_base.rs +++ b/compiler/rustc_target/src/spec/sbf_base.rs @@ -38,29 +38,30 @@ SECTIONS TargetOptions { allow_asm: true, - endian: Endian::Little, c_int_width: "64".to_string(), + dll_prefix: "".to_string(), + dynamic_linking: true, + eh_frame_header: false, + emit_debug_gdb_scripts: false, + endian: Endian::Little, env: String::new(), + executables: true, features: "+solana".to_string(), - vendor: "solana".to_string(), + link_script: Some(linker_script.to_string()), + linker: Some("rust-lld".to_owned()), linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), linker_is_gnu: true, - linker: Some("rust-lld".to_owned()), - link_script: Some(linker_script.to_string()), - pre_link_args, - executables: true, - dll_prefix: "".to_string(), - dynamic_linking: true, - only_cdylib: true, + main_needs_argc_argv: false, + max_atomic_width: Some(64), no_default_libraries: true, + only_cdylib: true, + os: "solana".to_string(), panic_strategy: PanicStrategy::Abort, position_independent_executables: true, + pre_link_args, requires_lto: false, singlethread: true, - max_atomic_width: Some(64), - eh_frame_header: false, - main_needs_argc_argv: false, - emit_debug_gdb_scripts: false, + vendor: "solana".to_string(), .. Default::default() } } From 0fc64e04939a4a7b039aa65940d0d202c5e52e0c Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Sun, 8 May 2022 09:42:37 +1000 Subject: [PATCH 079/103] [SOL] sbf: implement static-syscalls target feature Expose static-syscalls as a rust target-feature so it can be used with conditional compilation and implement sol_log_(), abort() and sol_alloc_free_() as static syscalls. This bumps src/llvm-project to pull the corresponding LLVM change. --- .../rustc_codegen_ssa/src/target_features.rs | 7 ++++- library/std/src/sys/sbf/alloc.rs | 9 ++++++ library/std/src/sys/sbf/mod.rs | 31 +++++++++++++++---- 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/target_features.rs b/compiler/rustc_codegen_ssa/src/target_features.rs index 760b7bbee723b..c9145999812b9 100644 --- a/compiler/rustc_codegen_ssa/src/target_features.rs +++ b/compiler/rustc_codegen_ssa/src/target_features.rs @@ -305,6 +305,10 @@ const WASM_ALLOWED_FEATURES: &[(&str, Option)] = &[ const BPF_ALLOWED_FEATURES: &[(&str, Option)] = &[("alu32", Some(sym::bpf_target_feature))]; +const SBF_ALLOWED_FEATURES: &[(&str, Option)] = + &[("alu32", Some(sym::sbf_target_feature)), ("static-syscalls", Some(sym::sbf_target_feature))]; + + const CSKY_ALLOWED_FEATURES: &[(&str, Option)] = &[ // tidy-alphabetical-start ("10e60", Some(sym::csky_target_feature)), @@ -379,6 +383,7 @@ pub fn all_known_features() -> impl Iterator &'static [(&'static str, Opt "csky" => CSKY_ALLOWED_FEATURES, "loongarch64" => LOONGARCH_ALLOWED_FEATURES, "bpf" => BPF_ALLOWED_FEATURES, - "sbf" => BPF_ALLOWED_FEATURES, + "sbf" => SBF_ALLOWED_FEATURES, _ => &[], } } diff --git a/library/std/src/sys/sbf/alloc.rs b/library/std/src/sys/sbf/alloc.rs index dcf18ead5c036..e6ef85d99adf5 100644 --- a/library/std/src/sys/sbf/alloc.rs +++ b/library/std/src/sys/sbf/alloc.rs @@ -32,6 +32,15 @@ unsafe impl GlobalAlloc for System { // // 0 as *mut u8 // } } + +#[cfg(not(target_feature = "static-syscalls"))] extern "C" { fn sol_alloc_free_(size: u64, ptr: u64) -> *mut u8; } + +#[cfg(target_feature = "static-syscalls")] +fn sol_alloc_free_(size: u64, ptr: u64) -> *mut u8 { + let syscall: extern "C" fn(u64, u64) -> *mut u8 = + unsafe { core::mem::transmute(2213547663u64) }; // murmur32 hash of "sol_alloc_free_" + syscall(size, ptr) +} diff --git a/library/std/src/sys/sbf/mod.rs b/library/std/src/sys/sbf/mod.rs index f5bf4bd825aad..7a563c0f4b65a 100644 --- a/library/std/src/sys/sbf/mod.rs +++ b/library/std/src/sys/sbf/mod.rs @@ -29,9 +29,9 @@ pub mod os; pub mod path; pub mod pipe; pub mod process; +pub mod stdio; pub mod thread; pub mod time; -pub mod stdio; #[path = "../unix/os_str.rs"] pub mod os_str; @@ -42,6 +42,7 @@ pub mod rwlock; pub mod thread_local_dtor; pub mod thread_local_key; +#[cfg(not(target_feature = "static-syscalls"))] extern "C" { fn abort() -> !; #[allow(improper_ctypes)] @@ -49,6 +50,18 @@ extern "C" { fn sol_log_(message: *const u8, length: u64); } +#[cfg(target_feature = "static-syscalls")] +unsafe extern "C" fn abort() -> ! { + let syscall: extern "C" fn() -> ! = core::mem::transmute(3069975057u64); // murmur32 hash of "abort" + syscall() +} + +#[cfg(target_feature = "static-syscalls")] +unsafe extern "C" fn sol_log_(message: *const u8, length: u64) { + let syscall: extern "C" fn(*const u8, u64) = core::mem::transmute(544561597u64); // murmur32 hash of "sol_log_" + syscall(message, length) +} + pub fn sol_log(message: &[u8]) { unsafe { sol_log_(message.as_ptr(), message.len() as u64); @@ -56,8 +69,15 @@ pub fn sol_log(message: &[u8]) { } pub fn panic(info: &core::panic::PanicInfo<'_>) -> ! { - unsafe { custom_panic(info); } - unsafe { abort(); } + unsafe { + #[cfg(not(target_feature = "static-syscalls"))] + custom_panic(info); + + #[cfg(target_feature = "static-syscalls")] + sol_log(info.to_string().as_bytes()); + + abort(); + } } pub fn unsupported() -> crate::io::Result { @@ -65,8 +85,7 @@ pub fn unsupported() -> crate::io::Result { } pub fn unsupported_err() -> crate::io::Error { - crate::io::Error::new(crate::io::ErrorKind::Other, - "operation not supported on SBF yet") + crate::io::Error::new(crate::io::ErrorKind::Other, "operation not supported on SBF yet") } pub fn decode_error_kind(_code: i32) -> crate::io::ErrorKind { @@ -84,7 +103,7 @@ pub unsafe fn strlen(mut s: *const c_char) -> usize { n += 1; s = s.offset(1); } - return n + return n; } pub fn abort_internal() -> ! { From ec32b5557f45280c7bca1f55172db7be61a49c62 Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Sat, 14 May 2022 17:20:37 +1000 Subject: [PATCH 080/103] [SOL] sbfv2: place the rodata segment at MM_PROGRAM_START With this _RELATIVE relocations can be ignored in the vm. Relocations are still produced in case we change address space layout in the future. --- compiler/rustc_codegen_ssa/src/back/linker.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index 333d1297de216..12d12fea0b13c 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -360,6 +360,10 @@ impl<'a> GccLinker<'a> { } else { self.linker_arg("--entry=entrypoint"); } + if self.sess.opts.cg.target_cpu.as_ref().unwrap_or(&self.sess.target.cpu) == "sbfv2" + { + self.linker_arg("--section-start=.text=0x100000000"); + } } } } From 5d88875ae36772ae0dafda1c07c1afed7d4deb42 Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Sat, 14 May 2022 17:29:34 +1000 Subject: [PATCH 081/103] [SOL] sbfv2: output _RELATIVE relocations in a separate SHT_RELR section sbfv2 only produces _RELATIVE relocations and those can be packed much more efficiently using SHT_RELR. See https://reviews.llvm.org/D48247. --- compiler/rustc_codegen_ssa/src/back/linker.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index 12d12fea0b13c..adf7a0b21be3f 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -363,6 +363,7 @@ impl<'a> GccLinker<'a> { if self.sess.opts.cg.target_cpu.as_ref().unwrap_or(&self.sess.target.cpu) == "sbfv2" { self.linker_arg("--section-start=.text=0x100000000"); + self.linker_arg("--pack-dyn-relocs=relr"); } } } From cf7807aca561b856622c4161acc7505477deecd5 Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Wed, 18 May 2022 07:38:42 +1000 Subject: [PATCH 082/103] [SOL] tests: update docker image name --- .github/workflows/ci.yml | 2 +- src/ci/github-actions/ci.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 359801a7e0e8c..4dd45048e9ddb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -194,7 +194,7 @@ jobs: - name: mingw-check os: ubuntu-latest env: {} - - name: x86_64-gnu-llvm-10 + - name: x86_64-gnu-llvm-12 os: ubuntu-latest env: {} - name: sbf-solana-solana diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml index 58e8060f88074..5a6f3c3d56db2 100644 --- a/src/ci/github-actions/ci.yml +++ b/src/ci/github-actions/ci.yml @@ -364,7 +364,7 @@ jobs: - name: mingw-check <<: *job-linux-xl - - name: x86_64-gnu-llvm-10 + - name: x86_64-gnu-llvm-12 <<: *job-linux-xl - name: sbf-solana-solana From b257692203e5382c6f23816354ebdd630080e5d9 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Thu, 7 Jul 2022 16:12:35 -0700 Subject: [PATCH 083/103] [SOL] Update run-bpf-tests revision in CI --- src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile index c7b091c0b650a..c9532514a3fa4 100644 --- a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile +++ b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile @@ -21,8 +21,8 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y RUN PATH="${HOME}/.cargo/bin:${PATH}" \ cargo install --git https://github.com/solana-labs/cargo-run-bpf-tests.git \ - --rev f0201b677976190568b8a04d8ede018fc6ccf053 \ - --bin cargo-run-bpf-tests --root /usr/local + --rev e80a6b4dc9f9f73ac317ddbc9bbcb711786b11d5 \ + --bin cargo-run-sbf-tests --root /usr/local COPY scripts/sccache.sh /scripts/ RUN sh /scripts/sccache.sh @@ -31,8 +31,8 @@ ENV RUST_CONFIGURE_ARGS \ --set rust.lld \ --set llvm.clang -ENV SCRIPT CARGO_TARGET_BPFEL_UNKNOWN_UNKNOWN_RUNNER=\"cargo-run-bpf-tests --heap-size 104857600\" \ - CARGO_TARGET_SBF_SOLANA_SOLANA_RUNNER=\"cargo-run-bpf-tests --heap-size 104857600\" \ +ENV SCRIPT CARGO_TARGET_BPFEL_UNKNOWN_UNKNOWN_RUNNER=\"cargo-run-sbf-tests --heap-size 104857600\" \ + CARGO_TARGET_SBF_SOLANA_SOLANA_RUNNER=\"cargo-run-sbf-tests --heap-size 104857600\" \ LLVM_HOME=/checkout/obj/build/x86_64-unknown-linux-gnu/llvm \ PATH="${HOME}/.cargo/bin:${PATH}" \ python3 /checkout/x.py --stage 1 test --host='' --target bpfel-unknown-unknown,sbf-solana-solana \ From 288d618ecc34fce2d27039604b3dd2ebfb9e1ba9 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Fri, 8 Jul 2022 19:21:43 -0700 Subject: [PATCH 084/103] [SOL] Update run-bpf-tests revision in CI --- src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile index c9532514a3fa4..d598bc0e906a4 100644 --- a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile +++ b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile @@ -21,7 +21,7 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y RUN PATH="${HOME}/.cargo/bin:${PATH}" \ cargo install --git https://github.com/solana-labs/cargo-run-bpf-tests.git \ - --rev e80a6b4dc9f9f73ac317ddbc9bbcb711786b11d5 \ + --rev 5f922041c3cd20f6bb56920a025065cdb13d5643 \ --bin cargo-run-sbf-tests --root /usr/local COPY scripts/sccache.sh /scripts/ From 985799f5fb5f04632399fa5944dcc0188fed5dc9 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Wed, 20 Jul 2022 17:31:43 -0700 Subject: [PATCH 085/103] [SOL] Adjust BPF customization after upgrading to rust 1.62.0 --- .github/workflows/ci.yml | 8 +- compiler/rustc_codegen_ssa/src/back/linker.rs | 2 +- .../src/spec/bpfel_unknown_unknown.rs | 6 +- compiler/rustc_target/src/spec/sbf_base.rs | 27 ++- .../src/spec/sbf_solana_solana.rs | 6 +- library/core/benches/lib.rs | 2 +- library/std/src/io/stdio.rs | 221 +----------------- library/std/src/lib.rs | 5 +- library/std/src/panic.rs | 8 +- library/std/src/panicking.rs | 42 ++-- library/std/src/rt.rs | 8 +- library/std/src/sync/remutex.rs | 8 +- library/std/src/sys/mod.rs | 2 +- library/std/src/sys/sbf/mod.rs | 17 +- library/std/src/sys/sbf/mutex.rs | 10 - library/std/src/sys/sbf/path.rs | 8 +- library/std/src/sys/sbf/process.rs | 12 +- library/std/src/sys/sbf/rwlock.rs | 14 +- library/std/src/sys/sbf/time.rs | 9 - library/std/src/thread/mod.rs | 26 ++- tests/ui/check-cfg/well-known-values.stderr | 2 +- .../modifiers-override-2.rs | 3 - .../modifiers-override-2.stderr | 2 - 23 files changed, 127 insertions(+), 321 deletions(-) delete mode 100644 tests/ui/native-library-link-flags/modifiers-override-2.rs delete mode 100644 tests/ui/native-library-link-flags/modifiers-override-2.stderr diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4dd45048e9ddb..20f777a2de9b2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -206,7 +206,7 @@ jobs: - name: disable git crlf conversion run: git config --global core.autocrlf false - name: checkout the source code - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 2 - name: configure the PR in which the error message will be posted @@ -251,6 +251,9 @@ jobs: - name: disable git crlf conversion run: src/ci/scripts/disable-git-crlf-conversion.sh if: success() && !env.SKIP_JOB + - name: checkout submodules + run: src/ci/scripts/checkout-submodules.sh + if: success() && !env.SKIP_JOB - name: install MSYS2 run: src/ci/scripts/install-msys2.sh if: success() && !env.SKIP_JOB @@ -266,9 +269,6 @@ jobs: - name: disable git crlf conversion run: src/ci/scripts/disable-git-crlf-conversion.sh if: success() && !env.SKIP_JOB - - name: checkout submodules - run: src/ci/scripts/checkout-submodules.sh - if: success() && !env.SKIP_JOB - name: ensure line endings are correct run: src/ci/scripts/verify-line-endings.sh if: success() && !env.SKIP_JOB diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index adf7a0b21be3f..f66d46f373b80 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -360,7 +360,7 @@ impl<'a> GccLinker<'a> { } else { self.linker_arg("--entry=entrypoint"); } - if self.sess.opts.cg.target_cpu.as_ref().unwrap_or(&self.sess.target.cpu) == "sbfv2" + if self.sess.opts.cg.target_cpu.as_ref().unwrap_or(&self.sess.target.cpu.as_ref().to_string()) == "sbfv2" { self.linker_arg("--section-start=.text=0x100000000"); self.linker_arg("--pack-dyn-relocs=relr"); diff --git a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs index bb13b79f770b9..b4df123cfc2b9 100644 --- a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs +++ b/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs @@ -3,10 +3,10 @@ use crate::spec::sbf_base; pub fn target() -> Target { Target { - llvm_target: "bpfel".to_string(), + llvm_target: "bpfel".into(), pointer_width: 64, - arch: "bpf".to_string(), - data_layout: "e-m:e-p:64:64-i64:64-n32:64-S128".to_string(), + arch: "bpf".into(), + data_layout: "e-m:e-p:64:64-i64:64-n32:64-S128".into(), options: sbf_base::opts(), } } diff --git a/compiler/rustc_target/src/spec/sbf_base.rs b/compiler/rustc_target/src/spec/sbf_base.rs index 0a491f39acdb9..20990d8d88fb2 100644 --- a/compiler/rustc_target/src/spec/sbf_base.rs +++ b/compiler/rustc_target/src/spec/sbf_base.rs @@ -1,6 +1,5 @@ use crate::abi::Endian; -use super::{LinkerFlavor, PanicStrategy, TargetOptions, LldFlavor}; -use std::{collections::BTreeMap}; +use super::{LinkArgs, LinkerFlavor, PanicStrategy, TargetOptions, LldFlavor}; pub fn opts() -> TargetOptions { let linker_script = r" @@ -30,38 +29,38 @@ SECTIONS } "; let mut lld_args = Vec::new(); - lld_args.push("--threads=1".to_string()); - lld_args.push("-z".to_string()); - lld_args.push("notext".to_string()); - let mut pre_link_args = BTreeMap::new(); + lld_args.push("--threads=1".into()); + lld_args.push("-z".into()); + lld_args.push("notext".into()); + let mut pre_link_args = LinkArgs::new(); pre_link_args.insert(LinkerFlavor::Lld(LldFlavor::Ld), lld_args); TargetOptions { allow_asm: true, - c_int_width: "64".to_string(), - dll_prefix: "".to_string(), + c_int_width: "64".into(), + dll_prefix: "".into(), dynamic_linking: true, eh_frame_header: false, emit_debug_gdb_scripts: false, endian: Endian::Little, - env: String::new(), + env: "".into(), executables: true, - features: "+solana".to_string(), - link_script: Some(linker_script.to_string()), - linker: Some("rust-lld".to_owned()), + features: "+solana".into(), + link_script: Some(linker_script.into()), + linker: Some("rust-lld".into()), linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), linker_is_gnu: true, main_needs_argc_argv: false, max_atomic_width: Some(64), no_default_libraries: true, only_cdylib: true, - os: "solana".to_string(), + os: "solana".into(), panic_strategy: PanicStrategy::Abort, position_independent_executables: true, pre_link_args, requires_lto: false, singlethread: true, - vendor: "solana".to_string(), + vendor: "solana".into(), .. Default::default() } } diff --git a/compiler/rustc_target/src/spec/sbf_solana_solana.rs b/compiler/rustc_target/src/spec/sbf_solana_solana.rs index 79783600a8151..a4adf32b7544e 100644 --- a/compiler/rustc_target/src/spec/sbf_solana_solana.rs +++ b/compiler/rustc_target/src/spec/sbf_solana_solana.rs @@ -3,10 +3,10 @@ use crate::spec::sbf_base; pub fn target() -> Target { Target { - llvm_target: "sbf".to_string(), + llvm_target: "sbf".into(), pointer_width: 64, - arch: "sbf".to_string(), - data_layout: "e-m:e-p:64:64-i64:64-n32:64-S128".to_string(), + arch: "sbf".into(), + data_layout: "e-m:e-p:64:64-i64:64-n32:64-S128".into(), options: sbf_base::opts(), } } diff --git a/library/core/benches/lib.rs b/library/core/benches/lib.rs index 74ef0949b8af2..daedcfab52462 100644 --- a/library/core/benches/lib.rs +++ b/library/core/benches/lib.rs @@ -1,5 +1,5 @@ // wasm32 does not support benches (no time). -#![cfg(not(target_arch = "wasm32"))] +#![cfg(not(any(target_arch = "wasm32", target_arch = "bpf", target_arch = "sbf")))] #![feature(flt2dec)] #![feature(test)] #![feature(trusted_random_access)] diff --git a/library/std/src/io/stdio.rs b/library/std/src/io/stdio.rs index 743ace5ce6cea..af7f60092a204 100644 --- a/library/std/src/io/stdio.rs +++ b/library/std/src/io/stdio.rs @@ -12,7 +12,7 @@ use crate::fs::File; #[cfg(not(target_os = "solana"))] use crate::io::{self, BorrowedCursor, BufReader, IoSlice, IoSliceMut, LineWriter, Lines}; #[cfg(target_os = "solana")] -use crate::io::{self, BufReader, IoSlice, IoSliceMut}; +use crate::io::{self, BufReader, IoSlice, IoSliceMut, LineWriter, Lines}; #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] use crate::sync::atomic::{AtomicBool, Ordering}; use crate::sync::{Arc, Mutex, MutexGuard, OnceLock, ReentrantMutex, ReentrantMutexGuard}; @@ -347,49 +347,6 @@ pub fn stdin() -> Stdin { Stdin {} } -/// Constructs a new locked handle to the standard input of the current -/// process. -/// -/// Each handle returned is a guard granting locked access to a shared -/// global buffer whose access is synchronized via a mutex. If you need -/// more explicit control over locking, for example, in a multi-threaded -/// program, use the [`io::stdin`] function to obtain an unlocked handle, -/// along with the [`Stdin::lock`] method. -/// -/// The lock is released when the returned guard goes out of scope. The -/// returned guard also implements the [`Read`] and [`BufRead`] traits for -/// accessing the underlying data. -/// -/// **Note**: The mutex locked by this handle is not reentrant. Even in a -/// single-threaded program, calling other code that accesses [`Stdin`] -/// could cause a deadlock or panic, if this locked handle is held across -/// that call. -/// -/// ### Note: Windows Portability Consideration -/// When operating in a console, the Windows implementation of this stream does not support -/// non-UTF-8 byte sequences. Attempting to read bytes that are not valid UTF-8 will return -/// an error. -/// -/// # Examples -/// -/// ```no_run -/// #![feature(stdio_locked)] -/// use std::io::{self, BufRead}; -/// -/// fn main() -> io::Result<()> { -/// let mut buffer = String::new(); -/// let mut handle = io::stdin_locked(); -/// -/// handle.read_line(&mut buffer)?; -/// Ok(()) -/// } -/// ``` -#[unstable(feature = "stdio_locked", issue = "86845")] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] -pub fn stdin_locked() -> StdinLock<'static> { - stdin().into_locked() -} - impl Stdin { /// Locks this handle to the standard input stream, returning a readable /// guard. @@ -413,7 +370,7 @@ impl Stdin { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[cfg(not(target_os = "solana"))] + #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] pub fn lock(&self) -> StdinLock<'static> { // Locks this handle with 'static lifetime. This depends on the // implementation detail that the underlying `Mutex` is static. @@ -452,45 +409,6 @@ impl Stdin { self.lock().read_line(buf) } - // Locks this handle with any lifetime. This depends on the - // implementation detail that the underlying `Mutex` is static. - #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] - fn lock_any<'a>(&self) -> StdinLock<'a> { - StdinLock { inner: self.inner.lock().unwrap_or_else(|e| e.into_inner()) } - } - - /// Consumes this handle to the standard input stream, locking the - /// shared global buffer associated with the stream and returning a - /// readable guard. - /// - /// The lock is released when the returned guard goes out of scope. The - /// returned guard also implements the [`Read`] and [`BufRead`] traits - /// for accessing the underlying data. - /// - /// It is often simpler to directly get a locked handle using the - /// [`stdin_locked`] function instead, unless nearby code also needs to - /// use an unlocked handle. - /// - /// # Examples - /// - /// ```no_run - /// #![feature(stdio_locked)] - /// use std::io::{self, BufRead}; - /// - /// fn main() -> io::Result<()> { - /// let mut buffer = String::new(); - /// let mut handle = io::stdin().into_locked(); - /// - /// handle.read_line(&mut buffer)?; - /// Ok(()) - /// } - /// ``` - #[unstable(feature = "stdio_locked", issue = "86845")] - #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] - pub fn into_locked(self) -> StdinLock<'static> { - self.lock_any() - } - /// Consumes this handle and returns an iterator over input lines. /// /// For detailed semantics of this method, see the documentation on @@ -508,34 +426,10 @@ impl Stdin { /// ``` #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "stdin_forwarders", since = "1.62.0")] - #[cfg(not(target_os = "solana"))] + #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] pub fn lines(self) -> Lines> { self.lock().lines() } - - /// Consumes this handle and returns an iterator over input bytes, - /// split at the specified byte value. - /// - /// For detailed semantics of this method, see the documentation on - /// [`BufRead::split`]. - /// - /// # Examples - /// - /// ```no_run - /// #![feature(stdin_forwarders)] - /// use std::io; - /// - /// let splits = io::stdin().split(b'-'); - /// for split in splits { - /// println!("got a chunk: {}", String::from_utf8_lossy(&split.unwrap())); - /// } - /// ``` - #[must_use = "`self` will be dropped if the result is not used"] - #[unstable(feature = "stdin_forwarders", issue = "87096")] - #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] - pub fn split(self, byte: u8) -> Split> { - self.into_locked().split(byte) - } } #[stable(feature = "std_debug", since = "1.16.0")] @@ -832,52 +726,13 @@ impl Stdout { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[cfg(not(target_os = "solana"))] + #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] pub fn lock(&self) -> StdoutLock<'static> { // Locks this handle with 'static lifetime. This depends on the // implementation detail that the underlying `ReentrantMutex` is // static. StdoutLock { inner: self.inner.lock() } } - - // Locks this handle with any lifetime. This depends on the - // implementation detail that the underlying `ReentrantMutex` is - // static. - #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] - fn lock_any<'a>(&self) -> StdoutLock<'a> { - StdoutLock { inner: self.inner.lock() } - } - - /// Consumes this handle to the standard output stream, locking the - /// shared global buffer associated with the stream and returning a - /// writable guard. - /// - /// The lock is released when the returned lock goes out of scope. The - /// returned guard also implements the [`Write`] trait for writing data. - /// - /// It is often simpler to directly get a locked handle using the - /// [`io::stdout_locked`] function instead, unless nearby code also - /// needs to use an unlocked handle. - /// - /// # Examples - /// - /// ```no_run - /// #![feature(stdio_locked)] - /// use std::io::{self, Write}; - /// - /// fn main() -> io::Result<()> { - /// let mut handle = io::stdout().into_locked(); - /// - /// handle.write_all(b"hello world")?; - /// - /// Ok(()) - /// } - /// ``` - #[unstable(feature = "stdio_locked", issue = "86845")] - #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] - pub fn into_locked(self) -> StdoutLock<'static> { - self.lock_any() - } } #[stable(feature = "std_debug", since = "1.16.0")] @@ -1127,36 +982,6 @@ pub fn stderr() -> Stderr { Stderr {} } -/// Constructs a new locked handle to the standard error of the current -/// process. -/// -/// This handle is not buffered. -/// -/// ### Note: Windows Portability Consideration -/// When operating in a console, the Windows implementation of this stream does not support -/// non-UTF-8 byte sequences. Attempting to write bytes that are not valid UTF-8 will return -/// an error. -/// -/// # Example -/// -/// ```no_run -/// #![feature(stdio_locked)] -/// use std::io::{self, Write}; -/// -/// fn main() -> io::Result<()> { -/// let mut handle = io::stderr_locked(); -/// -/// handle.write_all(b"hello world")?; -/// -/// Ok(()) -/// } -/// ``` -#[unstable(feature = "stdio_locked", issue = "86845")] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] -pub fn stderr_locked() -> StderrLock<'static> { - stderr().into_locked() -} - impl Stderr { /// Locks this handle to the standard error stream, returning a writable /// guard. @@ -1179,49 +1004,13 @@ impl Stderr { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[cfg(not(target_os = "solana"))] + #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] pub fn lock(&self) -> StderrLock<'static> { // Locks this handle with 'static lifetime. This depends on the // implementation detail that the underlying `ReentrantMutex` is // static. StderrLock { inner: self.inner.lock() } } - - // Locks this handle with any lifetime. This depends on the - // implementation detail that the underlying `ReentrantMutex` is - // static. - #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] - fn lock_any<'a>(&self) -> StderrLock<'a> { - StderrLock { inner: self.inner.lock() } - } - - /// Locks and consumes this handle to the standard error stream, - /// returning a writable guard. - /// - /// The lock is released when the returned guard goes out of scope. The - /// returned guard also implements the [`Write`] trait for writing - /// data. - /// - /// # Examples - /// - /// ``` - /// #![feature(stdio_locked)] - /// use std::io::{self, Write}; - /// - /// fn foo() -> io::Result<()> { - /// let stderr = io::stderr(); - /// let mut handle = stderr.into_locked(); - /// - /// handle.write_all(b"hello world")?; - /// - /// Ok(()) - /// } - /// ``` - #[unstable(feature = "stdio_locked", issue = "86845")] - #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] - pub fn into_locked(self) -> StderrLock<'static> { - self.lock_any() - } } #[stable(feature = "std_debug", since = "1.16.0")] diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 680432778b03a..44d04920e4be9 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -429,7 +429,8 @@ extern crate unwind; #[doc(masked)] #[allow(unused_extern_crates)] #[cfg(all( - not(all(windows, target_env = "msvc", not(target_vendor = "uwp"))), + not(all(windows, target_env = "msvc", not(target_vendor = "uwp"), + any(target_arch = "bpf", target_arch = "sbf"))), feature = "miniz_oxide" ))] extern crate miniz_oxide; @@ -640,7 +641,7 @@ pub mod alloc; // Private support modules mod panicking; -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] #[path = "../../backtrace/src/lib.rs"] #[allow(dead_code, unused_attributes, fuzzy_provenance_casts)] mod backtrace_rs; diff --git a/library/std/src/panic.rs b/library/std/src/panic.rs index dc2ecc1ed46c0..f51f65f66065a 100644 --- a/library/std/src/panic.rs +++ b/library/std/src/panic.rs @@ -5,6 +5,7 @@ use crate::any::Any; use crate::collections; use crate::panicking; +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] use crate::sync::atomic::{AtomicUsize, Ordering}; use crate::sync::{Mutex, RwLock}; use crate::thread::Result; @@ -56,7 +57,7 @@ pub use core::panic::{AssertUnwindSafe, RefUnwindSafe, UnwindSafe}; /// accessed later using [`PanicInfo::payload`]. /// /// See the [`panic!`] macro for more information about panicking. -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] #[stable(feature = "panic_any", since = "1.51.0")] #[inline] #[track_caller] @@ -220,6 +221,7 @@ pub fn always_abort() { /// The configuration for whether and how the default panic hook will capture /// and display the backtrace. +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[unstable(feature = "panic_backtrace_config", issue = "93346")] #[non_exhaustive] @@ -233,6 +235,7 @@ pub enum BacktraceStyle { Off, } +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] impl BacktraceStyle { pub(crate) fn full() -> Option { if cfg!(feature = "backtrace") { Some(BacktraceStyle::Full) } else { None } @@ -261,6 +264,7 @@ impl BacktraceStyle { // that backtrace. // // Internally stores equivalent of an Option. +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] static SHOULD_CAPTURE: AtomicUsize = AtomicUsize::new(0); /// Configure whether the default panic hook will capture and display a @@ -268,6 +272,7 @@ static SHOULD_CAPTURE: AtomicUsize = AtomicUsize::new(0); /// /// The default value for this setting may be set by the `RUST_BACKTRACE` /// environment variable; see the details in [`get_backtrace_style`]. +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] #[unstable(feature = "panic_backtrace_config", issue = "93346")] pub fn set_backtrace_style(style: BacktraceStyle) { if !cfg!(feature = "backtrace") { @@ -298,6 +303,7 @@ pub fn set_backtrace_style(style: BacktraceStyle) { /// the future /// /// Returns `None` if backtraces aren't currently supported. +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] #[unstable(feature = "panic_backtrace_config", issue = "93346")] pub fn get_backtrace_style() -> Option { if !cfg!(feature = "backtrace") { diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index 6ec723562da89..efc7646460fac 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -9,6 +9,7 @@ #![deny(unsafe_op_in_unsafe_fn)] +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] use crate::panic::BacktraceStyle; #[cfg(not(target_os = "solana"))] use core::panic::{PanicPayload}; @@ -27,13 +28,13 @@ use crate::sync::atomic::{AtomicBool, Ordering}; use crate::sync::{PoisonError, RwLock}; #[cfg(not(target_os = "solana"))] use crate::sys::stdio::panic_output; -#[cfg(not(target_os = "solana"))] +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] use crate::sys_common::backtrace; -#[cfg(not(target_os = "solana"))] +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] use crate::sys_common::rwlock::StaticRwLock; -#[cfg(not(target_os = "solana"))] +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] use crate::sys_common::thread_info; -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] use crate::thread; #[cfg(all(not(test), not(target_arch = "bpf"), not(target_arch = "sbf")))] @@ -88,7 +89,7 @@ enum Hook { Custom(Box) + 'static + Sync + Send>), } -#[cfg(not(target_os = "solana"))] +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] impl Hook { #[inline] fn into_box(self) -> Box) + 'static + Sync + Send> { @@ -197,7 +198,7 @@ pub fn set_hook(_hook: Box) + 'static + Sync + Send>) { /// panic!("Normal panic"); /// ``` #[must_use] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] #[stable(feature = "panic_hooks", since = "1.10.0")] pub fn take_hook() -> Box) + 'static + Sync + Send> { if thread::panicking() { @@ -211,6 +212,13 @@ pub fn take_hook() -> Box) + 'static + Sync + Send> { old_hook.into_box() } +/// Dummy version for satisfying library/test dependencies for BPF target +#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[stable(feature = "panic_hooks", since = "1.10.0")] +pub fn take_hook() -> Box) + 'static + Sync + Send> { + Box::new(default_hook) +} + /// Atomic combination of [`take_hook`] and [`set_hook`]. Use this to replace the panic handler with /// a new panic handler that does something and then executes the old handler. /// @@ -242,6 +250,7 @@ pub fn take_hook() -> Box) + 'static + Sync + Send> { /// /// panic!("Custom and then normal"); /// ``` +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] #[unstable(feature = "panic_update_hook", issue = "92649")] pub fn update_hook(hook_fn: F) where @@ -259,15 +268,20 @@ where *hook = Hook::Custom(Box::new(move |info| hook_fn(&prev, info))); } -/// Dummy version for satisfying library/test dependencies for BPF target -#[cfg(target_os = "solana")] -#[stable(feature = "panic_hooks", since = "1.10.0")] -pub fn take_hook() -> Box) + 'static + Sync + Send> { - Box::new(default_hook) +/// Dummy version for satisfying library/test dependencies for SBF target +#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[unstable(feature = "panic_update_hook", issue = "92649")] +pub fn update_hook(_hook_fn: F) +where + F: Fn(&(dyn Fn(&PanicInfo<'_>) + Send + Sync + 'static), &PanicInfo<'_>) + + Sync + + Send + + 'static, +{ } /// The default panic handler. -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] fn default_hook(info: &PanicInfo<'_>) { // If this is a double panic, make sure that we print a backtrace // for this panic. Otherwise only print it if logging is enabled. @@ -865,7 +879,7 @@ fn rust_panic_with_hook( /// This is the entry point for `resume_unwind`. /// It just forwards the payload to the panic runtime. #[cfg_attr(feature = "panic_immediate_abort", inline)] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] pub fn rust_panic_without_hook(payload: Box) -> ! { panic_count::increase(false); @@ -941,6 +955,7 @@ pub fn begin_panic(_msg: M) -> ! { let info = PanicInfo::internal_constructor( None, Location::caller(), + false, ); crate::sys::panic(&info); } @@ -958,6 +973,7 @@ pub fn begin_panic_fmt(msg: &fmt::Arguments<'_>) -> ! { let info = PanicInfo::internal_constructor( Some(msg), Location::caller(), + false, ); crate::sys::panic(&info); } diff --git a/library/std/src/rt.rs b/library/std/src/rt.rs index 7982c44e41893..fe10e9f97cba2 100644 --- a/library/std/src/rt.rs +++ b/library/std/src/rt.rs @@ -115,7 +115,7 @@ unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) { // One-time runtime cleanup. // Runs after `main` or at program exit. // NOTE: this is not guaranteed to run, for example when the program aborts. -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] pub(crate) fn cleanup() { static CLEANUP: Once = Once::new(); CLEANUP.call_once(|| unsafe { @@ -129,7 +129,7 @@ pub(crate) fn cleanup() { // To reduce the generated code of the new `lang_start`, this function is doing // the real work. #[cfg(not(test))] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] fn lang_start_internal( main: &(dyn Fn() -> i32 + Sync + crate::panic::RefUnwindSafe), argc: isize, @@ -164,7 +164,7 @@ fn lang_start_internal( #[cfg(not(test))] #[inline(never)] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] #[lang = "start"] fn lang_start( main: fn() -> T, @@ -189,5 +189,5 @@ fn lang_start( _argc: isize, _argv: *const *const u8, ) -> isize { - main().report() as isize + main().report().to_i32() as isize } diff --git a/library/std/src/sync/remutex.rs b/library/std/src/sync/remutex.rs index 65a1c7fbcc6d3..1253133b0dfff 100644 --- a/library/std/src/sync/remutex.rs +++ b/library/std/src/sync/remutex.rs @@ -72,7 +72,7 @@ impl !Send for ReentrantMutexGuard<'_, T> {} impl ReentrantMutex { /// Creates a new reentrant mutex in an unlocked state. - #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] + #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] pub const fn new(t: T) -> ReentrantMutex { ReentrantMutex { mutex: sys::Mutex::new(), @@ -94,7 +94,7 @@ impl ReentrantMutex { /// If another user of this mutex panicked while holding the mutex, then /// this call will return failure if the mutex would otherwise be /// acquired. - #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] + #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] pub fn lock(&self) -> ReentrantMutexGuard<'_, T> { let this_thread = current_thread_unique_ptr(); // Safety: We only touch lock_count when we own the lock. @@ -123,7 +123,7 @@ impl ReentrantMutex { /// If another user of this mutex panicked while holding the mutex, then /// this call will return failure if the mutex would otherwise be /// acquired. - #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] + #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] pub fn try_lock(&self) -> Option> { let this_thread = current_thread_unique_ptr(); // Safety: We only touch lock_count when we own the lock. @@ -142,6 +142,7 @@ impl ReentrantMutex { } } + #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] unsafe fn increment_lock_count(&self) { *self.lock_count.get() = (*self.lock_count.get()) .checked_add(1) @@ -174,6 +175,7 @@ impl Drop for ReentrantMutexGuard<'_, T> { /// Get an address that is unique per running thread. /// /// This can be used as a non-null usize-sized ID. +#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] pub fn current_thread_unique_ptr() -> usize { // Use a non-drop type to make sure it's still available during thread destruction. thread_local! { static X: u8 = const { 0 } } diff --git a/library/std/src/sys/mod.rs b/library/std/src/sys/mod.rs index 9dd457f9a65b4..363a470d8f407 100644 --- a/library/std/src/sys/mod.rs +++ b/library/std/src/sys/mod.rs @@ -35,7 +35,7 @@ cfg_if::cfg_if! { } else if #[cfg(target_os = "solid_asp3")] { mod solid; pub use self::solid::*; - } else if #[cfg(any(target_arch = "bpf", target_arch = "sbf"))] { + } else if #[cfg(target_os = "solana")] { mod sbf; pub use self::sbf::*; } else if #[cfg(target_os = "hermit")] { diff --git a/library/std/src/sys/sbf/mod.rs b/library/std/src/sys/sbf/mod.rs index 7a563c0f4b65a..41e4490a4b4eb 100644 --- a/library/std/src/sys/sbf/mod.rs +++ b/library/std/src/sys/sbf/mod.rs @@ -13,8 +13,6 @@ //! compiling for SBF. That way it's a compile time error for something that's //! guaranteed to be a runtime error! -use crate::os::raw::c_char; - pub mod alloc; pub mod args; //#[cfg(feature = "backtrace")] @@ -42,6 +40,12 @@ pub mod rwlock; pub mod thread_local_dtor; pub mod thread_local_key; +pub mod locks { + pub use super::condvar::*; + pub use super::mutex::*; + pub use super::rwlock::*; +} + #[cfg(not(target_feature = "static-syscalls"))] extern "C" { fn abort() -> !; @@ -97,15 +101,6 @@ pub fn decode_error_kind(_code: i32) -> crate::io::ErrorKind { #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] pub enum Void {} -pub unsafe fn strlen(mut s: *const c_char) -> usize { - let mut n = 0; - while *s != 0 { - n += 1; - s = s.offset(1); - } - return n; -} - pub fn abort_internal() -> ! { unsafe { abort() } } diff --git a/library/std/src/sys/sbf/mutex.rs b/library/std/src/sys/sbf/mutex.rs index c1c336135c98f..861b596adeb7e 100644 --- a/library/std/src/sys/sbf/mutex.rs +++ b/library/std/src/sys/sbf/mutex.rs @@ -40,13 +40,3 @@ impl Mutex { pub unsafe fn destroy(&self) { } } - -// All empty stubs because SBF has no threads, lock acquisition always -// succeeds. -pub struct ReentrantMutex { -} - -impl ReentrantMutex { - pub unsafe fn unlock(&self) {} - pub unsafe fn destroy(&self) {} -} diff --git a/library/std/src/sys/sbf/path.rs b/library/std/src/sys/sbf/path.rs index 7a18395610785..c805c15e70245 100644 --- a/library/std/src/sys/sbf/path.rs +++ b/library/std/src/sys/sbf/path.rs @@ -1,5 +1,7 @@ -use crate::path::Prefix; use crate::ffi::OsStr; +use crate::io; +use crate::path::{Path, PathBuf, Prefix}; +use crate::sys::unsupported; #[inline] pub fn is_sep_byte(b: u8) -> bool { @@ -17,3 +19,7 @@ pub fn parse_prefix(_: &OsStr) -> Option> { pub const MAIN_SEP_STR: &str = "/"; pub const MAIN_SEP: char = '/'; + +pub(crate) fn absolute(_path: &Path) -> io::Result { + unsupported() +} diff --git a/library/std/src/sys/sbf/process.rs b/library/std/src/sys/sbf/process.rs index a45409ddb90d6..fb04e2bdeff94 100644 --- a/library/std/src/sys/sbf/process.rs +++ b/library/std/src/sys/sbf/process.rs @@ -159,17 +159,23 @@ impl ExitStatusError { } #[derive(PartialEq, Eq, Clone, Copy, Debug)] -pub struct ExitCode(bool); +pub struct ExitCode(u8); impl ExitCode { - pub const SUCCESS: ExitCode = ExitCode(false); - pub const FAILURE: ExitCode = ExitCode(true); + pub const SUCCESS: ExitCode = ExitCode(0 as _); + pub const FAILURE: ExitCode = ExitCode(1 as _); pub fn as_i32(&self) -> i32 { self.0 as i32 } } +impl From for ExitCode { + fn from(code: u8) -> Self { + Self(code) + } +} + pub struct Process(Void); impl Process { diff --git a/library/std/src/sys/sbf/rwlock.rs b/library/std/src/sys/sbf/rwlock.rs index 66482f4dd8ba0..70036bbe5a2cd 100644 --- a/library/std/src/sys/sbf/rwlock.rs +++ b/library/std/src/sys/sbf/rwlock.rs @@ -1,17 +1,17 @@ use crate::cell::UnsafeCell; -pub struct RWLock { +pub struct RwLock { mode: UnsafeCell, } -pub type MovableRWLock = RWLock; +pub type MovableRwLock = RwLock; -unsafe impl Send for RWLock {} -unsafe impl Sync for RWLock {} // no threads on SBF +unsafe impl Send for RwLock {} +unsafe impl Sync for RwLock {} // no threads on SBF -impl RWLock { - pub const fn new() -> RWLock { - RWLock { +impl RwLock { + pub const fn new() -> RwLock { + RwLock { mode: UnsafeCell::new(0), } } diff --git a/library/std/src/sys/sbf/time.rs b/library/std/src/sys/sbf/time.rs index bce067a244f6e..9db3b8bd85b9f 100644 --- a/library/std/src/sys/sbf/time.rs +++ b/library/std/src/sys/sbf/time.rs @@ -1,5 +1,4 @@ use crate::time::Duration; -// use crate::sys::{TimeSysCall, TimeClock}; #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] pub struct Instant(Duration); @@ -14,14 +13,6 @@ impl Instant { Instant(Duration::from_secs(0)) } - pub const fn zero() -> Instant { - Instant(Duration::from_secs(0)) - } - - pub fn actually_monotonic() -> bool { - true - } - pub fn checked_sub_instant(&self, other: &Instant) -> Option { self.0.checked_sub(other.0) } diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index 8256f858481f3..fd45b8ea83682 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -449,7 +449,6 @@ impl Builder { /// /// [`io::Result`]: crate::io::Result #[unstable(feature = "thread_spawn_unchecked", issue = "55132")] - #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] pub unsafe fn spawn_unchecked<'a, F, T>(self, f: F) -> io::Result> where F: FnOnce() -> T, @@ -459,6 +458,7 @@ impl Builder { Ok(JoinHandle(unsafe { self.spawn_unchecked_(f, None) }?)) } + #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] unsafe fn spawn_unchecked_<'a, 'scope, F, T>( self, f: F, @@ -579,11 +579,16 @@ impl Builder { /// SBF version of spawn_unchecked #[unstable(feature = "thread_spawn_unchecked", issue = "55132")] #[cfg(any(target_arch = "bpf", target_arch = "sbf"))] - pub unsafe fn spawn_unchecked<'a, F, T>(self, _f: F) -> io::Result> + unsafe fn spawn_unchecked_<'a, 'scope, F, T>( + self, + _f: F, + scope_data: Option<&'scope scoped::ScopeData>, + ) -> io::Result> where F: FnOnce() -> T, F: Send + 'a, T: Send + 'a, + 'scope: 'a, { let Builder { name, stack_size } = self; let stack_size = stack_size.unwrap_or_else(thread::min_stack); @@ -591,14 +596,19 @@ impl Builder { CString::new(name).expect("thread name may not contain interior null bytes") })); let their_thread = my_thread.clone(); - let my_packet: Arc>>> = Arc::new(UnsafeCell::new(None)); + let my_packet: Arc> = + Arc::new(Packet { scope: scope_data, result: UnsafeCell::new(None) }); let main = move || { if let Some(name) = their_thread.cname() { imp::Thread::set_name(name); } }; - Ok(JoinHandle(JoinInner { + if let Some(scope_data) = scope_data { + scope_data.increment_num_running_threads(); + } + + Ok(JoinInner { // SAFETY: // // `imp::Thread::new` takes a closure with a `'static` lifetime, since it's passed @@ -613,16 +623,16 @@ impl Builder { // exist after the thread has terminated, which is signaled by `Thread::join` // returning. native: unsafe { - Some(imp::Thread::new( + imp::Thread::new( stack_size, mem::transmute::, Box>( Box::new(main), ), - )?) + )? }, thread: my_thread, - packet: Packet(my_packet), - })) + packet: my_packet, + }) } } diff --git a/tests/ui/check-cfg/well-known-values.stderr b/tests/ui/check-cfg/well-known-values.stderr index 6877d8f5bb727..644df1fb0f7a1 100644 --- a/tests/ui/check-cfg/well-known-values.stderr +++ b/tests/ui/check-cfg/well-known-values.stderr @@ -6,7 +6,7 @@ LL | #[cfg(target_os = "linuz")] | | | help: there is a expected value with a similar name: `"linux"` | - = note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous` + = note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solana`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous` = note: `#[warn(unexpected_cfgs)]` on by default warning: unexpected `cfg` condition value: `0` diff --git a/tests/ui/native-library-link-flags/modifiers-override-2.rs b/tests/ui/native-library-link-flags/modifiers-override-2.rs deleted file mode 100644 index 333f6786b0fba..0000000000000 --- a/tests/ui/native-library-link-flags/modifiers-override-2.rs +++ /dev/null @@ -1,3 +0,0 @@ -// compile-flags:-lstatic:+whole-archive,-whole-archive=foo - -fn main() {} diff --git a/tests/ui/native-library-link-flags/modifiers-override-2.stderr b/tests/ui/native-library-link-flags/modifiers-override-2.stderr deleted file mode 100644 index aa5b59c5b6f9e..0000000000000 --- a/tests/ui/native-library-link-flags/modifiers-override-2.stderr +++ /dev/null @@ -1,2 +0,0 @@ -error: multiple `whole-archive` modifiers in a single `-l` option - From 7ffc576049254d4b3a9ef970ee6e5aca4172a527 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Mon, 1 Aug 2022 13:02:41 -0700 Subject: [PATCH 086/103] [SOL] Update cargo-run-bpf-test revision for CI --- src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile index d598bc0e906a4..cde4eb99112ca 100644 --- a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile +++ b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile @@ -21,7 +21,7 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y RUN PATH="${HOME}/.cargo/bin:${PATH}" \ cargo install --git https://github.com/solana-labs/cargo-run-bpf-tests.git \ - --rev 5f922041c3cd20f6bb56920a025065cdb13d5643 \ + --rev 5f9b59b1b1d9ce0eaacff48ab19f151afff8dd15 \ --bin cargo-run-sbf-tests --root /usr/local COPY scripts/sccache.sh /scripts/ From c4c41bba707320a021aab25fbb856c17c610c89c Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Fri, 14 Oct 2022 09:54:13 -0400 Subject: [PATCH 087/103] [SOL] Update run-sbf-tests revision in CI --- src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile index cde4eb99112ca..454424b8e4daa 100644 --- a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile +++ b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile @@ -20,8 +20,8 @@ ENV RUSTUP_INIT_SKIP_PATH_CHECK="yes" RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y RUN PATH="${HOME}/.cargo/bin:${PATH}" \ - cargo install --git https://github.com/solana-labs/cargo-run-bpf-tests.git \ - --rev 5f9b59b1b1d9ce0eaacff48ab19f151afff8dd15 \ + cargo install --git https://github.com/solana-labs/cargo-run-sbf-tests.git \ + --rev 8b76e26ee3cddca60297847361b67603e4299209 \ --bin cargo-run-sbf-tests --root /usr/local COPY scripts/sccache.sh /scripts/ From 6f981868ad2d1bf3cffee244e8f464ba26f7c84c Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Mon, 24 Oct 2022 10:52:40 -0400 Subject: [PATCH 088/103] [SOL] switch to new SBF LLVM backend --- compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp | 7 +++++++ compiler/rustc_llvm/src/lib.rs | 10 +++++----- config.toml | 2 +- src/bootstrap/src/core/build_steps/llvm.rs | 2 +- src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile | 2 +- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp index 36b61bcbbf4fe..8a0ab7fd3ffd7 100644 --- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp @@ -169,6 +169,12 @@ extern "C" void LLVMTimeTraceProfilerFinish(const char* FileName) { #define SUBTARGET_BPF #endif +#ifdef LLVM_COMPONENT_SBF +#define SUBTARGET_SBF SUBTARGET(SBF) +#else +#define SUBTARGET_SBF +#endif + #define GEN_SUBTARGETS \ SUBTARGET_X86 \ SUBTARGET_ARM \ @@ -185,6 +191,7 @@ extern "C" void LLVMTimeTraceProfilerFinish(const char* FileName) { SUBTARGET_RISCV \ SUBTARGET_LOONGARCH \ SUBTARGET_BPF \ + SUBTARGET_SBF \ #define SUBTARGET(x) \ namespace llvm { \ diff --git a/compiler/rustc_llvm/src/lib.rs b/compiler/rustc_llvm/src/lib.rs index a605a41668304..80db713b5c6f7 100644 --- a/compiler/rustc_llvm/src/lib.rs +++ b/compiler/rustc_llvm/src/lib.rs @@ -208,10 +208,10 @@ pub fn initialize_available_targets() { ); init_target!( llvm_component = "sbf", - LLVMInitializeBPFTargetInfo, - LLVMInitializeBPFTarget, - LLVMInitializeBPFTargetMC, - LLVMInitializeBPFAsmPrinter, - LLVMInitializeBPFAsmParser + LLVMInitializeSBFTargetInfo, + LLVMInitializeSBFTarget, + LLVMInitializeSBFTargetMC, + LLVMInitializeSBFAsmPrinter, + LLVMInitializeSBFAsmParser ); } diff --git a/config.toml b/config.toml index ca45653597f37..ca632f65d8ac6 100644 --- a/config.toml +++ b/config.toml @@ -66,7 +66,7 @@ targets = "AArch64;X86" # not built by default and the experimental Rust compilation targets that depend # on them will not work unless the user opts in to building them. By default the # `WebAssembly`, `RISCV`, and `BPF` targets are enabled when compiling LLVM from scratch. -experimental-targets = "BPF" +experimental-targets = "BPF;SBF" # Cap the number of parallel linker invocations when compiling LLVM. # This can be useful when building LLVM with debug info, which significantly diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index d37299548c5c8..d93386d77c6be 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -299,7 +299,7 @@ impl Step for Llvm { Some(s) => s, None => { "AArch64;ARM;BPF;Hexagon;LoongArch;MSP430;Mips;NVPTX;PowerPC;RISCV;\ - Sparc;SystemZ;WebAssembly;X86" + SBF;Sparc;SystemZ;WebAssembly;X86" } }; diff --git a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile index 454424b8e4daa..20c98057493e9 100644 --- a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile +++ b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile @@ -21,7 +21,7 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y RUN PATH="${HOME}/.cargo/bin:${PATH}" \ cargo install --git https://github.com/solana-labs/cargo-run-sbf-tests.git \ - --rev 8b76e26ee3cddca60297847361b67603e4299209 \ + --rev 9d45e79cf11b2fdf0e3572d916fe058823c7c438 \ --bin cargo-run-sbf-tests --root /usr/local COPY scripts/sccache.sh /scripts/ From 2ac4c61352959ce39cd8d0de4ce21c87c7065345 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Mon, 5 Dec 2022 17:37:19 -0500 Subject: [PATCH 089/103] [SOL] Adjust SBF customization after upgrading to rust 1.65.0 --- .github/workflows/ci.yml | 5 +- .../rustc_codegen_ssa/src/back/metadata.rs | 3 +- compiler/rustc_target/src/abi/call/sbf.rs | 2 +- compiler/rustc_target/src/spec/sbf_base.rs | 4 +- .../rustc_target/src/spec/tests/tests_impl.rs | 3 +- library/core/benches/lib.rs | 2 +- library/core/benches/num/int_log/mod.rs | 2 +- library/core/src/fmt/mod.rs | 2 +- library/core/src/fmt/num.rs | 2 +- library/core/tests/array.rs | 6 +- library/core/tests/atomic.rs | 2 +- library/core/tests/future.rs | 2 +- library/core/tests/lazy.rs | 2 +- library/core/tests/num/mod.rs | 2 +- library/core/tests/ptr.rs | 2 +- library/proc_macro/src/lib.rs | 1 - library/std/src/alloc.rs | 16 +- library/std/src/backtrace.rs | 104 +++++-------- library/std/src/collections/hash/map.rs | 2 +- library/std/src/io/mod.rs | 2 +- library/std/src/io/stdio.rs | 138 +++++++++++------- library/std/src/lib.rs | 6 +- library/std/src/panic.rs | 18 +-- library/std/src/panicking.rs | 78 +++++----- library/std/src/process.rs | 2 +- library/std/src/rt.rs | 20 +-- library/std/src/sync/once.rs | 1 - library/std/src/sync/remutex.rs | 10 +- library/std/src/sys/mod.rs | 2 +- library/std/src/sys/sbf/condvar.rs | 9 +- library/std/src/sys/sbf/fs.rs | 16 +- library/std/src/sys/sbf/mutex.rs | 9 +- library/std/src/sys/sbf/net.rs | 2 - library/std/src/sys/sbf/rwlock.rs | 4 - library/std/src/sys_common/backtrace.rs | 2 +- library/std/src/sys_common/thread.rs | 10 +- library/std/src/sys_common/thread_info.rs | 2 +- library/std/src/thread/mod.rs | 24 +-- library/test/src/cli.rs | 34 ++--- library/test/src/console.rs | 4 +- library/test/src/helpers/concurrency.rs | 6 +- library/test/src/lib.rs | 4 +- src/bootstrap/src/lib.rs | 4 +- .../host-x86_64/sbf-solana-solana/Dockerfile | 8 +- tests/ui/check-cfg/compact-values.stderr | 2 +- 45 files changed, 304 insertions(+), 277 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 20f777a2de9b2..fa94fd871ee69 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -226,7 +226,7 @@ jobs: uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master with: github_token: "${{ secrets.github_token }}" - if: "success() && !env.SKIP_JOB && github.ref != 'refs/heads/try'" + if: "success() && !env.SKIP_JOB && github.ref != 'refs/heads/try' && github.ref != 'refs/heads/try-perf'" - name: collect CPU statistics run: src/ci/scripts/collect-cpu-stats.sh if: success() && !env.SKIP_JOB @@ -245,9 +245,6 @@ jobs: - name: install WIX run: src/ci/scripts/install-wix.sh if: success() && !env.SKIP_JOB - - name: ensure the build happens on a partition with enough space - run: src/ci/scripts/symlink-build-dir.sh - if: success() && !env.SKIP_JOB - name: disable git crlf conversion run: src/ci/scripts/disable-git-crlf-conversion.sh if: success() && !env.SKIP_JOB diff --git a/compiler/rustc_codegen_ssa/src/back/metadata.rs b/compiler/rustc_codegen_ssa/src/back/metadata.rs index cb60ed729c1bf..07d1f3e888504 100644 --- a/compiler/rustc_codegen_ssa/src/back/metadata.rs +++ b/compiler/rustc_codegen_ssa/src/back/metadata.rs @@ -208,9 +208,10 @@ pub(crate) fn create_object_file(sess: &Session) -> Option Architecture::Avr, "msp430" => Architecture::Msp430, "hexagon" => Architecture::Hexagon, - "bpf" => Architecture::Bpf, "loongarch64" => Architecture::LoongArch64, "csky" => Architecture::Csky, + "bpf" => Architecture::Bpf, + "sbf" => Architecture::Bpf, // Unsupported architecture. _ => return None, }; diff --git a/compiler/rustc_target/src/abi/call/sbf.rs b/compiler/rustc_target/src/abi/call/sbf.rs index b60c33b22fa47..d762c7fae9734 100644 --- a/compiler/rustc_target/src/abi/call/sbf.rs +++ b/compiler/rustc_target/src/abi/call/sbf.rs @@ -26,7 +26,7 @@ pub fn compute_abi_info(fn_abi: &mut FnAbi<'_, Ty>) { classify_ret(&mut fn_abi.ret); } - for arg in &mut fn_abi.args { + for arg in fn_abi.args.iter_mut() { if arg.is_ignore() { continue; } diff --git a/compiler/rustc_target/src/spec/sbf_base.rs b/compiler/rustc_target/src/spec/sbf_base.rs index 20990d8d88fb2..4cb112f607de1 100644 --- a/compiler/rustc_target/src/spec/sbf_base.rs +++ b/compiler/rustc_target/src/spec/sbf_base.rs @@ -1,5 +1,5 @@ use crate::abi::Endian; -use super::{LinkArgs, LinkerFlavor, PanicStrategy, TargetOptions, LldFlavor}; +use super::{cvs, LinkArgs, LinkerFlavor, PanicStrategy, TargetOptions, LldFlavor}; pub fn opts() -> TargetOptions { let linker_script = r" @@ -33,6 +33,7 @@ SECTIONS lld_args.push("-z".into()); lld_args.push("notext".into()); let mut pre_link_args = LinkArgs::new(); + pre_link_args.insert(LinkerFlavor::Ld, lld_args.clone()); pre_link_args.insert(LinkerFlavor::Lld(LldFlavor::Ld), lld_args); TargetOptions { @@ -46,6 +47,7 @@ SECTIONS env: "".into(), executables: true, features: "+solana".into(), + families: cvs!["solana"], link_script: Some(linker_script.into()), linker: Some("rust-lld".into()), linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), diff --git a/compiler/rustc_target/src/spec/tests/tests_impl.rs b/compiler/rustc_target/src/spec/tests/tests_impl.rs index 9dbce47b55a6e..4abea40c29557 100644 --- a/compiler/rustc_target/src/spec/tests/tests_impl.rs +++ b/compiler/rustc_target/src/spec/tests/tests_impl.rs @@ -27,7 +27,8 @@ impl Target { matches!(self.linker_flavor, LinkerFlavor::WasmLld(..)) ); assert_eq!(self.os == "emscripten", matches!(self.linker_flavor, LinkerFlavor::EmCc)); - assert_eq!(self.arch == "bpf", matches!(self.linker_flavor, LinkerFlavor::Bpf)); + assert_eq!(self.arch == "bpf" && self.features != "+solana", + matches!(self.linker_flavor, LinkerFlavor::Bpf)); assert_eq!(self.arch == "nvptx64", matches!(self.linker_flavor, LinkerFlavor::Ptx)); for args in [ diff --git a/library/core/benches/lib.rs b/library/core/benches/lib.rs index daedcfab52462..6ac4448931654 100644 --- a/library/core/benches/lib.rs +++ b/library/core/benches/lib.rs @@ -1,5 +1,5 @@ // wasm32 does not support benches (no time). -#![cfg(not(any(target_arch = "wasm32", target_arch = "bpf", target_arch = "sbf")))] +#![cfg(not(any(target_arch = "wasm32", target_family = "solana")))] #![feature(flt2dec)] #![feature(test)] #![feature(trusted_random_access)] diff --git a/library/core/benches/num/int_log/mod.rs b/library/core/benches/num/int_log/mod.rs index 050a88f7281b4..7e98c0d623433 100644 --- a/library/core/benches/num/int_log/mod.rs +++ b/library/core/benches/num/int_log/mod.rs @@ -1,4 +1,4 @@ -#![cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#![cfg(not(target_family = "solana"))] use rand::Rng; use test::{black_box, Bencher}; diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index c54f7408205fc..84ce99487009b 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -5,7 +5,7 @@ use crate::cell::{Cell, Ref, RefCell, RefMut, SyncUnsafeCell, UnsafeCell}; use crate::char::EscapeDebugExtArgs; use crate::iter; -#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[cfg(target_family = "solana")] use crate::intrinsics::abort; use crate::marker::PhantomData; use crate::mem; diff --git a/library/core/src/fmt/num.rs b/library/core/src/fmt/num.rs index bc84f662f5c75..fe80a7e3de320 100644 --- a/library/core/src/fmt/num.rs +++ b/library/core/src/fmt/num.rs @@ -474,7 +474,7 @@ mod imp { ); } -#[cfg(not(any(target_pointer_width = "64", target_arch = "wasm32", target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(any(target_pointer_width = "64", target_arch = "wasm32", target_family = "solana")))] mod imp { use super::*; impl_Display!(i8, u8, i16, u16, i32, u32, isize, usize as u32 via to_u32 named fmt_u32); diff --git a/library/core/tests/array.rs b/library/core/tests/array.rs index 740275fc44764..850eb850763a3 100644 --- a/library/core/tests/array.rs +++ b/library/core/tests/array.rs @@ -1,4 +1,4 @@ -#![cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#![cfg(not(target_family = "solana"))] use core::{array, assert_eq}; use core::convert::TryFrom; use core::num::NonZeroUsize; @@ -513,7 +513,7 @@ fn array_rsplit_array_mut_out_of_bounds() { } #[test] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] fn array_intoiter_advance_by() { use std::cell::Cell; struct DropCounter<'a>(usize, &'a Cell); @@ -567,7 +567,7 @@ fn array_intoiter_advance_by() { } #[test] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] fn array_intoiter_advance_back_by() { use std::cell::Cell; struct DropCounter<'a>(usize, &'a Cell); diff --git a/library/core/tests/atomic.rs b/library/core/tests/atomic.rs index bd4ca75a8979e..1e7cb8ccac45a 100644 --- a/library/core/tests/atomic.rs +++ b/library/core/tests/atomic.rs @@ -213,7 +213,7 @@ fn ptr_bitops_tagging() { } // SBF does not support mustable static data -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] mod statik { use super::*; diff --git a/library/core/tests/future.rs b/library/core/tests/future.rs index f0549da14e2ab..04dac6fb72ff7 100644 --- a/library/core/tests/future.rs +++ b/library/core/tests/future.rs @@ -1,4 +1,4 @@ -#![cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#![cfg(not(target_family = "solana"))] use std::future::{join, Future}; use std::pin::Pin; use std::sync::Arc; diff --git a/library/core/tests/lazy.rs b/library/core/tests/lazy.rs index 225975b43948e..b5c8e5ce4d591 100644 --- a/library/core/tests/lazy.rs +++ b/library/core/tests/lazy.rs @@ -25,7 +25,7 @@ fn once_cell_get_mut() { } // sbf doesn't have mutable static data -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] #[test] fn once_cell_drop() { static DROP_CNT: AtomicUsize = AtomicUsize::new(0); diff --git a/library/core/tests/num/mod.rs b/library/core/tests/num/mod.rs index bfa9e52e7de6a..b46835f68bcbd 100644 --- a/library/core/tests/num/mod.rs +++ b/library/core/tests/num/mod.rs @@ -31,7 +31,7 @@ mod bignum; mod const_from; mod dec2flt; // sbf doesn't support floats -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] mod flt2dec; mod int_log; mod ops; diff --git a/library/core/tests/ptr.rs b/library/core/tests/ptr.rs index 10f20328187cb..319564c454635 100644 --- a/library/core/tests/ptr.rs +++ b/library/core/tests/ptr.rs @@ -322,7 +322,7 @@ pub fn test_variadic_fnptr() { } // sbf doesn't support thread locals -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] #[test] fn write_unaligned_drop() { thread_local! { diff --git a/library/proc_macro/src/lib.rs b/library/proc_macro/src/lib.rs index a6e7e95070cd5..991fdb1256de3 100644 --- a/library/proc_macro/src/lib.rs +++ b/library/proc_macro/src/lib.rs @@ -9,7 +9,6 @@ //! //! [the book]: ../book/ch19-06-macros.html#procedural-macros-for-generating-code-from-attributes -#![cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] #![stable(feature = "proc_macro_lib", since = "1.15.0")] #![deny(missing_docs)] #![doc( diff --git a/library/std/src/alloc.rs b/library/std/src/alloc.rs index b01b8f5300424..55e4218491615 100644 --- a/library/std/src/alloc.rs +++ b/library/std/src/alloc.rs @@ -58,9 +58,9 @@ use core::intrinsics; use core::ptr::NonNull; -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] use core::sync::atomic::{AtomicPtr, Ordering}; -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] use core::mem; use core::ptr; @@ -289,7 +289,7 @@ unsafe impl Allocator for System { } } -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] static HOOK: AtomicPtr<()> = AtomicPtr::new(ptr::null_mut()); /// Registers a custom allocation error hook, replacing any that was previously registered. @@ -332,7 +332,7 @@ static HOOK: AtomicPtr<()> = AtomicPtr::new(ptr::null_mut()); /// set_alloc_error_hook(custom_alloc_error_hook); /// ``` #[unstable(feature = "alloc_error_hook", issue = "51245")] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] pub fn set_alloc_error_hook(hook: fn(Layout)) { HOOK.store(hook as *mut (), Ordering::SeqCst); } @@ -343,13 +343,13 @@ pub fn set_alloc_error_hook(hook: fn(Layout)) { /// /// If no custom hook is registered, the default hook will be returned. #[unstable(feature = "alloc_error_hook", issue = "51245")] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] pub fn take_alloc_error_hook() -> fn(Layout) { let hook = HOOK.swap(ptr::null_mut(), Ordering::SeqCst); if hook.is_null() { default_alloc_error_hook } else { unsafe { mem::transmute(hook) } } } -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] fn default_alloc_error_hook(layout: Layout) { extern "Rust" { // This symbol is emitted by rustc next to __rust_alloc_error_handler. @@ -369,14 +369,14 @@ fn default_alloc_error_hook(layout: Layout) { #[alloc_error_handler] #[unstable(feature = "alloc_internals", issue = "none")] pub fn rust_oom(_layout: Layout) -> ! { - #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] + #[cfg(not(target_family = "solana"))] { let hook = HOOK.load(Ordering::SeqCst); let hook: fn(Layout) = if hook.is_null() { default_alloc_error_hook } else { unsafe { mem::transmute(hook) } }; hook(_layout); } - #[cfg(any(target_arch = "bpf", target_arch = "sbf"))] + #[cfg(target_family = "solana")] { crate::sys::sol_log(b"Error: memory allocation failed, out of memory"); } diff --git a/library/std/src/backtrace.rs b/library/std/src/backtrace.rs index 7596d7e41ec40..7a2f54feab832 100644 --- a/library/std/src/backtrace.rs +++ b/library/std/src/backtrace.rs @@ -88,16 +88,20 @@ mod tests; // `Backtrace`, but that's a relatively small price to pay relative to capturing // a backtrace or actually symbolizing it. -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] use crate::backtrace_rs::{self, BytesOrWideString}; +#[cfg(not(target_family = "solana"))] use crate::env; +#[cfg(not(target_family = "solana"))] use crate::ffi::c_void; use crate::fmt; -use crate::panic::UnwindSafe; +#[cfg(not(target_family = "solana"))] use crate::sync::atomic::{AtomicUsize, Ordering::Relaxed}; +#[cfg(not(target_family = "solana"))] use crate::sync::LazyLock; -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] use crate::sys_common::backtrace::{lock, output_filename}; +#[cfg(not(target_family = "solana"))] use crate::vec::Vec; /// A captured OS thread stack backtrace. @@ -135,9 +139,11 @@ pub enum BacktraceStatus { enum Inner { Unsupported, Disabled, + #[cfg(not(target_family = "solana"))] Captured(LazyLock), } +#[cfg(not(target_family = "solana"))] struct Capture { actual_start: usize, frames: Vec, @@ -151,18 +157,21 @@ fn _assert_send_sync() { /// A single frame of a backtrace. #[unstable(feature = "backtrace_frames", issue = "79676")] pub struct BacktraceFrame { + #[cfg(not(target_family = "solana"))] frame: RawFrame, + #[cfg(not(target_family = "solana"))] symbols: Vec, } #[derive(Debug)] enum RawFrame { - #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] + #[cfg(not(target_family = "solana"))] Actual(backtrace_rs::Frame), #[cfg(test)] Fake, } +#[cfg(not(target_family = "solana"))] struct BacktraceSymbol { name: Option>, filename: Option, @@ -170,6 +179,7 @@ struct BacktraceSymbol { colno: Option, } +#[cfg(not(target_family = "solana"))] enum BytesOrWide { Bytes(Vec), Wide(Vec), @@ -177,7 +187,7 @@ enum BytesOrWide { #[stable(feature = "backtrace", since = "1.65.0")] impl fmt::Debug for Backtrace { - #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] + #[cfg(not(target_family = "solana"))] fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { let capture = match &self.inner { Inner::Unsupported => return fmt.write_str(""), @@ -202,7 +212,7 @@ impl fmt::Debug for Backtrace { dbg.finish() } - #[cfg(any(target_arch = "bpf", target_arch = "sbf"))] + #[cfg(target_family = "solana")] fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "") } @@ -210,20 +220,20 @@ impl fmt::Debug for Backtrace { #[unstable(feature = "backtrace_frames", issue = "79676")] impl fmt::Debug for BacktraceFrame { - #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] + #[cfg(not(target_family = "solana"))] fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { let mut dbg = fmt.debug_list(); dbg.entries(&self.symbols); dbg.finish() } - #[cfg(any(target_arch = "bpf", target_arch = "sbf"))] + #[cfg(target_family = "solana")] fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "") } } -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] impl fmt::Debug for BacktraceSymbol { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { // FIXME: improve formatting: https://github.com/rust-lang/rust/issues/65280 @@ -250,7 +260,7 @@ impl fmt::Debug for BacktraceSymbol { } } -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] impl fmt::Debug for BytesOrWide { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { output_filename( @@ -268,7 +278,7 @@ impl fmt::Debug for BytesOrWide { impl Backtrace { /// Returns whether backtrace captures are enabled through environment /// variables. - #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] + #[cfg(not(target_family = "solana"))] fn enabled() -> bool { // Cache the result of reading the environment variables to make // backtrace captures speedy, because otherwise reading environment @@ -290,7 +300,7 @@ impl Backtrace { enabled } - #[cfg(any(target_arch = "bpf", target_arch = "sbf"))] + #[cfg(target_family = "solana")] fn enabled() -> bool { false } @@ -346,7 +356,7 @@ impl Backtrace { // Capture a backtrace which start just before the function addressed by // `ip` - #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] + #[cfg(not(target_family = "solana"))] fn create(ip: usize) -> Backtrace { let _lock = lock(); let mut frames = Vec::new(); @@ -379,8 +389,8 @@ impl Backtrace { Backtrace { inner } } - #[cfg(any(target_arch = "bpf", target_arch = "sbf"))] - fn create(ip: usize) -> Backtrace { + #[cfg(target_family = "solana")] + fn create(_ip: usize) -> Backtrace { Backtrace { inner: Inner::Unsupported } @@ -395,6 +405,7 @@ impl Backtrace { match self.inner { Inner::Unsupported => BacktraceStatus::Unsupported, Inner::Disabled => BacktraceStatus::Disabled, + #[cfg(not(target_family = "solana"))] Inner::Captured(_) => BacktraceStatus::Captured, } } @@ -404,14 +415,23 @@ impl<'a> Backtrace { /// Returns an iterator over the backtrace frames. #[must_use] #[unstable(feature = "backtrace_frames", issue = "79676")] + #[cfg(not(target_family = "solana"))] pub fn frames(&'a self) -> &'a [BacktraceFrame] { if let Inner::Captured(c) = &self.inner { &c.frames } else { &[] } } + + /// Returns an iterator over the backtrace frames. + #[must_use] + #[unstable(feature = "backtrace_frames", issue = "79676")] + #[cfg(target_family = "solana")] + pub fn frames(&'a self) -> &'a [BacktraceFrame] { + &[] + } } #[stable(feature = "backtrace", since = "1.65.0")] impl fmt::Display for Backtrace { - #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] + #[cfg(not(target_family = "solana"))] fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { let capture = match &self.inner { Inner::Unsupported => return fmt.write_str("unsupported backtrace"), @@ -459,51 +479,14 @@ impl fmt::Display for Backtrace { Ok(()) } - #[cfg(any(target_arch = "bpf", target_arch = "sbf"))] + #[cfg(target_family = "solana")] fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "") } } -<<<<<<< HEAD -type LazyResolve = impl (FnOnce() -> Capture) + Send + Sync + UnwindSafe; -======= -struct LazilyResolvedCapture { - sync: Once, - capture: UnsafeCell, -} - -impl LazilyResolvedCapture { - fn new(capture: Capture) -> Self { - LazilyResolvedCapture { sync: Once::new(), capture: UnsafeCell::new(capture) } - } - fn force(&self) -> &Capture { - self.sync.call_once(|| { - // SAFETY: This exclusive reference can't overlap with any others - // `Once` guarantees callers will block until this closure returns - // `Once` also guarantees only a single caller will enter this closure - unsafe { &mut *self.capture.get() }.resolve(); - }); - - // SAFETY: This shared reference can't overlap with the exclusive reference above - unsafe { &*self.capture.get() } - } -} - -// SAFETY: Access to the inner value is synchronized using a thread-safe `Once` -// So long as `Capture` is `Sync`, `LazilyResolvedCapture` is too -unsafe impl Sync for LazilyResolvedCapture where Capture: Sync {} - -impl Capture { - #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] - fn resolve(&mut self) { - // If we're already resolved, nothing to do! - if self.resolved { - return; - } - self.resolved = true; ->>>>>>> a2fbab5821e ([SOL] Enable the std backtrace API) +type LazyResolve = impl (FnOnce() -> Capture) + Send + Sync + UnwindSafe; fn lazy_resolve(mut capture: Capture) -> LazyResolve { move || { @@ -535,18 +518,9 @@ fn lazy_resolve(mut capture: Capture) -> LazyResolve { capture } - - #[cfg(any(target_arch = "bpf", target_arch = "sbf"))] - fn resolve(&mut self) { - // If we're already resolved, nothing to do! - if self.resolved { - return; - } - self.resolved = true; - } } -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] impl RawFrame { fn ip(&self) -> *mut c_void { match self { diff --git a/library/std/src/collections/hash/map.rs b/library/std/src/collections/hash/map.rs index 5e0df1170b0d8..a2f0bcf7aa278 100644 --- a/library/std/src/collections/hash/map.rs +++ b/library/std/src/collections/hash/map.rs @@ -3111,7 +3111,7 @@ impl RandomState { #[must_use] #[stable(feature = "hashmap_build_hasher", since = "1.7.0")] pub fn new() -> RandomState { - if cfg!(any(target_arch = "bpf", target_arch = "sbf")) { + if cfg!(target_family = "solana") { // sbf doesn't support thread_local!() RandomState { k0: 0, k1: 0 } } else { diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index 47eec5320c348..aa4c0af190646 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -344,7 +344,7 @@ mod util; const DEFAULT_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE; -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] pub(crate) use stdio::cleanup; struct Guard<'a> { diff --git a/library/std/src/io/stdio.rs b/library/std/src/io/stdio.rs index af7f60092a204..3e7ea71a5564f 100644 --- a/library/std/src/io/stdio.rs +++ b/library/std/src/io/stdio.rs @@ -5,22 +5,24 @@ mod tests; use crate::io::prelude::*; -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] use crate::cell::{Cell, RefCell}; use crate::fmt; use crate::fs::File; #[cfg(not(target_os = "solana"))] use crate::io::{self, BorrowedCursor, BufReader, IoSlice, IoSliceMut, LineWriter, Lines}; #[cfg(target_os = "solana")] -use crate::io::{self, BufReader, IoSlice, IoSliceMut, LineWriter, Lines}; -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +use crate::io::{self, BufReader, IoSlice, IoSliceMut}; +#[cfg(not(target_family = "solana"))] use crate::sync::atomic::{AtomicBool, Ordering}; -use crate::sync::{Arc, Mutex, MutexGuard, OnceLock, ReentrantMutex, ReentrantMutexGuard}; +use crate::sync::{Arc, Mutex, MutexGuard}; +#[cfg(not(target_family = "solana"))] +use crate::sync::{OnceLock, ReentrantMutex, ReentrantMutexGuard}; use crate::sys::stdio; type LocalStream = Arc>>; -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] thread_local! { /// Used by the test crate to capture the output of the print macros and panics. static OUTPUT_CAPTURE: Cell> = { @@ -40,7 +42,7 @@ thread_local! { /// have a consistent order between set_output_capture and print_to *within /// the same thread*. Within the same thread, things always have a perfectly /// consistent order. So Ordering::Relaxed is fine. -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] static OUTPUT_CAPTURE_USED: AtomicBool = AtomicBool::new(false); /// A handle to a raw instance of the standard input stream of this process. @@ -69,7 +71,7 @@ struct StderrRaw(stdio::Stderr); /// /// The returned handle has no external synchronization or buffering. #[unstable(feature = "libstd_sys_internals", issue = "none")] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] const fn stdin_raw() -> StdinRaw { StdinRaw(stdio::Stdin::new()) } @@ -84,7 +86,7 @@ const fn stdin_raw() -> StdinRaw { /// The returned handle has no external synchronization or buffering layered on /// top. #[unstable(feature = "libstd_sys_internals", issue = "none")] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] const fn stdout_raw() -> StdoutRaw { StdoutRaw(stdio::Stdout::new()) } @@ -97,7 +99,7 @@ const fn stdout_raw() -> StdoutRaw { /// The returned handle has no external synchronization or buffering layered on /// top. #[unstable(feature = "libstd_sys_internals", issue = "none")] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] const fn stderr_raw() -> StderrRaw { StderrRaw(stdio::Stderr::new()) } @@ -240,7 +242,7 @@ fn handle_ebadf(r: io::Result, default: T) -> io::Result { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub struct Stdin { - #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] + #[cfg(not(target_family = "solana"))] inner: &'static Mutex>, } @@ -330,7 +332,7 @@ pub struct StdinLock<'a> { /// ``` #[must_use] #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] pub fn stdin() -> Stdin { static INSTANCE: OnceLock>> = OnceLock::new(); Stdin { @@ -342,7 +344,7 @@ pub fn stdin() -> Stdin { /// SBF dummy #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[cfg(target_family = "solana")] pub fn stdin() -> Stdin { Stdin {} } @@ -370,7 +372,7 @@ impl Stdin { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] + #[cfg(not(target_family = "solana"))] pub fn lock(&self) -> StdinLock<'static> { // Locks this handle with 'static lifetime. This depends on the // implementation detail that the underlying `Mutex` is static. @@ -404,7 +406,7 @@ impl Stdin { /// in which case it will wait for the Enter key to be pressed before /// continuing #[stable(feature = "rust1", since = "1.0.0")] - #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] + #[cfg(not(target_family = "solana"))] pub fn read_line(&self, buf: &mut String) -> io::Result { self.lock().read_line(buf) } @@ -426,7 +428,7 @@ impl Stdin { /// ``` #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "stdin_forwarders", since = "1.62.0")] - #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] + #[cfg(not(target_family = "solana"))] pub fn lines(self) -> Lines> { self.lock().lines() } @@ -440,7 +442,7 @@ impl fmt::Debug for Stdin { } #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] impl Read for Stdin { fn read(&mut self, buf: &mut [u8]) -> io::Result { self.lock().read(buf) @@ -467,7 +469,7 @@ impl Read for Stdin { } #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[cfg(target_family = "solana")] impl Read for Stdin { fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) @@ -583,7 +585,7 @@ pub struct Stdout { // FIXME: this should be LineWriter or BufWriter depending on the state of // stdout (tty or not). Note that if this is not line buffered it // should also flush-on-panic or some form of flush-on-abort. - #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] + #[cfg(not(target_family = "solana"))] inner: &'static ReentrantMutex>>, } @@ -605,18 +607,18 @@ pub struct Stdout { /// standard library or via raw Windows API calls, will fail. #[must_use = "if unused stdout will immediately unlock"] #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] pub struct StdoutLock<'a> { inner: ReentrantMutexGuard<'a, RefCell>>, } /// SBF dummy #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[cfg(target_family = "solana")] pub struct StdoutLock { } -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] static STDOUT: OnceLock>>> = OnceLock::new(); /// Constructs a new handle to the standard output of the current process. @@ -668,7 +670,7 @@ static STDOUT: OnceLock>>> = OnceLo #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "io_stdout")] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] pub fn stdout() -> Stdout { Stdout { inner: STDOUT @@ -678,7 +680,7 @@ pub fn stdout() -> Stdout { /// Dummy stdout for SBF target #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[cfg(target_family = "solana")] pub fn stdout() -> Stdout { Stdout {} } @@ -686,7 +688,7 @@ pub fn stdout() -> Stdout { // Flush the data and disable buffering during shutdown // by replacing the line writer by one with zero // buffering capacity. -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] pub fn cleanup() { let mut initialized = false; let stdout = STDOUT.get_or_init(|| { @@ -726,13 +728,23 @@ impl Stdout { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] + #[cfg(not(target_family = "solana"))] pub fn lock(&self) -> StdoutLock<'static> { // Locks this handle with 'static lifetime. This depends on the // implementation detail that the underlying `ReentrantMutex` is // static. StdoutLock { inner: self.inner.lock() } } + + /// Dummy lock for SBF + #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(target_family = "solana")] + pub fn lock(&self) -> StdoutLock { + // Locks this handle with 'static lifetime. This depends on the + // implementation detail that the underlying `ReentrantMutex` is + // static. + StdoutLock { } + } } #[stable(feature = "std_debug", since = "1.16.0")] @@ -743,7 +755,7 @@ impl fmt::Debug for Stdout { } #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] impl Write for Stdout { fn write(&mut self, buf: &[u8]) -> io::Result { (&*self).write(buf) @@ -770,7 +782,7 @@ impl Write for Stdout { } #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[cfg(target_family = "solana")] impl Write for Stdout { fn write(&mut self, buf: &[u8]) -> io::Result { crate::sys::sol_log(buf); @@ -799,7 +811,7 @@ impl Write for Stdout { } #[stable(feature = "write_mt", since = "1.48.0")] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] impl Write for &Stdout { fn write(&mut self, buf: &[u8]) -> io::Result { self.lock().write(buf) @@ -826,7 +838,7 @@ impl Write for &Stdout { } #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] impl Write for StdoutLock<'_> { fn write(&mut self, buf: &[u8]) -> io::Result { self.inner.borrow_mut().write(buf) @@ -849,8 +861,34 @@ impl Write for StdoutLock<'_> { } } +#[stable(feature = "rust1", since = "1.0.0")] +#[cfg(target_family = "solana")] +impl Write for StdoutLock { + fn write(&mut self, buf: &[u8]) -> io::Result { + crate::sys::sol_log(buf); + Ok(buf.len()) + } + fn write_vectored(&mut self, _bufs: &[IoSlice<'_>]) -> io::Result { + Ok(0) + } + #[inline] + fn is_write_vectored(&self) -> bool { + false + } + fn flush(&mut self) -> io::Result<()> { + Ok(()) + } + fn write_all(&mut self, buf: &[u8]) -> io::Result<()> { + crate::sys::sol_log(buf); + Ok(()) + } + fn write_all_vectored(&mut self, _bufs: &mut [IoSlice<'_>]) -> io::Result<()> { + Ok(()) + } +} + #[stable(feature = "std_debug", since = "1.16.0")] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] impl fmt::Debug for StdoutLock<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("StdoutLock").finish_non_exhaustive() @@ -858,7 +896,7 @@ impl fmt::Debug for StdoutLock<'_> { } #[stable(feature = "std_debug", since = "1.16.0")] -#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[cfg(target_family = "solana")] impl fmt::Debug for StdoutLock { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("StdoutLock { .. }") @@ -884,7 +922,7 @@ impl fmt::Debug for StdoutLock { /// standard library or via raw Windows API calls, will fail. #[stable(feature = "rust1", since = "1.0.0")] pub struct Stderr { - #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] + #[cfg(not(target_family = "solana"))] inner: &'static ReentrantMutex>, } @@ -906,14 +944,14 @@ pub struct Stderr { /// standard library or via raw Windows API calls, will fail. #[must_use = "if unused stderr will immediately unlock"] #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] pub struct StderrLock<'a> { inner: ReentrantMutexGuard<'a, RefCell>, } /// SBF dummy #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[cfg(target_family = "solana")] pub struct StderrLock { } @@ -964,7 +1002,7 @@ pub struct StderrLock { #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "io_stderr")] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] pub fn stderr() -> Stderr { // Note that unlike `stdout()` we don't use `at_exit` here to register a // destructor. Stderr is not buffered, so there's no need to run a @@ -977,7 +1015,7 @@ pub fn stderr() -> Stderr { /// SBF dummy #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[cfg(target_family = "solana")] pub fn stderr() -> Stderr { Stderr {} } @@ -1004,7 +1042,7 @@ impl Stderr { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] + #[cfg(not(target_family = "solana"))] pub fn lock(&self) -> StderrLock<'static> { // Locks this handle with 'static lifetime. This depends on the // implementation detail that the underlying `ReentrantMutex` is @@ -1021,7 +1059,7 @@ impl fmt::Debug for Stderr { } #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] impl Write for Stderr { fn write(&mut self, buf: &[u8]) -> io::Result { (&*self).write(buf) @@ -1048,7 +1086,7 @@ impl Write for Stderr { } #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[cfg(target_family = "solana")] impl Write for Stderr { fn write(&mut self, buf: &[u8]) -> io::Result { crate::sys::sol_log(buf); @@ -1077,7 +1115,7 @@ impl Write for Stderr { } #[stable(feature = "write_mt", since = "1.48.0")] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] impl Write for &Stderr { fn write(&mut self, buf: &[u8]) -> io::Result { self.lock().write(buf) @@ -1104,7 +1142,7 @@ impl Write for &Stderr { } #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] impl Write for StderrLock<'_> { fn write(&mut self, buf: &[u8]) -> io::Result { self.inner.borrow_mut().write(buf) @@ -1128,7 +1166,7 @@ impl Write for StderrLock<'_> { } #[stable(feature = "std_debug", since = "1.16.0")] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] impl fmt::Debug for StderrLock<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("StderrLock").finish_non_exhaustive() @@ -1136,7 +1174,7 @@ impl fmt::Debug for StderrLock<'_> { } #[stable(feature = "std_debug", since = "1.16.0")] -#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[cfg(target_family = "solana")] impl fmt::Debug for StderrLock { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("StderrLock { .. }") @@ -1144,7 +1182,7 @@ impl fmt::Debug for StderrLock { } /// Sets the thread-local output capture buffer and returns the old one. -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] #[unstable( feature = "internal_output_capture", reason = "this function is meant for use in the test crate \ @@ -1162,7 +1200,7 @@ pub fn set_output_capture(sink: Option) -> Option { } /// Dummy version for satisfying test library dependencies when building the SBF target. -#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[cfg(target_family = "solana")] #[unstable( feature = "internal_output_capture", reason = "this function is meant for use in the test crate \ @@ -1187,7 +1225,7 @@ pub fn set_output_capture(_sink: Option) -> Option { /// /// Writing to non-blocking stdout/stderr can cause an error, which will lead /// this function to panic. -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] fn print_to(args: fmt::Arguments<'_>, global_s: fn() -> T, label: &str) where T: Write, @@ -1273,7 +1311,7 @@ impl_is_terminal!(File, Stdin, StdinLock<'_>, Stdout, StdoutLock<'_>, Stderr, St )] #[doc(hidden)] #[cfg(not(test))] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] pub fn _print(args: fmt::Arguments<'_>) { print_to(args, stdout, "stdout"); } @@ -1284,7 +1322,7 @@ pub fn _print(args: fmt::Arguments<'_>) { issue = "none")] #[doc(hidden)] #[cfg(not(test))] -#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[cfg(target_family = "solana")] pub fn _print(_args: fmt::Arguments<'_>) { } @@ -1295,7 +1333,7 @@ pub fn _print(_args: fmt::Arguments<'_>) { )] #[doc(hidden)] #[cfg(not(test))] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] pub fn _eprint(args: fmt::Arguments<'_>) { print_to(args, stderr, "stderr"); } @@ -1306,7 +1344,7 @@ pub fn _eprint(args: fmt::Arguments<'_>) { issue = "none")] #[doc(hidden)] #[cfg(not(test))] -#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[cfg(target_family = "solana")] pub fn _eprint(_args: fmt::Arguments<'_>) { } diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 44d04920e4be9..43cdd9a0a6ae2 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -429,10 +429,10 @@ extern crate unwind; #[doc(masked)] #[allow(unused_extern_crates)] #[cfg(all( - not(all(windows, target_env = "msvc", not(target_vendor = "uwp"), - any(target_arch = "bpf", target_arch = "sbf"))), + not(all(windows, target_env = "msvc", not(target_vendor = "uwp"))), feature = "miniz_oxide" ))] +#[cfg(all(not(target_family = "solana"), feature = "miniz_oxide"))] extern crate miniz_oxide; // During testing, this crate is not actually the "real" std library, but rather @@ -641,7 +641,7 @@ pub mod alloc; // Private support modules mod panicking; -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] #[path = "../../backtrace/src/lib.rs"] #[allow(dead_code, unused_attributes, fuzzy_provenance_casts)] mod backtrace_rs; diff --git a/library/std/src/panic.rs b/library/std/src/panic.rs index f51f65f66065a..956bd2e86f568 100644 --- a/library/std/src/panic.rs +++ b/library/std/src/panic.rs @@ -5,7 +5,7 @@ use crate::any::Any; use crate::collections; use crate::panicking; -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] use crate::sync::atomic::{AtomicUsize, Ordering}; use crate::sync::{Mutex, RwLock}; use crate::thread::Result; @@ -57,7 +57,7 @@ pub use core::panic::{AssertUnwindSafe, RefUnwindSafe, UnwindSafe}; /// accessed later using [`PanicInfo::payload`]. /// /// See the [`panic!`] macro for more information about panicking. -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] #[stable(feature = "panic_any", since = "1.51.0")] #[inline] #[track_caller] @@ -170,14 +170,14 @@ pub fn catch_unwind R + UnwindSafe, R>(f: F) -> Result { /// } /// ``` #[stable(feature = "resume_unwind", since = "1.9.0")] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] pub fn resume_unwind(payload: Box) -> ! { panicking::rust_panic_without_hook(payload) } /// SBF version of resume_unwind #[stable(feature = "resume_unwind", since = "1.9.0")] -#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[cfg(target_family = "solana")] pub fn resume_unwind(_payload: Box) -> ! { // Only used by thread, redirect to plain old panic panicking::begin_panic_fmt(&format_args!("unwind")) @@ -221,7 +221,7 @@ pub fn always_abort() { /// The configuration for whether and how the default panic hook will capture /// and display the backtrace. -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[unstable(feature = "panic_backtrace_config", issue = "93346")] #[non_exhaustive] @@ -235,7 +235,7 @@ pub enum BacktraceStyle { Off, } -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] impl BacktraceStyle { pub(crate) fn full() -> Option { if cfg!(feature = "backtrace") { Some(BacktraceStyle::Full) } else { None } @@ -264,7 +264,7 @@ impl BacktraceStyle { // that backtrace. // // Internally stores equivalent of an Option. -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] static SHOULD_CAPTURE: AtomicUsize = AtomicUsize::new(0); /// Configure whether the default panic hook will capture and display a @@ -272,7 +272,7 @@ static SHOULD_CAPTURE: AtomicUsize = AtomicUsize::new(0); /// /// The default value for this setting may be set by the `RUST_BACKTRACE` /// environment variable; see the details in [`get_backtrace_style`]. -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] #[unstable(feature = "panic_backtrace_config", issue = "93346")] pub fn set_backtrace_style(style: BacktraceStyle) { if !cfg!(feature = "backtrace") { @@ -303,7 +303,7 @@ pub fn set_backtrace_style(style: BacktraceStyle) { /// the future /// /// Returns `None` if backtraces aren't currently supported. -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] #[unstable(feature = "panic_backtrace_config", issue = "93346")] pub fn get_backtrace_style() -> Option { if !cfg!(feature = "backtrace") { diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index efc7646460fac..ca6029d713bab 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -9,7 +9,7 @@ #![deny(unsafe_op_in_unsafe_fn)] -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] use crate::panic::BacktraceStyle; #[cfg(not(target_os = "solana"))] use core::panic::{PanicPayload}; @@ -19,29 +19,29 @@ use crate::any::Any; use crate::fmt; use crate::intrinsics; use crate::mem::ManuallyDrop; -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] use crate::mem; -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] use crate::process; -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] use crate::sync::atomic::{AtomicBool, Ordering}; use crate::sync::{PoisonError, RwLock}; #[cfg(not(target_os = "solana"))] use crate::sys::stdio::panic_output; -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] use crate::sys_common::backtrace; -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] use crate::sys_common::rwlock::StaticRwLock; -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] use crate::sys_common::thread_info; -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] use crate::thread; -#[cfg(all(not(test), not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(all(not(test), not(target_family = "solana")))] use crate::io::set_output_capture; // make sure to use the stderr output configured // by libtest in the real copy of std -#[cfg(all(test, not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(all(test, not(target_family = "solana")))] use realstd::io::set_output_capture; // Binary interface to the panic runtime that the standard library depends on. @@ -62,14 +62,14 @@ extern "C" { extern "Rust" { /// `PanicPayload` lazily performs allocation only when needed (this avoids /// allocations when using the "abort" panic runtime). - #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] + #[cfg(not(target_family = "solana"))] fn __rust_start_panic(payload: &mut dyn PanicPayload) -> u32; } /// This function is called by the panic runtime if FFI code catches a Rust /// panic but doesn't rethrow it. We don't support this case since it messes /// with our panic count. -#[cfg(all(not(test), not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(all(not(test), not(target_family = "solana")))] #[rustc_std_internal_symbol] extern "C" fn __rust_drop_panic() -> ! { rtabort!("Rust panics must be rethrown"); @@ -77,7 +77,7 @@ extern "C" fn __rust_drop_panic() -> ! { /// This function is called by the panic runtime if it catches an exception /// object which does not correspond to a Rust panic. -#[cfg(all(not(test), not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(all(not(test), not(target_family = "solana")))] #[rustc_std_internal_symbol] extern "C" fn __rust_foreign_exception() -> ! { rtabort!("Rust cannot catch foreign exceptions"); @@ -89,7 +89,7 @@ enum Hook { Custom(Box) + 'static + Sync + Send>), } -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] impl Hook { #[inline] fn into_box(self) -> Box) + 'static + Sync + Send> { @@ -147,7 +147,7 @@ static HOOK: RwLock = RwLock::new(Hook::Default); /// /// panic!("Normal panic"); /// ``` -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] #[stable(feature = "panic_hooks", since = "1.10.0")] pub fn set_hook(hook: Box) + 'static + Sync + Send>) { if thread::panicking() { @@ -164,7 +164,7 @@ pub fn set_hook(hook: Box) + 'static + Sync + Send>) { } /// Dummy version for satisfying library/test dependencies for SBF target -#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[cfg(target_family = "solana")] #[stable(feature = "panic_hooks", since = "1.10.0")] pub fn set_hook(_hook: Box) + 'static + Sync + Send>) { } @@ -198,7 +198,7 @@ pub fn set_hook(_hook: Box) + 'static + Sync + Send>) { /// panic!("Normal panic"); /// ``` #[must_use] -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] #[stable(feature = "panic_hooks", since = "1.10.0")] pub fn take_hook() -> Box) + 'static + Sync + Send> { if thread::panicking() { @@ -213,7 +213,7 @@ pub fn take_hook() -> Box) + 'static + Sync + Send> { } /// Dummy version for satisfying library/test dependencies for BPF target -#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[cfg(target_family = "solana")] #[stable(feature = "panic_hooks", since = "1.10.0")] pub fn take_hook() -> Box) + 'static + Sync + Send> { Box::new(default_hook) @@ -250,7 +250,7 @@ pub fn take_hook() -> Box) + 'static + Sync + Send> { /// /// panic!("Custom and then normal"); /// ``` -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] #[unstable(feature = "panic_update_hook", issue = "92649")] pub fn update_hook(hook_fn: F) where @@ -269,7 +269,7 @@ where } /// Dummy version for satisfying library/test dependencies for SBF target -#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[cfg(target_family = "solana")] #[unstable(feature = "panic_update_hook", issue = "92649")] pub fn update_hook(_hook_fn: F) where @@ -281,7 +281,7 @@ where } /// The default panic handler. -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] fn default_hook(info: &PanicInfo<'_>) { // If this is a double panic, make sure that we print a backtrace // for this panic. Otherwise only print it if logging is enabled. @@ -340,7 +340,7 @@ fn default_hook(info: &PanicInfo<'_>) { } } -#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[cfg(target_family = "solana")] fn default_hook(_info: &PanicInfo<'_>) { } @@ -389,7 +389,7 @@ pub mod panic_count { #[cfg(not(feature = "panic_immediate_abort"))] #[unstable(feature = "update_panic_count", issue = "none")] pub mod panic_count { - #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] + #[cfg(not(target_family = "solana"))] use crate::cell::Cell; use crate::sync::atomic::{AtomicUsize, Ordering}; @@ -404,7 +404,7 @@ pub mod panic_count { // Panic count for the current thread and whether a panic hook is currently // being executed.. - #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] + #[cfg(not(target_family = "solana"))] thread_local! { static LOCAL_PANIC_COUNT: Cell<(usize, bool)> = const { Cell::new((0, false)) } } @@ -465,7 +465,7 @@ pub mod panic_count { }); } - #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] + #[cfg(not(target_family = "solana"))] pub fn decrease() { GLOBAL_PANIC_COUNT.fetch_sub(1, Ordering::Relaxed); LOCAL_PANIC_COUNT.with(|c| { @@ -480,14 +480,14 @@ pub mod panic_count { // Disregards ALWAYS_ABORT_FLAG #[must_use] - #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] + #[cfg(not(target_family = "solana"))] pub fn get_count() -> usize { LOCAL_PANIC_COUNT.with(|c| c.get().0) } // Disregards ALWAYS_ABORT_FLAG #[must_use] - #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] + #[cfg(not(target_family = "solana"))] #[inline] pub fn count_is_zero() -> bool { if GLOBAL_PANIC_COUNT.load(Ordering::Relaxed) & !ALWAYS_ABORT_FLAG == 0 { @@ -585,7 +585,7 @@ pub unsafe fn r#try R>(f: F) -> Result> // optimizer (in most cases this function is not inlined even as a normal, // non-cold function, though, as of the writing of this comment). #[cold] - #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] + #[cfg(not(target_family = "solana"))] unsafe fn cleanup(payload: *mut u8) -> Box { // SAFETY: The whole unsafe block hinges on a correct implementation of // the panic handler `__rust_panic_cleanup`. As such we can only @@ -597,7 +597,7 @@ pub unsafe fn r#try R>(f: F) -> Result> } #[cold] - #[cfg(any(target_arch = "bpf", target_arch = "sbf"))] + #[cfg(target_family = "solana")] unsafe fn cleanup(payload: *mut u8) -> Box { // SAFETY: The whole unsafe block hinges on a correct implementation of // the panic handler `__rust_panic_cleanup`. As such we can only @@ -654,7 +654,7 @@ pub unsafe fn r#try R>(f: F) -> Result> } /// Determines whether the current thread is unwinding because of panic. -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] #[inline] pub fn panicking() -> bool { !panic_count::count_is_zero() @@ -741,7 +741,7 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! { /// This is the entry point of panicking for the non-format-string variants of /// panic!() and assert!(). In particular, this is the only entry point that supports /// arbitrary payloads, not just format strings. -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] #[unstable(feature = "libstd_sys_internals", reason = "used by the panic! macro", issue = "none")] #[cfg_attr(not(test), lang = "begin_panic")] // lang item for CTFE panic support @@ -805,7 +805,7 @@ pub const fn begin_panic(msg: M) -> ! { /// Executes the primary logic for a panic, including checking for recursive /// panics, panic hooks, and finally dispatching to the panic runtime to either /// abort or unwind. -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] fn rust_panic_with_hook( payload: &mut dyn PanicPayload, message: Option<&fmt::Arguments<'_>>, @@ -879,7 +879,7 @@ fn rust_panic_with_hook( /// This is the entry point for `resume_unwind`. /// It just forwards the payload to the panic runtime. #[cfg_attr(feature = "panic_immediate_abort", inline)] -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] pub fn rust_panic_without_hook(payload: Box) -> ! { panic_count::increase(false); @@ -900,7 +900,7 @@ pub fn rust_panic_without_hook(payload: Box) -> ! { /// An unmangled function (through `rustc_std_internal_symbol`) on which to slap /// yer breakpoints. -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] #[inline(never)] #[cfg_attr(not(test), rustc_std_internal_symbol)] #[cfg(not(feature = "panic_immediate_abort"))] @@ -922,27 +922,27 @@ fn rust_panic(_: &mut dyn PanicPayload) -> ! { /// This function is called by the panic runtime if it catches an exception /// object which does not correspond to a Rust panic. -#[cfg(all(not(test), any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(all(not(test), target_family = "solana"))] #[rustc_std_internal_symbol] extern "C" fn __rust_foreign_exception() -> ! { rtabort!("Rust cannot catch foreign exceptions"); } /// Determines whether the current thread is unwinding because of panic. -#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[cfg(target_family = "solana")] pub fn panicking() -> bool { true } /// Entry point of panic from the libcore crate. -#[cfg(all(not(test), any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(all(not(test), target_family = "solana"))] #[panic_handler] pub fn rust_begin_panic(info: &PanicInfo<'_>) -> ! { crate::sys::panic(info); } /// Entry point of panicking for panic!() and assert!() SBF version. -#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[cfg(target_family = "solana")] #[unstable(feature = "libstd_sys_internals", reason = "used by the panic! macro", issue = "none")] #[cfg_attr(not(test), lang = "begin_panic")] // lang item for CTFE panic support @@ -961,7 +961,7 @@ pub fn begin_panic(_msg: M) -> ! { } /// The entry point for panicking with a formatted message SBF version. -#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[cfg(target_family = "solana")] #[unstable(feature = "libstd_sys_internals", reason = "used by the panic! macro", issue = "none")] #[cold] // If panic_immediate_abort, inline the abort call, diff --git a/library/std/src/process.rs b/library/std/src/process.rs index 6f802ca943e0c..33bcca7381023 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -2207,7 +2207,7 @@ impl Child { #[stable(feature = "rust1", since = "1.0.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "process_exit")] pub fn exit(code: i32) -> ! { - #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] + #[cfg(not(target_family = "solana"))] crate::rt::cleanup(); crate::sys::os::exit(code) } diff --git a/library/std/src/rt.rs b/library/std/src/rt.rs index fe10e9f97cba2..c08e39d314564 100644 --- a/library/std/src/rt.rs +++ b/library/std/src/rt.rs @@ -16,20 +16,20 @@ #![deny(unsafe_op_in_unsafe_fn)] #![allow(unused_macros)] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] use crate::ffi::CString; // Re-export some of our utilities which are expected by other crates. pub use crate::panicking::{begin_panic, panic_count}; pub use core::panicking::{panic_display, panic_fmt}; -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] use crate::sync::Once; -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] use crate::sys; -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] use crate::sys_common::thread_info; -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] use crate::thread::Thread; // Prints to the "panic output", depending on the platform this may be: @@ -97,7 +97,7 @@ macro_rules! rtunwrap { // Even though it is an `u8`, it only ever has 4 values. These are documented in // `compiler/rustc_session/src/config/sigpipe.rs`. #[cfg_attr(test, allow(dead_code))] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) { unsafe { sys::init(argc, argv, sigpipe); @@ -115,7 +115,7 @@ unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) { // One-time runtime cleanup. // Runs after `main` or at program exit. // NOTE: this is not guaranteed to run, for example when the program aborts. -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] pub(crate) fn cleanup() { static CLEANUP: Once = Once::new(); CLEANUP.call_once(|| unsafe { @@ -129,7 +129,7 @@ pub(crate) fn cleanup() { // To reduce the generated code of the new `lang_start`, this function is doing // the real work. #[cfg(not(test))] -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] fn lang_start_internal( main: &(dyn Fn() -> i32 + Sync + crate::panic::RefUnwindSafe), argc: isize, @@ -164,7 +164,7 @@ fn lang_start_internal( #[cfg(not(test))] #[inline(never)] -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] #[lang = "start"] fn lang_start( main: fn() -> T, @@ -182,7 +182,7 @@ fn lang_start( } #[cfg(not(test))] -#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[cfg(target_family = "solana")] #[lang = "start"] fn lang_start( main: fn() -> T, diff --git a/library/std/src/sync/once.rs b/library/std/src/sync/once.rs index 255a9fa64ecdb..2bb4f3f9e0383 100644 --- a/library/std/src/sync/once.rs +++ b/library/std/src/sync/once.rs @@ -316,7 +316,6 @@ impl OnceState { /// Poison the associated [`Once`] without explicitly panicking. // NOTE: This is currently only exposed for `OnceLock`. - #[cfg(not(target_os = "solana"))] #[inline] pub(crate) fn poison(&self) { self.inner.poison(); diff --git a/library/std/src/sync/remutex.rs b/library/std/src/sync/remutex.rs index 1253133b0dfff..5d38a70dd2d5f 100644 --- a/library/std/src/sync/remutex.rs +++ b/library/std/src/sync/remutex.rs @@ -72,7 +72,7 @@ impl !Send for ReentrantMutexGuard<'_, T> {} impl ReentrantMutex { /// Creates a new reentrant mutex in an unlocked state. - #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] + #[cfg(not(target_family = "solana"))] pub const fn new(t: T) -> ReentrantMutex { ReentrantMutex { mutex: sys::Mutex::new(), @@ -94,7 +94,7 @@ impl ReentrantMutex { /// If another user of this mutex panicked while holding the mutex, then /// this call will return failure if the mutex would otherwise be /// acquired. - #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] + #[cfg(not(target_family = "solana"))] pub fn lock(&self) -> ReentrantMutexGuard<'_, T> { let this_thread = current_thread_unique_ptr(); // Safety: We only touch lock_count when we own the lock. @@ -123,7 +123,7 @@ impl ReentrantMutex { /// If another user of this mutex panicked while holding the mutex, then /// this call will return failure if the mutex would otherwise be /// acquired. - #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] + #[cfg(not(target_family = "solana"))] pub fn try_lock(&self) -> Option> { let this_thread = current_thread_unique_ptr(); // Safety: We only touch lock_count when we own the lock. @@ -142,7 +142,7 @@ impl ReentrantMutex { } } - #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] + #[cfg(not(target_family = "solana"))] unsafe fn increment_lock_count(&self) { *self.lock_count.get() = (*self.lock_count.get()) .checked_add(1) @@ -175,7 +175,7 @@ impl Drop for ReentrantMutexGuard<'_, T> { /// Get an address that is unique per running thread. /// /// This can be used as a non-null usize-sized ID. -#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] pub fn current_thread_unique_ptr() -> usize { // Use a non-drop type to make sure it's still available during thread destruction. thread_local! { static X: u8 = const { 0 } } diff --git a/library/std/src/sys/mod.rs b/library/std/src/sys/mod.rs index 363a470d8f407..62a2863d1f3ef 100644 --- a/library/std/src/sys/mod.rs +++ b/library/std/src/sys/mod.rs @@ -35,7 +35,7 @@ cfg_if::cfg_if! { } else if #[cfg(target_os = "solid_asp3")] { mod solid; pub use self::solid::*; - } else if #[cfg(target_os = "solana")] { + } else if #[cfg(target_family = "solana")] { mod sbf; pub use self::sbf::*; } else if #[cfg(target_os = "hermit")] { diff --git a/library/std/src/sys/sbf/condvar.rs b/library/std/src/sys/sbf/condvar.rs index 792330a6eb551..8905d07a4415b 100644 --- a/library/std/src/sys/sbf/condvar.rs +++ b/library/std/src/sys/sbf/condvar.rs @@ -3,16 +3,13 @@ use crate::time::Duration; pub struct Condvar { } -pub type MovableCondvar = Box; +pub type MovableCondvar = Condvar; impl Condvar { pub const fn new() -> Condvar { Condvar { } } - #[inline] - pub unsafe fn init(&mut self) {} - #[inline] pub unsafe fn notify_one(&self) { } @@ -28,8 +25,4 @@ impl Condvar { pub unsafe fn wait_timeout(&self, _mutex: &Mutex, _dur: Duration) -> bool { panic!("can't block with web assembly"); } - - #[inline] - pub unsafe fn destroy(&self) { - } } diff --git a/library/std/src/sys/sbf/fs.rs b/library/std/src/sys/sbf/fs.rs index 2b9e18532af86..caba7c4654613 100644 --- a/library/std/src/sys/sbf/fs.rs +++ b/library/std/src/sys/sbf/fs.rs @@ -1,7 +1,7 @@ use crate::ffi::OsString; use crate::fmt; use crate::hash::{Hash, Hasher}; -use crate::io::{self, SeekFrom, IoSlice, IoSliceMut, ReadBuf}; +use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut, SeekFrom}; use crate::path::{Path, PathBuf}; use crate::sys::time::SystemTime; use crate::sys::{unsupported, Void}; @@ -19,6 +19,9 @@ pub struct OpenOptions { } pub struct FilePermissions(Void); +#[derive(Copy, Clone, Debug, Default)] +pub struct FileTimes { } + pub struct FileType(Void); #[derive(Debug)] @@ -87,6 +90,11 @@ impl fmt::Debug for FilePermissions { } } +impl FileTimes { + pub fn set_accessed(&mut self, _t: SystemTime) {} + pub fn set_modified(&mut self, _t: SystemTime) {} +} + impl FileType { pub fn is_dir(&self) -> bool { match self.0 {} @@ -209,7 +217,7 @@ impl File { false } - pub fn read_buf(&self, _buf: &mut ReadBuf<'_>) -> io::Result<()> { + pub fn read_buf(&self, _cursor: BorrowedCursor<'_>) -> io::Result<()> { match self.0 {} } @@ -242,6 +250,10 @@ impl File { match self.0 {} } + pub fn set_times(&self, _times: FileTimes) -> io::Result<()> { + match self.0 {} + } + pub fn diverge(&self) -> ! { match self.0 {} } diff --git a/library/std/src/sys/sbf/mutex.rs b/library/std/src/sys/sbf/mutex.rs index 861b596adeb7e..28916d8d53555 100644 --- a/library/std/src/sys/sbf/mutex.rs +++ b/library/std/src/sys/sbf/mutex.rs @@ -1,14 +1,21 @@ use crate::cell::UnsafeCell; +use crate::sys_common::lazy_box::{LazyBox, LazyInit}; pub struct Mutex { inner: UnsafeCell, } -pub type MovableMutex = Box; +pub(crate) type MovableMutex = LazyBox; unsafe impl Send for Mutex {} unsafe impl Sync for Mutex {} // no threads on SBF +impl LazyInit for Mutex { + fn init() -> Box { + Box::new(Self::new()) + } +} + #[allow(dead_code)] // sys isn't exported yet impl Mutex { pub const fn new() -> Mutex { diff --git a/library/std/src/sys/sbf/net.rs b/library/std/src/sys/sbf/net.rs index 88d0c76a59056..6e1048660031f 100644 --- a/library/std/src/sys/sbf/net.rs +++ b/library/std/src/sys/sbf/net.rs @@ -371,6 +371,4 @@ pub mod netc { #[derive(Copy, Clone)] pub struct sockaddr { } - - pub type socklen_t = usize; } diff --git a/library/std/src/sys/sbf/rwlock.rs b/library/std/src/sys/sbf/rwlock.rs index 70036bbe5a2cd..35bcfc560b739 100644 --- a/library/std/src/sys/sbf/rwlock.rs +++ b/library/std/src/sys/sbf/rwlock.rs @@ -67,8 +67,4 @@ impl RwLock { pub unsafe fn write_unlock(&self) { *self.mode.get() += 1; } - - #[inline] - pub unsafe fn destroy(&self) { - } } diff --git a/library/std/src/sys_common/backtrace.rs b/library/std/src/sys_common/backtrace.rs index e1c0aeeafabf2..2b8a67b2aac3a 100644 --- a/library/std/src/sys_common/backtrace.rs +++ b/library/std/src/sys_common/backtrace.rs @@ -1,4 +1,4 @@ -#![cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#![cfg(not(target_family = "solana"))] use crate::backtrace_rs::{self, BacktraceFmt, BytesOrWideString, PrintFmt}; use crate::borrow::Cow; diff --git a/library/std/src/sys_common/thread.rs b/library/std/src/sys_common/thread.rs index e8974c220610d..9f51c6c1affbe 100644 --- a/library/std/src/sys_common/thread.rs +++ b/library/std/src/sys_common/thread.rs @@ -1,11 +1,11 @@ -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] use crate::env; -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] use crate::sync::atomic::{self, Ordering}; -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] use crate::sys::thread as imp; -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] pub fn min_stack() -> usize { static MIN: atomic::AtomicUsize = atomic::AtomicUsize::new(0); match MIN.load(Ordering::Relaxed) { @@ -21,7 +21,7 @@ pub fn min_stack() -> usize { amt } -#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[cfg(target_family = "solana")] pub fn min_stack() -> usize { 0 } diff --git a/library/std/src/sys_common/thread_info.rs b/library/std/src/sys_common/thread_info.rs index 383630a1491a5..e92c857c045ed 100644 --- a/library/std/src/sys_common/thread_info.rs +++ b/library/std/src/sys_common/thread_info.rs @@ -1,4 +1,4 @@ -#![cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#![cfg(not(target_family = "solana"))] #![allow(dead_code)] // stack_guard isn't used right now on all platforms use crate::cell::OnceCell; diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index fd45b8ea83682..363a81b0755ac 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -175,7 +175,7 @@ use crate::str; use crate::sync::Arc; use crate::sys::thread as imp; use crate::sys_common::thread; -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] use crate::sys_common::thread_info; use crate::sys_common::thread_parking::Parker; use crate::sys_common::{AsInner, IntoInner}; @@ -458,7 +458,7 @@ impl Builder { Ok(JoinHandle(unsafe { self.spawn_unchecked_(f, None) }?)) } - #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] + #[cfg(not(target_family = "solana"))] unsafe fn spawn_unchecked_<'a, 'scope, F, T>( self, f: F, @@ -577,12 +577,11 @@ impl Builder { } /// SBF version of spawn_unchecked - #[unstable(feature = "thread_spawn_unchecked", issue = "55132")] - #[cfg(any(target_arch = "bpf", target_arch = "sbf"))] + #[cfg(target_family = "solana")] unsafe fn spawn_unchecked_<'a, 'scope, F, T>( self, _f: F, - scope_data: Option<&'scope scoped::ScopeData>, + scope_data: Option>, ) -> io::Result> where F: FnOnce() -> T, @@ -596,15 +595,18 @@ impl Builder { CString::new(name).expect("thread name may not contain interior null bytes") })); let their_thread = my_thread.clone(); - let my_packet: Arc> = - Arc::new(Packet { scope: scope_data, result: UnsafeCell::new(None) }); + let my_packet: Arc> = Arc::new(Packet { + scope: scope_data, + result: UnsafeCell::new(None), + _marker: PhantomData, + }); let main = move || { if let Some(name) = their_thread.cname() { imp::Thread::set_name(name); } }; - if let Some(scope_data) = scope_data { + if let Some(scope_data) = &my_packet.scope { scope_data.increment_num_running_threads(); } @@ -770,7 +772,7 @@ where /// ``` #[must_use] #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] pub fn current() -> Thread { thread_info::current_thread().expect( "use of std::thread::current() is not possible \ @@ -782,7 +784,7 @@ pub fn current() -> Thread { /// #[must_use] #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[cfg(target_family = "solana")] pub fn current() -> Thread { Thread::new(None) } @@ -1268,7 +1270,7 @@ impl ThreadId { Err(id) => last = id, } } - } else if #[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))] { + } else if #[cfg(not(target_os = "solana"))] { use crate::sync::{Mutex, PoisonError}; static COUNTER: Mutex = Mutex::new(0); diff --git a/library/test/src/cli.rs b/library/test/src/cli.rs index 34f73cf758f94..5639076f1a3eb 100644 --- a/library/test/src/cli.rs +++ b/library/test/src/cli.rs @@ -1,6 +1,6 @@ //! Module converting command-line arguments into test configuration. -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] use std::env; use std::path::PathBuf; @@ -47,7 +47,7 @@ impl TestOpts { /// Result of parsing the options. pub type OptRes = Result; /// Result of parsing the option part. -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] type OptPartRes = Result; fn optgroups() -> getopts::Options { @@ -223,7 +223,7 @@ pub fn parse_opts(args: &[String]) -> Option { } // Gets the option value and checks if unstable features are enabled. -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] macro_rules! unstable_optflag { ($matches:ident, $allow_unstable:ident, $option_name:literal) => {{ let opt = $matches.opt_present($option_name); @@ -239,7 +239,7 @@ macro_rules! unstable_optflag { } // Gets the option value and checks if unstable features are enabled. -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] macro_rules! unstable_optopt { ($matches:ident, $allow_unstable:ident, $option_name:literal) => {{ let opt = $matches.opt_str($option_name); @@ -256,7 +256,7 @@ macro_rules! unstable_optopt { // Implementation of `parse_opts` that doesn't care about help message // and returns a `Result`. -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] fn parse_opts_impl(matches: getopts::Matches) -> OptRes { let allow_unstable = get_allow_unstable(&matches)?; @@ -311,7 +311,7 @@ fn parse_opts_impl(matches: getopts::Matches) -> OptRes { Ok(test_opts) } -#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[cfg(target_family = "solana")] fn parse_opts_impl(_matches: getopts::Matches) -> OptRes { let test_opts = TestOpts { list: false, @@ -338,7 +338,7 @@ fn parse_opts_impl(_matches: getopts::Matches) -> OptRes { } // FIXME: Copied from librustc_ast until linkage errors are resolved. Issue #47566 -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] fn is_nightly() -> bool { // Whether this is a feature-staged build, i.e., on the beta or stable channel let disable_unstable_features = @@ -350,7 +350,7 @@ fn is_nightly() -> bool { } // Gets the CLI options associated with `report-time` feature. -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] fn get_time_options( matches: &getopts::Matches, allow_unstable: bool, @@ -369,7 +369,7 @@ fn get_time_options( Ok(options) } -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] fn get_shuffle(matches: &getopts::Matches, allow_unstable: bool) -> OptPartRes { let mut shuffle = unstable_optflag!(matches, allow_unstable, "shuffle"); if !shuffle && allow_unstable { @@ -382,7 +382,7 @@ fn get_shuffle(matches: &getopts::Matches, allow_unstable: bool) -> OptPartRes OptPartRes> { let mut shuffle_seed = match unstable_optopt!(matches, allow_unstable, "shuffle-seed") { Some(n_str) => match n_str.parse::() { @@ -410,7 +410,7 @@ fn get_shuffle_seed(matches: &getopts::Matches, allow_unstable: bool) -> OptPart Ok(shuffle_seed) } -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] fn get_test_threads(matches: &getopts::Matches) -> OptPartRes> { let test_threads = match matches.opt_str("test-threads") { Some(n_str) => match n_str.parse::() { @@ -429,7 +429,7 @@ fn get_test_threads(matches: &getopts::Matches) -> OptPartRes> { Ok(test_threads) } -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] fn get_format( matches: &getopts::Matches, quiet: bool, @@ -462,7 +462,7 @@ fn get_format( Ok(format) } -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] fn get_color_config(matches: &getopts::Matches) -> OptPartRes { let color = match matches.opt_str("color").as_deref() { Some("auto") | None => ColorConfig::AutoColor, @@ -480,7 +480,7 @@ fn get_color_config(matches: &getopts::Matches) -> OptPartRes { Ok(color) } -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] fn get_nocapture(matches: &getopts::Matches) -> OptPartRes { let mut nocapture = matches.opt_present("nocapture"); if !nocapture { @@ -493,7 +493,7 @@ fn get_nocapture(matches: &getopts::Matches) -> OptPartRes { Ok(nocapture) } -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] fn get_run_ignored(matches: &getopts::Matches, include_ignored: bool) -> OptPartRes { let run_ignored = match (include_ignored, matches.opt_present("ignored")) { (true, true) => { @@ -507,7 +507,7 @@ fn get_run_ignored(matches: &getopts::Matches, include_ignored: bool) -> OptPart Ok(run_ignored) } -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] fn get_allow_unstable(matches: &getopts::Matches) -> OptPartRes { let mut allow_unstable = false; @@ -529,7 +529,7 @@ fn get_allow_unstable(matches: &getopts::Matches) -> OptPartRes { Ok(allow_unstable) } -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] fn get_log_file(matches: &getopts::Matches) -> OptPartRes> { let logfile = matches.opt_str("logfile").map(|s| PathBuf::from(&s)); diff --git a/library/test/src/console.rs b/library/test/src/console.rs index 0efbf9e1417d0..75cd81d0c7869 100644 --- a/library/test/src/console.rs +++ b/library/test/src/console.rs @@ -291,12 +291,12 @@ fn on_test_event( /// A simple console test runner. /// Runs provided tests reporting process and results to the stdout. pub fn run_tests_console(opts: &TestOpts, tests: Vec) -> io::Result { - #[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] + #[cfg(not(target_family = "solana"))] let output = match term::stdout() { None => OutputLocation::Raw(io::stdout()), Some(t) => OutputLocation::Pretty(t), }; - #[cfg(any(target_arch = "bpf", target_arch = "sbf"))] + #[cfg(target_family = "solana")] let output = OutputLocation::Raw(io::stdout()); let max_name_len = tests diff --git a/library/test/src/helpers/concurrency.rs b/library/test/src/helpers/concurrency.rs index b3b4cea699e81..38f3fc190afdf 100644 --- a/library/test/src/helpers/concurrency.rs +++ b/library/test/src/helpers/concurrency.rs @@ -1,9 +1,9 @@ //! Helper module which helps to determine amount of threads to be used //! during tests execution. -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] use std::{env, num::NonZeroUsize, thread}; -#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))] +#[cfg(not(target_family = "solana"))] pub fn get_concurrency() -> usize { if let Ok(value) = env::var("RUST_TEST_THREADS") { match value.parse::().ok() { @@ -15,7 +15,7 @@ pub fn get_concurrency() -> usize { } } -#[cfg(any(target_arch = "bpf", target_arch = "sbf"))] +#[cfg(target_family = "solana")] pub fn get_concurrency() -> usize { 1 } diff --git a/library/test/src/lib.rs b/library/test/src/lib.rs index b9fcbdda497b8..8b59c1b77c58e 100644 --- a/library/test/src/lib.rs +++ b/library/test/src/lib.rs @@ -162,9 +162,9 @@ pub fn test_main(args: &[String], tests: Vec, options: Option>(); - #[cfg(any(target_arch = "bpf", target_arch = "sbf"))] + #[cfg(target_family = "solana")] let args: [String; 0] = []; let owned_tests: Vec<_> = tests.iter().map(make_owned_test).collect(); test_main(&args, owned_tests, None) diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 4647202bd9275..62648218d4458 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -98,7 +98,9 @@ const EXTRA_CHECK_CFGS: &[(Option, &str, Option<&[&'static str]>)] = &[ /* Extra values not defined in the built-in targets yet, but used in std */ (Some(Mode::Std), "target_env", Some(&["libnx"])), // (Some(Mode::Std), "target_os", Some(&[])), - (Some(Mode::Std), "target_arch", Some(&["asmjs", "spirv", "nvptx", "xtensa"])), + (Some(Mode::Std), "target_arch", Some(&["asmjs", "spirv", "nvptx", "sbf", "xtensa"])), + (Some(Mode::Std), "target_family", Some(&["solana"])), + (Some(Mode::Std), "target_os", Some(&["solana"])), /* Extra names used by dependencies */ // FIXME: Used by serde_json, but we should not be triggering on external dependencies. (Some(Mode::Rustc), "no_btreemap_remove_entry", None), diff --git a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile index 20c98057493e9..f7b7924f36a3b 100644 --- a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile +++ b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile @@ -1,4 +1,6 @@ -FROM ubuntu:20.04 +FROM ubuntu:22.04 + +ARG DEBIAN_FRONTEND=noninteractive RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ g++ \ @@ -27,6 +29,10 @@ RUN PATH="${HOME}/.cargo/bin:${PATH}" \ COPY scripts/sccache.sh /scripts/ RUN sh /scripts/sccache.sh +# We are disabling CI LLVM since this builder is intentionally using a host +# LLVM, rather than the typical src/llvm-project LLVM. +ENV NO_DOWNLOAD_CI_LLVM 1 + ENV RUST_CONFIGURE_ARGS \ --set rust.lld \ --set llvm.clang diff --git a/tests/ui/check-cfg/compact-values.stderr b/tests/ui/check-cfg/compact-values.stderr index bb2f4915b5ef6..d7b2fa8f16ae3 100644 --- a/tests/ui/check-cfg/compact-values.stderr +++ b/tests/ui/check-cfg/compact-values.stderr @@ -4,7 +4,7 @@ warning: unexpected `cfg` condition value: `X` LL | #[cfg(target(os = "linux", arch = "X"))] | ^^^^^^^^^^ | - = note: expected values for `target_arch` are: `aarch64`, `arm`, `avr`, `bpf`, `csky`, `hexagon`, `loongarch64`, `m68k`, `mips`, `mips32r6`, `mips64`, `mips64r6`, `msp430`, `nvptx64`, `powerpc`, `powerpc64`, `riscv32`, `riscv64`, `s390x`, `sparc`, `sparc64`, `wasm32`, `wasm64`, `x86`, `x86_64` + = note: expected values for `target_arch` are: `aarch64`, `arm`, `avr`, `bpf`, `csky`, `hexagon`, `loongarch64`, `m68k`, `mips`, `mips32r6`, `mips64`, `mips64r6`, `msp430`, `nvptx64`, `powerpc`, `powerpc64`, `riscv32`, `riscv64`, `s390x`, `sbf`, `sparc`, `sparc64`, `wasm32`, `wasm64`, `x86`, `x86_64` = note: `#[warn(unexpected_cfgs)]` on by default warning: 1 warning emitted From 19463cc0a424f4e3a530ddb993b70be92139b365 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Wed, 7 Dec 2022 12:30:56 -0500 Subject: [PATCH 090/103] [SOL] Update run-sbf-tests revision in CI --- src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile index f7b7924f36a3b..0fd9915618207 100644 --- a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile +++ b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile @@ -23,7 +23,7 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y RUN PATH="${HOME}/.cargo/bin:${PATH}" \ cargo install --git https://github.com/solana-labs/cargo-run-sbf-tests.git \ - --rev 9d45e79cf11b2fdf0e3572d916fe058823c7c438 \ + --rev 6ff73da5c7595e49f9c5226417419dfb4842bc0c \ --bin cargo-run-sbf-tests --root /usr/local COPY scripts/sccache.sh /scripts/ From ca8abbefaf2b95ea9662a43c71726a6046fa9597 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Wed, 7 Dec 2022 21:19:53 -0500 Subject: [PATCH 091/103] [SOL] Temporarily patch BPF ELF file header with SBF machine code --- compiler/rustc_codegen_ssa/src/back/link.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 8aec3df29d9a0..b078f99321707 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -46,7 +46,7 @@ use std::cell::OnceCell; use std::collections::BTreeSet; use std::ffi::OsString; use std::fs::{read, File, OpenOptions}; -use std::io::{BufWriter, Write}; +use std::io::{prelude::*, BufWriter, SeekFrom, Write}; use std::ops::Deref; use std::path::{Path, PathBuf}; use std::process::{ExitStatus, Output, Stdio}; @@ -310,6 +310,9 @@ fn link_rlib<'a>( let (metadata, metadata_position) = create_wrapper_file(sess, b".rmeta".to_vec(), codegen_results.metadata.raw_data()); let metadata = emit_wrapper_file(sess, &metadata, tmpdir, METADATA_FILENAME); + if sess.target.arch == "sbf" { + patch_synthetic_object_file(sess, &metadata); + } match metadata_position { MetadataPosition::First => { // Most of the time metadata in rlib files is wrapped in a "dummy" object @@ -1941,9 +1944,23 @@ fn add_linked_symbol_object( if let Err(error) = result { sess.emit_fatal(errors::FailedToWrite { path, error }); } + if sess.target.arch == "sbf" { + patch_synthetic_object_file(sess, &path); + } cmd.add_object(&path); } +fn patch_synthetic_object_file(sess: &Session, path: &PathBuf) { + const EM_SBF: [u8; 2] = [0x07, 0x01]; + if let Ok(mut sf) = fs::OpenOptions::new().write(true).open(path) { + if let Ok(_) = sf.seek(SeekFrom::Start(0x12)) { + sf.write(&EM_SBF).unwrap(); + } + } else { + sess.fatal(&format!("failed to patch {}", path.display())); + } +} + /// Add object files containing code from the current crate. fn add_local_crate_regular_objects(cmd: &mut dyn Linker, codegen_results: &CodegenResults) { for obj in codegen_results.modules.iter().filter_map(|m| m.object.as_ref()) { From 44697caa6b2d796b6159652d77318227e9b585e3 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Tue, 13 Dec 2022 18:10:00 -0500 Subject: [PATCH 092/103] [SOL] Update run-sbf-tests revision in CI --- src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile index 0fd9915618207..43ef5839ae4e4 100644 --- a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile +++ b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile @@ -23,7 +23,7 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y RUN PATH="${HOME}/.cargo/bin:${PATH}" \ cargo install --git https://github.com/solana-labs/cargo-run-sbf-tests.git \ - --rev 6ff73da5c7595e49f9c5226417419dfb4842bc0c \ + --rev 836eec95d0fd79b7718b940bd64245f99e806055 \ --bin cargo-run-sbf-tests --root /usr/local COPY scripts/sccache.sh /scripts/ From 09d7bfaf128a5295eccf65389713fe026b636534 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Tue, 31 Jan 2023 12:01:17 -0500 Subject: [PATCH 093/103] [SOL] Add lldb to enabled projects in [llvm] section of config.toml --- config.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.toml b/config.toml index ca632f65d8ac6..422f3c9a62740 100644 --- a/config.toml +++ b/config.toml @@ -106,7 +106,7 @@ link-shared = false #allow-old-toolchain = false # Which LLVM projects to build along with the LLVM base libraries/tools -enable-projects = "clang;lld" +enable-projects = "clang;lld;lldb" # ============================================================================= # General build configuration options @@ -230,7 +230,7 @@ docs = false [install] # Instead of installing to /usr/local, install to this path instead. -prefix = "opt/bpf-rust" +prefix = "opt/sbf-rust" # Where to install system configuration files # If this is a relative path, it will get installed in `prefix` above From 1af5a38e8d4e0cefb90898398447a340daf6e975 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Thu, 2 Feb 2023 10:28:17 -0500 Subject: [PATCH 094/103] [SOL] Fix Ci error caused by insufficient git history fetched --- .github/workflows/ci.yml | 10 +++++----- src/ci/github-actions/ci.yml | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fa94fd871ee69..da90cb5cc2ada 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -76,7 +76,7 @@ jobs: - name: checkout the source code uses: actions/checkout@v4 with: - fetch-depth: 2 + fetch-depth: 0 - name: configure the PR in which the error message will be posted run: "echo \"[CI_PR_NUMBER=$num]\"" env: @@ -208,7 +208,7 @@ jobs: - name: checkout the source code uses: actions/checkout@v3 with: - fetch-depth: 2 + fetch-depth: 0 - name: configure the PR in which the error message will be posted run: "echo \"[CI_PR_NUMBER=$num]\"" env: @@ -589,7 +589,7 @@ jobs: - name: checkout the source code uses: actions/checkout@v4 with: - fetch-depth: 2 + fetch-depth: 0 - name: configure the PR in which the error message will be posted run: "echo \"[CI_PR_NUMBER=$num]\"" env: @@ -719,7 +719,7 @@ jobs: - name: checkout the source code uses: actions/checkout@v4 with: - fetch-depth: 2 + fetch-depth: 0 - name: configure the PR in which the error message will be posted run: "echo \"[CI_PR_NUMBER=$num]\"" env: @@ -836,7 +836,7 @@ jobs: - name: checkout the source code uses: actions/checkout@v4 with: - fetch-depth: 2 + fetch-depth: 0 - name: publish toolstate run: src/ci/publish_toolstate.sh shell: bash diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml index 5a6f3c3d56db2..8d4b464e9197e 100644 --- a/src/ci/github-actions/ci.yml +++ b/src/ci/github-actions/ci.yml @@ -123,7 +123,7 @@ x--expand-yaml-anchors--remove: - name: checkout the source code uses: actions/checkout@v4 with: - fetch-depth: 2 + fetch-depth: 0 # Rust Log Analyzer can't currently detect the PR number of a GitHub # Actions build on its own, so a hint in the log message is needed to @@ -773,7 +773,7 @@ jobs: - name: checkout the source code uses: actions/checkout@v4 with: - fetch-depth: 2 + fetch-depth: 0 - name: publish toolstate run: src/ci/publish_toolstate.sh From ee8e63885630184089cf96e64797bfe9479f20a3 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Sun, 19 Feb 2023 21:13:01 -0500 Subject: [PATCH 095/103] [SOL] Temporarily patch BPF ELF file header only for SBFv2 cpu --- compiler/rustc_codegen_ssa/src/back/link.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index b078f99321707..b656866df52a5 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -310,7 +310,8 @@ fn link_rlib<'a>( let (metadata, metadata_position) = create_wrapper_file(sess, b".rmeta".to_vec(), codegen_results.metadata.raw_data()); let metadata = emit_wrapper_file(sess, &metadata, tmpdir, METADATA_FILENAME); - if sess.target.arch == "sbf" { + if sess.opts.cg.target_cpu.as_ref().unwrap_or( + &sess.target.cpu.as_ref().to_string()) == "sbfv2" { patch_synthetic_object_file(sess, &metadata); } match metadata_position { @@ -1944,7 +1945,8 @@ fn add_linked_symbol_object( if let Err(error) = result { sess.emit_fatal(errors::FailedToWrite { path, error }); } - if sess.target.arch == "sbf" { + if sess.opts.cg.target_cpu.as_ref().unwrap_or( + &sess.target.cpu.as_ref().to_string()) == "sbfv2" { patch_synthetic_object_file(sess, &path); } cmd.add_object(&path); From 77e22f6e53e629d8beafe393e9ca30e735311043 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Sun, 5 Mar 2023 16:53:06 -0500 Subject: [PATCH 096/103] [SOL] Update run-sbf-tests revision in CI --- src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile index 43ef5839ae4e4..6355ef8aa2c55 100644 --- a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile +++ b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile @@ -23,7 +23,7 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y RUN PATH="${HOME}/.cargo/bin:${PATH}" \ cargo install --git https://github.com/solana-labs/cargo-run-sbf-tests.git \ - --rev 836eec95d0fd79b7718b940bd64245f99e806055 \ + --rev b5500813b130ff7ce2d32e85f4e4e6377fe24cda \ --bin cargo-run-sbf-tests --root /usr/local COPY scripts/sccache.sh /scripts/ From 866b0a9514d3eb491186a13f2e02a203630ea102 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Tue, 21 Mar 2023 18:29:33 -0400 Subject: [PATCH 097/103] [SOL] Adjust SBF customization after upgrading to rust 1.68.0 --- .github/workflows/ci.yml | 4 ++++ compiler/rustc_target/src/spec/sbf_base.rs | 16 ++++++---------- config.toml | 2 ++ library/core/tests/slice.rs | 16 ++++++++-------- library/std/Cargo.toml | 2 +- library/std/src/error.rs | 4 +++- library/std/src/io/mod.rs | 1 + library/std/src/io/stdio.rs | 9 +++++++-- library/std/src/panicking.rs | 17 ++++++++--------- library/std/src/process.rs | 5 +++++ library/std/src/rt.rs | 1 + library/std/src/sync/mod.rs | 1 + library/std/src/sync/mpmc/utils.rs | 2 ++ library/std/src/sys/sbf/futex.rs | 14 ++++++++++++++ library/std/src/sys/sbf/mod.rs | 14 ++++++++------ library/std/src/sys/sbf/pipe.rs | 4 ++++ library/std/src/sys/sbf/process.rs | 4 ++++ library/std/src/sys/sbf/thread_local_key.rs | 6 +----- library/std/src/sys_common/once/mod.rs | 1 + library/std/src/thread/mod.rs | 2 +- library/test/src/cli.rs | 8 ++++++++ library/test/src/lib.rs | 4 +++- .../host-x86_64/sbf-solana-solana/Dockerfile | 6 +++--- src/ci/github-actions/ci.yml | 1 + 24 files changed, 97 insertions(+), 47 deletions(-) create mode 100644 library/std/src/sys/sbf/futex.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index da90cb5cc2ada..c26c0ca8dd203 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,6 +63,7 @@ jobs: os: ubuntu-20.04-16core-64gb env: {} - name: sbf-solana-solana + tidy: false os: ubuntu-latest env: {} - name: x86_64-gnu-tools @@ -239,6 +240,9 @@ jobs: - name: install sccache run: src/ci/scripts/install-sccache.sh if: success() && !env.SKIP_JOB + - name: select Xcode + run: src/ci/scripts/select-xcode.sh + if: success() && !env.SKIP_JOB - name: install clang run: src/ci/scripts/install-clang.sh if: success() && !env.SKIP_JOB diff --git a/compiler/rustc_target/src/spec/sbf_base.rs b/compiler/rustc_target/src/spec/sbf_base.rs index 4cb112f607de1..e1451902b448c 100644 --- a/compiler/rustc_target/src/spec/sbf_base.rs +++ b/compiler/rustc_target/src/spec/sbf_base.rs @@ -1,5 +1,5 @@ use crate::abi::Endian; -use super::{cvs, LinkArgs, LinkerFlavor, PanicStrategy, TargetOptions, LldFlavor}; +use super::{Cc, cvs, LinkerFlavor, Lld, PanicStrategy, TargetOptions}; pub fn opts() -> TargetOptions { let linker_script = r" @@ -28,13 +28,10 @@ SECTIONS } } "; - let mut lld_args = Vec::new(); - lld_args.push("--threads=1".into()); - lld_args.push("-z".into()); - lld_args.push("notext".into()); - let mut pre_link_args = LinkArgs::new(); - pre_link_args.insert(LinkerFlavor::Ld, lld_args.clone()); - pre_link_args.insert(LinkerFlavor::Lld(LldFlavor::Ld), lld_args); + let pre_link_args = TargetOptions::link_args( + LinkerFlavor::Gnu(Cc::No, Lld::No), + &["--threads=1", "-z", "notext"], + ); TargetOptions { allow_asm: true, @@ -50,8 +47,7 @@ SECTIONS families: cvs!["solana"], link_script: Some(linker_script.into()), linker: Some("rust-lld".into()), - linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), - linker_is_gnu: true, + linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes), main_needs_argc_argv: false, max_atomic_width: Some(64), no_default_libraries: true, diff --git a/config.toml b/config.toml index 422f3c9a62740..26bc3f20ba9d8 100644 --- a/config.toml +++ b/config.toml @@ -108,6 +108,8 @@ link-shared = false # Which LLVM projects to build along with the LLVM base libraries/tools enable-projects = "clang;lld;lldb" +download-ci-llvm = false + # ============================================================================= # General build configuration options # ============================================================================= diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs index 1fa0ac9e07a8f..c0ee96ad78d72 100644 --- a/library/core/tests/slice.rs +++ b/library/core/tests/slice.rs @@ -1802,19 +1802,19 @@ fn brute_force_rotate_test_1() { } #[test] -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(any(target_arch = "wasm32", target_family = "solana")))] fn sort_unstable() { use core::cmp::Ordering::{Equal, Greater, Less}; use core::slice::heapsort; use rand::{seq::SliceRandom, Rng}; // Miri is too slow (but still need to `chain` to make the types match) - let lens = if cfg!(miri) { (2..20).chain(0..0) } else { (2..25).chain(200..210) }; + let lens = if cfg!(miri) { (2..20).chain(0..0) } else { (2..25).chain(500..510) }; let rounds = if cfg!(miri) { 1 } else { 100 }; - let mut v = [0; 300]; - let mut tmp = [0; 300]; - let mut rng = StdRng::seed_from_u64(0); + let mut v = [0; 600]; + let mut tmp = [0; 600]; + let mut rng = crate::test_rng(); for len in lens { let v = &mut v[0..len]; @@ -1876,16 +1876,16 @@ fn sort_unstable() { } #[test] -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(any(target_arch = "wasm32", target_family = "solana")))] #[cfg_attr(miri, ignore)] // Miri is too slow fn select_nth_unstable() { use core::cmp::Ordering::{Equal, Greater, Less}; use rand::seq::SliceRandom; use rand::Rng; - let mut rng = StdRng::seed_from_u64(0); + let mut rng = crate::test_rng(); - for len in (2..21).chain(200..201) { + for len in (2..21).chain(500..501) { let mut orig = vec![0; len]; for &modulus in &[5, 10, 1000] { diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index 8fb54e9906269..a1f1ab9f8ffed 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -24,7 +24,7 @@ hashbrown = { version = "0.14", default-features = false, features = ['rustc-dep std_detect = { path = "../stdarch/crates/std_detect", default-features = false, features = ['rustc-dep-of-std'] } # Dependencies of the `backtrace` crate -[target.'cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))'.dependencies] +[target.'cfg(not(target_family = "solana"))'.dependencies] addr2line = { version = "0.21.0", optional = true, default-features = false } rustc-demangle = { version = "0.1.21", features = ['rustc-dep-of-std'] } diff --git a/library/std/src/error.rs b/library/std/src/error.rs index 7c0d889199584..b358fdcc56a7f 100644 --- a/library/std/src/error.rs +++ b/library/std/src/error.rs @@ -4,7 +4,7 @@ #[cfg(test)] mod tests; -#[cfg(not(target_os = "solana"))] +#[cfg(not(target_family = "solana"))] use crate::backtrace::Backtrace; use crate::fmt::{self, Write}; @@ -458,6 +458,7 @@ impl Report where E: Error, { + #[cfg(not(target_family = "solana"))] fn backtrace(&self) -> Option<&Backtrace> { // have to grab the backtrace on the first error directly since that error may not be // 'static @@ -508,6 +509,7 @@ where } } + #[cfg(not(target_family = "solana"))] if self.show_backtrace { let backtrace = self.backtrace(); diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index aa4c0af190646..a2eb9e758ed56 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -310,6 +310,7 @@ use crate::sys_common::memchr; pub use self::buffered::WriterPanicked; #[unstable(feature = "raw_os_error_ty", issue = "107792")] pub use self::error::RawOsError; +#[cfg(not(target_family = "solana"))] pub(crate) use self::stdio::attempt_print_to_stderr; #[unstable(feature = "internal_output_capture", issue = "none")] #[doc(no_inline, hidden)] diff --git a/library/std/src/io/stdio.rs b/library/std/src/io/stdio.rs index 3e7ea71a5564f..567505b543d3e 100644 --- a/library/std/src/io/stdio.rs +++ b/library/std/src/io/stdio.rs @@ -8,10 +8,11 @@ use crate::io::prelude::*; #[cfg(not(target_family = "solana"))] use crate::cell::{Cell, RefCell}; use crate::fmt; +#[cfg(not(target_family = "solana"))] use crate::fs::File; -#[cfg(not(target_os = "solana"))] +#[cfg(not(target_family = "solana"))] use crate::io::{self, BorrowedCursor, BufReader, IoSlice, IoSliceMut, LineWriter, Lines}; -#[cfg(target_os = "solana")] +#[cfg(target_family = "solana")] use crate::io::{self, BufReader, IoSlice, IoSliceMut}; #[cfg(not(target_family = "solana"))] use crate::sync::atomic::{AtomicBool, Ordering}; @@ -1240,6 +1241,7 @@ where } } +#[cfg(not(target_family = "solana"))] fn print_to_buffer_if_capture_used(args: fmt::Arguments<'_>) -> bool { OUTPUT_CAPTURE_USED.load(Ordering::Relaxed) && OUTPUT_CAPTURE.try_with(|s| { @@ -1256,6 +1258,7 @@ fn print_to_buffer_if_capture_used(args: fmt::Arguments<'_>) -> bool { /// Used by impl Termination for Result to print error after `main` or a test /// has returned. Should avoid panicking, although we can't help it if one of /// the Display impls inside args decides to. +#[cfg(not(target_family = "solana"))] pub(crate) fn attempt_print_to_stderr(args: fmt::Arguments<'_>) { if print_to_buffer_if_capture_used(args) { return; @@ -1287,6 +1290,7 @@ pub trait IsTerminal: crate::sealed::Sealed { fn is_terminal(&self) -> bool; } +#[cfg(not(target_family = "solana"))] macro_rules! impl_is_terminal { ($($t:ty),*$(,)?) => {$( #[unstable(feature = "sealed", issue = "none")] @@ -1302,6 +1306,7 @@ macro_rules! impl_is_terminal { )*} } +#[cfg(not(target_family = "solana"))] impl_is_terminal!(File, Stdin, StdinLock<'_>, Stdout, StdoutLock<'_>, Stderr, StderrLock<'_>); #[unstable( diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index ca6029d713bab..6bd6598f5421e 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -25,14 +25,13 @@ use crate::mem; use crate::process; #[cfg(not(target_family = "solana"))] use crate::sync::atomic::{AtomicBool, Ordering}; +#[cfg(not(target_family = "solana"))] use crate::sync::{PoisonError, RwLock}; -#[cfg(not(target_os = "solana"))] +#[cfg(not(target_family = "solana"))] use crate::sys::stdio::panic_output; #[cfg(not(target_family = "solana"))] use crate::sys_common::backtrace; #[cfg(not(target_family = "solana"))] -use crate::sys_common::rwlock::StaticRwLock; -#[cfg(not(target_family = "solana"))] use crate::sys_common::thread_info; #[cfg(not(target_family = "solana"))] use crate::thread; @@ -83,7 +82,7 @@ extern "C" fn __rust_foreign_exception() -> ! { rtabort!("Rust cannot catch foreign exceptions"); } -#[cfg(not(target_os = "solana"))] +#[cfg(not(target_family = "solana"))] enum Hook { Default, Custom(Box) + 'static + Sync + Send>), @@ -100,7 +99,7 @@ impl Hook { } } -#[cfg(not(target_os = "solana"))] +#[cfg(not(target_family = "solana"))] impl Default for Hook { #[inline] fn default() -> Hook { @@ -108,7 +107,7 @@ impl Default for Hook { } } -#[cfg(not(target_os = "solana"))] +#[cfg(not(target_family = "solana"))] static HOOK: RwLock = RwLock::new(Hook::Default); /// Registers a custom panic hook, replacing the previously registered hook. @@ -441,7 +440,7 @@ pub mod panic_count { // // This also updates thread-local state to keep track of whether a panic // hook is currently executing. - #[cfg(not(target_os = "solana"))] + #[cfg(not(target_family = "solana"))] pub fn increase(run_panic_hook: bool) -> Option { let global_count = GLOBAL_PANIC_COUNT.fetch_add(1, Ordering::Relaxed); if global_count & ALWAYS_ABORT_FLAG != 0 { @@ -508,7 +507,7 @@ pub mod panic_count { // Slow path is in a separate function to reduce the amount of code // inlined from `count_is_zero`. - #[cfg(not(target_os = "solana"))] + #[cfg(not(target_family = "solana"))] #[inline(never)] #[cold] fn is_zero_slow_path() -> bool { @@ -661,7 +660,7 @@ pub fn panicking() -> bool { } /// Entry point of panics from the core crate (`panic_impl` lang item). -#[cfg(not(any(test, target_os = "solana")))] +#[cfg(not(any(test, target_family = "solana")))] #[panic_handler] pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! { struct FormatStringPayload<'a> { diff --git a/library/std/src/process.rs b/library/std/src/process.rs index 33bcca7381023..510b4af13c8c5 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -2361,10 +2361,15 @@ impl Termination for Result { fn report(self) -> ExitCode { match self { Ok(val) => val.report(), + #[cfg(not(target_family = "solana"))] Err(err) => { io::attempt_print_to_stderr(format_args_nl!("Error: {err:?}")); ExitCode::FAILURE } + #[cfg(target_family = "solana")] + Err(_err) => { + ExitCode::FAILURE + } } } } diff --git a/library/std/src/rt.rs b/library/std/src/rt.rs index c08e39d314564..5bac2a8b942ec 100644 --- a/library/std/src/rt.rs +++ b/library/std/src/rt.rs @@ -188,6 +188,7 @@ fn lang_start( main: fn() -> T, _argc: isize, _argv: *const *const u8, + _sigpipe: u8, ) -> isize { main().report().to_i32() as isize } diff --git a/library/std/src/sync/mod.rs b/library/std/src/sync/mod.rs index f6a7c0a9f7549..017a09f8915fc 100644 --- a/library/std/src/sync/mod.rs +++ b/library/std/src/sync/mod.rs @@ -180,6 +180,7 @@ pub use self::lazy_lock::LazyLock; #[stable(feature = "once_cell", since = "1.70.0")] pub use self::once_lock::OnceLock; +#[cfg(not(target_family = "solana"))] pub(crate) use self::remutex::{ReentrantMutex, ReentrantMutexGuard}; pub mod mpsc; diff --git a/library/std/src/sync/mpmc/utils.rs b/library/std/src/sync/mpmc/utils.rs index 0cbc61160f7ee..9fb7e6672b3d4 100644 --- a/library/std/src/sync/mpmc/utils.rs +++ b/library/std/src/sync/mpmc/utils.rs @@ -3,6 +3,7 @@ use crate::ops::{Deref, DerefMut}; /// Pads and aligns a value to the length of a cache line. #[derive(Clone, Copy, Default, Hash, PartialEq, Eq)] +#[cfg_attr(target_family = "solana", repr(align(8)))] // Starting from Intel's Sandy Bridge, spatial prefetcher is now pulling pairs of 64-byte cache // lines at a time, so we have to align to 128 bytes rather than 64. // @@ -66,6 +67,7 @@ use crate::ops::{Deref, DerefMut}; target_arch = "mips64r6", target_arch = "riscv64", target_arch = "s390x", + target_family = "solana", )), repr(align(64)) )] diff --git a/library/std/src/sys/sbf/futex.rs b/library/std/src/sys/sbf/futex.rs new file mode 100644 index 0000000000000..b8e83deb4f65a --- /dev/null +++ b/library/std/src/sys/sbf/futex.rs @@ -0,0 +1,14 @@ +use crate::sync::atomic::AtomicU32; +use crate::time::Duration; + +pub fn futex_wait(_futex: &AtomicU32, _expected: u32, _timeout: Option) -> bool { + false +} + +#[inline] +pub fn futex_wake(_futex: &AtomicU32) -> bool { + false +} + +#[inline] +pub fn futex_wake_all(_futex: &AtomicU32) {} diff --git a/library/std/src/sys/sbf/mod.rs b/library/std/src/sys/sbf/mod.rs index 41e4490a4b4eb..55e4ce34c33b3 100644 --- a/library/std/src/sys/sbf/mod.rs +++ b/library/std/src/sys/sbf/mod.rs @@ -20,6 +20,7 @@ pub mod args; pub mod cmath; pub mod env; pub mod fs; +pub mod futex; pub mod io; pub mod memchr; pub mod net; @@ -34,16 +35,17 @@ pub mod time; #[path = "../unix/os_str.rs"] pub mod os_str; -pub mod condvar; -pub mod mutex; -pub mod rwlock; pub mod thread_local_dtor; pub mod thread_local_key; +#[path = "../unix/locks"] pub mod locks { - pub use super::condvar::*; - pub use super::mutex::*; - pub use super::rwlock::*; + mod futex_condvar; + mod futex_mutex; + mod futex_rwlock; + pub(crate) use futex_condvar::Condvar; + pub(crate) use futex_mutex::Mutex; + pub(crate) use futex_rwlock::RwLock; } #[cfg(not(target_feature = "static-syscalls"))] diff --git a/library/std/src/sys/sbf/pipe.rs b/library/std/src/sys/sbf/pipe.rs index d455c28715df2..a28a5072dada3 100644 --- a/library/std/src/sys/sbf/pipe.rs +++ b/library/std/src/sys/sbf/pipe.rs @@ -18,6 +18,10 @@ impl AnonPipe { false } + pub fn read_to_end(&self, _buf: &mut Vec) -> io::Result { + match self.0 {} + } + pub fn write(&self, _buf: &[u8]) -> io::Result { match self.0 {} } diff --git a/library/std/src/sys/sbf/process.rs b/library/std/src/sys/sbf/process.rs index fb04e2bdeff94..73d786add2858 100644 --- a/library/std/src/sys/sbf/process.rs +++ b/library/std/src/sys/sbf/process.rs @@ -65,6 +65,10 @@ impl Command { unsupported() } + pub fn output(&mut self) -> io::Result<(ExitStatus, Vec, Vec)> { + unsupported() + } + pub fn get_args(&self) -> CommandArgs<'_> { let mut iter = self.args.iter(); iter.next(); diff --git a/library/std/src/sys/sbf/thread_local_key.rs b/library/std/src/sys/sbf/thread_local_key.rs index 29e9854bcfccb..4e33321d75503 100644 --- a/library/std/src/sys/sbf/thread_local_key.rs +++ b/library/std/src/sys/sbf/thread_local_key.rs @@ -1,3 +1,4 @@ +#![allow(fuzzy_provenance_casts)] use crate::boxed::Box; use crate::ptr; @@ -33,8 +34,3 @@ pub unsafe fn destroy(key: Key) { f(key.value); } } - -#[inline] -pub fn requires_synchronized_create() -> bool { - false -} diff --git a/library/std/src/sys_common/once/mod.rs b/library/std/src/sys_common/once/mod.rs index 359697d831317..0821e0fb01fc3 100644 --- a/library/std/src/sys_common/once/mod.rs +++ b/library/std/src/sys_common/once/mod.rs @@ -17,6 +17,7 @@ cfg_if::cfg_if! { target_os = "dragonfly", target_os = "fuchsia", target_os = "hermit", + target_os = "solana", ))] { mod futex; pub use futex::{Once, OnceState}; diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index 363a81b0755ac..27b74794c3683 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -1270,7 +1270,7 @@ impl ThreadId { Err(id) => last = id, } } - } else if #[cfg(not(target_os = "solana"))] { + } else if #[cfg(not(target_family = "solana"))] { use crate::sync::{Mutex, PoisonError}; static COUNTER: Mutex = Mutex::new(0); diff --git a/library/test/src/cli.rs b/library/test/src/cli.rs index 5639076f1a3eb..6f3f18180ca88 100644 --- a/library/test/src/cli.rs +++ b/library/test/src/cli.rs @@ -6,6 +6,7 @@ use std::path::PathBuf; use super::options::{ColorConfig, Options, OutputFormat, RunIgnored}; use super::time::TestTimeOptions; +#[cfg(not(target_family = "solana"))] use std::io::{self, IsTerminal}; #[derive(Debug)] @@ -35,6 +36,7 @@ pub struct TestOpts { } impl TestOpts { + #[cfg(not(target_family = "solana"))] pub fn use_color(&self) -> bool { match self.color { ColorConfig::AutoColor => !self.nocapture && io::stdout().is_terminal(), @@ -42,6 +44,11 @@ impl TestOpts { ColorConfig::NeverColor => false, } } + + #[cfg(target_family = "solana")] + pub fn use_color(&self) -> bool { + false + } } /// Result of parsing the options. @@ -332,6 +339,7 @@ fn parse_opts_impl(_matches: getopts::Matches) -> OptRes { skip: Vec::new(), time_options: None, options: Options::new(), + fail_fast: false, }; Ok(test_opts) diff --git a/library/test/src/lib.rs b/library/test/src/lib.rs index 8b59c1b77c58e..8e8bb0cb0988c 100644 --- a/library/test/src/lib.rs +++ b/library/test/src/lib.rs @@ -62,7 +62,6 @@ use std::{ collections::VecDeque, env, io, io::prelude::Write, - mem::ManuallyDrop, panic::{self, catch_unwind, AssertUnwindSafe, PanicInfo}, process::{self, Command, Termination}, sync::mpsc::{channel, Sender}, @@ -70,6 +69,8 @@ use std::{ thread, time::{Duration, Instant}, }; +#[cfg(not(target_family = "solana"))] +use std::mem::ManuallyDrop; pub mod bench; mod cli; @@ -122,6 +123,7 @@ pub fn test_main(args: &[String], tests: Vec, options: Option Date: Wed, 16 Aug 2023 16:28:48 -0400 Subject: [PATCH 098/103] [SOL] Set default visibility of symbols in SBF binaries to hidden Make a solana specific version of __rdl_oom handler that doesn't use a static variable. This variable can't be supported is Solana execution environment. --- compiler/rustc_target/src/spec/sbf_base.rs | 1 + library/alloc/src/alloc.rs | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/compiler/rustc_target/src/spec/sbf_base.rs b/compiler/rustc_target/src/spec/sbf_base.rs index e1451902b448c..d6248b9e30f4a 100644 --- a/compiler/rustc_target/src/spec/sbf_base.rs +++ b/compiler/rustc_target/src/spec/sbf_base.rs @@ -36,6 +36,7 @@ SECTIONS TargetOptions { allow_asm: true, c_int_width: "64".into(), + default_hidden_visibility: true, dll_prefix: "".into(), dynamic_linking: true, eh_frame_header: false, diff --git a/library/alloc/src/alloc.rs b/library/alloc/src/alloc.rs index 2499f1053d860..d0d56fdad0ff9 100644 --- a/library/alloc/src/alloc.rs +++ b/library/alloc/src/alloc.rs @@ -405,6 +405,7 @@ pub mod __alloc_error_handler { // called via generated `__rust_alloc_error_handler` if there is no // `#[alloc_error_handler]`. #[rustc_std_internal_symbol] + #[cfg(not(target_family = "solana"))] pub unsafe fn __rdl_oom(size: usize, _align: usize) -> ! { extern "Rust" { // This symbol is emitted by rustc next to __rust_alloc_error_handler. @@ -421,6 +422,14 @@ pub mod __alloc_error_handler { ) } } + + #[rustc_std_internal_symbol] + #[cfg(target_family = "solana")] + pub unsafe fn __rdl_oom(size: usize, _align: usize) -> ! { + core::panicking::panic_nounwind_fmt(format_args!( + "memory allocation of {size} bytes failed" + )) + } } /// Specialize clones into pre-allocated, uninitialized memory. From fe9b2b98b8ce1529f3c57ea91daf72bf8ef164cd Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Sat, 19 Aug 2023 08:07:45 -0400 Subject: [PATCH 099/103] [SOL] Update run-sbf-tests revision in CI --- src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile index 112127bd45d3f..26bec8e16986f 100644 --- a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile +++ b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile @@ -23,7 +23,7 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y RUN PATH="${HOME}/.cargo/bin:${PATH}" \ cargo install --git https://github.com/solana-labs/cargo-run-solana-tests.git \ - --rev 12186c99173cc30771897932159b53acca836321 \ + --rev 6d90ebb6bde748a4ce6f415ed85dc3fb42b1e97b \ --bin cargo-run-solana-tests --root /usr/local COPY scripts/sccache.sh /scripts/ From 4a3a7c4d83ede53fad09d64fb5608c82a11209cf Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Tue, 26 Sep 2023 17:23:39 -0400 Subject: [PATCH 100/103] [SOL] Adjust SBF customization after upgrading to rust 1.72.0 --- .github/workflows/ci.yml | 51 ++-- compiler/rustc_codegen_llvm/src/allocator.rs | 14 +- compiler/rustc_codegen_ssa/src/back/link.rs | 2 +- compiler/rustc_codegen_ssa/src/base.rs | 7 - config.toml | 2 +- library/alloc/src/alloc.rs | 2 + library/core/src/fmt/mod.rs | 2 - library/std/Cargo.toml | 1 + library/std/src/io/stdio.rs | 5 +- library/std/src/panicking.rs | 1 + library/std/src/sync/mpmc/context.rs | 12 + library/std/src/sync/mpmc/waker.rs | 8 + library/std/src/sys/mod.rs | 3 +- library/std/src/sys/sbf/fs.rs | 4 - library/std/src/sys/sbf/mod.rs | 11 +- library/std/src/sys/sbf/net.rs | 6 +- library/std/src/sys/sbf/pipe.rs | 48 ---- library/std/src/sys/sbf/process.rs | 230 ------------------ library/std/src/sys/sbf/thread_local_dtor.rs | 7 - library/std/src/sys/sbf/thread_local_key.rs | 36 --- .../src/sys/unsupported/thread_local_dtor.rs | 3 +- library/std/src/thread/mod.rs | 3 +- library/test/src/lib.rs | 2 +- .../host-x86_64/sbf-solana-solana/Dockerfile | 6 +- src/ci/github-actions/ci.yml | 8 +- 25 files changed, 91 insertions(+), 383 deletions(-) delete mode 100644 library/std/src/sys/sbf/pipe.rs delete mode 100644 library/std/src/sys/sbf/process.rs delete mode 100644 library/std/src/sys/sbf/thread_local_dtor.rs delete mode 100644 library/std/src/sys/sbf/thread_local_key.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c26c0ca8dd203..bb78c6a2c7ca6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,7 +43,9 @@ jobs: CI_JOB_NAME: "${{ matrix.name }}" CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse HEAD_SHA: "${{ github.event.pull_request.head.sha || github.sha }}" - SCCACHE_BUCKET: rust-lang-ci-sccache2 + SCCACHE_BUCKET: cached-ci-artifacts + SCCACHE_REGION: us-east-2 + SCCACHE_S3_NO_CREDENTIALS: 1 TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate" CACHE_DOMAIN: cached-ci-artifacts.s3.us-east-2.amazonaws.com if: "github.event_name == 'pull_request'" @@ -64,7 +66,7 @@ jobs: env: {} - name: sbf-solana-solana tidy: false - os: ubuntu-latest + os: ubuntu-20.04-16core-64gb env: {} - name: x86_64-gnu-tools os: ubuntu-20.04-16core-64gb @@ -91,9 +93,6 @@ jobs: - name: decide whether to skip this job run: src/ci/scripts/should-skip-this.sh if: success() && !env.SKIP_JOB - - name: ensure the channel matches the target branch - run: src/ci/scripts/verify-channel.sh - if: success() && !env.SKIP_JOB - name: collect CPU statistics run: src/ci/scripts/collect-cpu-stats.sh if: success() && !env.SKIP_JOB @@ -179,6 +178,8 @@ jobs: name: push env: CI_JOB_NAME: "${{ matrix.name }}" + CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse + HEAD_SHA: "${{ github.event.pull_request.head.sha || github.sha }}" SCCACHE_BUCKET: cached-ci-artifacts SCCACHE_REGION: us-east-2 DEPLOY_BUCKET: rust-lang-ci2 @@ -187,19 +188,20 @@ jobs: TOOLSTATE_PUBLISH: 0 CACHES_AWS_ACCESS_KEY_ID: AKIASSXOBJJGY5HRQO4U ARTIFACTS_AWS_ACCESS_KEY_ID: AKIA46X5W6CZN24CBO55 - CACHE_DOMAIN: cached-ci-artifacts.s3.us-east-2.amazonaws.com + AWS_REGION: us-west-1 + CACHE_DOMAIN: ci-caches.rust-lang.org if: "github.event_name == 'push' && startsWith(github.ref, 'refs/heads/solana-') && github.repository == 'solana-labs/rust'" strategy: matrix: include: - name: mingw-check - os: ubuntu-latest + os: ubuntu-20.04-16core-64gb env: {} - name: x86_64-gnu-llvm-12 - os: ubuntu-latest + os: ubuntu-20.04-16core-64gb env: {} - name: sbf-solana-solana - os: ubuntu-latest + os: ubuntu-20.04-16core-64gb env: {} timeout-minutes: 600 runs-on: "${{ matrix.os }}" @@ -223,20 +225,12 @@ jobs: - name: decide whether to skip this job run: src/ci/scripts/should-skip-this.sh if: success() && !env.SKIP_JOB - - name: configure GitHub Actions to kill the build when outdated - uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master - with: - github_token: "${{ secrets.github_token }}" - if: "success() && !env.SKIP_JOB && github.ref != 'refs/heads/try' && github.ref != 'refs/heads/try-perf'" - name: collect CPU statistics run: src/ci/scripts/collect-cpu-stats.sh if: success() && !env.SKIP_JOB - name: show the current environment run: src/ci/scripts/dump-environment.sh if: success() && !env.SKIP_JOB - - name: install awscli - run: src/ci/scripts/install-awscli.sh - if: success() && !env.SKIP_JOB - name: install sccache run: src/ci/scripts/install-sccache.sh if: success() && !env.SKIP_JOB @@ -288,6 +282,17 @@ jobs: AWS_SECRET_ACCESS_KEY: "${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.CACHES_AWS_ACCESS_KEY_ID)] }}" TOOLSTATE_REPO_ACCESS_TOKEN: "${{ secrets.TOOLSTATE_REPO_ACCESS_TOKEN }}" if: success() && !env.SKIP_JOB + - name: create github artifacts + run: src/ci/scripts/create-doc-artifacts.sh + if: success() && !env.SKIP_JOB + - name: upload artifacts to github + uses: actions/upload-artifact@v3 + with: + name: "${{ env.DOC_ARTIFACT_NAME }}" + path: obj/artifacts/doc + if-no-files-found: ignore + retention-days: 5 + if: success() && !env.SKIP_JOB - name: upload artifacts to S3 run: src/ci/scripts/upload-artifacts.sh env: @@ -301,7 +306,8 @@ jobs: CI_JOB_NAME: "${{ matrix.name }}" CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse HEAD_SHA: "${{ github.event.pull_request.head.sha || github.sha }}" - SCCACHE_BUCKET: rust-lang-ci-sccache2 + SCCACHE_BUCKET: cached-ci-artifacts + SCCACHE_REGION: us-east-2 DEPLOY_BUCKET: rust-lang-ci2 TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate" TOOLSTATE_ISSUES_API_URL: "https://api.github.com/repos/rust-lang/rust/issues" @@ -607,9 +613,6 @@ jobs: - name: decide whether to skip this job run: src/ci/scripts/should-skip-this.sh if: success() && !env.SKIP_JOB - - name: ensure the channel matches the target branch - run: src/ci/scripts/verify-channel.sh - if: success() && !env.SKIP_JOB - name: collect CPU statistics run: src/ci/scripts/collect-cpu-stats.sh if: success() && !env.SKIP_JOB @@ -698,7 +701,8 @@ jobs: CI_JOB_NAME: "${{ matrix.name }}" CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse HEAD_SHA: "${{ github.event.pull_request.head.sha || github.sha }}" - SCCACHE_BUCKET: rust-lang-ci-sccache2 + SCCACHE_BUCKET: cached-ci-artifacts + SCCACHE_REGION: us-east-2 DEPLOY_BUCKET: rust-lang-ci2 TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate" TOOLSTATE_ISSUES_API_URL: "https://api.github.com/repos/rust-lang/rust/issues" @@ -737,9 +741,6 @@ jobs: - name: decide whether to skip this job run: src/ci/scripts/should-skip-this.sh if: success() && !env.SKIP_JOB - - name: ensure the channel matches the target branch - run: src/ci/scripts/verify-channel.sh - if: success() && !env.SKIP_JOB - name: collect CPU statistics run: src/ci/scripts/collect-cpu-stats.sh if: success() && !env.SKIP_JOB diff --git a/compiler/rustc_codegen_llvm/src/allocator.rs b/compiler/rustc_codegen_llvm/src/allocator.rs index db5c1388ef846..d7d3a2563202f 100644 --- a/compiler/rustc_codegen_llvm/src/allocator.rs +++ b/compiler/rustc_codegen_llvm/src/allocator.rs @@ -83,13 +83,15 @@ pub(crate) unsafe fn codegen( let llval = llvm::LLVMConstInt(i8, val as u64, False); llvm::LLVMSetInitializer(ll_g, llval); - let name = NO_ALLOC_SHIM_IS_UNSTABLE; - let ll_g = llvm::LLVMRustGetOrInsertGlobal(llmod, name.as_ptr().cast(), name.len(), i8); - if tcx.sess.target.default_hidden_visibility { - llvm::LLVMRustSetVisibility(ll_g, llvm::Visibility::Hidden); + if tcx.sess.target.arch != "sbf" { + let name = NO_ALLOC_SHIM_IS_UNSTABLE; + let ll_g = llvm::LLVMRustGetOrInsertGlobal(llmod, name.as_ptr().cast(), name.len(), i8); + if tcx.sess.target.default_hidden_visibility { + llvm::LLVMRustSetVisibility(ll_g, llvm::Visibility::Hidden); + } + let llval = llvm::LLVMConstInt(i8, 0, False); + llvm::LLVMSetInitializer(ll_g, llval); } - let llval = llvm::LLVMConstInt(i8, 0, False); - llvm::LLVMSetInitializer(ll_g, llval); if tcx.sess.opts.debuginfo != DebugInfo::None { let dbg_cx = debuginfo::CodegenUnitDebugContext::new(llmod); diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index b656866df52a5..b426bc0d00c26 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -1959,7 +1959,7 @@ fn patch_synthetic_object_file(sess: &Session, path: &PathBuf) { sf.write(&EM_SBF).unwrap(); } } else { - sess.fatal(&format!("failed to patch {}", path.display())); + sess.fatal(format!("failed to patch {}", path.display())); } } diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index cbdc82e5b7add..9ab953ba10b48 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -420,7 +420,6 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( rust_main_def_id: DefId, entry_type: EntryFnType, ) -> Bx::Function { -<<<<<<< HEAD // The entry function is either `int main(void)` or `int main(int argc, char **argv)`, or // `usize efi_main(void *handle, void *system_table)` depending on the target. let is_bpf = cx.sess().target.arch == "bpf" && cx.sess().opts.test; @@ -428,12 +427,6 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( cx.type_func(&[cx.type_ptr(), cx.type_ptr()], cx.type_isize()) } else if cx.sess().target.main_needs_argc_argv { cx.type_func(&[cx.type_int(), cx.type_ptr()], cx.type_int()) -======= - // The entry function is either `int main(void)` or `int main(int argc, char **argv)`, - // depending on whether the target needs `argc` and `argv` to be passed in. - let llfty = if cx.sess().target.main_needs_argc_argv { - cx.type_func(&[cx.type_int(), cx.type_ptr_to(cx.type_i8p())], cx.type_int()) ->>>>>>> e5c32090239 ([SOL] rework test harness codegen a bit) } else { cx.type_func(&[], cx.type_int()) }; diff --git a/config.toml b/config.toml index 26bc3f20ba9d8..9a195b3c27fb0 100644 --- a/config.toml +++ b/config.toml @@ -74,7 +74,7 @@ experimental-targets = "BPF;SBF" # each linker process. # If absent or 0, linker invocations are treated like any other job and # controlled by rustbuild's -j parameter. -#link-jobs = 0 +link-jobs = 2 # When invoking `llvm-config` this configures whether the `--shared` argument is # passed to prefer linking to shared libraries. diff --git a/library/alloc/src/alloc.rs b/library/alloc/src/alloc.rs index d0d56fdad0ff9..e73540a51ebb9 100644 --- a/library/alloc/src/alloc.rs +++ b/library/alloc/src/alloc.rs @@ -36,6 +36,7 @@ extern "Rust" { #[rustc_nounwind] fn __rust_alloc_zeroed(size: usize, align: usize) -> *mut u8; + #[cfg(not(target_family = "solana"))] static __rust_no_alloc_shim_is_unstable: u8; } @@ -93,6 +94,7 @@ pub unsafe fn alloc(layout: Layout) -> *mut u8 { unsafe { // Make sure we don't accidentally allow omitting the allocator shim in // stable code until it is actually stabilized. + #[cfg(not(target_family = "solana"))] core::ptr::read_volatile(&__rust_no_alloc_shim_is_unstable); __rust_alloc(layout.size(), layout.align()) diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index 84ce99487009b..e1b7b46a1ed2f 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -5,8 +5,6 @@ use crate::cell::{Cell, Ref, RefCell, RefMut, SyncUnsafeCell, UnsafeCell}; use crate::char::EscapeDebugExtArgs; use crate::iter; -#[cfg(target_family = "solana")] -use crate::intrinsics::abort; use crate::marker::PhantomData; use crate::mem; use crate::num::fmt as numfmt; diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index a1f1ab9f8ffed..a7bd780465042 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -14,6 +14,7 @@ crate-type = ["dylib", "rlib"] [dependencies] alloc = { path = "../alloc", public = true } cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] } +panic_unwind = { path = "../panic_unwind", optional = true } panic_abort = { path = "../panic_abort" } core = { path = "../core", public = true } libc = { version = "0.2.150", default-features = false, features = ['rustc-dep-of-std'], public = true } diff --git a/library/std/src/io/stdio.rs b/library/std/src/io/stdio.rs index 567505b543d3e..76e48322ad7e2 100644 --- a/library/std/src/io/stdio.rs +++ b/library/std/src/io/stdio.rs @@ -13,7 +13,7 @@ use crate::fs::File; #[cfg(not(target_family = "solana"))] use crate::io::{self, BorrowedCursor, BufReader, IoSlice, IoSliceMut, LineWriter, Lines}; #[cfg(target_family = "solana")] -use crate::io::{self, BufReader, IoSlice, IoSliceMut}; +use crate::io::{self, BorrowedCursor, BufReader, IoSlice, IoSliceMut}; #[cfg(not(target_family = "solana"))] use crate::sync::atomic::{AtomicBool, Ordering}; use crate::sync::{Arc, Mutex, MutexGuard}; @@ -475,6 +475,9 @@ impl Read for Stdin { fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } + fn read_buf(&mut self, _buf: BorrowedCursor<'_>) -> io::Result<()> { + Ok(()) + } fn read_vectored(&mut self, _bufs: &mut [IoSliceMut<'_>]) -> io::Result { Ok(0) } diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index 6bd6598f5421e..65abea4ca4642 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -457,6 +457,7 @@ pub mod panic_count { }) } + #[cfg(not(target_family = "solana"))] pub fn finished_panic_hook() { LOCAL_PANIC_COUNT.with(|c| { let (count, _) = c.get(); diff --git a/library/std/src/sync/mpmc/context.rs b/library/std/src/sync/mpmc/context.rs index bbfc6ce00ffc2..8cd1f60a57c9c 100644 --- a/library/std/src/sync/mpmc/context.rs +++ b/library/std/src/sync/mpmc/context.rs @@ -3,6 +3,7 @@ use super::select::Selected; use super::waker::current_thread_id; +#[cfg(not(target_family = "solana"))] use crate::cell::Cell; use crate::ptr; use crate::sync::atomic::{AtomicPtr, AtomicUsize, Ordering}; @@ -34,6 +35,7 @@ struct Inner { impl Context { /// Creates a new context for the duration of the closure. + #[cfg(not(target_family = "solana"))] #[inline] pub fn with(f: F) -> R where @@ -63,6 +65,15 @@ impl Context { .unwrap_or_else(|_| f(&Context::new())) } + #[cfg(target_family = "solana")] + #[inline] + pub fn with(f: F) -> R + where + F: FnOnce(&Context) -> R, + { + f(&Context::new()) + } + /// Creates a new `Context`. #[cold] fn new() -> Context { @@ -77,6 +88,7 @@ impl Context { } /// Resets `select` and `packet`. + #[cfg(not(target_family = "solana"))] #[inline] fn reset(&self) { self.inner.select.store(Selected::Waiting.into(), Ordering::Release); diff --git a/library/std/src/sync/mpmc/waker.rs b/library/std/src/sync/mpmc/waker.rs index 9aab1b9417edb..21b1802f3464b 100644 --- a/library/std/src/sync/mpmc/waker.rs +++ b/library/std/src/sync/mpmc/waker.rs @@ -201,6 +201,7 @@ impl Drop for SyncWaker { } /// Returns a unique id for the current thread. +#[cfg(not(target_family = "solana"))] #[inline] pub fn current_thread_id() -> usize { // `u8` is not drop so this variable will be available during thread destruction, @@ -208,3 +209,10 @@ pub fn current_thread_id() -> usize { thread_local! { static DUMMY: u8 = 0 } DUMMY.with(|x| (x as *const u8).addr()) } + +/// Returns a unique id for the current thread. +#[cfg(target_family = "solana")] +#[inline] +pub fn current_thread_id() -> usize { + 0 +} diff --git a/library/std/src/sys/mod.rs b/library/std/src/sys/mod.rs index 62a2863d1f3ef..528194fd99b58 100644 --- a/library/std/src/sys/mod.rs +++ b/library/std/src/sys/mod.rs @@ -63,8 +63,9 @@ cfg_if::cfg_if! { } cfg_if::cfg_if! { + if #[cfg(target_family = "solana")] { // Fuchsia components default to full backtrace. - if #[cfg(target_os = "fuchsia")] { + } else if #[cfg(target_os = "fuchsia")] { pub const FULL_BACKTRACE_DEFAULT: bool = true; } else { pub const FULL_BACKTRACE_DEFAULT: bool = false; diff --git a/library/std/src/sys/sbf/fs.rs b/library/std/src/sys/sbf/fs.rs index caba7c4654613..54d4a18c2ed8b 100644 --- a/library/std/src/sys/sbf/fs.rs +++ b/library/std/src/sys/sbf/fs.rs @@ -253,10 +253,6 @@ impl File { pub fn set_times(&self, _times: FileTimes) -> io::Result<()> { match self.0 {} } - - pub fn diverge(&self) -> ! { - match self.0 {} - } } impl DirBuilder { diff --git a/library/std/src/sys/sbf/mod.rs b/library/std/src/sys/sbf/mod.rs index 55e4ce34c33b3..1baf6ff5470cb 100644 --- a/library/std/src/sys/sbf/mod.rs +++ b/library/std/src/sys/sbf/mod.rs @@ -26,18 +26,23 @@ pub mod memchr; pub mod net; pub mod os; pub mod path; +#[path = "../unsupported/pipe.rs"] pub mod pipe; +#[path = "../unsupported/process.rs"] pub mod process; pub mod stdio; pub mod thread; +#[path = "../unsupported/thread_local_dtor.rs"] +pub mod thread_local_dtor; +#[path = "../unsupported/thread_local_key.rs"] +pub mod thread_local_key; +#[path = "../unsupported/thread_parking.rs"] +pub mod thread_parking; pub mod time; #[path = "../unix/os_str.rs"] pub mod os_str; -pub mod thread_local_dtor; -pub mod thread_local_key; - #[path = "../unix/locks"] pub mod locks { mod futex_condvar; diff --git a/library/std/src/sys/sbf/net.rs b/library/std/src/sys/sbf/net.rs index 6e1048660031f..9b3d7b86cb313 100644 --- a/library/std/src/sys/sbf/net.rs +++ b/library/std/src/sys/sbf/net.rs @@ -1,5 +1,5 @@ use crate::fmt; -use crate::io::{self, IoSlice, IoSliceMut}; +use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut}; use crate::net::{SocketAddr, Shutdown, Ipv4Addr, Ipv6Addr}; use crate::time::Duration; use crate::sys::{unsupported, Void}; @@ -45,6 +45,10 @@ impl TcpStream { match self.0 {} } + pub fn read_buf(&self, _: BorrowedCursor<'_>) -> io::Result<()> { + match self.0 {} + } + pub fn read_vectored(&self, _: &mut [IoSliceMut<'_>]) -> io::Result { match self.0 {} } diff --git a/library/std/src/sys/sbf/pipe.rs b/library/std/src/sys/sbf/pipe.rs deleted file mode 100644 index a28a5072dada3..0000000000000 --- a/library/std/src/sys/sbf/pipe.rs +++ /dev/null @@ -1,48 +0,0 @@ -use crate::io::{self, IoSlice, IoSliceMut}; -use crate::sys::Void; - -pub struct AnonPipe(Void); - -impl AnonPipe { - pub fn read(&self, _buf: &mut [u8]) -> io::Result { - match self.0 {} - } - - - pub fn read_vectored(&self, _bufs: &mut [IoSliceMut<'_>]) -> io::Result { - match self.0 {} - } - - #[inline] - pub fn is_read_vectored(&self) -> bool { - false - } - - pub fn read_to_end(&self, _buf: &mut Vec) -> io::Result { - match self.0 {} - } - - pub fn write(&self, _buf: &[u8]) -> io::Result { - match self.0 {} - } - - pub fn write_vectored(&self, _bufs: &[IoSlice<'_>]) -> io::Result { - match self.0 {} - } - - #[inline] - pub fn is_write_vectored(&self) -> bool { - false - } - - pub fn diverge(&self) -> ! { - match self.0 {} - } -} - -pub fn read2(p1: AnonPipe, - _v1: &mut Vec, - _p2: AnonPipe, - _v2: &mut Vec) -> io::Result<()> { - match p1.0 {} -} diff --git a/library/std/src/sys/sbf/process.rs b/library/std/src/sys/sbf/process.rs deleted file mode 100644 index 73d786add2858..0000000000000 --- a/library/std/src/sys/sbf/process.rs +++ /dev/null @@ -1,230 +0,0 @@ -use crate::ffi::{CString, OsStr}; -use crate::fmt; -use crate::io; -use crate::num::NonZeroI32; -use crate::path::Path; -use crate::sys::fs::File; -use crate::sys::pipe::AnonPipe; -use crate::sys::{unsupported, Void}; -use crate::sys_common::process::{CommandEnv, CommandEnvs}; - -pub use crate::ffi::OsString as EnvKey; - -//////////////////////////////////////////////////////////////////////////////// -// Command -//////////////////////////////////////////////////////////////////////////////// - -pub struct Command { - env: CommandEnv, - args: Vec, -} - -// passed back to std::process with the pipes connected to the child, if any -// were requested -pub struct StdioPipes { - pub stdin: Option, - pub stdout: Option, - pub stderr: Option, -} - -pub enum Stdio { - Inherit, - Null, - MakePipe, -} - -impl Command { - pub fn new(_program: &OsStr) -> Command { - Command { - env: Default::default(), - args: vec![CString::new("").unwrap()] - } - } - - pub fn arg(&mut self, _arg: &OsStr) { - } - - pub fn env_mut(&mut self) -> &mut CommandEnv { - &mut self.env - } - - pub fn cwd(&mut self, _dir: &OsStr) { - } - - pub fn stdin(&mut self, _stdin: Stdio) { - } - - pub fn stdout(&mut self, _stdout: Stdio) { - } - - pub fn stderr(&mut self, _stderr: Stdio) { - } - - pub fn spawn(&mut self, _default: Stdio, _needs_stdin: bool) - -> io::Result<(Process, StdioPipes)> { - unsupported() - } - - pub fn output(&mut self) -> io::Result<(ExitStatus, Vec, Vec)> { - unsupported() - } - - pub fn get_args(&self) -> CommandArgs<'_> { - let mut iter = self.args.iter(); - iter.next(); - CommandArgs { iter } - } - - pub fn get_envs(&self) -> CommandEnvs<'_> { - self.env.iter() - } - - pub fn get_current_dir(&self) -> Option<&Path> { - Some(Path::new(OsStr::new(""))) - } - - pub fn get_program(&self) -> &OsStr { - OsStr::new("") - } -} - -impl From for Stdio { - fn from(pipe: AnonPipe) -> Stdio { - pipe.diverge() - } -} - -impl From for Stdio { - fn from(file: File) -> Stdio { - file.diverge() - } -} - -impl fmt::Debug for Command { - fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { - Ok(()) - } -} - -pub struct ExitStatus(Void); - -impl ExitStatus { - pub fn exit_ok(&self) -> Result<(), ExitStatusError> { - match self.0 {} - } - - pub fn code(&self) -> Option { - match self.0 {} - } -} - -impl Clone for ExitStatus { - fn clone(&self) -> ExitStatus { - match self.0 {} - } -} - -impl Copy for ExitStatus {} - -impl PartialEq for ExitStatus { - fn eq(&self, _other: &ExitStatus) -> bool { - match self.0 {} - } -} - -impl Eq for ExitStatus { -} - -impl fmt::Debug for ExitStatus { - fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self.0 {} - } -} - -impl fmt::Display for ExitStatus { - fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self.0 {} - } -} - -#[derive(PartialEq, Eq, Clone, Copy, Debug)] -pub struct ExitStatusError(ExitStatus); - -impl Into for ExitStatusError { - fn into(self) -> ExitStatus { - match self.0 {} - } -} - -impl ExitStatusError { - pub fn code(self) -> Option { - match self.0 {} - } -} - -#[derive(PartialEq, Eq, Clone, Copy, Debug)] -pub struct ExitCode(u8); - -impl ExitCode { - pub const SUCCESS: ExitCode = ExitCode(0 as _); - pub const FAILURE: ExitCode = ExitCode(1 as _); - - pub fn as_i32(&self) -> i32 { - self.0 as i32 - } -} - -impl From for ExitCode { - fn from(code: u8) -> Self { - Self(code) - } -} - -pub struct Process(Void); - -impl Process { - pub fn id(&self) -> u32 { - match self.0 {} - } - - pub fn kill(&mut self) -> io::Result<()> { - match self.0 {} - } - - pub fn wait(&mut self) -> io::Result { - match self.0 {} - } - - pub fn try_wait(&mut self) -> io::Result> { - match self.0 {} - } -} - -pub struct CommandArgs<'a> { - iter: crate::slice::Iter<'a, CString>, -} - -impl<'a> Iterator for CommandArgs<'a> { - type Item = &'a OsStr; - fn next(&mut self) -> Option<&'a OsStr> { - self.iter.next().map(|_| OsStr::new("")) - } - fn size_hint(&self) -> (usize, Option) { - self.iter.size_hint() - } -} - -impl<'a> ExactSizeIterator for CommandArgs<'a> { - fn len(&self) -> usize { - self.iter.len() - } - fn is_empty(&self) -> bool { - self.iter.is_empty() - } -} - -impl<'a> fmt::Debug for CommandArgs<'a> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_list().entries(self.iter.clone()).finish() - } -} diff --git a/library/std/src/sys/sbf/thread_local_dtor.rs b/library/std/src/sys/sbf/thread_local_dtor.rs deleted file mode 100644 index 5391ed83ebc36..0000000000000 --- a/library/std/src/sys/sbf/thread_local_dtor.rs +++ /dev/null @@ -1,7 +0,0 @@ -#![cfg(target_thread_local)] -#![unstable(feature = "thread_local_internals", issue = "none")] - -pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) { - use crate::sys_common::thread_local_dtor::register_dtor_fallback; - register_dtor_fallback(t, dtor); -} diff --git a/library/std/src/sys/sbf/thread_local_key.rs b/library/std/src/sys/sbf/thread_local_key.rs deleted file mode 100644 index 4e33321d75503..0000000000000 --- a/library/std/src/sys/sbf/thread_local_key.rs +++ /dev/null @@ -1,36 +0,0 @@ -#![allow(fuzzy_provenance_casts)] -use crate::boxed::Box; -use crate::ptr; - -pub type Key = usize; - -struct Allocated { - value: *mut u8, - dtor: Option, -} - -#[inline] -pub unsafe fn create(dtor: Option) -> Key { - Box::into_raw(Box::new(Allocated { - value: ptr::null_mut(), - dtor, - })) as usize -} - -#[inline] -pub unsafe fn set(key: Key, value: *mut u8) { - (*(key as *mut Allocated)).value = value; -} - -#[inline] -pub unsafe fn get(key: Key) -> *mut u8 { - (*(key as *mut Allocated)).value -} - -#[inline] -pub unsafe fn destroy(key: Key) { - let key = Box::from_raw(key as *mut Allocated); - if let Some(f) = key.dtor { - f(key.value); - } -} diff --git a/library/std/src/sys/unsupported/thread_local_dtor.rs b/library/std/src/sys/unsupported/thread_local_dtor.rs index 84660ea588156..858a227b8cb42 100644 --- a/library/std/src/sys/unsupported/thread_local_dtor.rs +++ b/library/std/src/sys/unsupported/thread_local_dtor.rs @@ -1,6 +1,7 @@ #![unstable(feature = "thread_local_internals", issue = "none")] -#[cfg_attr(target_family = "wasm", allow(unused))] // unused on wasm32-unknown-unknown + // unused on solana and wasm32-unknown-unknown +#[cfg_attr(any(target_family = "solana", target_family = "wasm"), allow(unused))] pub unsafe fn register_dtor(_t: *mut u8, _dtor: unsafe extern "C" fn(*mut u8)) { // FIXME: right now there is no concept of "thread exit", but this is likely // going to show up at some point in the form of an exported symbol that the diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index 27b74794c3683..834a7bb3ed9aa 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -1249,12 +1249,13 @@ impl ThreadId { // Generate a new unique thread ID. fn new() -> ThreadId { #[cold] + #[cfg(not(target_family = "solana"))] fn exhausted() -> ! { panic!("failed to generate unique thread ID: bitspace exhausted") } cfg_if::cfg_if! { - if #[cfg(target_has_atomic = "64")] { + if #[cfg(all(target_has_atomic = "64", not(target_family = "solana")))] { use crate::sync::atomic::{AtomicU64, Ordering::Relaxed}; static COUNTER: AtomicU64 = AtomicU64::new(0); diff --git a/library/test/src/lib.rs b/library/test/src/lib.rs index 8e8bb0cb0988c..a41ad66a7419b 100644 --- a/library/test/src/lib.rs +++ b/library/test/src/lib.rs @@ -604,7 +604,7 @@ pub fn run_test( // If the platform is single-threaded we're just going to run // the test synchronously, regardless of the concurrency // level. - let supports_threads = !cfg!(target_os = "emscripten") && !cfg!(target_family = "wasm"); + let supports_threads = !cfg!(target_os = "emscripten") && !cfg!(target_family = "wasm") && !cfg!(target_family = "solana"); if supports_threads { let cfg = thread::Builder::new().name(name.as_slice().to_owned()); let mut runtest = Arc::new(Mutex::new(Some(runtest))); diff --git a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile index 26bec8e16986f..a30e321d14c96 100644 --- a/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile +++ b/src/ci/docker/host-x86_64/sbf-solana-solana/Dockerfile @@ -23,7 +23,7 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y RUN PATH="${HOME}/.cargo/bin:${PATH}" \ cargo install --git https://github.com/solana-labs/cargo-run-solana-tests.git \ - --rev 6d90ebb6bde748a4ce6f415ed85dc3fb42b1e97b \ + --rev f7c1d109367c0ab4167d2eb41712777bcc66c9a4 \ --bin cargo-run-solana-tests --root /usr/local COPY scripts/sccache.sh /scripts/ @@ -37,8 +37,8 @@ ENV RUST_CONFIGURE_ARGS \ --set rust.lld \ --set llvm.clang -ENV SCRIPT CARGO_TARGET_BPFEL_UNKNOWN_UNKNOWN_RUNNER=\"cargo-run-sbf-tests --heap-size 104857600\" \ - CARGO_TARGET_SBF_SOLANA_SOLANA_RUNNER=\"cargo-run-sbf-tests --heap-size 104857600\" \ +ENV SCRIPT CARGO_TARGET_BPFEL_UNKNOWN_UNKNOWN_RUNNER=\"cargo-run-solana-tests --heap-size 104857600\" \ + CARGO_TARGET_SBF_SOLANA_SOLANA_RUNNER=\"cargo-run-solana-tests --heap-size 104857600\" \ LLVM_HOME=/checkout/obj/build/x86_64-unknown-linux-gnu/llvm \ PATH="${HOME}/.cargo/bin:${PATH}" \ python3 /checkout/x.py --stage 1 test --host='' --target bpfel-unknown-unknown,sbf-solana-solana \ diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml index e1ab8c7c323f8..4f09e22c0c138 100644 --- a/src/ci/github-actions/ci.yml +++ b/src/ci/github-actions/ci.yml @@ -347,7 +347,7 @@ jobs: <<: *job-linux-16c - name: sbf-solana-solana - <<: *job-linux-xl + <<: *job-linux-16c tidy: false - name: x86_64-gnu-tools @@ -363,13 +363,13 @@ jobs: matrix: include: - name: mingw-check - <<: *job-linux-xl + <<: *job-linux-16c - name: x86_64-gnu-llvm-12 - <<: *job-linux-xl + <<: *job-linux-16c - name: sbf-solana-solana - <<: *job-linux-xl + <<: *job-linux-16c auto: <<: *base-ci-job From 7f1fc21d253e8eec38acba44ed5ca023e1104112 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Thu, 19 Oct 2023 17:50:35 -0400 Subject: [PATCH 101/103] [SOL] Fix CI failures --- .github/workflows/ci.yml | 91 +++++++++---------- .reuse/dep5 | 2 + src/ci/github-actions/ci.yml | 6 +- src/tools/tidy/src/pal.rs | 1 - tests/ui/check-cfg/values-target-json.stderr | 2 +- .../linkage-attr/unstable-flavor.bpf.stderr | 2 - .../linkage-attr/unstable-flavor.ptx.stderr | 2 - tests/ui/linkage-attr/unstable-flavor.rs | 14 --- 8 files changed, 51 insertions(+), 69 deletions(-) delete mode 100644 tests/ui/linkage-attr/unstable-flavor.bpf.stderr delete mode 100644 tests/ui/linkage-attr/unstable-flavor.ptx.stderr delete mode 100644 tests/ui/linkage-attr/unstable-flavor.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bb78c6a2c7ca6..f24253c17dc0b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -54,22 +54,21 @@ jobs: matrix: include: - name: mingw-check - os: ubuntu-20.04-4core-16gb + os: ubuntu-latest env: {} - name: mingw-check-tidy - os: ubuntu-20.04-4core-16gb + os: ubuntu-latest env: {} - name: x86_64-gnu-llvm-15 env: ENABLE_GCC_CODEGEN: "1" - os: ubuntu-20.04-16core-64gb - env: {} + os: ubuntu-latest - name: sbf-solana-solana tidy: false - os: ubuntu-20.04-16core-64gb + os: ubuntu-latest env: {} - name: x86_64-gnu-tools - os: ubuntu-20.04-16core-64gb + os: ubuntu-latest env: {} timeout-minutes: 600 runs-on: "${{ matrix.os }}" @@ -195,13 +194,13 @@ jobs: matrix: include: - name: mingw-check - os: ubuntu-20.04-16core-64gb + os: ubuntu-latest env: {} - name: x86_64-gnu-llvm-12 - os: ubuntu-20.04-16core-64gb + os: ubuntu-latest env: {} - name: sbf-solana-solana - os: ubuntu-20.04-16core-64gb + os: ubuntu-latest env: {} timeout-minutes: 600 runs-on: "${{ matrix.os }}" @@ -326,108 +325,108 @@ jobs: - ARM64 - linux - name: arm-android - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest env: {} - name: armhf-gnu - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest env: {} - name: dist-aarch64-linux env: CODEGEN_BACKENDS: "llvm,cranelift" - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest - name: dist-android - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest env: {} - name: dist-arm-linux - os: ubuntu-20.04-16core-64gb + os: ubuntu-latest env: {} - name: dist-armhf-linux - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest env: {} - name: dist-armv7-linux - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest env: {} - name: dist-i586-gnu-i586-i686-musl - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest env: {} - name: dist-i686-linux - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest env: {} - name: dist-loongarch64-linux - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest env: {} - name: dist-powerpc-linux - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest env: {} - name: dist-powerpc64-linux - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest env: {} - name: dist-powerpc64le-linux - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest env: {} - name: dist-riscv64-linux - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest env: {} - name: dist-s390x-linux - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest env: {} - name: dist-various-1 - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest env: {} - name: dist-various-2 - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest env: {} - name: dist-x86_64-freebsd - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest env: {} - name: dist-x86_64-illumos - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest env: {} - name: dist-x86_64-linux env: CODEGEN_BACKENDS: "llvm,cranelift" - os: ubuntu-20.04-16core-64gb + os: ubuntu-latest - name: dist-x86_64-linux-alt env: IMAGE: dist-x86_64-linux CODEGEN_BACKENDS: "llvm,cranelift" - os: ubuntu-20.04-16core-64gb + os: ubuntu-latest - name: dist-x86_64-musl env: CODEGEN_BACKENDS: "llvm,cranelift" - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest - name: dist-x86_64-netbsd - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest env: {} - name: i686-gnu - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest env: {} - name: i686-gnu-nopt - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest env: {} - name: mingw-check - os: ubuntu-20.04-4core-16gb + os: ubuntu-latest env: {} - name: test-various - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest env: {} - name: x86_64-gnu - os: ubuntu-20.04-4core-16gb + os: ubuntu-latest env: {} - name: x86_64-gnu-stable env: IMAGE: x86_64-gnu RUST_CI_OVERRIDE_RELEASE_CHANNEL: stable CI_ONLY_WHEN_CHANNEL: nightly - os: ubuntu-20.04-4core-16gb + os: ubuntu-latest - name: x86_64-gnu-aux - os: ubuntu-20.04-4core-16gb + os: ubuntu-latest env: {} - name: x86_64-gnu-debug - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest env: {} - name: x86_64-gnu-distcheck - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest env: {} - name: x86_64-gnu-llvm-17 env: @@ -436,18 +435,18 @@ jobs: - name: x86_64-gnu-llvm-16 env: RUST_BACKTRACE: 1 - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest - name: x86_64-gnu-llvm-15 env: RUST_BACKTRACE: 1 - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest - name: x86_64-gnu-nopt - os: ubuntu-20.04-4core-16gb + os: ubuntu-latest env: {} - name: x86_64-gnu-tools env: DEPLOY_TOOLSTATES_JSON: toolstates-linux.json - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest - name: dist-x86_64-apple env: SCRIPT: "./x.py dist bootstrap --include-default-paths --host=x86_64-apple-darwin --target=x86_64-apple-darwin" @@ -718,7 +717,7 @@ jobs: - name: dist-x86_64-linux env: CODEGEN_BACKENDS: "llvm,cranelift" - os: ubuntu-20.04-16core-64gb + os: ubuntu-latest timeout-minutes: 600 runs-on: "${{ matrix.os }}" steps: diff --git a/.reuse/dep5 b/.reuse/dep5 index 245ed2659f91f..dafee8ff6bb03 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -13,10 +13,12 @@ Files: compiler/* tests/* src/* .github/* + build.sh Cargo.lock Cargo.toml CODE_OF_CONDUCT.md config.example.toml + config.toml configure CONTRIBUTING.md COPYRIGHT diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml index 4f09e22c0c138..c7412b76e60f5 100644 --- a/src/ci/github-actions/ci.yml +++ b/src/ci/github-actions/ci.yml @@ -79,15 +79,15 @@ x--expand-yaml-anchors--remove: env: {} - &job-linux-4c - os: ubuntu-20.04-4core-16gb + os: ubuntu-latest <<: *base-job - &job-linux-8c - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest <<: *base-job - &job-linux-16c - os: ubuntu-20.04-16core-64gb + os: ubuntu-latest <<: *base-job - &job-macos-xl diff --git a/src/tools/tidy/src/pal.rs b/src/tools/tidy/src/pal.rs index d1c3abef34b7c..e3b5925a7358d 100644 --- a/src/tools/tidy/src/pal.rs +++ b/src/tools/tidy/src/pal.rs @@ -140,7 +140,6 @@ fn check_cfgs( || cfg.contains("target_env") || cfg.contains("target_abi") || cfg.contains("target_vendor") - || cfg.contains("target_family") || cfg.contains("unix") || cfg.contains("windows"); diff --git a/tests/ui/check-cfg/values-target-json.stderr b/tests/ui/check-cfg/values-target-json.stderr index e71149f337f58..ab04d953ad575 100644 --- a/tests/ui/check-cfg/values-target-json.stderr +++ b/tests/ui/check-cfg/values-target-json.stderr @@ -6,7 +6,7 @@ LL | #[cfg(target_os = "linuz")] | | | help: there is a expected value with a similar name: `"linux"` | - = note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `ericos`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous` + = note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `ericos`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solana`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous` = note: `#[warn(unexpected_cfgs)]` on by default warning: 1 warning emitted diff --git a/tests/ui/linkage-attr/unstable-flavor.bpf.stderr b/tests/ui/linkage-attr/unstable-flavor.bpf.stderr deleted file mode 100644 index 819da2fb01788..0000000000000 --- a/tests/ui/linkage-attr/unstable-flavor.bpf.stderr +++ /dev/null @@ -1,2 +0,0 @@ -error: the linker flavor `bpf` is unstable, the `-Z unstable-options` flag must also be passed to use the unstable values - diff --git a/tests/ui/linkage-attr/unstable-flavor.ptx.stderr b/tests/ui/linkage-attr/unstable-flavor.ptx.stderr deleted file mode 100644 index 2ebdc1a903399..0000000000000 --- a/tests/ui/linkage-attr/unstable-flavor.ptx.stderr +++ /dev/null @@ -1,2 +0,0 @@ -error: the linker flavor `ptx` is unstable, the `-Z unstable-options` flag must also be passed to use the unstable values - diff --git a/tests/ui/linkage-attr/unstable-flavor.rs b/tests/ui/linkage-attr/unstable-flavor.rs deleted file mode 100644 index c2c16b28bff10..0000000000000 --- a/tests/ui/linkage-attr/unstable-flavor.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Even though this test only checks 2 of the 10 or so unstable linker flavors, it exercizes the -// unique codepath checking all unstable options (see `LinkerFlavorCli::is_unstable` and its -// caller). If it passes, all the other unstable options are rejected as well. -// -// revisions: bpf ptx -// [bpf] compile-flags: --target=bpfel-unknown-none -C linker-flavor=bpf --crate-type=rlib -// [bpf] error-pattern: linker flavor `bpf` is unstable, the `-Z unstable-options` flag -// [bpf] needs-llvm-components: -// [ptx] compile-flags: --target=nvptx64-nvidia-cuda -C linker-flavor=ptx --crate-type=rlib -// [ptx] error-pattern: linker flavor `ptx` is unstable, the `-Z unstable-options` flag -// [ptx] needs-llvm-components: - -#![feature(no_core)] -#![no_core] From 87d0b56c870ddc2a8bb123e20efcbf5706bb86a2 Mon Sep 17 00:00:00 2001 From: Lucas Steuernagel Date: Fri, 2 Feb 2024 18:24:45 -0300 Subject: [PATCH 102/103] [SOL] Adjust compiler after upgrade to 1.75.0 --- .github/workflows/ci.yml | 10 ++++- Cargo.lock | 43 ++++++++++++------- Cargo.toml | 2 +- .../rustc_codegen_gcc/src/intrinsic/mod.rs | 3 +- compiler/rustc_codegen_ssa/src/base.rs | 3 +- compiler/rustc_target/src/spec/base/mod.rs | 1 + .../src/spec/{ => base}/sbf_base.rs | 2 +- .../{ => targets}/bpfel_unknown_unknown.rs | 2 +- .../spec/{ => targets}/sbf_solana_solana.rs | 2 +- library/alloc/src/alloc.rs | 2 +- library/std/src/backtrace.rs | 5 ++- library/std/src/panicking.rs | 7 +-- library/std/src/sys/sbf/cmath.rs | 4 ++ library/std/src/sys/sbf/mod.rs | 5 +++ library/std/src/sys/sbf/os.rs | 7 +++ src/bootstrap/Cargo.toml | 2 +- src/bootstrap/src/utils/cc_detect.rs | 11 ++--- src/tools/tidy/src/extdeps.rs | 2 +- 18 files changed, 73 insertions(+), 40 deletions(-) rename compiler/rustc_target/src/spec/{ => base}/sbf_base.rs (95%) rename compiler/rustc_target/src/spec/{ => targets}/bpfel_unknown_unknown.rs (88%) rename compiler/rustc_target/src/spec/{ => targets}/sbf_solana_solana.rs (88%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f24253c17dc0b..4db0b6c6da44e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -208,7 +208,7 @@ jobs: - name: disable git crlf conversion run: git config --global core.autocrlf false - name: checkout the source code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: configure the PR in which the error message will be posted @@ -230,6 +230,9 @@ jobs: - name: show the current environment run: src/ci/scripts/dump-environment.sh if: success() && !env.SKIP_JOB + - name: install awscli + run: src/ci/scripts/install-awscli.sh + if: success() && !env.SKIP_JOB - name: install sccache run: src/ci/scripts/install-sccache.sh if: success() && !env.SKIP_JOB @@ -239,6 +242,9 @@ jobs: - name: install clang run: src/ci/scripts/install-clang.sh if: success() && !env.SKIP_JOB + - name: install tidy + run: src/ci/scripts/install-tidy.sh + if: success() && !env.SKIP_JOB - name: install WIX run: src/ci/scripts/install-wix.sh if: success() && !env.SKIP_JOB @@ -431,7 +437,7 @@ jobs: - name: x86_64-gnu-llvm-17 env: RUST_BACKTRACE: 1 - os: ubuntu-20.04-8core-32gb + os: ubuntu-latest - name: x86_64-gnu-llvm-16 env: RUST_BACKTRACE: 1 diff --git a/Cargo.lock b/Cargo.lock index 9a8935920b745..dc44cb3685bc8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -723,8 +723,7 @@ checksum = "55b672471b4e9f9e95499ea597ff64941a309b2cdbffcc46f2cc5e2d971fd335" [[package]] name = "compiler_builtins" version = "0.1.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3b73c3443a5fd2438d7ba4853c64e4c8efc2404a9e28a9234cc2d5eebc6c242" +source = "git+https://github.com/solana-labs/compiler-builtins?tag=solana-tools-v1.40#81ef46f3fe1357095acdd089a700890fe4e13974" dependencies = [ "cc", "rustc-std-workspace-core", @@ -781,8 +780,8 @@ checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" name = "core" version = "0.0.0" dependencies = [ - "getrandom 0.1.14", - "rand 0.7.3", + "getrandom 0.1.16", + "rand", "rand_xorshift", ] @@ -1592,6 +1591,17 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", +] + [[package]] name = "getrandom" version = "0.2.10" @@ -1600,7 +1610,7 @@ checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" dependencies = [ "cfg-if", "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", ] [[package]] @@ -2524,7 +2534,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" dependencies = [ "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", "windows-sys 0.48.0", ] @@ -2545,7 +2555,7 @@ dependencies = [ "colored", "ctrlc", "env_logger 0.10.0", - "getrandom", + "getrandom 0.2.10", "lazy_static", "libc", "libffi", @@ -3176,7 +3186,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom", + "getrandom 0.2.10", ] [[package]] @@ -3241,7 +3251,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ - "getrandom", + "getrandom 0.2.10", "redox_syscall 0.2.16", "thiserror", ] @@ -5138,7 +5148,7 @@ dependencies = [ "rustc-demangle", "std_detect", "unwind", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", ] [[package]] @@ -5964,7 +5974,7 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d023da39d1fde5a8a3fe1f3e01ca9632ada0a63e9797de55a879d6e2236277be" dependencies = [ - "getrandom", + "getrandom 0.2.10", ] [[package]] @@ -6004,6 +6014,12 @@ dependencies = [ "try-lock", ] +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -6439,8 +6455,3 @@ dependencies = [ "crossbeam-utils", "flate2", ] - -[[patch.unused]] -name = "compiler_builtins" -version = "0.1.76" -source = "git+https://github.com/solana-labs/compiler-builtins#2044d7e16a99d951853ce362e384027dec4c5b92" diff --git a/Cargo.toml b/Cargo.toml index c735a5b648c8f..9b1a4496e7879 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -105,7 +105,7 @@ miniz_oxide.debug = 0 object.debug = 0 [patch.crates-io] -compiler_builtins = { git = "https://github.com/solana-labs/compiler-builtins" } +compiler_builtins = { git = "https://github.com/solana-labs/compiler-builtins", tag = "solana-tools-v1.40" } # See comments in `library/rustc-std-workspace-core/README.md` for what's going on # here rustc-std-workspace-core = { path = 'library/rustc-std-workspace-core' } diff --git a/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs b/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs index ba1cae03f3e41..0324e206b463e 100644 --- a/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs +++ b/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs @@ -14,7 +14,8 @@ use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue}; use rustc_codegen_ssa::mir::place::PlaceRef; use rustc_codegen_ssa::traits::{ArgAbiMethods, BuilderMethods, ConstMethods, IntrinsicCallMethods}; #[cfg(feature="master")] -use rustc_codegen_ssa::traits::{BaseTypeMethods, MiscMethods}; +use rustc_codegen_ssa::traits::MiscMethods; +use rustc_codegen_ssa::traits::BaseTypeMethods; use rustc_codegen_ssa::errors::InvalidMonomorphization; use rustc_middle::bug; use rustc_middle::ty::{self, Instance, Ty}; diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 9ab953ba10b48..198e5696357af 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -422,7 +422,6 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( ) -> Bx::Function { // The entry function is either `int main(void)` or `int main(int argc, char **argv)`, or // `usize efi_main(void *handle, void *system_table)` depending on the target. - let is_bpf = cx.sess().target.arch == "bpf" && cx.sess().opts.test; let llfty = if cx.sess().target.os.contains("uefi") { cx.type_func(&[cx.type_ptr(), cx.type_ptr()], cx.type_isize()) } else if cx.sess().target.main_needs_argc_argv { @@ -487,7 +486,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( (rust_main, start_ty, vec![arg_argc, arg_argv]) }; - let result = bx.call(start_ty, None, start_fn, &args, None); + let result = bx.call(start_ty, None, None, start_fn, &args, None); if cx.sess().target.os.contains("uefi") { bx.ret(result); } else { diff --git a/compiler/rustc_target/src/spec/base/mod.rs b/compiler/rustc_target/src/spec/base/mod.rs index d137aaa535858..77e97ea58967d 100644 --- a/compiler/rustc_target/src/spec/base/mod.rs +++ b/compiler/rustc_target/src/spec/base/mod.rs @@ -22,6 +22,7 @@ pub(crate) mod netbsd; pub(crate) mod nto_qnx; pub(crate) mod openbsd; pub(crate) mod redox; +pub(crate) mod sbf_base; pub(crate) mod solaris; pub(crate) mod solid; pub(crate) mod teeos; diff --git a/compiler/rustc_target/src/spec/sbf_base.rs b/compiler/rustc_target/src/spec/base/sbf_base.rs similarity index 95% rename from compiler/rustc_target/src/spec/sbf_base.rs rename to compiler/rustc_target/src/spec/base/sbf_base.rs index d6248b9e30f4a..50ffc6c883fc7 100644 --- a/compiler/rustc_target/src/spec/sbf_base.rs +++ b/compiler/rustc_target/src/spec/base/sbf_base.rs @@ -1,5 +1,5 @@ use crate::abi::Endian; -use super::{Cc, cvs, LinkerFlavor, Lld, PanicStrategy, TargetOptions}; +use crate::spec::{Cc, cvs, LinkerFlavor, Lld, PanicStrategy, TargetOptions}; pub fn opts() -> TargetOptions { let linker_script = r" diff --git a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs b/compiler/rustc_target/src/spec/targets/bpfel_unknown_unknown.rs similarity index 88% rename from compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs rename to compiler/rustc_target/src/spec/targets/bpfel_unknown_unknown.rs index b4df123cfc2b9..6d28df29e797b 100644 --- a/compiler/rustc_target/src/spec/bpfel_unknown_unknown.rs +++ b/compiler/rustc_target/src/spec/targets/bpfel_unknown_unknown.rs @@ -1,5 +1,5 @@ use crate::spec::Target; -use crate::spec::sbf_base; +use crate::spec::base::sbf_base; pub fn target() -> Target { Target { diff --git a/compiler/rustc_target/src/spec/sbf_solana_solana.rs b/compiler/rustc_target/src/spec/targets/sbf_solana_solana.rs similarity index 88% rename from compiler/rustc_target/src/spec/sbf_solana_solana.rs rename to compiler/rustc_target/src/spec/targets/sbf_solana_solana.rs index a4adf32b7544e..534b4f911257d 100644 --- a/compiler/rustc_target/src/spec/sbf_solana_solana.rs +++ b/compiler/rustc_target/src/spec/targets/sbf_solana_solana.rs @@ -1,5 +1,5 @@ use crate::spec::Target; -use crate::spec::sbf_base; +use crate::spec::base::sbf_base; pub fn target() -> Target { Target { diff --git a/library/alloc/src/alloc.rs b/library/alloc/src/alloc.rs index e73540a51ebb9..bdb2cc4f714b7 100644 --- a/library/alloc/src/alloc.rs +++ b/library/alloc/src/alloc.rs @@ -430,7 +430,7 @@ pub mod __alloc_error_handler { pub unsafe fn __rdl_oom(size: usize, _align: usize) -> ! { core::panicking::panic_nounwind_fmt(format_args!( "memory allocation of {size} bytes failed" - )) + ), /* force_no_backtrace */ false) } } diff --git a/library/std/src/backtrace.rs b/library/std/src/backtrace.rs index 7a2f54feab832..9f9dc58b4a886 100644 --- a/library/std/src/backtrace.rs +++ b/library/std/src/backtrace.rs @@ -96,6 +96,8 @@ use crate::env; use crate::ffi::c_void; use crate::fmt; #[cfg(not(target_family = "solana"))] +use crate::panic::UnwindSafe; +#[cfg(not(target_family = "solana"))] use crate::sync::atomic::{AtomicUsize, Ordering::Relaxed}; #[cfg(not(target_family = "solana"))] use crate::sync::LazyLock; @@ -485,9 +487,10 @@ impl fmt::Display for Backtrace { } } - +#[cfg(not(target_family = "solana"))] type LazyResolve = impl (FnOnce() -> Capture) + Send + Sync + UnwindSafe; +#[cfg(not(target_family = "solana"))] fn lazy_resolve(mut capture: Capture) -> LazyResolve { move || { // Use the global backtrace lock to synchronize this as it's a diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index 65abea4ca4642..3e3c871ad7f58 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -11,7 +11,7 @@ #[cfg(not(target_family = "solana"))] use crate::panic::BacktraceStyle; -#[cfg(not(target_os = "solana"))] +#[cfg(not(target_family = "solana"))] use core::panic::{PanicPayload}; use core::panic::{Location, PanicInfo}; @@ -521,14 +521,12 @@ pub use realstd::rt::panic_count; /// Invoke a closure, capturing the cause of an unwinding panic if one occurs. #[cfg(feature = "panic_immediate_abort")] -#[cfg(not(target_arch = "bpf"))] pub unsafe fn r#try R>(f: F) -> Result> { Ok(f()) } /// Invoke a closure, capturing the cause of an unwinding panic if one occurs. #[cfg(not(feature = "panic_immediate_abort"))] -#[cfg(not(target_arch = "bpf"))] pub unsafe fn r#try R>(f: F) -> Result> { union Data { f: ManuallyDrop, @@ -915,6 +913,7 @@ fn rust_panic(_: &mut dyn PanicPayload) -> ! { unsafe { crate::intrinsics::abort(); } +} // Note: The panicking functions have been stripped and rewritten // in order to save space in SBF programs. Panic messages @@ -956,6 +955,7 @@ pub fn begin_panic(_msg: M) -> ! { None, Location::caller(), false, + false, ); crate::sys::panic(&info); } @@ -974,6 +974,7 @@ pub fn begin_panic_fmt(msg: &fmt::Arguments<'_>) -> ! { Some(msg), Location::caller(), false, + false, ); crate::sys::panic(&info); } diff --git a/library/std/src/sys/sbf/cmath.rs b/library/std/src/sys/sbf/cmath.rs index fa7783122c2e9..d8ef962c1ac20 100644 --- a/library/std/src/sys/sbf/cmath.rs +++ b/library/std/src/sys/sbf/cmath.rs @@ -26,4 +26,8 @@ extern { pub fn tanf(n: f32) -> f32; pub fn tanh(n: f64) -> f64; pub fn tanhf(n: f32) -> f32; + pub fn tgamma(n: f64) -> f64; + pub fn tgammaf(n: f32) -> f32; + pub fn lgamma_r(n: f64, s: &mut i32) -> f64; + pub fn lgammaf_r(n: f32, s: &mut i32) -> f32; } diff --git a/library/std/src/sys/sbf/mod.rs b/library/std/src/sys/sbf/mod.rs index 1baf6ff5470cb..e9279d94d2382 100644 --- a/library/std/src/sys/sbf/mod.rs +++ b/library/std/src/sys/sbf/mod.rs @@ -120,3 +120,8 @@ pub fn abort_internal() -> ! { pub fn hashmap_random_keys() -> (u64, u64) { (1, 2) } + +#[inline] +pub fn is_interrupted(_errno: i32) -> bool { + false +} diff --git a/library/std/src/sys/sbf/os.rs b/library/std/src/sys/sbf/os.rs index 19190b24060a0..c54c53d90442d 100644 --- a/library/std/src/sys/sbf/os.rs +++ b/library/std/src/sys/sbf/os.rs @@ -61,6 +61,7 @@ pub fn current_exe() -> io::Result { unsupported() } +#[derive(Debug)] pub struct Env(Void); impl Iterator for Env { @@ -70,6 +71,12 @@ impl Iterator for Env { } } +impl Env { + pub fn str_debug(&self) -> impl fmt::Debug + '_ { + [OsString::new(), OsString::new()] + } +} + pub fn env() -> Env { panic!(); } diff --git a/src/bootstrap/Cargo.toml b/src/bootstrap/Cargo.toml index b1a21dff79525..e4d359141cec1 100644 --- a/src/bootstrap/Cargo.toml +++ b/src/bootstrap/Cargo.toml @@ -24,7 +24,7 @@ test = false [[bin]] name = "rustdoc" -path = "bin/rustdoc.rs" +path = "src/bin/rustdoc.rs" test = false [[bin]] diff --git a/src/bootstrap/src/utils/cc_detect.rs b/src/bootstrap/src/utils/cc_detect.rs index 44621d61af3c5..057e568c6db3a 100644 --- a/src/bootstrap/src/utils/cc_detect.rs +++ b/src/bootstrap/src/utils/cc_detect.rs @@ -138,9 +138,6 @@ pub fn find_target(build: &Build, target: TargetSelection) { { cfg.compiler(cxx); true - } else if &*target.triple == "sbf-solana-solana" || &*target.triple == "bpfel-unknown-unknown" { - set_compiler(&mut cfg, Language::CPlusPlus, target, config, build); - true } else { // Use an auto-detected compiler (or one configured via `CXX_target_triple` env vars). cfg.try_get_compiler().is_ok() @@ -222,11 +219,9 @@ fn default_compiler( None } } - "bpfel-unknown-unknown" => { - cfg.compiler(build.llvm_bin(target).join(compiler.clang())); - } - "sbf-solana-solana" => { - cfg.compiler(build.llvm_bin(target).join(compiler.clang())); + + "bpfel-unknown-unknown" | "sbf-solana-solana" => { + Some(PathBuf::from(build.llvm_bin(target).join(compiler.clang()))) } t if t.contains("musl") && compiler == Language::C => { diff --git a/src/tools/tidy/src/extdeps.rs b/src/tools/tidy/src/extdeps.rs index 6b4792018dea8..faeabd807b123 100644 --- a/src/tools/tidy/src/extdeps.rs +++ b/src/tools/tidy/src/extdeps.rs @@ -5,7 +5,7 @@ use std::path::Path; /// List of allowed sources for packages. const ALLOWED_SOURCES: &[&str] = &["\"registry+https://github.com/rust-lang/crates.io-index\"", -"\"git+https://github.com/solana-labs/compiler-builtins?tag=bpf-tools-v1.7#875087b410b77e0561b653882b431c84515eb044\""]; +"\"git+https://github.com/solana-labs/compiler-builtins?tag=solana-tools-v1.40#81ef46f3fe1357095acdd089a700890fe4e13974\""]; /// Checks for external package sources. `root` is the path to the directory that contains the /// workspace `Cargo.toml`. From 933bd94ea1eece6b5e9327bc361b9d3548c44a41 Mon Sep 17 00:00:00 2001 From: Lucas Steuernagel Date: Wed, 7 Feb 2024 11:20:28 -0300 Subject: [PATCH 103/103] [SOL] Adjust flaky CI test --- src/tools/miri/tests/pass/float_nan.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tools/miri/tests/pass/float_nan.rs b/src/tools/miri/tests/pass/float_nan.rs index 9b0a40c41b9cb..97f2b4ca02d45 100644 --- a/src/tools/miri/tests/pass/float_nan.rs +++ b/src/tools/miri/tests/pass/float_nan.rs @@ -20,8 +20,8 @@ use NaNKind::*; #[track_caller] fn check_all_outcomes(expected: HashSet, generate: impl Fn() -> T) { let mut seen = HashSet::new(); - // Let's give it 8x as many tries as we are expecting values. - let tries = expected.len() * 8; + // Let's give it 16x as many tries as we are expecting values. + let tries = expected.len() * 16; for _ in 0..tries { let val = generate(); assert!(expected.contains(&val), "got an unexpected value: {val}");