about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJamie Cunliffe <Jamie.Cunliffe@arm.com>2021-07-08 16:50:29 +0100
committerJamie Cunliffe <Jamie.Cunliffe@arm.com>2021-07-14 13:32:51 +0100
commit7c98b3cfe30d3c4e3ba6ad27bc711819e34382d6 (patch)
tree4e55756fab2f4d098ffad5fa8bc30c72ce3712bf
parent95fb1315217976ff4c268bb03c9b4132f0dfa9fd (diff)
downloadrust-7c98b3cfe30d3c4e3ba6ad27bc711819e34382d6.tar.gz
rust-7c98b3cfe30d3c4e3ba6ad27bc711819e34382d6.zip
Keep metadata when using gc-sections with profile-generate.
When building with profile-generate request that metadata is kept
during the gc_sections call, as this can sometimes strip out profile
data.
This missing information in the prof files can then result in missing
functions when using the profile information.
-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 59447e9de13..c9a0ef841bb 100644
--- a/compiler/rustc_codegen_ssa/src/back/link.rs
+++ b/compiler/rustc_codegen_ssa/src/back/link.rs
@@ -1931,7 +1931,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);
     }