[lld] [lld][ELF] Introduce an option to keep data section prefix. (PR #148985)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 31 22:37:36 PDT 2025


================
@@ -103,13 +103,48 @@ 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)) {
+    StringRef secName = s->name;
+    if (!secName.consume_front(v))
+      continue;
+    if (!secName.empty() && secName[0] != '.') {
----------------
MaskRay wrote:

Nit: drop braces for single-line simple body.

https://github.com/llvm/llvm-project/pull/148985


More information about the llvm-commits mailing list