Skip to content

Rollup of 8 pull requests #89659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Oct 8, 2021
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ff697c6
On macOS, make strip="symbols" not pass any options to strip
joshtriplett Aug 18, 2021
142f6c0
Implement #[link_ordinal] attribute in the context of #[link(kind = "…
ricobbe Sep 11, 2021
fa23d4f
Implement #85440
smoelius Sep 18, 2021
a6738c7
Add tests
smoelius Sep 19, 2021
32b6ac5
Check `allow_unstable` before checking environment variables
smoelius Sep 30, 2021
e16e15f
Add documentation
smoelius Oct 4, 2021
ecf4741
Add tracking issue
smoelius Oct 6, 2021
c3dfda0
Rebase Result::map_or_else doc wording on top of #89400.
orlp Sep 9, 2021
ce21756
Access Session while decoding expn_id.
cjgillot Oct 2, 2021
daf8903
Do not re-hash foreign spans.
cjgillot Oct 2, 2021
4028b09
Do not ICE if some foreign expansions were not encoded.
cjgillot Oct 2, 2021
a17193d
Enable AutoFDO.
May 7, 2021
afe5335
Use correct edition for panic in [debug_]assert!() etc.
m-ou-se Oct 7, 2021
fcd9fa9
Add tests for panic and [debug_]assert in Rust 2021.
m-ou-se Oct 7, 2021
6162fc0
Add wrapper for -Z gcc-ld=lld to invoke rust-lld with the correct flavor
hkratz Sep 25, 2021
6c2d4bf
Rollup merge of #87918 - mikebenfield:pr-afdo, r=nikic
workingjubilee Oct 8, 2021
cbb561f
Rollup merge of #88137 - joshtriplett:osx-strip-symbols-no-option, r=…
workingjubilee Oct 8, 2021
2b6d7f7
Rollup merge of #88772 - orlp:result-map-or-else-docfix, r=yaahc
workingjubilee Oct 8, 2021
6c17601
Rollup merge of #89025 - ricobbe:raw-dylib-link-ordinal, r=michaelwoe…
workingjubilee Oct 8, 2021
37f17bc
Rollup merge of #89082 - smoelius:master, r=kennytm
workingjubilee Oct 8, 2021
1c1c6ed
Rollup merge of #89288 - rusticstuff:lld_wrapper, r=Mark-Simulacrum
workingjubilee Oct 8, 2021
aed1801
Rollup merge of #89476 - cjgillot:expn-id, r=petrochenkov
workingjubilee Oct 8, 2021
30e068f
Rollup merge of #89622 - m-ou-se:debug-assert-2021, r=estebank
workingjubilee Oct 8, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
@@ -1965,6 +1965,10 @@ dependencies = [
"walkdir",
]

[[package]]
name = "lld-wrapper"
version = "0.1.0"

[[package]]
name = "lock_api"
version = "0.4.1"
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@ members = [
"src/tools/jsondocck",
"src/tools/html-checker",
"src/tools/bump-stage0",
"src/tools/lld-wrapper",
]

exclude = [
6 changes: 3 additions & 3 deletions compiler/rustc_builtin_macros/src/assert.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use rustc_errors::{Applicability, DiagnosticBuilder};

use crate::panic::use_panic_2021;
use rustc_ast::ptr::P;
use rustc_ast::token;
use rustc_ast::tokenstream::{DelimSpan, TokenStream};
use rustc_ast::{self as ast, *};
use rustc_ast_pretty::pprust;
use rustc_errors::{Applicability, DiagnosticBuilder};
use rustc_expand::base::*;
use rustc_parse::parser::Parser;
use rustc_span::symbol::{sym, Ident, Symbol};
@@ -28,7 +28,7 @@ pub fn expand_assert<'cx>(
let sp = cx.with_call_site_ctxt(span);

let panic_call = if let Some(tokens) = custom_message {
let path = if span.rust_2021() {
let path = if use_panic_2021(span) {
// On edition 2021, we always call `$crate::panic::panic_2021!()`.
Path {
span: sp,
19 changes: 18 additions & 1 deletion compiler/rustc_builtin_macros/src/panic.rs
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ use rustc_ast::ptr::P;
use rustc_ast::tokenstream::{DelimSpan, TokenStream};
use rustc_ast::*;
use rustc_expand::base::*;
use rustc_span::edition::Edition;
use rustc_span::symbol::sym;
use rustc_span::Span;

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

let sp = cx.with_call_site_ctxt(sp);

@@ -46,3 +47,19 @@ pub fn expand_panic<'cx>(
),
)
}

pub fn use_panic_2021(mut span: Span) -> bool {
// To determine the editon, we check the first span up the expansion
// stack that does not have #[allow_internal_unstable(edition_panic)].
// (To avoid using the edition of e.g. the assert!() or debug_assert!() definition.)
loop {
let expn = span.ctxt().outer_expn_data();
if let Some(features) = expn.allow_internal_unstable {
if features.iter().any(|&f| f == sym::edition_panic) {
span = expn.call_site;
continue;
}
}
break expn.edition >= Edition::Edition2021;
}
}
4 changes: 4 additions & 0 deletions compiler/rustc_codegen_llvm/src/attributes.rs
Original file line number Diff line number Diff line change
@@ -263,6 +263,10 @@ pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty::
attributes::emit_uwtable(llfn, true);
}

if cx.sess().opts.debugging_opts.profile_sample_use.is_some() {
llvm::AddFunctionAttrString(llfn, Function, cstr!("use-sample-profile"));
}

// FIXME: none of these three functions interact with source level attributes.
set_frame_pointer_type(cx, llfn);
set_instrument_function(cx, llfn);
10 changes: 5 additions & 5 deletions compiler/rustc_codegen_llvm/src/back/archive.rs
Original file line number Diff line number Diff line change
@@ -163,13 +163,13 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
// All import names are Rust identifiers and therefore cannot contain \0 characters.
// FIXME: when support for #[link_name] implemented, ensure that import.name values don't
// have any \0 characters
let import_name_vector: Vec<CString> = dll_imports
let import_name_and_ordinal_vector: Vec<(CString, Option<u16>)> = dll_imports
.iter()
.map(|import: &DllImport| {
if self.config.sess.target.arch == "x86" {
LlvmArchiveBuilder::i686_decorated_name(import)
(LlvmArchiveBuilder::i686_decorated_name(import), import.ordinal)
} else {
CString::new(import.name.to_string()).unwrap()
(CString::new(import.name.to_string()).unwrap(), import.ordinal)
}
})
.collect();
@@ -184,9 +184,9 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
dll_imports.iter().map(|import| import.name.to_string()).collect::<Vec<_>>().join(", "),
);

let ffi_exports: Vec<LLVMRustCOFFShortExport> = import_name_vector
let ffi_exports: Vec<LLVMRustCOFFShortExport> = import_name_and_ordinal_vector
.iter()
.map(|name_z| LLVMRustCOFFShortExport::from_name(name_z.as_ptr()))
.map(|(name_z, ordinal)| LLVMRustCOFFShortExport::new(name_z.as_ptr(), *ordinal))
.collect();
let result = unsafe {
crate::llvm::LLVMRustWriteImportLibrary(
15 changes: 15 additions & 0 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
@@ -370,6 +370,13 @@ fn get_pgo_use_path(config: &ModuleConfig) -> Option<CString> {
.map(|path_buf| CString::new(path_buf.to_string_lossy().as_bytes()).unwrap())
}

fn get_pgo_sample_use_path(config: &ModuleConfig) -> Option<CString> {
config
.pgo_sample_use
.as_ref()
.map(|path_buf| CString::new(path_buf.to_string_lossy().as_bytes()).unwrap())
}

pub(crate) fn should_use_new_llvm_pass_manager(config: &ModuleConfig) -> bool {
// The new pass manager is enabled by default for LLVM >= 13.
// This matches Clang, which also enables it since Clang 13.
@@ -389,6 +396,7 @@ pub(crate) unsafe fn optimize_with_new_llvm_pass_manager(
let using_thin_buffers = opt_stage == llvm::OptStage::PreLinkThinLTO || config.bitcode_needed();
let pgo_gen_path = get_pgo_gen_path(config);
let pgo_use_path = get_pgo_use_path(config);
let pgo_sample_use_path = get_pgo_sample_use_path(config);
let is_lto = opt_stage == llvm::OptStage::ThinLTO || opt_stage == llvm::OptStage::FatLTO;
// Sanitizer instrumentation is only inserted during the pre-link optimization stage.
let sanitizer_options = if !is_lto {
@@ -439,6 +447,8 @@ pub(crate) unsafe fn optimize_with_new_llvm_pass_manager(
pgo_use_path.as_ref().map_or(std::ptr::null(), |s| s.as_ptr()),
config.instrument_coverage,
config.instrument_gcov,
pgo_sample_use_path.as_ref().map_or(std::ptr::null(), |s| s.as_ptr()),
config.debug_info_for_profiling,
llvm_selfprofiler,
selfprofile_before_pass_callback,
selfprofile_after_pass_callback,
@@ -544,6 +554,9 @@ pub(crate) unsafe fn optimize(
if config.instrument_coverage {
llvm::LLVMRustAddPass(mpm, find_pass("instrprof").unwrap());
}
if config.debug_info_for_profiling {
llvm::LLVMRustAddPass(mpm, find_pass("add-discriminators").unwrap());
}

add_sanitizer_passes(config, &mut extra_passes);

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

llvm::LLVMRustConfigurePassManagerBuilder(
builder,
@@ -1011,6 +1025,7 @@ pub unsafe fn with_llvm_pmb(
prepare_for_thin_lto,
pgo_gen_path.as_ref().map_or(ptr::null(), |s| s.as_ptr()),
pgo_use_path.as_ref().map_or(ptr::null(), |s| s.as_ptr()),
pgo_sample_use_path.as_ref().map_or(ptr::null(), |s| s.as_ptr()),
);

llvm::LLVMPassManagerBuilderSetSizeLevel(builder, opt_size as u32);
14 changes: 12 additions & 2 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
@@ -34,11 +34,18 @@ pub enum LLVMRustResult {
#[repr(C)]
pub struct LLVMRustCOFFShortExport {
pub name: *const c_char,
pub ordinal_present: bool,
// value of `ordinal` only important when `ordinal_present` is true
pub ordinal: u16,
}

impl LLVMRustCOFFShortExport {
pub fn from_name(name: *const c_char) -> LLVMRustCOFFShortExport {
LLVMRustCOFFShortExport { name }
pub fn new(name: *const c_char, ordinal: Option<u16>) -> LLVMRustCOFFShortExport {
LLVMRustCOFFShortExport {
name,
ordinal_present: ordinal.is_some(),
ordinal: ordinal.unwrap_or(0),
}
}
}

@@ -2176,6 +2183,7 @@ extern "C" {
PrepareForThinLTO: bool,
PGOGenPath: *const c_char,
PGOUsePath: *const c_char,
PGOSampleUsePath: *const c_char,
);
pub fn LLVMRustAddLibraryInfo(
PM: &PassManager<'a>,
@@ -2210,6 +2218,8 @@ extern "C" {
PGOUsePath: *const c_char,
InstrumentCoverage: bool,
InstrumentGCOV: bool,
PGOSampleUsePath: *const c_char,
DebugInfoForProfiling: bool,
llvm_selfprofiler: *mut c_void,
begin_callback: SelfProfileBeforePassCallback,
end_callback: SelfProfileAfterPassCallback,
22 changes: 10 additions & 12 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
@@ -1024,14 +1024,20 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
}

if sess.target.is_like_osx {
if let Some(option) = osx_strip_opt(sess.opts.debugging_opts.strip) {
strip_symbols_in_osx(sess, &out_filename, option);
match sess.opts.debugging_opts.strip {
Strip::Debuginfo => strip_symbols_in_osx(sess, &out_filename, Some("-S")),
Strip::Symbols => strip_symbols_in_osx(sess, &out_filename, None),
Strip::None => {}
}
}
}

fn strip_symbols_in_osx<'a>(sess: &'a Session, out_filename: &Path, option: &str) {
let prog = Command::new("strip").arg(option).arg(out_filename).output();
fn strip_symbols_in_osx<'a>(sess: &'a Session, out_filename: &Path, option: Option<&str>) {
let mut cmd = Command::new("strip");
if let Some(option) = option {
cmd.arg(option);
}
let prog = cmd.arg(out_filename).output();
match prog {
Ok(prog) => {
if !prog.status.success() {
@@ -1049,14 +1055,6 @@ fn strip_symbols_in_osx<'a>(sess: &'a Session, out_filename: &Path, option: &str
}
}

fn osx_strip_opt<'a>(strip: Strip) -> Option<&'a str> {
match strip {
Strip::Debuginfo => Some("-S"),
Strip::Symbols => Some("-x"),
Strip::None => None,
}
}

fn escape_string(s: &[u8]) -> String {
str::from_utf8(s).map(|s| s.to_owned()).unwrap_or_else(|_| {
let mut x = "Non-UTF-8 output: ".to_string();
3 changes: 3 additions & 0 deletions compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
@@ -286,6 +286,9 @@ impl<'a> GccLinker<'a> {
config::OptLevel::Aggressive => "O3",
};

if let Some(path) = &self.sess.opts.debugging_opts.profile_sample_use {
self.linker_arg(&format!("-plugin-opt=sample-profile={}", path.display()));
};
self.linker_arg(&format!("-plugin-opt={}", opt_level));
self.linker_arg(&format!("-plugin-opt=mcpu={}", self.target_cpu));
}
4 changes: 4 additions & 0 deletions compiler/rustc_codegen_ssa/src/back/write.rs
Original file line number Diff line number Diff line change
@@ -83,6 +83,8 @@ pub struct ModuleConfig {

pub pgo_gen: SwitchWithOptPath,
pub pgo_use: Option<PathBuf>,
pub pgo_sample_use: Option<PathBuf>,
pub debug_info_for_profiling: bool,
pub instrument_coverage: bool,
pub instrument_gcov: bool,

@@ -176,6 +178,8 @@ impl ModuleConfig {
SwitchWithOptPath::Disabled
),
pgo_use: if_regular!(sess.opts.cg.profile_use.clone(), None),
pgo_sample_use: if_regular!(sess.opts.debugging_opts.profile_sample_use.clone(), None),
debug_info_for_profiling: sess.opts.debugging_opts.debug_info_for_profiling,
instrument_coverage: if_regular!(sess.instrument_coverage(), false),
instrument_gcov: if_regular!(
// compiler_builtins overrides the codegen-units settings,
2 changes: 2 additions & 0 deletions compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
@@ -715,6 +715,7 @@ fn test_debugging_options_tracking_hash() {
tracked!(chalk, true);
tracked!(codegen_backend, Some("abc".to_string()));
tracked!(crate_attr, vec!["abc".to_string()]);
tracked!(debug_info_for_profiling, true);
tracked!(debug_macros, true);
tracked!(dep_info_omit_d_target, true);
tracked!(dual_proc_macros, true);
@@ -752,6 +753,7 @@ fn test_debugging_options_tracking_hash() {
tracked!(profile, true);
tracked!(profile_emit, Some(PathBuf::from("abc")));
tracked!(profiler_runtime, "abc".to_string());
tracked!(profile_sample_use, Some(PathBuf::from("abc")));
tracked!(relax_elf_relocations, Some(true));
tracked!(relro_level, Some(RelroLevel::Full));
tracked!(remap_cwd_prefix, Some(PathBuf::from("abc")));
30 changes: 21 additions & 9 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "llvm/Transforms/IPO/AlwaysInliner.h"
#include "llvm/Transforms/IPO/FunctionImport.h"
#include "llvm/Transforms/Utils/AddDiscriminators.h"
#include "llvm/Transforms/Utils/FunctionImportUtils.h"
#include "llvm/LTO/LTO.h"
#include "llvm-c/Transforms/PassManagerBuilder.h"
@@ -39,6 +40,7 @@
#include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h"
#include "llvm/Transforms/Utils/CanonicalizeAliases.h"
#include "llvm/Transforms/Utils/NameAnonGlobals.h"
#include "llvm/Transforms/Utils.h"

using namespace llvm;

@@ -523,21 +525,22 @@ extern "C" void LLVMRustDisposeTargetMachine(LLVMTargetMachineRef TM) {
extern "C" void LLVMRustConfigurePassManagerBuilder(
LLVMPassManagerBuilderRef PMBR, LLVMRustCodeGenOptLevel OptLevel,
bool MergeFunctions, bool SLPVectorize, bool LoopVectorize, bool PrepareForThinLTO,
const char* PGOGenPath, const char* PGOUsePath) {
const char* PGOGenPath, const char* PGOUsePath, const char* PGOSampleUsePath) {
unwrap(PMBR)->MergeFunctions = MergeFunctions;
unwrap(PMBR)->SLPVectorize = SLPVectorize;
unwrap(PMBR)->OptLevel = fromRust(OptLevel);
unwrap(PMBR)->LoopVectorize = LoopVectorize;
unwrap(PMBR)->PrepareForThinLTO = PrepareForThinLTO;

if (PGOGenPath) {
assert(!PGOUsePath);
assert(!PGOUsePath && !PGOSampleUsePath);
unwrap(PMBR)->EnablePGOInstrGen = true;
unwrap(PMBR)->PGOInstrGen = PGOGenPath;
}
if (PGOUsePath) {
assert(!PGOGenPath);
} else if (PGOUsePath) {
assert(!PGOSampleUsePath);
unwrap(PMBR)->PGOInstrUse = PGOUsePath;
} else if (PGOSampleUsePath) {
unwrap(PMBR)->PGOSampleUse = PGOSampleUsePath;
}
}

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

Optional<PGOOptions> PGOOpt;
if (PGOGenPath) {
assert(!PGOUsePath);
PGOOpt = PGOOptions(PGOGenPath, "", "", PGOOptions::IRInstr);
assert(!PGOUsePath && !PGOSampleUsePath);
PGOOpt = PGOOptions(PGOGenPath, "", "", PGOOptions::IRInstr,
PGOOptions::NoCSAction, DebugInfoForProfiling);
} else if (PGOUsePath) {
assert(!PGOGenPath);
PGOOpt = PGOOptions(PGOUsePath, "", "", PGOOptions::IRUse);
assert(!PGOSampleUsePath);
PGOOpt = PGOOptions(PGOUsePath, "", "", PGOOptions::IRUse,
PGOOptions::NoCSAction, DebugInfoForProfiling);
} else if (PGOSampleUsePath) {
PGOOpt = PGOOptions(PGOSampleUsePath, "", "", PGOOptions::SampleUse,
PGOOptions::NoCSAction, DebugInfoForProfiling);
} else if (DebugInfoForProfiling) {
PGOOpt = PGOOptions("", "", "", PGOOptions::NoAction,
PGOOptions::NoCSAction, DebugInfoForProfiling);
}

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