Index: lld/ELF/Writer.cpp =================================================================== --- lld/ELF/Writer.cpp +++ lld/ELF/Writer.cpp @@ -122,13 +122,18 @@ // When no SECTIONS is specified, emulate GNU ld's internal linker scripts // by grouping sections with certain prefixes. - // GNU ld places text sections with prefix ".text.hot.", ".text.unlikely.", - // ".text.startup." or ".text.exit." before others. We provide an option -z - // keep-text-section-prefix to group such sections into separate output - // sections. This is more flexible. See also sortISDBySectionOrder(). + // GNU ld places text sections with prefix ".text.hot.", ".text.unknown.", + // ".text.unlikely.", ".text.startup." or ".text.exit." before others. + // We provide an option -z keep-text-section-prefix to group such sections + // into separate output sections. This is more flexible. See also + // sortISDBySectionOrder(). + // ".text.unknown" means the hotness of the section is unknown. When + // SampleFDO is used, if a function doesn't have sample, it could be very + // cold or it could be a new function never being sampled. Those functions + // will be kept in the ".text.unknown" section. if (config->zKeepTextSectionPrefix) - for (StringRef v : - {".text.hot.", ".text.unlikely.", ".text.startup.", ".text.exit."}) + for (StringRef v : {".text.hot.", ".text.unknown.", ".text.unlikely.", + ".text.startup.", ".text.exit."}) if (isSectionPrefix(v, s->name)) return v.drop_back(); Index: lld/test/ELF/text-section-prefix.s =================================================================== --- lld/test/ELF/text-section-prefix.s +++ lld/test/ELF/text-section-prefix.s @@ -1,6 +1,7 @@ # REQUIRES: x86 ## -z keep-text-section-prefix separates text sections with prefix .text.hot, -## .text.unlikely, .text.startup, or .text.exit, in the absence of a SECTIONS command. +## .text.unknown, .text.unlikely, .text.startup, or .text.exit, in the absence +## of a SECTIONS command. # RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o # RUN: ld.lld %t.o -o %t1 @@ -13,9 +14,10 @@ # KEEP: [ 1] .text # KEEP-NEXT: [ 2] .text.hot -# KEEP-NEXT: [ 3] .text.startup -# KEEP-NEXT: [ 4] .text.exit -# KEEP-NEXT: [ 5] .text.unlikely +# KEEP-NEXT: [ 3] .text.unknown +# KEEP-NEXT: [ 4] .text.startup +# KEEP-NEXT: [ 5] .text.exit +# KEEP-NEXT: [ 6] .text.unlikely # NOKEEP: [ 1] .text # NOKEEP-NOT: .text @@ -29,6 +31,7 @@ # SCRIPT: .text # SCRIPT-NEXT: .text.f # SCRIPT-NEXT: .text.hot.f_hot +# SCRIPT-NEXT: .text.unknown.f_unknown # SCRIPT-NEXT: .text.startup.f_startup # SCRIPT-NEXT: .text.exit.f_exit # SCRIPT-NEXT: .text.unlikely.f_unlikely @@ -43,6 +46,9 @@ .section .text.hot.f_hot,"ax" nop +.section .text.unknown.f_unknown,"ax" + nop + .section .text.startup.f_startup,"ax" nop