Skip to content

Commit 4f0c949

Browse files
committed
Auto merge of #143912 - fmease:rollup-vlt5sn8, r=fmease
Rollup of 16 pull requests Successful merges: - #142885 (core: Add `BorrowedCursor::with_unfilled_buf`) - #143217 (Port #[link_ordinal] to the new attribute parsing infrastructure) - #143355 (wrapping shift: remove first bitmask and table) - #143448 (remote-test-client: Exit code `128 + <signal-number>` instead of `3`) - #143592 (UWP: link ntdll functions using raw-dylib) - #143681 (bootstrap/miri: avoid rebuilds for test builds) - #143710 (Updates to random number generation APIs) - #143724 (Tidy cleanup) - #143820 (Fixed a core crate compilation failure when enabling the `optimize_for_size` feature on some targets) - #143850 (Compiletest: Simplify {Html,Json}DocCk directive handling) - #143855 (Port `#[omit_gdb_pretty_printer_section]` to the new attribute parsing) - #143868 (warn on align on fields to avoid breaking changes) - #143875 (update issue number for `const_trait_impl`) - #143881 (Use zero for initialized Once state) - #143887 (Run bootstrap tests sooner in the `x test` pipeline) - #143893 (Don't require `eh_personality` lang item on targets that have a personality) Failed merges: - #143878 (Port `#[pointee]` to the new attribute parsing infrastructure) - #143891 (Port `#[coverage]` to the new attribute system) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9c3064e + 62d6214 commit 4f0c949

File tree

110 files changed

+873
-896
lines changed

Some content is hidden

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

110 files changed

+873
-896
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,9 @@ pub enum AttributeKind {
294294
/// Represents `#[link_name]`.
295295
LinkName { name: Symbol, span: Span },
296296

297+
/// Represents `#[link_ordinal]`.
298+
LinkOrdinal { ordinal: u16, span: Span },
299+
297300
/// Represents [`#[link_section]`](https://doc.rust-lang.org/reference/abi.html#the-link_section-attribute)
298301
LinkSection { name: Symbol, span: Span },
299302

@@ -328,6 +331,9 @@ pub enum AttributeKind {
328331
/// Represents `#[non_exhaustive]`
329332
NonExhaustive(Span),
330333

334+
/// Represents `#[omit_gdb_pretty_printer_section]`
335+
OmitGdbPrettyPrinterSection,
336+
331337
/// Represents `#[optimize(size|speed)]`
332338
Optimize(OptimizeAttr, Span),
333339

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ impl AttributeKind {
4040
Ignore { .. } => No,
4141
Inline(..) => No,
4242
LinkName { .. } => Yes,
43+
LinkOrdinal { .. } => No,
4344
LinkSection { .. } => No,
4445
LoopMatch(..) => No,
4546
MacroTransparency(..) => Yes,
@@ -50,6 +51,7 @@ impl AttributeKind {
5051
NoImplicitPrelude(..) => No,
5152
NoMangle(..) => No,
5253
NonExhaustive(..) => Yes,
54+
OmitGdbPrettyPrinterSection => No,
5355
Optimize(..) => No,
5456
ParenSugar(..) => No,
5557
PassByValue(..) => Yes,

compiler/rustc_attr_parsing/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ attr_parsing_invalid_repr_hint_no_value =
7878
attr_parsing_invalid_since =
7979
'since' must be a Rust version number, such as "1.31.0"
8080
81+
attr_parsing_link_ordinal_out_of_range = ordinal value in `link_ordinal` is too large: `{$ordinal}`
82+
.note = the value may not exceed `u16::MAX`
83+
8184
attr_parsing_missing_feature =
8285
missing 'feature'
8386

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,11 @@ impl<S: Stage> CombineAttributeParser<S> for TargetFeatureParser {
334334
features
335335
}
336336
}
337+
338+
pub(crate) struct OmitGdbPrettyPrinterSectionParser;
339+
340+
impl<S: Stage> NoArgsAttributeParser<S> for OmitGdbPrettyPrinterSectionParser {
341+
const PATH: &[Symbol] = &[sym::omit_gdb_pretty_printer_section];
342+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
343+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::OmitGdbPrettyPrinterSection;
344+
}

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use rustc_attr_data_structures::AttributeKind;
2-
use rustc_attr_data_structures::AttributeKind::{LinkName, LinkSection};
2+
use rustc_attr_data_structures::AttributeKind::{LinkName, LinkOrdinal, LinkSection};
33
use rustc_feature::{AttributeTemplate, template};
44
use rustc_span::{Span, Symbol, sym};
55

66
use crate::attributes::{
77
AttributeOrder, NoArgsAttributeParser, OnDuplicate, SingleAttributeParser,
88
};
9-
use crate::context::{AcceptContext, Stage};
9+
use crate::context::{AcceptContext, Stage, parse_single_integer};
1010
use crate::parser::ArgParser;
11-
use crate::session_diagnostics::NullOnLinkSection;
11+
use crate::session_diagnostics::{LinkOrdinalOutOfRange, NullOnLinkSection};
1212

1313
pub(crate) struct LinkNameParser;
1414

@@ -87,3 +87,36 @@ impl<S: Stage> NoArgsAttributeParser<S> for StdInternalSymbolParser {
8787
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
8888
const CREATE: fn(Span) -> AttributeKind = AttributeKind::StdInternalSymbol;
8989
}
90+
91+
pub(crate) struct LinkOrdinalParser;
92+
93+
impl<S: Stage> SingleAttributeParser<S> for LinkOrdinalParser {
94+
const PATH: &[Symbol] = &[sym::link_ordinal];
95+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
96+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
97+
const TEMPLATE: AttributeTemplate = template!(List: "ordinal");
98+
99+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
100+
let ordinal = parse_single_integer(cx, args)?;
101+
102+
// According to the table at
103+
// https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#import-header, the
104+
// ordinal must fit into 16 bits. Similarly, the Ordinal field in COFFShortExport (defined
105+
// in llvm/include/llvm/Object/COFFImportFile.h), which we use to communicate import
106+
// information to LLVM for `#[link(kind = "raw-dylib"_])`, is also defined to be uint16_t.
107+
//
108+
// FIXME: should we allow an ordinal of 0? The MSVC toolchain has inconsistent support for
109+
// this: both LINK.EXE and LIB.EXE signal errors and abort when given a .DEF file that
110+
// specifies a zero ordinal. However, llvm-dlltool is perfectly happy to generate an import
111+
// library for such a .DEF file, and MSVC's LINK.EXE is also perfectly happy to consume an
112+
// import library produced by LLVM with an ordinal of 0, and it generates an .EXE. (I
113+
// don't know yet if the resulting EXE runs, as I haven't yet built the necessary DLL --
114+
// see earlier comment about LINK.EXE failing.)
115+
let Ok(ordinal) = ordinal.try_into() else {
116+
cx.emit_err(LinkOrdinalOutOfRange { span: cx.attr_span, ordinal });
117+
return None;
118+
};
119+
120+
Some(LinkOrdinal { ordinal, span: cx.attr_span })
121+
}
122+
}

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
use rustc_ast::LitKind;
21
use rustc_attr_data_structures::AttributeKind;
32
use rustc_feature::{AttributeTemplate, template};
43
use rustc_span::{Symbol, sym};
54

65
use crate::attributes::{AttributeOrder, OnDuplicate, SingleAttributeParser};
7-
use crate::context::{AcceptContext, Stage};
6+
use crate::context::{AcceptContext, Stage, parse_single_integer};
87
use crate::parser::ArgParser;
98

109
pub(crate) struct RustcLayoutScalarValidRangeStart;
@@ -16,8 +15,8 @@ impl<S: Stage> SingleAttributeParser<S> for RustcLayoutScalarValidRangeStart {
1615
const TEMPLATE: AttributeTemplate = template!(List: "start");
1716

1817
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
19-
parse_rustc_layout_scalar_valid_range(cx, args)
20-
.map(|n| AttributeKind::RustcLayoutScalarValidRangeStart(n, cx.attr_span))
18+
parse_single_integer(cx, args)
19+
.map(|n| AttributeKind::RustcLayoutScalarValidRangeStart(Box::new(n), cx.attr_span))
2120
}
2221
}
2322

@@ -30,34 +29,11 @@ impl<S: Stage> SingleAttributeParser<S> for RustcLayoutScalarValidRangeEnd {
3029
const TEMPLATE: AttributeTemplate = template!(List: "end");
3130

3231
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
33-
parse_rustc_layout_scalar_valid_range(cx, args)
34-
.map(|n| AttributeKind::RustcLayoutScalarValidRangeEnd(n, cx.attr_span))
32+
parse_single_integer(cx, args)
33+
.map(|n| AttributeKind::RustcLayoutScalarValidRangeEnd(Box::new(n), cx.attr_span))
3534
}
3635
}
3736

38-
fn parse_rustc_layout_scalar_valid_range<S: Stage>(
39-
cx: &mut AcceptContext<'_, '_, S>,
40-
args: &ArgParser<'_>,
41-
) -> Option<Box<u128>> {
42-
let Some(list) = args.list() else {
43-
cx.expected_list(cx.attr_span);
44-
return None;
45-
};
46-
let Some(single) = list.single() else {
47-
cx.expected_single_argument(list.span);
48-
return None;
49-
};
50-
let Some(lit) = single.lit() else {
51-
cx.expected_integer_literal(single.span());
52-
return None;
53-
};
54-
let LitKind::Int(num, _ty) = lit.kind else {
55-
cx.expected_integer_literal(single.span());
56-
return None;
57-
};
58-
Some(Box::new(num.0))
59-
}
60-
6137
pub(crate) struct RustcObjectLifetimeDefaultParser;
6238

6339
impl<S: Stage> SingleAttributeParser<S> for RustcObjectLifetimeDefaultParser {

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::ops::{Deref, DerefMut};
55
use std::sync::LazyLock;
66

77
use private::Sealed;
8-
use rustc_ast::{self as ast, MetaItemLit, NodeId};
8+
use rustc_ast::{self as ast, LitKind, MetaItemLit, NodeId};
99
use rustc_attr_data_structures::AttributeKind;
1010
use rustc_attr_data_structures::lints::{AttributeLint, AttributeLintKind};
1111
use rustc_errors::{DiagCtxtHandle, Diagnostic};
@@ -16,16 +16,16 @@ use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym};
1616

1717
use crate::attributes::allow_unstable::{AllowConstFnUnstableParser, AllowInternalUnstableParser};
1818
use crate::attributes::codegen_attrs::{
19-
ColdParser, ExportNameParser, NakedParser, NoMangleParser, OptimizeParser, TargetFeatureParser,
20-
TrackCallerParser, UsedParser,
19+
ColdParser, ExportNameParser, NakedParser, NoMangleParser, OmitGdbPrettyPrinterSectionParser,
20+
OptimizeParser, TargetFeatureParser, TrackCallerParser, UsedParser,
2121
};
2222
use crate::attributes::confusables::ConfusablesParser;
2323
use crate::attributes::deprecation::DeprecationParser;
2424
use crate::attributes::dummy::DummyParser;
2525
use crate::attributes::inline::{InlineParser, RustcForceInlineParser};
2626
use crate::attributes::link_attrs::{
27-
ExportStableParser, FfiConstParser, FfiPureParser, LinkNameParser, LinkSectionParser,
28-
StdInternalSymbolParser,
27+
ExportStableParser, FfiConstParser, FfiPureParser, LinkNameParser, LinkOrdinalParser,
28+
LinkSectionParser, StdInternalSymbolParser,
2929
};
3030
use crate::attributes::lint_helpers::{AsPtrParser, PassByValueParser, PubTransparentParser};
3131
use crate::attributes::loop_match::{ConstContinueParser, LoopMatchParser};
@@ -141,6 +141,7 @@ attribute_parsers!(
141141
Single<IgnoreParser>,
142142
Single<InlineParser>,
143143
Single<LinkNameParser>,
144+
Single<LinkOrdinalParser>,
144145
Single<LinkSectionParser>,
145146
Single<MustUseParser>,
146147
Single<OptimizeParser>,
@@ -171,6 +172,7 @@ attribute_parsers!(
171172
Single<WithoutArgs<NoImplicitPreludeParser>>,
172173
Single<WithoutArgs<NoMangleParser>>,
173174
Single<WithoutArgs<NonExhaustiveParser>>,
175+
Single<WithoutArgs<OmitGdbPrettyPrinterSectionParser>>,
174176
Single<WithoutArgs<ParenSugarParser>>,
175177
Single<WithoutArgs<PassByValueParser>>,
176178
Single<WithoutArgs<PubTransparentParser>>,
@@ -772,3 +774,32 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
772774
}
773775
}
774776
}
777+
778+
/// Parse a single integer.
779+
///
780+
/// Used by attributes that take a single integer as argument, such as
781+
/// `#[link_ordinal]` and `#[rustc_layout_scalar_valid_range_start]`.
782+
/// `cx` is the context given to the attribute.
783+
/// `args` is the parser for the attribute arguments.
784+
pub(crate) fn parse_single_integer<S: Stage>(
785+
cx: &mut AcceptContext<'_, '_, S>,
786+
args: &ArgParser<'_>,
787+
) -> Option<u128> {
788+
let Some(list) = args.list() else {
789+
cx.expected_list(cx.attr_span);
790+
return None;
791+
};
792+
let Some(single) = list.single() else {
793+
cx.expected_single_argument(list.span);
794+
return None;
795+
};
796+
let Some(lit) = single.lit() else {
797+
cx.expected_integer_literal(single.span());
798+
return None;
799+
};
800+
let LitKind::Int(num, _ty) = lit.kind else {
801+
cx.expected_integer_literal(single.span());
802+
return None;
803+
};
804+
Some(num.0)
805+
}

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,15 @@ pub(crate) struct NakedFunctionIncompatibleAttribute {
514514
pub attr: String,
515515
}
516516

517+
#[derive(Diagnostic)]
518+
#[diag(attr_parsing_link_ordinal_out_of_range)]
519+
#[note]
520+
pub(crate) struct LinkOrdinalOutOfRange {
521+
#[primary_span]
522+
pub span: Span,
523+
pub ordinal: u128,
524+
}
525+
517526
pub(crate) enum AttributeParseErrorReason {
518527
ExpectedNoArgs,
519528
ExpectedStringLiteral { byte_string: Option<Span> },

compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
// .debug_gdb_scripts binary section.
22

3-
use rustc_ast::attr;
3+
use rustc_attr_data_structures::{AttributeKind, find_attr};
44
use rustc_codegen_ssa::base::collect_debugger_visualizers_transitive;
55
use rustc_codegen_ssa::traits::*;
66
use rustc_hir::def_id::LOCAL_CRATE;
77
use rustc_middle::bug;
88
use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerType;
99
use rustc_session::config::{CrateType, DebugInfo};
10-
use rustc_span::sym;
1110

1211
use crate::builder::Builder;
1312
use crate::common::CodegenCx;
@@ -87,7 +86,7 @@ pub(crate) fn get_or_insert_gdb_debug_scripts_section_global<'ll>(
8786

8887
pub(crate) fn needs_gdb_debug_scripts_section(cx: &CodegenCx<'_, '_>) -> bool {
8988
let omit_gdb_pretty_printer_section =
90-
attr::contains_name(cx.tcx.hir_krate_attrs(), sym::omit_gdb_pretty_printer_section);
89+
find_attr!(cx.tcx.hir_krate_attrs(), AttributeKind::OmitGdbPrettyPrinterSection);
9190

9291
// To ensure the section `__rustc_debug_gdb_scripts_section__` will not create
9392
// ODR violations at link time, this section will not be emitted for rlibs since

compiler/rustc_codegen_ssa/messages.ftl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@ codegen_ssa_ignoring_emit_path = ignoring emit path because multiple .{$extensio
8080
8181
codegen_ssa_ignoring_output = ignoring -o because multiple .{$extension} files were produced
8282
83-
codegen_ssa_illegal_link_ordinal_format = illegal ordinal format in `link_ordinal`
84-
.note = an unsuffixed integer value, e.g., `1`, is expected
85-
8683
codegen_ssa_incorrect_cgu_reuse_type =
8784
CGU-reuse for `{$cgu_user_name}` is `{$actual_reuse}` but should be {$at_least ->
8885
[one] {"at least "}
@@ -93,9 +90,6 @@ codegen_ssa_insufficient_vs_code_product = VS Code is a different product, and i
9390
9491
codegen_ssa_invalid_instruction_set = invalid instruction set specified
9592
96-
codegen_ssa_invalid_link_ordinal_nargs = incorrect number of arguments to `#[link_ordinal]`
97-
.note = the attribute requires exactly one argument
98-
9993
codegen_ssa_invalid_literal_value = invalid literal value
10094
.label = value must be an integer between `0` and `255`
10195

0 commit comments

Comments
 (0)