about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-07-18 23:14:31 +0000
committerbors <bors@rust-lang.org>2021-07-18 23:14:31 +0000
commitb548d9f1c656953c3843693e060302c5c392d149 (patch)
tree3f532cdbf9c0c40b4f83264db22af8d95a1eccc9
parent59216858a323978a97593cba22b5ed84350a3783 (diff)
parent7c98b3cfe30d3c4e3ba6ad27bc711819e34382d6 (diff)
downloadrust-b548d9f1c656953c3843693e060302c5c392d149.tar.gz
rust-b548d9f1c656953c3843693e060302c5c392d149.zip
Auto merge of #87004 - JamieCunliffe:pgo-gc-sections, r=Mark-Simulacrum
Don't use gc-sections with profile-generate.

When building with profile-generate don't call gc_sections as this can
can sometimes strip out profile data. This missing information in the
prof files can then result in missing functions when using the profile
information.

#78226

r? `@Mark-Simulacrum`
-rw-r--r--compiler/rustc_codegen_ssa/src/back/link.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs
index 773a1c500b2..ab211e9daff 100644
--- a/compiler/rustc_codegen_ssa/src/back/link.rs
+++ b/compiler/rustc_codegen_ssa/src/back/link.rs
@@ -1934,7 +1934,12 @@ fn add_order_independent_options(
     // Try to strip as much out of the generated object by removing unused
     // sections if possible. See more comments in linker.rs
     if !sess.link_dead_code() {
-        let keep_metadata = crate_type == CrateType::Dylib;
+        // If PGO is enabled sometimes gc_sections will remove the profile data section
+        // as it appears to be unused. This can then cause the PGO profile file to lose
+        // some functions. If we are generating a profile we shouldn't strip those metadata
+        // sections to ensure we have all the data for PGO.
+        let keep_metadata =
+            crate_type == CrateType::Dylib || sess.opts.cg.profile_generate.enabled();
         cmd.gc_sections(keep_metadata);
     }