[lld] [lld][ELF] Introduce an option to keep data section prefix. (PR #148985)
Mingming Liu via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 23 12:24:36 PDT 2025
================
@@ -105,13 +110,41 @@ StringRef LinkerScript::getOutputSectionName(const InputSectionBase *s) const {
return ".text";
}
- for (StringRef v : {".data.rel.ro", ".data", ".rodata",
- ".bss.rel.ro", ".bss", ".ldata",
- ".lrodata", ".lbss", ".gcc_except_table",
- ".init_array", ".fini_array", ".tbss",
- ".tdata", ".ARM.exidx", ".ARM.extab",
- ".ctors", ".dtors", ".sbss",
- ".sdata", ".srodata"})
+ // When zKeepDataSectionPrefix is true, keep .hot and .unlikely suffixes
+ // in data sections.
+ static constexpr StringRef dataSectionPrefixes[] = {
+ ".data.rel.ro", ".data", ".rodata", ".bss.rel.ro", ".bss",
+ };
+
+ for (auto [index, v] : llvm::enumerate(dataSectionPrefixes)) {
+ if (isSectionPrefix(v, s->name)) {
+ // The .bss.rel.ro section is considered rarely accessed. So this section
+ // is not partitioned and zKeepDataSectionPrefix is not applied to
+ // make the executable simpler with fewer elf sections.
+ if (ctx.arg.zKeepDataSectionPrefix && index != 3) {
+ if (isSectionPrefix(".hot", s->name.substr(v.size())))
----------------
mingmingl-llvm wrote:
Incorporate this by adding a helper function `trimSectionPrefix`. Since this function is only called once, I'm open to remove `trimSectionPrefix` and inline its content at the callsite.
https://github.com/llvm/llvm-project/pull/148985
More information about the llvm-commits
mailing list