Skip to content

Commit 3013b26

Browse files
committed
Auto merge of rust-lang#89659 - workingjubilee:rollup-0vggc69, r=workingjubilee
Rollup of 8 pull requests Successful merges: - rust-lang#87918 (Enable AutoFDO.) - rust-lang#88137 (On macOS, make strip="symbols" not pass any options to strip) - rust-lang#88772 (Fixed confusing wording on Result::map_or_else.) - rust-lang#89025 (Implement `#[link_ordinal(n)]`) - rust-lang#89082 (Implement rust-lang#85440 (Random test ordering)) - rust-lang#89288 (Wrapper for `-Z gcc-ld=lld` to invoke rust-lld with the correct flavor) - rust-lang#89476 (Correct decoding of foreign expansions during incr. comp.) - rust-lang#89622 (Use correct edition for panic in [debug_]assert!().) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents c2171ee + 30e068f commit 3013b26

Some content is hidden

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

65 files changed

+1034
-123
lines changed

Cargo.lock

+4
Original file line numberDiff line numberDiff line change
@@ -1965,6 +1965,10 @@ dependencies = [
19651965
"walkdir",
19661966
]
19671967

1968+
[[package]]
1969+
name = "lld-wrapper"
1970+
version = "0.1.0"
1971+
19681972
[[package]]
19691973
name = "lock_api"
19701974
version = "0.4.1"

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ members = [
3636
"src/tools/jsondocck",
3737
"src/tools/html-checker",
3838
"src/tools/bump-stage0",
39+
"src/tools/lld-wrapper",
3940
]
4041

4142
exclude = [

compiler/rustc_builtin_macros/src/assert.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use rustc_errors::{Applicability, DiagnosticBuilder};
2-
1+
use crate::panic::use_panic_2021;
32
use rustc_ast::ptr::P;
43
use rustc_ast::token;
54
use rustc_ast::tokenstream::{DelimSpan, TokenStream};
65
use rustc_ast::{self as ast, *};
76
use rustc_ast_pretty::pprust;
7+
use rustc_errors::{Applicability, DiagnosticBuilder};
88
use rustc_expand::base::*;
99
use rustc_parse::parser::Parser;
1010
use rustc_span::symbol::{sym, Ident, Symbol};
@@ -28,7 +28,7 @@ pub fn expand_assert<'cx>(
2828
let sp = cx.with_call_site_ctxt(span);
2929

3030
let panic_call = if let Some(tokens) = custom_message {
31-
let path = if span.rust_2021() {
31+
let path = if use_panic_2021(span) {
3232
// On edition 2021, we always call `$crate::panic::panic_2021!()`.
3333
Path {
3434
span: sp,

compiler/rustc_builtin_macros/src/panic.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use rustc_ast::ptr::P;
22
use rustc_ast::tokenstream::{DelimSpan, TokenStream};
33
use rustc_ast::*;
44
use rustc_expand::base::*;
5+
use rustc_span::edition::Edition;
56
use rustc_span::symbol::sym;
67
use rustc_span::Span;
78

@@ -19,7 +20,7 @@ pub fn expand_panic<'cx>(
1920
sp: Span,
2021
tts: TokenStream,
2122
) -> Box<dyn MacResult + 'cx> {
22-
let panic = if sp.rust_2021() { sym::panic_2021 } else { sym::panic_2015 };
23+
let panic = if use_panic_2021(sp) { sym::panic_2021 } else { sym::panic_2015 };
2324

2425
let sp = cx.with_call_site_ctxt(sp);
2526

@@ -46,3 +47,19 @@ pub fn expand_panic<'cx>(
4647
),
4748
)
4849
}
50+
51+
pub fn use_panic_2021(mut span: Span) -> bool {
52+
// To determine the editon, we check the first span up the expansion
53+
// stack that does not have #[allow_internal_unstable(edition_panic)].
54+
// (To avoid using the edition of e.g. the assert!() or debug_assert!() definition.)
55+
loop {
56+
let expn = span.ctxt().outer_expn_data();
57+
if let Some(features) = expn.allow_internal_unstable {
58+
if features.iter().any(|&f| f == sym::edition_panic) {
59+
span = expn.call_site;
60+
continue;
61+
}
62+
}
63+
break expn.edition >= Edition::Edition2021;
64+
}
65+
}

compiler/rustc_codegen_llvm/src/attributes.rs

+4
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty::
263263
attributes::emit_uwtable(llfn, true);
264264
}
265265

266+
if cx.sess().opts.debugging_opts.profile_sample_use.is_some() {
267+
llvm::AddFunctionAttrString(llfn, Function, cstr!("use-sample-profile"));
268+
}
269+
266270
// FIXME: none of these three functions interact with source level attributes.
267271
set_frame_pointer_type(cx, llfn);
268272
set_instrument_function(cx, llfn);

compiler/rustc_codegen_llvm/src/back/archive.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,13 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
163163
// All import names are Rust identifiers and therefore cannot contain \0 characters.
164164
// FIXME: when support for #[link_name] implemented, ensure that import.name values don't
165165
// have any \0 characters
166-
let import_name_vector: Vec<CString> = dll_imports
166+
let import_name_and_ordinal_vector: Vec<(CString, Option<u16>)> = dll_imports
167167
.iter()
168168
.map(|import: &DllImport| {
169169
if self.config.sess.target.arch == "x86" {
170-
LlvmArchiveBuilder::i686_decorated_name(import)
170+
(LlvmArchiveBuilder::i686_decorated_name(import), import.ordinal)
171171
} else {
172-
CString::new(import.name.to_string()).unwrap()
172+
(CString::new(import.name.to_string()).unwrap(), import.ordinal)
173173
}
174174
})
175175
.collect();
@@ -184,9 +184,9 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
184184
dll_imports.iter().map(|import| import.name.to_string()).collect::<Vec<_>>().join(", "),
185185
);
186186

187-
let ffi_exports: Vec<LLVMRustCOFFShortExport> = import_name_vector
187+
let ffi_exports: Vec<LLVMRustCOFFShortExport> = import_name_and_ordinal_vector
188188
.iter()
189-
.map(|name_z| LLVMRustCOFFShortExport::from_name(name_z.as_ptr()))
189+
.map(|(name_z, ordinal)| LLVMRustCOFFShortExport::new(name_z.as_ptr(), *ordinal))
190190
.collect();
191191
let result = unsafe {
192192
crate::llvm::LLVMRustWriteImportLibrary(

compiler/rustc_codegen_llvm/src/back/write.rs

+15
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,13 @@ fn get_pgo_use_path(config: &ModuleConfig) -> Option<CString> {
370370
.map(|path_buf| CString::new(path_buf.to_string_lossy().as_bytes()).unwrap())
371371
}
372372

373+
fn get_pgo_sample_use_path(config: &ModuleConfig) -> Option<CString> {
374+
config
375+
.pgo_sample_use
376+
.as_ref()
377+
.map(|path_buf| CString::new(path_buf.to_string_lossy().as_bytes()).unwrap())
378+
}
379+
373380
pub(crate) fn should_use_new_llvm_pass_manager(config: &ModuleConfig) -> bool {
374381
// The new pass manager is enabled by default for LLVM >= 13.
375382
// This matches Clang, which also enables it since Clang 13.
@@ -389,6 +396,7 @@ pub(crate) unsafe fn optimize_with_new_llvm_pass_manager(
389396
let using_thin_buffers = opt_stage == llvm::OptStage::PreLinkThinLTO || config.bitcode_needed();
390397
let pgo_gen_path = get_pgo_gen_path(config);
391398
let pgo_use_path = get_pgo_use_path(config);
399+
let pgo_sample_use_path = get_pgo_sample_use_path(config);
392400
let is_lto = opt_stage == llvm::OptStage::ThinLTO || opt_stage == llvm::OptStage::FatLTO;
393401
// Sanitizer instrumentation is only inserted during the pre-link optimization stage.
394402
let sanitizer_options = if !is_lto {
@@ -439,6 +447,8 @@ pub(crate) unsafe fn optimize_with_new_llvm_pass_manager(
439447
pgo_use_path.as_ref().map_or(std::ptr::null(), |s| s.as_ptr()),
440448
config.instrument_coverage,
441449
config.instrument_gcov,
450+
pgo_sample_use_path.as_ref().map_or(std::ptr::null(), |s| s.as_ptr()),
451+
config.debug_info_for_profiling,
442452
llvm_selfprofiler,
443453
selfprofile_before_pass_callback,
444454
selfprofile_after_pass_callback,
@@ -544,6 +554,9 @@ pub(crate) unsafe fn optimize(
544554
if config.instrument_coverage {
545555
llvm::LLVMRustAddPass(mpm, find_pass("instrprof").unwrap());
546556
}
557+
if config.debug_info_for_profiling {
558+
llvm::LLVMRustAddPass(mpm, find_pass("add-discriminators").unwrap());
559+
}
547560

548561
add_sanitizer_passes(config, &mut extra_passes);
549562

@@ -1001,6 +1014,7 @@ pub unsafe fn with_llvm_pmb(
10011014
let inline_threshold = config.inline_threshold;
10021015
let pgo_gen_path = get_pgo_gen_path(config);
10031016
let pgo_use_path = get_pgo_use_path(config);
1017+
let pgo_sample_use_path = get_pgo_sample_use_path(config);
10041018

10051019
llvm::LLVMRustConfigurePassManagerBuilder(
10061020
builder,
@@ -1011,6 +1025,7 @@ pub unsafe fn with_llvm_pmb(
10111025
prepare_for_thin_lto,
10121026
pgo_gen_path.as_ref().map_or(ptr::null(), |s| s.as_ptr()),
10131027
pgo_use_path.as_ref().map_or(ptr::null(), |s| s.as_ptr()),
1028+
pgo_sample_use_path.as_ref().map_or(ptr::null(), |s| s.as_ptr()),
10141029
);
10151030

10161031
llvm::LLVMPassManagerBuilderSetSizeLevel(builder, opt_size as u32);

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,18 @@ pub enum LLVMRustResult {
3434
#[repr(C)]
3535
pub struct LLVMRustCOFFShortExport {
3636
pub name: *const c_char,
37+
pub ordinal_present: bool,
38+
// value of `ordinal` only important when `ordinal_present` is true
39+
pub ordinal: u16,
3740
}
3841

3942
impl LLVMRustCOFFShortExport {
40-
pub fn from_name(name: *const c_char) -> LLVMRustCOFFShortExport {
41-
LLVMRustCOFFShortExport { name }
43+
pub fn new(name: *const c_char, ordinal: Option<u16>) -> LLVMRustCOFFShortExport {
44+
LLVMRustCOFFShortExport {
45+
name,
46+
ordinal_present: ordinal.is_some(),
47+
ordinal: ordinal.unwrap_or(0),
48+
}
4249
}
4350
}
4451

@@ -2176,6 +2183,7 @@ extern "C" {
21762183
PrepareForThinLTO: bool,
21772184
PGOGenPath: *const c_char,
21782185
PGOUsePath: *const c_char,
2186+
PGOSampleUsePath: *const c_char,
21792187
);
21802188
pub fn LLVMRustAddLibraryInfo(
21812189
PM: &PassManager<'a>,
@@ -2210,6 +2218,8 @@ extern "C" {
22102218
PGOUsePath: *const c_char,
22112219
InstrumentCoverage: bool,
22122220
InstrumentGCOV: bool,
2221+
PGOSampleUsePath: *const c_char,
2222+
DebugInfoForProfiling: bool,
22132223
llvm_selfprofiler: *mut c_void,
22142224
begin_callback: SelfProfileBeforePassCallback,
22152225
end_callback: SelfProfileAfterPassCallback,

compiler/rustc_codegen_ssa/src/back/link.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -1024,14 +1024,20 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
10241024
}
10251025

10261026
if sess.target.is_like_osx {
1027-
if let Some(option) = osx_strip_opt(sess.opts.debugging_opts.strip) {
1028-
strip_symbols_in_osx(sess, &out_filename, option);
1027+
match sess.opts.debugging_opts.strip {
1028+
Strip::Debuginfo => strip_symbols_in_osx(sess, &out_filename, Some("-S")),
1029+
Strip::Symbols => strip_symbols_in_osx(sess, &out_filename, None),
1030+
Strip::None => {}
10291031
}
10301032
}
10311033
}
10321034

1033-
fn strip_symbols_in_osx<'a>(sess: &'a Session, out_filename: &Path, option: &str) {
1034-
let prog = Command::new("strip").arg(option).arg(out_filename).output();
1035+
fn strip_symbols_in_osx<'a>(sess: &'a Session, out_filename: &Path, option: Option<&str>) {
1036+
let mut cmd = Command::new("strip");
1037+
if let Some(option) = option {
1038+
cmd.arg(option);
1039+
}
1040+
let prog = cmd.arg(out_filename).output();
10351041
match prog {
10361042
Ok(prog) => {
10371043
if !prog.status.success() {
@@ -1049,14 +1055,6 @@ fn strip_symbols_in_osx<'a>(sess: &'a Session, out_filename: &Path, option: &str
10491055
}
10501056
}
10511057

1052-
fn osx_strip_opt<'a>(strip: Strip) -> Option<&'a str> {
1053-
match strip {
1054-
Strip::Debuginfo => Some("-S"),
1055-
Strip::Symbols => Some("-x"),
1056-
Strip::None => None,
1057-
}
1058-
}
1059-
10601058
fn escape_string(s: &[u8]) -> String {
10611059
str::from_utf8(s).map(|s| s.to_owned()).unwrap_or_else(|_| {
10621060
let mut x = "Non-UTF-8 output: ".to_string();

compiler/rustc_codegen_ssa/src/back/linker.rs

+3
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,9 @@ impl<'a> GccLinker<'a> {
286286
config::OptLevel::Aggressive => "O3",
287287
};
288288

289+
if let Some(path) = &self.sess.opts.debugging_opts.profile_sample_use {
290+
self.linker_arg(&format!("-plugin-opt=sample-profile={}", path.display()));
291+
};
289292
self.linker_arg(&format!("-plugin-opt={}", opt_level));
290293
self.linker_arg(&format!("-plugin-opt=mcpu={}", self.target_cpu));
291294
}

compiler/rustc_codegen_ssa/src/back/write.rs

+4
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ pub struct ModuleConfig {
8383

8484
pub pgo_gen: SwitchWithOptPath,
8585
pub pgo_use: Option<PathBuf>,
86+
pub pgo_sample_use: Option<PathBuf>,
87+
pub debug_info_for_profiling: bool,
8688
pub instrument_coverage: bool,
8789
pub instrument_gcov: bool,
8890

@@ -176,6 +178,8 @@ impl ModuleConfig {
176178
SwitchWithOptPath::Disabled
177179
),
178180
pgo_use: if_regular!(sess.opts.cg.profile_use.clone(), None),
181+
pgo_sample_use: if_regular!(sess.opts.debugging_opts.profile_sample_use.clone(), None),
182+
debug_info_for_profiling: sess.opts.debugging_opts.debug_info_for_profiling,
179183
instrument_coverage: if_regular!(sess.instrument_coverage(), false),
180184
instrument_gcov: if_regular!(
181185
// compiler_builtins overrides the codegen-units settings,

compiler/rustc_interface/src/tests.rs

+2
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ fn test_debugging_options_tracking_hash() {
715715
tracked!(chalk, true);
716716
tracked!(codegen_backend, Some("abc".to_string()));
717717
tracked!(crate_attr, vec!["abc".to_string()]);
718+
tracked!(debug_info_for_profiling, true);
718719
tracked!(debug_macros, true);
719720
tracked!(dep_info_omit_d_target, true);
720721
tracked!(dual_proc_macros, true);
@@ -752,6 +753,7 @@ fn test_debugging_options_tracking_hash() {
752753
tracked!(profile, true);
753754
tracked!(profile_emit, Some(PathBuf::from("abc")));
754755
tracked!(profiler_runtime, "abc".to_string());
756+
tracked!(profile_sample_use, Some(PathBuf::from("abc")));
755757
tracked!(relax_elf_relocations, Some(true));
756758
tracked!(relro_level, Some(RelroLevel::Full));
757759
tracked!(remap_cwd_prefix, Some(PathBuf::from("abc")));

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+21-9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
2626
#include "llvm/Transforms/IPO/AlwaysInliner.h"
2727
#include "llvm/Transforms/IPO/FunctionImport.h"
28+
#include "llvm/Transforms/Utils/AddDiscriminators.h"
2829
#include "llvm/Transforms/Utils/FunctionImportUtils.h"
2930
#include "llvm/LTO/LTO.h"
3031
#include "llvm-c/Transforms/PassManagerBuilder.h"
@@ -39,6 +40,7 @@
3940
#include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h"
4041
#include "llvm/Transforms/Utils/CanonicalizeAliases.h"
4142
#include "llvm/Transforms/Utils/NameAnonGlobals.h"
43+
#include "llvm/Transforms/Utils.h"
4244

4345
using namespace llvm;
4446

@@ -523,21 +525,22 @@ extern "C" void LLVMRustDisposeTargetMachine(LLVMTargetMachineRef TM) {
523525
extern "C" void LLVMRustConfigurePassManagerBuilder(
524526
LLVMPassManagerBuilderRef PMBR, LLVMRustCodeGenOptLevel OptLevel,
525527
bool MergeFunctions, bool SLPVectorize, bool LoopVectorize, bool PrepareForThinLTO,
526-
const char* PGOGenPath, const char* PGOUsePath) {
528+
const char* PGOGenPath, const char* PGOUsePath, const char* PGOSampleUsePath) {
527529
unwrap(PMBR)->MergeFunctions = MergeFunctions;
528530
unwrap(PMBR)->SLPVectorize = SLPVectorize;
529531
unwrap(PMBR)->OptLevel = fromRust(OptLevel);
530532
unwrap(PMBR)->LoopVectorize = LoopVectorize;
531533
unwrap(PMBR)->PrepareForThinLTO = PrepareForThinLTO;
532534

533535
if (PGOGenPath) {
534-
assert(!PGOUsePath);
536+
assert(!PGOUsePath && !PGOSampleUsePath);
535537
unwrap(PMBR)->EnablePGOInstrGen = true;
536538
unwrap(PMBR)->PGOInstrGen = PGOGenPath;
537-
}
538-
if (PGOUsePath) {
539-
assert(!PGOGenPath);
539+
} else if (PGOUsePath) {
540+
assert(!PGOSampleUsePath);
540541
unwrap(PMBR)->PGOInstrUse = PGOUsePath;
542+
} else if (PGOSampleUsePath) {
543+
unwrap(PMBR)->PGOSampleUse = PGOSampleUsePath;
541544
}
542545
}
543546

@@ -759,6 +762,7 @@ LLVMRustOptimizeWithNewPassManager(
759762
LLVMRustSanitizerOptions *SanitizerOptions,
760763
const char *PGOGenPath, const char *PGOUsePath,
761764
bool InstrumentCoverage, bool InstrumentGCOV,
765+
const char *PGOSampleUsePath, bool DebugInfoForProfiling,
762766
void* LlvmSelfProfiler,
763767
LLVMRustSelfProfileBeforePassCallback BeforePassCallback,
764768
LLVMRustSelfProfileAfterPassCallback AfterPassCallback,
@@ -797,11 +801,19 @@ LLVMRustOptimizeWithNewPassManager(
797801

798802
Optional<PGOOptions> PGOOpt;
799803
if (PGOGenPath) {
800-
assert(!PGOUsePath);
801-
PGOOpt = PGOOptions(PGOGenPath, "", "", PGOOptions::IRInstr);
804+
assert(!PGOUsePath && !PGOSampleUsePath);
805+
PGOOpt = PGOOptions(PGOGenPath, "", "", PGOOptions::IRInstr,
806+
PGOOptions::NoCSAction, DebugInfoForProfiling);
802807
} else if (PGOUsePath) {
803-
assert(!PGOGenPath);
804-
PGOOpt = PGOOptions(PGOUsePath, "", "", PGOOptions::IRUse);
808+
assert(!PGOSampleUsePath);
809+
PGOOpt = PGOOptions(PGOUsePath, "", "", PGOOptions::IRUse,
810+
PGOOptions::NoCSAction, DebugInfoForProfiling);
811+
} else if (PGOSampleUsePath) {
812+
PGOOpt = PGOOptions(PGOSampleUsePath, "", "", PGOOptions::SampleUse,
813+
PGOOptions::NoCSAction, DebugInfoForProfiling);
814+
} else if (DebugInfoForProfiling) {
815+
PGOOpt = PGOOptions("", "", "", PGOOptions::NoAction,
816+
PGOOptions::NoCSAction, DebugInfoForProfiling);
805817
}
806818

807819
#if LLVM_VERSION_GE(12, 0) && !LLVM_VERSION_GE(13,0)

0 commit comments

Comments
 (0)