Skip to content

Commit 7c98b3c

Browse files
committed
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.
1 parent 95fb131 commit 7c98b3c

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
@@ -1931,7 +1931,12 @@ fn add_order_independent_options(
19311931
// Try to strip as much out of the generated object by removing unused
19321932
// sections if possible. See more comments in linker.rs
19331933
if !sess.link_dead_code() {
1934-
let keep_metadata = crate_type == CrateType::Dylib;
1934+
// If PGO is enabled sometimes gc_sections will remove the profile data section
1935+
// as it appears to be unused. This can then cause the PGO profile file to lose
1936+
// some functions. If we are generating a profile we shouldn't strip those metadata
1937+
// sections to ensure we have all the data for PGO.
1938+
let keep_metadata =
1939+
crate_type == CrateType::Dylib || sess.opts.cg.profile_generate.enabled();
19351940
cmd.gc_sections(keep_metadata);
19361941
}
19371942

0 commit comments

Comments
 (0)