Skip to content

Commit b548d9f

Browse files
committed
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`
2 parents 5921685 + 7c98b3c commit b548d9f

File tree

1 file changed

+6
-1
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+6
-1
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1934,7 +1934,12 @@ fn add_order_independent_options(
19341934
// Try to strip as much out of the generated object by removing unused
19351935
// sections if possible. See more comments in linker.rs
19361936
if !sess.link_dead_code() {
1937-
let keep_metadata = crate_type == CrateType::Dylib;
1937+
// If PGO is enabled sometimes gc_sections will remove the profile data section
1938+
// as it appears to be unused. This can then cause the PGO profile file to lose
1939+
// some functions. If we are generating a profile we shouldn't strip those metadata
1940+
// sections to ensure we have all the data for PGO.
1941+
let keep_metadata =
1942+
crate_type == CrateType::Dylib || sess.opts.cg.profile_generate.enabled();
19381943
cmd.gc_sections(keep_metadata);
19391944
}
19401945

0 commit comments

Comments
 (0)