Skip to content

Commit 85be36c

Browse files
authored
Merge pull request #4601 from RalfJung/rustup
Rustup
2 parents 0d906b7 + 0cd72a2 commit 85be36c

File tree

599 files changed

+42413
-11370
lines changed

Some content is hidden

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

599 files changed

+42413
-11370
lines changed

compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use rustc_ast::AttrStyle;
12
use rustc_errors::DiagArgValue;
23
use rustc_hir::attrs::MacroUseArgs;
34

@@ -133,3 +134,65 @@ impl<S: Stage> NoArgsAttributeParser<S> for AllowInternalUnsafeParser {
133134
]);
134135
const CREATE: fn(Span) -> AttributeKind = |span| AttributeKind::AllowInternalUnsafe(span);
135136
}
137+
138+
pub(crate) struct MacroExportParser;
139+
140+
impl<S: Stage> SingleAttributeParser<S> for MacroExportParser {
141+
const PATH: &[Symbol] = &[sym::macro_export];
142+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
143+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
144+
const TEMPLATE: AttributeTemplate = template!(Word, List: &["local_inner_macros"]);
145+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowListWarnRest(&[
146+
Allow(Target::MacroDef),
147+
Error(Target::WherePredicate),
148+
Error(Target::Crate),
149+
]);
150+
151+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
152+
let suggestions = || {
153+
<Self as SingleAttributeParser<S>>::TEMPLATE
154+
.suggestions(AttrStyle::Inner, "macro_export")
155+
};
156+
let local_inner_macros = match args {
157+
ArgParser::NoArgs => false,
158+
ArgParser::List(list) => {
159+
let Some(l) = list.single() else {
160+
let span = cx.attr_span;
161+
cx.emit_lint(
162+
AttributeLintKind::InvalidMacroExportArguments {
163+
suggestions: suggestions(),
164+
},
165+
span,
166+
);
167+
return None;
168+
};
169+
match l.meta_item().and_then(|i| i.path().word_sym()) {
170+
Some(sym::local_inner_macros) => true,
171+
_ => {
172+
let span = cx.attr_span;
173+
cx.emit_lint(
174+
AttributeLintKind::InvalidMacroExportArguments {
175+
suggestions: suggestions(),
176+
},
177+
span,
178+
);
179+
return None;
180+
}
181+
}
182+
}
183+
ArgParser::NameValue(_) => {
184+
let span = cx.attr_span;
185+
let suggestions = suggestions();
186+
cx.emit_err(IllFormedAttributeInputLint {
187+
num_suggestions: suggestions.len(),
188+
suggestions: DiagArgValue::StrListSepByAnd(
189+
suggestions.into_iter().map(|s| format!("`{s}`").into()).collect(),
190+
),
191+
span,
192+
});
193+
return None;
194+
}
195+
};
196+
Some(AttributeKind::MacroExport { span: cx.attr_span, local_inner_macros })
197+
}
198+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use crate::attributes::lint_helpers::{
4040
};
4141
use crate::attributes::loop_match::{ConstContinueParser, LoopMatchParser};
4242
use crate::attributes::macro_attrs::{
43-
AllowInternalUnsafeParser, MacroEscapeParser, MacroUseParser,
43+
AllowInternalUnsafeParser, MacroEscapeParser, MacroExportParser, MacroUseParser,
4444
};
4545
use crate::attributes::must_use::MustUseParser;
4646
use crate::attributes::no_implicit_prelude::NoImplicitPreludeParser;
@@ -183,6 +183,7 @@ attribute_parsers!(
183183
Single<LinkOrdinalParser>,
184184
Single<LinkSectionParser>,
185185
Single<LinkageParser>,
186+
Single<MacroExportParser>,
186187
Single<MoveSizeLimitParser>,
187188
Single<MustUseParser>,
188189
Single<ObjcClassParser>,

compiler/rustc_attr_parsing/src/lints.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ pub fn emit_attribute_lint<L: LintEmitter>(lint: &AttributeLint<L::Id>, lint_emi
3131
},
3232
);
3333
}
34+
AttributeLintKind::InvalidMacroExportArguments { suggestions } => lint_emitter
35+
.emit_node_span_lint(
36+
rustc_session::lint::builtin::INVALID_MACRO_EXPORT_ARGUMENTS,
37+
*id,
38+
*span,
39+
session_diagnostics::IllFormedAttributeInput {
40+
num_suggestions: suggestions.len(),
41+
suggestions: DiagArgValue::StrListSepByAnd(
42+
suggestions.into_iter().map(|s| format!("`{s}`").into()).collect(),
43+
),
44+
},
45+
),
3446
AttributeLintKind::EmptyAttribute { first_span } => lint_emitter.emit_node_span_lint(
3547
rustc_session::lint::builtin::UNUSED_ATTRIBUTES,
3648
*id,

compiler/rustc_codegen_gcc/src/asm.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -698,8 +698,12 @@ fn reg_class_to_gcc(reg_class: InlineAsmRegClass) -> &'static str {
698698
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg_nonzero) => "b",
699699
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::freg) => "f",
700700
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::vreg) => "v",
701-
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::cr)
702-
| InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::xer) => {
701+
InlineAsmRegClass::PowerPC(
702+
PowerPCInlineAsmRegClass::cr
703+
| PowerPCInlineAsmRegClass::ctr
704+
| PowerPCInlineAsmRegClass::lr
705+
| PowerPCInlineAsmRegClass::xer,
706+
) => {
703707
unreachable!("clobber-only")
704708
}
705709
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg) => "r",
@@ -777,8 +781,12 @@ fn dummy_output_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, reg: InlineAsmRegCl
777781
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::vreg) => {
778782
cx.type_vector(cx.type_i32(), 4)
779783
}
780-
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::cr)
781-
| InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::xer) => {
784+
InlineAsmRegClass::PowerPC(
785+
PowerPCInlineAsmRegClass::cr
786+
| PowerPCInlineAsmRegClass::ctr
787+
| PowerPCInlineAsmRegClass::lr
788+
| PowerPCInlineAsmRegClass::xer,
789+
) => {
782790
unreachable!("clobber-only")
783791
}
784792
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg) => cx.type_i32(),

compiler/rustc_codegen_llvm/src/asm.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,8 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
340340
attrs.push(llvm::AttributeKind::WillReturn.create_attr(self.cx.llcx));
341341
} else if options.contains(InlineAsmOptions::NOMEM) {
342342
attrs.push(llvm::MemoryEffects::InaccessibleMemOnly.create_attr(self.cx.llcx));
343-
} else {
344-
// LLVM doesn't have an attribute to represent ReadOnly + SideEffect
343+
} else if options.contains(InlineAsmOptions::READONLY) {
344+
attrs.push(llvm::MemoryEffects::ReadOnlyNotPure.create_attr(self.cx.llcx));
345345
}
346346
attributes::apply_to_callsite(result, llvm::AttributePlace::Function, &{ attrs });
347347

@@ -662,7 +662,12 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
662662
PowerPC(PowerPCInlineAsmRegClass::reg_nonzero) => "b",
663663
PowerPC(PowerPCInlineAsmRegClass::freg) => "f",
664664
PowerPC(PowerPCInlineAsmRegClass::vreg) => "v",
665-
PowerPC(PowerPCInlineAsmRegClass::cr) | PowerPC(PowerPCInlineAsmRegClass::xer) => {
665+
PowerPC(
666+
PowerPCInlineAsmRegClass::cr
667+
| PowerPCInlineAsmRegClass::ctr
668+
| PowerPCInlineAsmRegClass::lr
669+
| PowerPCInlineAsmRegClass::xer,
670+
) => {
666671
unreachable!("clobber-only")
667672
}
668673
RiscV(RiscVInlineAsmRegClass::reg) => "r",
@@ -830,7 +835,12 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
830835
PowerPC(PowerPCInlineAsmRegClass::reg_nonzero) => cx.type_i32(),
831836
PowerPC(PowerPCInlineAsmRegClass::freg) => cx.type_f64(),
832837
PowerPC(PowerPCInlineAsmRegClass::vreg) => cx.type_vector(cx.type_i32(), 4),
833-
PowerPC(PowerPCInlineAsmRegClass::cr) | PowerPC(PowerPCInlineAsmRegClass::xer) => {
838+
PowerPC(
839+
PowerPCInlineAsmRegClass::cr
840+
| PowerPCInlineAsmRegClass::ctr
841+
| PowerPCInlineAsmRegClass::lr
842+
| PowerPCInlineAsmRegClass::xer,
843+
) => {
834844
unreachable!("clobber-only")
835845
}
836846
RiscV(RiscVInlineAsmRegClass::reg) => cx.type_i32(),

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ pub(crate) fn target_machine_factory(
204204
optlvl: config::OptLevel,
205205
target_features: &[String],
206206
) -> TargetMachineFactoryFn<LlvmCodegenBackend> {
207+
// Self-profile timer for creating a _factory_.
208+
let _prof_timer = sess.prof.generic_activity("target_machine_factory");
209+
207210
let reloc_model = to_llvm_relocation_model(sess.relocation_model());
208211

209212
let (opt_level, _) = to_llvm_opt_settings(optlvl);
@@ -259,6 +262,9 @@ pub(crate) fn target_machine_factory(
259262
.into_string()
260263
.unwrap_or_default();
261264
let command_line_args = quote_command_line_args(&sess.expanded_args);
265+
// Self-profile counter for the number of bytes produced by command-line quoting.
266+
// Values are summed, so the summary result is cumulative across all TM factories.
267+
sess.prof.artifact_size("quoted_command_line_args", "-", command_line_args.len() as u64);
262268

263269
let debuginfo_compression = sess.opts.debuginfo_compression.to_string();
264270
match sess.opts.debuginfo_compression {
@@ -281,7 +287,11 @@ pub(crate) fn target_machine_factory(
281287

282288
let use_wasm_eh = wants_wasm_eh(sess);
283289

290+
let prof = SelfProfilerRef::clone(&sess.prof);
284291
Arc::new(move |config: TargetMachineFactoryConfig| {
292+
// Self-profile timer for invoking a factory to create a target machine.
293+
let _prof_timer = prof.generic_activity("target_machine_factory_inner");
294+
285295
let path_to_cstring_helper = |path: Option<PathBuf>| -> CString {
286296
let path = path.unwrap_or_default();
287297
let path = path_mapping

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ use rustc_middle::util::Providers;
4545
use rustc_session::Session;
4646
use rustc_session::config::{OptLevel, OutputFilenames, PrintKind, PrintRequest};
4747
use rustc_span::Symbol;
48+
use rustc_target::spec::{RelocModel, TlsModel};
4849

4950
mod abi;
5051
mod allocator;
@@ -244,16 +245,7 @@ impl CodegenBackend for LlvmCodegenBackend {
244245
match req.kind {
245246
PrintKind::RelocationModels => {
246247
writeln!(out, "Available relocation models:").unwrap();
247-
for name in &[
248-
"static",
249-
"pic",
250-
"pie",
251-
"dynamic-no-pic",
252-
"ropi",
253-
"rwpi",
254-
"ropi-rwpi",
255-
"default",
256-
] {
248+
for name in RelocModel::ALL.iter().map(RelocModel::desc).chain(["default"]) {
257249
writeln!(out, " {name}").unwrap();
258250
}
259251
writeln!(out).unwrap();
@@ -267,9 +259,7 @@ impl CodegenBackend for LlvmCodegenBackend {
267259
}
268260
PrintKind::TlsModels => {
269261
writeln!(out, "Available TLS models:").unwrap();
270-
for name in
271-
&["global-dynamic", "local-dynamic", "initial-exec", "local-exec", "emulated"]
272-
{
262+
for name in TlsModel::ALL.iter().map(TlsModel::desc) {
273263
writeln!(out, " {name}").unwrap();
274264
}
275265
writeln!(out).unwrap();

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,7 @@ pub(crate) enum MemoryEffects {
710710
None,
711711
ReadOnly,
712712
InaccessibleMemOnly,
713+
ReadOnlyNotPure,
713714
}
714715

715716
/// LLVMOpcode

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,11 @@ impl<'a> Linker for GccLinker<'a> {
845845
self.sess.dcx().emit_fatal(errors::VersionScriptWriteFailure { error });
846846
}
847847
self.link_arg("--dynamic-list").link_arg(path);
848+
} else if self.sess.target.is_like_wasm {
849+
self.link_arg("--no-export-dynamic");
850+
for (sym, _) in symbols {
851+
self.link_arg("--export").link_arg(sym);
852+
}
848853
} else {
849854
// Write an LD version script
850855
let res: io::Result<()> = try {

compiler/rustc_codegen_ssa/src/mir/naked_asm.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ fn prefix_and_suffix<'tcx>(
228228
writeln!(begin, "{asm_name}:").unwrap();
229229

230230
writeln!(end).unwrap();
231+
// emit a label starting with `func_end` for `cargo asm` and other tooling that might
232+
// pattern match on assembly generated by LLVM.
233+
writeln!(end, ".Lfunc_end_{asm_name}:").unwrap();
231234
writeln!(end, ".size {asm_name}, . - {asm_name}").unwrap();
232235
writeln!(end, ".popsection").unwrap();
233236
if !arch_suffix.is_empty() {
@@ -246,6 +249,7 @@ fn prefix_and_suffix<'tcx>(
246249
writeln!(begin, "{asm_name}:").unwrap();
247250

248251
writeln!(end).unwrap();
252+
writeln!(end, ".Lfunc_end_{asm_name}:").unwrap();
249253
writeln!(end, ".popsection").unwrap();
250254
if !arch_suffix.is_empty() {
251255
writeln!(end, "{}", arch_suffix).unwrap();
@@ -263,6 +267,7 @@ fn prefix_and_suffix<'tcx>(
263267
writeln!(begin, "{asm_name}:").unwrap();
264268

265269
writeln!(end).unwrap();
270+
writeln!(end, ".Lfunc_end_{asm_name}:").unwrap();
266271
writeln!(end, ".popsection").unwrap();
267272
if !arch_suffix.is_empty() {
268273
writeln!(end, "{}", arch_suffix).unwrap();
@@ -287,6 +292,7 @@ fn prefix_and_suffix<'tcx>(
287292
writeln!(end).unwrap();
288293
// .size is ignored for function symbols, so we can skip it
289294
writeln!(end, "end_function").unwrap();
295+
writeln!(end, ".Lfunc_end_{asm_name}:").unwrap();
290296
}
291297
BinaryFormat::Xcoff => {
292298
// the LLVM XCOFFAsmParser is extremely incomplete and does not implement many of the

0 commit comments

Comments
 (0)