From e8a1575cf6fe7105535db36e396a3a9a58765205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 19 Feb 2018 01:40:48 +0100 Subject: [PATCH 01/18] profiler-builtins: define COMPILER_RT_HAS_UNAME on non-msvc platforms. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise lprofGetHostName, used by the PGO generator, won't be available. This means that PGO and coverage profiling would be restricted to systems with uname, but that seems acceptable. Signed-off-by: Emilio Cobos Álvarez --- src/libprofiler_builtins/build.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libprofiler_builtins/build.rs b/src/libprofiler_builtins/build.rs index dd88dd933f691..92244886552e6 100644 --- a/src/libprofiler_builtins/build.rs +++ b/src/libprofiler_builtins/build.rs @@ -50,6 +50,7 @@ fn main() { cfg.flag("-fomit-frame-pointer"); cfg.flag("-ffreestanding"); cfg.define("VISIBILITY_HIDDEN", None); + cfg.define("COMPILER_RT_HAS_UNAME", Some("1")); } for src in profile_sources { From 804f959507ec38f5b3e1f7593c8c3aef5a7a2c83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 19 Feb 2018 01:46:39 +0100 Subject: [PATCH 02/18] session: Add two tracked, exclusive codegen options for PGO profile usage and generation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Emilio Cobos Álvarez --- src/librustc/session/config.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index f41765b642d96..e5d7a618b355d 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1027,6 +1027,11 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options, "`-C save-temps` might not produce all requested temporary products \ when incremental compilation is enabled.")], "save all temporary output files during compilation"), + pgo_gen: Option = (None, parse_opt_string, [TRACKED], + "Generate PGO profile data, to a given file, or to the default \ + location if it's empty."), + pgo_use: String = (String::new(), parse_string, [TRACKED], + "Use PGO profile data from the given profile file."), rpath: bool = (false, parse_bool, [UNTRACKED], "set rpath values in libs/exes"), overflow_checks: Option = (None, parse_opt_bool, [TRACKED], @@ -1801,6 +1806,13 @@ pub fn build_session_options_and_crate_config( let mut codegen_units = cg.codegen_units; let mut disable_thinlto = false; + if cg.pgo_gen.is_some() && !cg.pgo_use.is_empty() { + early_error( + error_format, + "options `-C pgo-gen` and `-C pgo-use` are exclussive", + ); + } + // Issue #30063: if user requests llvm-related output to one // particular path, disable codegen-units. let incompatible: Vec<_> = output_types @@ -2824,6 +2836,14 @@ mod tests { opts.cg.lto = Lto::Fat; assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash()); + opts = reference.clone(); + opts.cg.pgo_gen = Some(String::from("abc")); + assert_ne!(reference.dep_tracking_hash(), opts.dep_tracking_hash()); + + opts = reference.clone(); + opts.cg.pgo_use = String::from("abc"); + assert_ne!(reference.dep_tracking_hash(), opts.dep_tracking_hash()); + opts = reference.clone(); opts.cg.target_cpu = Some(String::from("abc")); assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash()); From 50a38725e1841aa2283f198dbc8ef2bd5bd1370b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 19 Feb 2018 01:55:50 +0100 Subject: [PATCH 03/18] rustc_metadata: Load the profiler runtime if we're generating PGO profile data. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This contains all the actual profiling code. Signed-off-by: Emilio Cobos Álvarez --- src/librustc_metadata/creader.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index baaf57c890898..812bbf29cf19e 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -784,7 +784,9 @@ impl<'a> CrateLoader<'a> { } fn inject_profiler_runtime(&mut self) { - if self.sess.opts.debugging_opts.profile { + if self.sess.opts.debugging_opts.profile || + self.sess.opts.cg.pgo_gen.is_some() + { info!("loading profiler"); let symbol = Symbol::intern("profiler_builtins"); From 324ca7acd59be59abe0562287d5493f78a60823a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 19 Feb 2018 01:57:12 +0100 Subject: [PATCH 04/18] rustc_llvm: rustc_trans: Thread the PGO config down to the pass manager builder. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Emilio Cobos Álvarez --- src/librustc_llvm/ffi.rs | 4 +++- src/librustc_trans/back/write.rs | 37 +++++++++++++++++++++++++++----- src/rustllvm/PassWrapper.cpp | 12 ++++++++++- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/librustc_llvm/ffi.rs b/src/librustc_llvm/ffi.rs index c0cdd21277062..25506f6a86e89 100644 --- a/src/librustc_llvm/ffi.rs +++ b/src/librustc_llvm/ffi.rs @@ -1641,7 +1641,9 @@ extern "C" { OptLevel: CodeGenOptLevel, MergeFunctions: bool, SLPVectorize: bool, - LoopVectorize: bool); + LoopVectorize: bool, + PGOGenPath: *const c_char, + PGOUsePath: *const c_char); pub fn LLVMRustAddLibraryInfo(PM: PassManagerRef, M: ModuleRef, DisableSimplifyLibCalls: bool); diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs index 3e7422557e9b6..2a8d280ee2632 100644 --- a/src/librustc_trans/back/write.rs +++ b/src/librustc_trans/back/write.rs @@ -240,6 +240,9 @@ pub struct ModuleConfig { /// Some(level) to optimize binary size, or None to not affect program size. opt_size: Option, + pgo_gen: Option, + pgo_use: String, + // Flags indicating which outputs to produce. emit_no_opt_bc: bool, emit_bc: bool, @@ -274,6 +277,9 @@ impl ModuleConfig { opt_level: None, opt_size: None, + pgo_gen: None, + pgo_use: String::new(), + emit_no_opt_bc: false, emit_bc: false, emit_bc_compressed: false, @@ -932,6 +938,9 @@ pub fn start_async_translation(tcx: TyCtxt, modules_config.passes.push("insert-gcov-profiling".to_owned()) } + modules_config.pgo_gen = sess.opts.cg.pgo_gen.clone(); + modules_config.pgo_use = sess.opts.cg.pgo_use.clone(); + modules_config.opt_level = Some(get_llvm_opt_level(sess.opts.optimize)); modules_config.opt_size = Some(get_llvm_opt_size(sess.opts.optimize)); @@ -2046,6 +2055,8 @@ pub unsafe fn with_llvm_pmb(llmod: ModuleRef, config: &ModuleConfig, opt_level: llvm::CodeGenOptLevel, f: &mut FnMut(llvm::PassManagerBuilderRef)) { + use std::ptr; + // Create the PassManagerBuilder for LLVM. We configure it with // reasonable defaults and prepare it to actually populate the pass // manager. @@ -2053,11 +2064,27 @@ pub unsafe fn with_llvm_pmb(llmod: ModuleRef, let opt_size = config.opt_size.unwrap_or(llvm::CodeGenOptSizeNone); let inline_threshold = config.inline_threshold; - llvm::LLVMRustConfigurePassManagerBuilder(builder, - opt_level, - config.merge_functions, - config.vectorize_slp, - config.vectorize_loop); + let pgo_gen_path = config.pgo_gen.as_ref().map(|s| { + let s = if s.is_empty() { "default_%m.profraw" } else { s }; + CString::new(s.as_bytes()).unwrap() + }); + + let pgo_use_path = if config.pgo_use.is_empty() { + None + } else { + Some(CString::new(config.pgo_use.as_bytes()).unwrap()) + }; + + llvm::LLVMRustConfigurePassManagerBuilder( + builder, + opt_level, + config.merge_functions, + config.vectorize_slp, + config.vectorize_loop, + 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()), + ); + llvm::LLVMPassManagerBuilderSetSizeLevel(builder, opt_size as u32); if opt_size != llvm::CodeGenOptSizeNone { diff --git a/src/rustllvm/PassWrapper.cpp b/src/rustllvm/PassWrapper.cpp index 06d1301d70003..bee8ae5853f86 100644 --- a/src/rustllvm/PassWrapper.cpp +++ b/src/rustllvm/PassWrapper.cpp @@ -428,12 +428,22 @@ extern "C" void LLVMRustAddAnalysisPasses(LLVMTargetMachineRef TM, extern "C" void LLVMRustConfigurePassManagerBuilder( LLVMPassManagerBuilderRef PMBR, LLVMRustCodeGenOptLevel OptLevel, - bool MergeFunctions, bool SLPVectorize, bool LoopVectorize) { + bool MergeFunctions, bool SLPVectorize, bool LoopVectorize, + const char* PGOGenPath, const char* PGOUsePath) { // Ignore mergefunc for now as enabling it causes crashes. // unwrap(PMBR)->MergeFunctions = MergeFunctions; unwrap(PMBR)->SLPVectorize = SLPVectorize; unwrap(PMBR)->OptLevel = fromRust(OptLevel); unwrap(PMBR)->LoopVectorize = LoopVectorize; + if (PGOGenPath) { + assert(!PGOUsePath); + unwrap(PMBR)->EnablePGOInstrGen = true; + unwrap(PMBR)->PGOInstrGen = PGOGenPath; + } + if (PGOUsePath) { + assert(!PGOGenPath); + unwrap(PMBR)->PGOInstrUse = PGOUsePath; + } } // Unfortunately, the LLVM C API doesn't provide a way to set the `LibraryInfo` From 99127abca8c9678e14ee11bee4d46bc34ec8b164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 19 Feb 2018 01:57:55 +0100 Subject: [PATCH 05/18] rustc_trans: disable probestack when using pgo-gen. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Executables crash in the probestack function otherwise... I haven't debugged much further than that. Signed-off-by: Emilio Cobos Álvarez --- src/librustc_trans/attributes.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/librustc_trans/attributes.rs b/src/librustc_trans/attributes.rs index df78ccdd2298a..f53c1e84f6e8e 100644 --- a/src/librustc_trans/attributes.rs +++ b/src/librustc_trans/attributes.rs @@ -92,6 +92,11 @@ pub fn set_probestack(cx: &CodegenCx, llfn: ValueRef) { _ => {} } + // probestack doesn't play nice either with pgo-gen. + if cx.sess().opts.cg.pgo_gen.is_some() { + return; + } + // Flag our internal `__rust_probestack` function as the stack probe symbol. // This is defined in the `compiler-builtins` crate for each architecture. llvm::AddFunctionAttrStringValue( From 9c61c7284a39db3471b395ccc5704ef77dc653ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 19 Feb 2018 02:04:49 +0100 Subject: [PATCH 06/18] rustc_trans: Fix PGO generation linking on Linux by adding the relevant linker commands. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See the linked LLVM reviews for the clang counter-parts. Signed-off-by: Emilio Cobos Álvarez --- src/librustc_trans/back/link.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index 542cdc5baad32..657563eac2cf8 100644 --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -1085,6 +1085,20 @@ fn link_args(cmd: &mut Linker, cmd.build_static_executable(); } + // If we're doing PGO generation stuff and on a GNU-like linker, use the + // "-u" flag to properly pull in the profiler runtime bits. + // + // This is because LLVM otherwise won't add the needed initialization for us + // on Linux (though the extra flag should be harmless if it does). + // + // See https://reviews.llvm.org/D14033 and https://reviews.llvm.org/D14030. + // + // Though it may be worth to try to revert those changes upstream, since the + // overhead of the initialization should be minor. + if sess.opts.cg.pgo_gen.is_some() && sess.target.target.options.linker_is_gnu { + cmd.args(&["-u".to_owned(), "__llvm_profile_runtime".to_owned()]); + } + // FIXME (#2397): At some point we want to rpath our guesses as to // where extern libraries might live, based on the // addl_lib_search_paths From e2183d3c707e87f2b333f9742b8de9885d36b7a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 19 Feb 2018 02:49:48 +0100 Subject: [PATCH 07/18] Test that pgo-gen works properly. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Emilio Cobos Álvarez --- src/test/run-make/pgo-gen/Makefile | 8 ++++++++ src/test/run-make/pgo-gen/test.rs | 11 +++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/test/run-make/pgo-gen/Makefile create mode 100644 src/test/run-make/pgo-gen/test.rs diff --git a/src/test/run-make/pgo-gen/Makefile b/src/test/run-make/pgo-gen/Makefile new file mode 100644 index 0000000000000..a6b7b2c02b287 --- /dev/null +++ b/src/test/run-make/pgo-gen/Makefile @@ -0,0 +1,8 @@ +-include ../tools.mk + +all: +ifeq ($(PROFILER_SUPPORT),1) + $(RUSTC) -g -C pgo-gen=test.profraw test.rs + $(call RUN,test) || exit 1 + [ -e "$(TMPDIR)/test.profraw" ] || (echo "No .profraw file"; exit 1) +endif diff --git a/src/test/run-make/pgo-gen/test.rs b/src/test/run-make/pgo-gen/test.rs new file mode 100644 index 0000000000000..3f07b46791d22 --- /dev/null +++ b/src/test/run-make/pgo-gen/test.rs @@ -0,0 +1,11 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() {} From aaeb40ab3b13d02ae148104ca6defffe6e77851f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 19 Feb 2018 03:20:51 +0100 Subject: [PATCH 08/18] profiler_builtins: Add missing ProfilingNameVar file to the profiler build. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise opt builds with pgo-gen fail, d'oh. Signed-off-by: Emilio Cobos Álvarez --- src/libprofiler_builtins/build.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libprofiler_builtins/build.rs b/src/libprofiler_builtins/build.rs index 92244886552e6..6c7407760dfa5 100644 --- a/src/libprofiler_builtins/build.rs +++ b/src/libprofiler_builtins/build.rs @@ -27,6 +27,7 @@ fn main() { "InstrProfilingFile.c", "InstrProfilingMerge.c", "InstrProfilingMergeFile.c", + "InstrProfilingNameVar.c", "InstrProfilingPlatformDarwin.c", "InstrProfilingPlatformLinux.c", "InstrProfilingPlatformOther.c", From a95c8c66a72e82e2eb41bccb450e2bf5b0d67e7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 12 Mar 2018 18:11:59 +0100 Subject: [PATCH 09/18] librustc_llvm: Show PGO diagnostics properly. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Emilio Cobos Álvarez --- src/librustc_llvm/diagnostic.rs | 5 +++++ src/librustc_llvm/ffi.rs | 1 + src/librustc_trans/back/write.rs | 9 +++++++-- src/rustllvm/RustWrapper.cpp | 3 +++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/librustc_llvm/diagnostic.rs b/src/librustc_llvm/diagnostic.rs index c5cdf6566921c..e73c570ed8231 100644 --- a/src/librustc_llvm/diagnostic.rs +++ b/src/librustc_llvm/diagnostic.rs @@ -121,6 +121,7 @@ impl InlineAsmDiagnostic { pub enum Diagnostic { Optimization(OptimizationDiagnostic), InlineAsm(InlineAsmDiagnostic), + PGO(DiagnosticInfoRef), /// LLVM has other types that we do not wrap here. UnknownDiagnostic(DiagnosticInfoRef), @@ -160,6 +161,10 @@ impl Diagnostic { Optimization(OptimizationDiagnostic::unpack(OptimizationFailure, di)) } + Dk::PGOProfile => { + PGO(di) + } + _ => UnknownDiagnostic(di), } } diff --git a/src/librustc_llvm/ffi.rs b/src/librustc_llvm/ffi.rs index 25506f6a86e89..1271773fa02b3 100644 --- a/src/librustc_llvm/ffi.rs +++ b/src/librustc_llvm/ffi.rs @@ -322,6 +322,7 @@ pub enum DiagnosticKind { OptimizationRemarkAnalysisAliasing, OptimizationRemarkOther, OptimizationFailure, + PGOProfile, } /// LLVMRustArchiveKind diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs index 2a8d280ee2632..99558652d6909 100644 --- a/src/librustc_trans/back/write.rs +++ b/src/librustc_trans/back/write.rs @@ -498,8 +498,13 @@ unsafe extern "C" fn diagnostic_handler(info: DiagnosticInfoRef, user: *mut c_vo opt.message)); } } - - _ => (), + llvm::diagnostic::PGO(diagnostic_ref) => { + let msg = llvm::build_string(|s| { + llvm::LLVMRustWriteDiagnosticInfoToString(diagnostic_ref, s) + }).expect("non-UTF8 PGO diagnostic"); + diag_handler.note_without_error(&msg); + } + llvm::diagnostic::UnknownDiagnostic(..) => {}, } } diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index a5644d6f9e2e1..970c1c6a0110b 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -1021,6 +1021,7 @@ enum class LLVMRustDiagnosticKind { OptimizationRemarkAnalysisAliasing, OptimizationRemarkOther, OptimizationFailure, + PGOProfile, }; static LLVMRustDiagnosticKind toRust(DiagnosticKind Kind) { @@ -1043,6 +1044,8 @@ static LLVMRustDiagnosticKind toRust(DiagnosticKind Kind) { return LLVMRustDiagnosticKind::OptimizationRemarkAnalysisFPCommute; case DK_OptimizationRemarkAnalysisAliasing: return LLVMRustDiagnosticKind::OptimizationRemarkAnalysisAliasing; + case DK_PGOProfile: + return LLVMRustDiagnosticKind::PGOProfile; default: return (Kind >= DK_FirstRemark && Kind <= DK_LastRemark) ? LLVMRustDiagnosticKind::OptimizationRemarkOther From 036e0d7943f274fc3269a9cd67d2c922e397fcaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 12 Mar 2018 20:45:35 +0100 Subject: [PATCH 10/18] librustc_trans: disable profiling pre-inlining. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It destroys performance actually. Signed-off-by: Emilio Cobos Álvarez --- src/librustc_trans/llvm_util.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_trans/llvm_util.rs b/src/librustc_trans/llvm_util.rs index 5113b65a5c470..12364b32d1163 100644 --- a/src/librustc_trans/llvm_util.rs +++ b/src/librustc_trans/llvm_util.rs @@ -61,6 +61,7 @@ unsafe fn configure_llvm(sess: &Session) { add("rustc"); // fake program name if sess.time_llvm_passes() { add("-time-passes"); } if sess.print_llvm_passes() { add("-debug-pass=Structure"); } + add("-disable-preinline"); for arg in &sess.opts.cg.llvm_args { add(&(*arg)); From 688275a4009a7a87fb211f0b690f386fc2de8740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 12 Mar 2018 21:11:25 +0100 Subject: [PATCH 11/18] librustc: Convert -C pgo-gen and -C pgo-use into -Z flags. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Emilio Cobos Álvarez --- src/librustc/session/config.rs | 40 +++++++++++++++--------------- src/librustc_metadata/creader.rs | 2 +- src/librustc_trans/attributes.rs | 2 +- src/librustc_trans/back/link.rs | 4 ++- src/librustc_trans/back/write.rs | 4 +-- src/test/run-make/pgo-gen/Makefile | 2 +- 6 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index e5d7a618b355d..7f92a087ebfc8 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1027,11 +1027,6 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options, "`-C save-temps` might not produce all requested temporary products \ when incremental compilation is enabled.")], "save all temporary output files during compilation"), - pgo_gen: Option = (None, parse_opt_string, [TRACKED], - "Generate PGO profile data, to a given file, or to the default \ - location if it's empty."), - pgo_use: String = (String::new(), parse_string, [TRACKED], - "Use PGO profile data from the given profile file."), rpath: bool = (false, parse_bool, [UNTRACKED], "set rpath values in libs/exes"), overflow_checks: Option = (None, parse_opt_bool, [TRACKED], @@ -1254,6 +1249,11 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, "extra arguments to prepend to the linker invocation (space separated)"), profile: bool = (false, parse_bool, [TRACKED], "insert profiling code"), + pgo_gen: Option = (None, parse_opt_string, [TRACKED], + "Generate PGO profile data, to a given file, or to the default \ + location if it's empty."), + pgo_use: String = (String::new(), parse_string, [TRACKED], + "Use PGO profile data from the given profile file."), relro_level: Option = (None, parse_relro_level, [TRACKED], "choose which RELRO level to use"), nll: bool = (false, parse_bool, [UNTRACKED], @@ -1776,6 +1776,13 @@ pub fn build_session_options_and_crate_config( ); } + if debugging_opts.pgo_gen.is_some() && !debugging_opts.pgo_use.is_empty() { + early_error( + error_format, + "options `-Z pgo-gen` and `-Z pgo-use` are exclusive", + ); + } + let mut output_types = BTreeMap::new(); if !debugging_opts.parse_only { for list in matches.opt_strs("emit") { @@ -1806,13 +1813,6 @@ pub fn build_session_options_and_crate_config( let mut codegen_units = cg.codegen_units; let mut disable_thinlto = false; - if cg.pgo_gen.is_some() && !cg.pgo_use.is_empty() { - early_error( - error_format, - "options `-C pgo-gen` and `-C pgo-use` are exclussive", - ); - } - // Issue #30063: if user requests llvm-related output to one // particular path, disable codegen-units. let incompatible: Vec<_> = output_types @@ -2836,14 +2836,6 @@ mod tests { opts.cg.lto = Lto::Fat; assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash()); - opts = reference.clone(); - opts.cg.pgo_gen = Some(String::from("abc")); - assert_ne!(reference.dep_tracking_hash(), opts.dep_tracking_hash()); - - opts = reference.clone(); - opts.cg.pgo_use = String::from("abc"); - assert_ne!(reference.dep_tracking_hash(), opts.dep_tracking_hash()); - opts = reference.clone(); opts.cg.target_cpu = Some(String::from("abc")); assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash()); @@ -2904,6 +2896,14 @@ mod tests { opts.debugging_opts.tls_model = Some(String::from("tls model")); assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash()); + opts = reference.clone(); + opts.debugging_opts.pgo_gen = Some(String::from("abc")); + assert_ne!(reference.dep_tracking_hash(), opts.dep_tracking_hash()); + + opts = reference.clone(); + opts.debugging_opts.pgo_use = String::from("abc"); + assert_ne!(reference.dep_tracking_hash(), opts.dep_tracking_hash()); + opts = reference.clone(); opts.cg.metadata = vec![String::from("A"), String::from("B")]; assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash()); diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index 812bbf29cf19e..802665b6ddbc5 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -785,7 +785,7 @@ impl<'a> CrateLoader<'a> { fn inject_profiler_runtime(&mut self) { if self.sess.opts.debugging_opts.profile || - self.sess.opts.cg.pgo_gen.is_some() + self.sess.opts.debugging_opts.pgo_gen.is_some() { info!("loading profiler"); diff --git a/src/librustc_trans/attributes.rs b/src/librustc_trans/attributes.rs index f53c1e84f6e8e..c968b8525a5b1 100644 --- a/src/librustc_trans/attributes.rs +++ b/src/librustc_trans/attributes.rs @@ -93,7 +93,7 @@ pub fn set_probestack(cx: &CodegenCx, llfn: ValueRef) { } // probestack doesn't play nice either with pgo-gen. - if cx.sess().opts.cg.pgo_gen.is_some() { + if cx.sess().opts.debugging_opts.pgo_gen.is_some() { return; } diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index 657563eac2cf8..19f0d5866ef34 100644 --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -1095,7 +1095,9 @@ fn link_args(cmd: &mut Linker, // // Though it may be worth to try to revert those changes upstream, since the // overhead of the initialization should be minor. - if sess.opts.cg.pgo_gen.is_some() && sess.target.target.options.linker_is_gnu { + if sess.opts.debugging_opts.pgo_gen.is_some() && + sess.target.target.options.linker_is_gnu + { cmd.args(&["-u".to_owned(), "__llvm_profile_runtime".to_owned()]); } diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs index 99558652d6909..26cdca1cdbf4d 100644 --- a/src/librustc_trans/back/write.rs +++ b/src/librustc_trans/back/write.rs @@ -943,8 +943,8 @@ pub fn start_async_translation(tcx: TyCtxt, modules_config.passes.push("insert-gcov-profiling".to_owned()) } - modules_config.pgo_gen = sess.opts.cg.pgo_gen.clone(); - modules_config.pgo_use = sess.opts.cg.pgo_use.clone(); + modules_config.pgo_gen = sess.opts.debugging_opts.pgo_gen.clone(); + modules_config.pgo_use = sess.opts.debugging_opts.pgo_use.clone(); modules_config.opt_level = Some(get_llvm_opt_level(sess.opts.optimize)); modules_config.opt_size = Some(get_llvm_opt_size(sess.opts.optimize)); diff --git a/src/test/run-make/pgo-gen/Makefile b/src/test/run-make/pgo-gen/Makefile index a6b7b2c02b287..bc5cef2370c64 100644 --- a/src/test/run-make/pgo-gen/Makefile +++ b/src/test/run-make/pgo-gen/Makefile @@ -2,7 +2,7 @@ all: ifeq ($(PROFILER_SUPPORT),1) - $(RUSTC) -g -C pgo-gen=test.profraw test.rs + $(RUSTC) -g -Z pgo-gen=test.profraw test.rs $(call RUN,test) || exit 1 [ -e "$(TMPDIR)/test.profraw" ] || (echo "No .profraw file"; exit 1) endif From e31addf7c358aba28ce0910e93d009397a72a05f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 12 Mar 2018 21:15:16 +0100 Subject: [PATCH 12/18] librustc_trans: Gate the preinliner with another -Z flag. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Emilio Cobos Álvarez --- src/librustc/session/config.rs | 3 +++ src/librustc_trans/llvm_util.rs | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 7f92a087ebfc8..9fd370c54be92 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1254,6 +1254,9 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, location if it's empty."), pgo_use: String = (String::new(), parse_string, [TRACKED], "Use PGO profile data from the given profile file."), + disable_instrumentation_preinliner: bool = + (false, parse_bool, [TRACKED], "Disable the instrumentation pre-inliner, \ + useful for profiling / PGO."), relro_level: Option = (None, parse_relro_level, [TRACKED], "choose which RELRO level to use"), nll: bool = (false, parse_bool, [UNTRACKED], diff --git a/src/librustc_trans/llvm_util.rs b/src/librustc_trans/llvm_util.rs index 12364b32d1163..1c8f09ce7b3f1 100644 --- a/src/librustc_trans/llvm_util.rs +++ b/src/librustc_trans/llvm_util.rs @@ -61,7 +61,9 @@ unsafe fn configure_llvm(sess: &Session) { add("rustc"); // fake program name if sess.time_llvm_passes() { add("-time-passes"); } if sess.print_llvm_passes() { add("-debug-pass=Structure"); } - add("-disable-preinline"); + if sess.opts.debugging_opts.disable_instrumentation_preinliner { + add("-disable-preinline"); + } for arg in &sess.opts.cg.llvm_args { add(&(*arg)); From 8a4cebd16f4fa3ba2234c6d4453051b568c6d904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 12 Mar 2018 21:18:01 +0100 Subject: [PATCH 13/18] librustc_trans: Turn PGO diagnostics into warnings. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit They should at least be that, they usually warn about control flow mismatches, and or the profile being useless, which looks like at least a warning to me. Signed-off-by: Emilio Cobos Álvarez --- src/librustc_trans/back/write.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs index 26cdca1cdbf4d..2cbb88fed05c2 100644 --- a/src/librustc_trans/back/write.rs +++ b/src/librustc_trans/back/write.rs @@ -502,7 +502,7 @@ unsafe extern "C" fn diagnostic_handler(info: DiagnosticInfoRef, user: *mut c_vo let msg = llvm::build_string(|s| { llvm::LLVMRustWriteDiagnosticInfoToString(diagnostic_ref, s) }).expect("non-UTF8 PGO diagnostic"); - diag_handler.note_without_error(&msg); + diag_handler.warn(&msg); } llvm::diagnostic::UnknownDiagnostic(..) => {}, } From 4053e25bfb55b6e1bf6766158ccd06cb87de79c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 13 Mar 2018 12:40:57 +0100 Subject: [PATCH 14/18] librustc_trans: Mark some profiler symbols as exported to avoid LTO removing them. --- src/librustc_trans/back/symbol_export.rs | 14 ++++++++++++++ src/test/run-make/pgo-gen-lto/Makefile | 8 ++++++++ src/test/run-make/pgo-gen-lto/test.rs | 11 +++++++++++ 3 files changed, 33 insertions(+) create mode 100644 src/test/run-make/pgo-gen-lto/Makefile create mode 100644 src/test/run-make/pgo-gen-lto/test.rs diff --git a/src/librustc_trans/back/symbol_export.rs b/src/librustc_trans/back/symbol_export.rs index fd79ae7435ed1..d205e6ca4eda6 100644 --- a/src/librustc_trans/back/symbol_export.rs +++ b/src/librustc_trans/back/symbol_export.rs @@ -223,6 +223,20 @@ fn exported_symbols_provider_local<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } } + if tcx.sess.opts.debugging_opts.pgo_gen.is_some() { + // These are weak symbols that point to the profile version and the + // profile name, which need to be treated as exported so LTO doesn't nix + // them. + const PROFILER_WEAK_SYMBOLS: [&'static str; 2] = [ + "__llvm_profile_raw_version", + "__llvm_profile_filename", + ]; + for sym in &PROFILER_WEAK_SYMBOLS { + let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(sym)); + symbols.push((exported_symbol, SymbolExportLevel::C)); + } + } + if tcx.sess.crate_types.borrow().contains(&config::CrateTypeDylib) { let symbol_name = metadata_symbol_name(tcx); let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(&symbol_name)); diff --git a/src/test/run-make/pgo-gen-lto/Makefile b/src/test/run-make/pgo-gen-lto/Makefile new file mode 100644 index 0000000000000..5de2c707f3579 --- /dev/null +++ b/src/test/run-make/pgo-gen-lto/Makefile @@ -0,0 +1,8 @@ +-include ../tools.mk + +all: +ifeq ($(PROFILER_SUPPORT),1) + $(RUSTC) -Copt-level=3 -Clto=fat -Z pgo-gen=test.profraw test.rs + $(call RUN,test) || exit 1 + [ -e "$(TMPDIR)/test.profraw" ] || (echo "No .profraw file"; exit 1) +endif diff --git a/src/test/run-make/pgo-gen-lto/test.rs b/src/test/run-make/pgo-gen-lto/test.rs new file mode 100644 index 0000000000000..3f07b46791d22 --- /dev/null +++ b/src/test/run-make/pgo-gen-lto/test.rs @@ -0,0 +1,11 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() {} From e155ecdc9714f3ac76b554dc15ba06e219f576e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 15 Mar 2018 16:56:45 +0100 Subject: [PATCH 15/18] try to fix the build on older LLVM versions. --- src/librustc_llvm/ffi.rs | 1 + src/librustc_trans/base.rs | 7 +++++++ src/rustllvm/PassWrapper.cpp | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/src/librustc_llvm/ffi.rs b/src/librustc_llvm/ffi.rs index 1271773fa02b3..d9c18e6cf0c40 100644 --- a/src/librustc_llvm/ffi.rs +++ b/src/librustc_llvm/ffi.rs @@ -1739,6 +1739,7 @@ extern "C" { pub fn LLVMRustModuleCost(M: ModuleRef) -> u64; pub fn LLVMRustThinLTOAvailable() -> bool; + pub fn LLVMRustPGOAvailable() -> bool; pub fn LLVMRustWriteThinBitcodeToFile(PMR: PassManagerRef, M: ModuleRef, BC: *const c_char) -> bool; diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs index 56eece9f31e7e..c839e5340f58d 100644 --- a/src/librustc_trans/base.rs +++ b/src/librustc_trans/base.rs @@ -708,6 +708,13 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } } + if (tcx.sess.opts.debugging_opts.pgo_gen.is_some() || + !tcx.sess.opts.debugging_opts.pgo_use.is_empty()) && + unsafe { !llvm::LLVMRustPGOAvailable() } + { + tcx.sess.fatal("this compiler's LLVM does not support PGO"); + } + let crate_hash = tcx.crate_hash(LOCAL_CRATE); let link_meta = link::build_link_meta(crate_hash); diff --git a/src/rustllvm/PassWrapper.cpp b/src/rustllvm/PassWrapper.cpp index bee8ae5853f86..3d5cce81278ac 100644 --- a/src/rustllvm/PassWrapper.cpp +++ b/src/rustllvm/PassWrapper.cpp @@ -44,6 +44,10 @@ #include "llvm-c/Transforms/PassManagerBuilder.h" +#if LLVM_VERSION_GE(4, 0) +#define PGO_AVAILABLE +#endif + using namespace llvm; using namespace llvm::legacy; @@ -435,6 +439,8 @@ extern "C" void LLVMRustConfigurePassManagerBuilder( unwrap(PMBR)->SLPVectorize = SLPVectorize; unwrap(PMBR)->OptLevel = fromRust(OptLevel); unwrap(PMBR)->LoopVectorize = LoopVectorize; + +#ifdef PGO_AVAILABLE if (PGOGenPath) { assert(!PGOUsePath); unwrap(PMBR)->EnablePGOInstrGen = true; @@ -444,6 +450,9 @@ extern "C" void LLVMRustConfigurePassManagerBuilder( assert(!PGOGenPath); unwrap(PMBR)->PGOInstrUse = PGOUsePath; } +#else + assert(!PGOGenPath && !PGOUsePath && "Should've caught earlier"); +#endif } // Unfortunately, the LLVM C API doesn't provide a way to set the `LibraryInfo` @@ -776,6 +785,15 @@ LLVMRustThinLTOAvailable() { #endif } +extern "C" bool +LLVMRustPGOAvailable() { +#ifdef PGO_AVAILABLE + return true; +#else + return false; +#endif +} + #if LLVM_VERSION_GE(4, 0) // Here you'll find an implementation of ThinLTO as used by the Rust compiler From 96b87296ce89d5b5cb53f21cd7893b3ae3d80c10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 19 Mar 2018 22:29:58 +0100 Subject: [PATCH 16/18] Move linker code to the Linker trait instead. --- src/librustc_trans/back/link.rs | 16 ++-------------- src/librustc_trans/back/linker.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index 19f0d5866ef34..75ba83a7c620a 100644 --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -1085,20 +1085,8 @@ fn link_args(cmd: &mut Linker, cmd.build_static_executable(); } - // If we're doing PGO generation stuff and on a GNU-like linker, use the - // "-u" flag to properly pull in the profiler runtime bits. - // - // This is because LLVM otherwise won't add the needed initialization for us - // on Linux (though the extra flag should be harmless if it does). - // - // See https://reviews.llvm.org/D14033 and https://reviews.llvm.org/D14030. - // - // Though it may be worth to try to revert those changes upstream, since the - // overhead of the initialization should be minor. - if sess.opts.debugging_opts.pgo_gen.is_some() && - sess.target.target.options.linker_is_gnu - { - cmd.args(&["-u".to_owned(), "__llvm_profile_runtime".to_owned()]); + if sess.opts.debugging_opts.pgo_gen.is_some() { + cmd.pgo_gen(); } // FIXME (#2397): At some point we want to rpath our guesses as to diff --git a/src/librustc_trans/back/linker.rs b/src/librustc_trans/back/linker.rs index 9bd7d83a19185..c8bbfed41eb51 100644 --- a/src/librustc_trans/back/linker.rs +++ b/src/librustc_trans/back/linker.rs @@ -117,6 +117,7 @@ pub trait Linker { fn partial_relro(&mut self); fn no_relro(&mut self); fn optimize(&mut self); + fn pgo_gen(&mut self); fn debuginfo(&mut self); fn no_default_libraries(&mut self); fn build_dylib(&mut self, out_filename: &Path); @@ -280,6 +281,24 @@ impl<'a> Linker for GccLinker<'a> { } } + fn pgo_gen(&mut self) { + if !self.sess.target.target.options.linker_is_gnu { return } + + // If we're doing PGO generation stuff and on a GNU-like linker, use the + // "-u" flag to properly pull in the profiler runtime bits. + // + // This is because LLVM otherwise won't add the needed initialization + // for us on Linux (though the extra flag should be harmless if it + // does). + // + // See https://reviews.llvm.org/D14033 and https://reviews.llvm.org/D14030. + // + // Though it may be worth to try to revert those changes upstream, since + // the overhead of the initialization should be minor. + self.cmd.arg("-u"); + self.cmd.arg("__llvm_profile_runtime"); + } + fn debuginfo(&mut self) { // Don't do anything special here for GNU-style linkers. } @@ -509,6 +528,10 @@ impl<'a> Linker for MsvcLinker<'a> { // Needs more investigation of `/OPT` arguments } + fn pgo_gen(&mut self) { + // Nothing needed here. + } + fn debuginfo(&mut self) { // This will cause the Microsoft linker to generate a PDB file // from the CodeView line tables in the object files. @@ -712,6 +735,10 @@ impl<'a> Linker for EmLinker<'a> { self.cmd.args(&["--memory-init-file", "0"]); } + fn pgo_gen(&mut self) { + // noop, but maybe we need something like the gnu linker? + } + fn debuginfo(&mut self) { // Preserve names or generate source maps depending on debug info self.cmd.arg(match self.sess.opts.debuginfo { @@ -877,6 +904,9 @@ impl Linker for WasmLd { fn optimize(&mut self) { } + fn pgo_gen(&mut self) { + } + fn debuginfo(&mut self) { } From 5af2f80fdd152bc9ffb6f19043de8967fe9d0071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 25 Mar 2018 03:29:15 +0200 Subject: [PATCH 17/18] pgo: Move the tests to run-make-fulldeps, and make the profile file be in the tmp directory properly. --- src/test/{run-make => run-make-fulldeps}/pgo-gen-lto/Makefile | 2 +- src/test/{run-make => run-make-fulldeps}/pgo-gen-lto/test.rs | 0 src/test/{run-make => run-make-fulldeps}/pgo-gen/Makefile | 2 +- src/test/{run-make => run-make-fulldeps}/pgo-gen/test.rs | 0 4 files changed, 2 insertions(+), 2 deletions(-) rename src/test/{run-make => run-make-fulldeps}/pgo-gen-lto/Makefile (67%) rename src/test/{run-make => run-make-fulldeps}/pgo-gen-lto/test.rs (100%) rename src/test/{run-make => run-make-fulldeps}/pgo-gen/Makefile (73%) rename src/test/{run-make => run-make-fulldeps}/pgo-gen/test.rs (100%) diff --git a/src/test/run-make/pgo-gen-lto/Makefile b/src/test/run-make-fulldeps/pgo-gen-lto/Makefile similarity index 67% rename from src/test/run-make/pgo-gen-lto/Makefile rename to src/test/run-make-fulldeps/pgo-gen-lto/Makefile index 5de2c707f3579..e8c695f52bec0 100644 --- a/src/test/run-make/pgo-gen-lto/Makefile +++ b/src/test/run-make-fulldeps/pgo-gen-lto/Makefile @@ -2,7 +2,7 @@ all: ifeq ($(PROFILER_SUPPORT),1) - $(RUSTC) -Copt-level=3 -Clto=fat -Z pgo-gen=test.profraw test.rs + $(RUSTC) -Copt-level=3 -Clto=fat -Z pgo-gen="$(TMPDIR)/test.profraw" test.rs $(call RUN,test) || exit 1 [ -e "$(TMPDIR)/test.profraw" ] || (echo "No .profraw file"; exit 1) endif diff --git a/src/test/run-make/pgo-gen-lto/test.rs b/src/test/run-make-fulldeps/pgo-gen-lto/test.rs similarity index 100% rename from src/test/run-make/pgo-gen-lto/test.rs rename to src/test/run-make-fulldeps/pgo-gen-lto/test.rs diff --git a/src/test/run-make/pgo-gen/Makefile b/src/test/run-make-fulldeps/pgo-gen/Makefile similarity index 73% rename from src/test/run-make/pgo-gen/Makefile rename to src/test/run-make-fulldeps/pgo-gen/Makefile index bc5cef2370c64..7dc227b5a145a 100644 --- a/src/test/run-make/pgo-gen/Makefile +++ b/src/test/run-make-fulldeps/pgo-gen/Makefile @@ -2,7 +2,7 @@ all: ifeq ($(PROFILER_SUPPORT),1) - $(RUSTC) -g -Z pgo-gen=test.profraw test.rs + $(RUSTC) -g -Z pgo-gen="$(TMPDIR)/test.profraw" test.rs $(call RUN,test) || exit 1 [ -e "$(TMPDIR)/test.profraw" ] || (echo "No .profraw file"; exit 1) endif diff --git a/src/test/run-make/pgo-gen/test.rs b/src/test/run-make-fulldeps/pgo-gen/test.rs similarity index 100% rename from src/test/run-make/pgo-gen/test.rs rename to src/test/run-make-fulldeps/pgo-gen/test.rs From 1e1d907e6a407a474d46af343678e45c4eb327f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 25 Mar 2018 23:17:47 +0200 Subject: [PATCH 18/18] pgo: Blindly try to fix Windows build. --- src/libprofiler_builtins/build.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libprofiler_builtins/build.rs b/src/libprofiler_builtins/build.rs index 6c7407760dfa5..8d6c7d68dfe23 100644 --- a/src/libprofiler_builtins/build.rs +++ b/src/libprofiler_builtins/build.rs @@ -43,6 +43,8 @@ fn main() { cfg.define("strdup", Some("_strdup")); cfg.define("open", Some("_open")); cfg.define("fdopen", Some("_fdopen")); + cfg.define("getpid", Some("_getpid")); + cfg.define("fileno", Some("_fileno")); } else { // Turn off various features of gcc and such, mostly copying // compiler-rt's build system already