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

Farid Zakaria via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 2 20:47:22 PDT 2026


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

## Motivation
The default output section name rules in `getOutputSectionName()` already merge .ldata.*, .lrodata.*, and .lbss.* into their respective output sections, but .ltext.* was missing from the prefix list. This caused mcmodel=large builds with `-ffunction-sections` to produce a separate output section for every function instead of combining them into .ltext.

We actually then ran into a bunch of esoteric issues because we the had to handle SHN_XINDEX binaries with >65535 sections, so in that sense it helped us find those gaps :)

## Changes
Add .ltext to the prefix list alongside the other large-model section prefixes.

>From 7d36cec945893c7c2121c5e2045a8fb018414d78 Mon Sep 17 00:00:00 2001
From: Farid Zakaria <fmzakari at fb.com>
Date: Thu, 2 Apr 2026 20:40:11 -0700
Subject: [PATCH] [lld][ELF] Merge .ltext.* input sections into .ltext output
 section

The default output section name rules in getOutputSectionName() already
merge .ldata.*, .lrodata.*, and .lbss.* into their respective output
sections, but .ltext.* was missing from the prefix list. This caused
mcmodel=large builds with -ffunction-sections to produce a separate
output section for every function instead of combining them into .ltext.

Add .ltext to the prefix list alongside the other large-model section
prefixes, and extend the existing x86-64-section-layout.s test to
verify that .ltext.1 is merged into .ltext.

Co-authored-by: Grigory Pastukhov <gpastukhov at meta.com>
---
 lld/ELF/LinkerScript.cpp             | 5 +++--
 lld/test/ELF/x86-64-section-layout.s | 7 ++++++-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 76f04a27b9997..6ca652782ad36 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -104,8 +104,9 @@ StringRef LinkerScript::getOutputSectionName(const InputSectionBase *s) const {
   }
 
   for (StringRef v : {".data.rel.ro", ".data",       ".rodata",
-                      ".bss.rel.ro",  ".bss",        ".ldata",
-                      ".lrodata",     ".lbss",       ".gcc_except_table",
+                      ".bss.rel.ro",  ".bss",        ".ltext",
+                      ".ldata",       ".lrodata",    ".lbss",
+                      ".gcc_except_table",
                       ".init_array",  ".fini_array", ".tbss",
                       ".tdata",       ".ARM.exidx",  ".ARM.extab",
                       ".ctors",       ".dtors",      ".sbss",
diff --git a/lld/test/ELF/x86-64-section-layout.s b/lld/test/ELF/x86-64-section-layout.s
index 1432271b885a8..cdd747be47c7d 100644
--- a/lld/test/ELF/x86-64-section-layout.s
+++ b/lld/test/ELF/x86-64-section-layout.s
@@ -173,12 +173,17 @@ SECTIONS {
 }
 
 #--- c.s
-## Test .ltext layout
+## Test .ltext layout. .ltext.1 should be merged into .ltext.
 .section .ltext,"axl", at progbits
 .globl f
 f:
   ret
 
+.section .ltext.1,"axl", at progbits
+.globl f1
+f1:
+  ret
+
 .section .ltext_w,"awxl", at progbits
 .globl g
 g:



More information about the llvm-commits mailing list