[lld] [lld][ELF] Merge .ltext.* input sections into .ltext output section (PR #190305)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 2 21:56:37 PDT 2026


================
@@ -96,13 +94,15 @@ StringRef LinkerScript::getOutputSectionName(const InputSectionBase *s) const {
   // cold parts in .text.split instead of .text.unlikely mitigates against poor
   // profile inaccuracy. Techniques such as hugepage remapping can make
   // conservative decisions at the section granularity.
-  if (isSectionPrefix(".text", s->name)) {
-    if (ctx.arg.zKeepTextSectionPrefix)
-      for (StringRef v : {".text.hot", ".text.unknown", ".text.unlikely",
-                          ".text.startup", ".text.exit", ".text.split"})
-        if (isSectionPrefix(v.substr(5), s->name.substr(5)))
-          return v;
-    return ".text";
+  for (StringRef prefix : {".text", ".ltext"}) {
+    if (isSectionPrefix(prefix, s->name)) {
+      if (ctx.arg.zKeepTextSectionPrefix)
+        for (StringRef v : {".text.hot", ".text.unknown", ".text.unlikely",
+                            ".text.startup", ".text.exit", ".text.split"})
+          if (isSectionPrefix(v.substr(5), s->name.substr(prefix.size())))
+            return saver().save(prefix + v.substr(5));
----------------
MaskRay wrote:

`saver().save` allocates a string for every input section that matches the pattern. This is a large performance regression.

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


More information about the llvm-commits mailing list