[patch] AVR: Sort .text.* input sections by their name.

Georg-Johann Lay via Binutils <[email protected]> Mon, 20 Jul 2026 20:44:51 +0200
Newsgroups gmane.comp.gnu.binutils
Message-ID <[email protected]>
This patch sorts the .text.* input sections by their name
in order to increase code locality, e.g. for code from
libgcc and AVR-LibC.  For example, libgcc puts their
multiplications and helpers in .text.libgcc.mul, but
without SORT the linker may locate functions related by
their input section far apart, inserting function from
unrelated input sections in between them.

Ok for trunk?

Johann

--

AVR: Sort .text.* input sections by their name.

This patch sorts the .text.* input sections by their name
in order to increase code locality, e.g. for code from
libgcc and AVR-LibC.  For example, libgcc puts their
multiplications and helpers in .text.libgcc.mul, but
without SORT the linker may locate functions related by
their input section far apart, inserting function from
unrelated input sections in between them.

	PR ld/34415
ld/
	* scripttempl/avr.sc (text): SORT *(.text.*) input sections.
	by their name.

diff --git a/ld/scripttempl/avr.sc b/ld/scripttempl/avr.sc
index b3cf421a78b..e918181700b 100644
--- a/ld/scripttempl/avr.sc
+++ b/ld/scripttempl/avr.sc
@@ -248,7 +248,7 @@ cat <<EOF
      KEEP (*(.init9))}
      *(.text)
      ${RELOCATING+. = ALIGN(2);
-    *(.text.*)
+    *(SORT(.text.*))
      . = ALIGN(2);
      *(.fini9)  /* _exit() starts here.  */
      KEEP (*(.fini9))