Re: [PATCH v6 3/7] Adjust symbol ordering in text output section

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On 2024-10-26 07:14, Rong Xu wrote:
When the -ffunction-sections compiler option is enabled, each function
is placed in a separate section named .text.function_name rather than
putting all functions in a single .text section.

However, using -function-sections can cause problems with the
linker script. The comments included in include/asm-generic/vmlinux.lds.h
note these issues.:
   “TEXT_MAIN here will match .text.fixup and .text.unlikely if dead
    code elimination is enabled, so these sections should be converted
    to use ".." first.”

It is unclear whether there is a straightforward method for converting
a suffix to "..".

This patch modifies the order of subsections within the text output
section. Specifically, it repositions sections with certain fixed patterns
(for example .text.unlikely) before TEXT_MAIN, ensuring that they are
grouped and matched together. It also places .text.hot section at the
beginning of a page to help the TLB performance.

Note that the limitation arises because the linker script employs glob
patterns instead of regular expressions for string matching. While there
is a method to maintain the current order using complex patterns, this
significantly complicates the pattern and increases the likelihood of
errors.

This patch also changes vmlinux.lds.S for the sparc64 architecture to
accommodate specific symbol placement requirements.

With this patch (622240ea8d71a75055399fd4b3cc2b190e44d2e2 in next-20241108) my Edgerouter 6P hangs on boot (Cavium Octeon III, mips64, running in big endian). It's using device tree passed from the vendored u-boot (attached in case it's relevant).

Disabling dead code elimination does not fix the issue.

Please let me know if there's anything else you need.

Regards,
Klara Modin


Co-developed-by: Han Shen <shenhan@xxxxxxxxxx>
Signed-off-by: Han Shen <shenhan@xxxxxxxxxx>
Signed-off-by: Rong Xu <xur@xxxxxxxxxx>
Suggested-by: Sriraman Tallam <tmsriram@xxxxxxxxxx>
Suggested-by: Krzysztof Pszeniczny <kpszeniczny@xxxxxxxxxx>
Tested-by: Yonghong Song <yonghong.song@xxxxxxxxx>
Tested-by: Yabin Cui <yabinc@xxxxxxxxxx>
Change-Id: I5202d40bc7e24f93c2bfb2f0d987e9dc57dec1b1
---
  arch/sparc/kernel/vmlinux.lds.S   |  5 +++++
  include/asm-generic/vmlinux.lds.h | 19 ++++++++++++-------
  2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/arch/sparc/kernel/vmlinux.lds.S b/arch/sparc/kernel/vmlinux.lds.S
index d317a843f7ea9..f1b86eb303404 100644
--- a/arch/sparc/kernel/vmlinux.lds.S
+++ b/arch/sparc/kernel/vmlinux.lds.S
@@ -48,6 +48,11 @@ SECTIONS
  	{
  		_text = .;
  		HEAD_TEXT
+	        ALIGN_FUNCTION();
+#ifdef CONFIG_SPARC64
+	        /* Match text section symbols in head_64.S first */
+	        *head_64.o(.text)
+#endif
  		TEXT_TEXT
  		SCHED_TEXT
  		LOCK_TEXT
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index eeadbaeccf88b..fd901951549c0 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -553,19 +553,24 @@
   * .text section. Map to function alignment to avoid address changes
   * during second ld run in second ld pass when generating System.map
   *
- * TEXT_MAIN here will match .text.fixup and .text.unlikely if dead
- * code elimination is enabled, so these sections should be converted
- * to use ".." first.
+ * TEXT_MAIN here will match symbols with a fixed pattern (for example,
+ * .text.hot or .text.unlikely) if dead code elimination or
+ * function-section is enabled. Match these symbols first before
+ * TEXT_MAIN to ensure they are grouped together.
+ *
+ * Also placing .text.hot section at the beginning of a page, this
+ * would help the TLB performance.
   */
  #define TEXT_TEXT							\
  		ALIGN_FUNCTION();					\
+		*(.text.asan.* .text.tsan.*)				\
+		*(.text.unknown .text.unknown.*)			\
+		*(.text.unlikely .text.unlikely.*)			\
+		. = ALIGN(PAGE_SIZE);					\
  		*(.text.hot .text.hot.*)				\
  		*(TEXT_MAIN .text.fixup)				\
-		*(.text.unlikely .text.unlikely.*)			\
-		*(.text.unknown .text.unknown.*)			\
  		NOINSTR_TEXT						\
-		*(.ref.text)						\
-		*(.text.asan.* .text.tsan.*)
+		*(.ref.text)
/* sched.text is aling to function alignment to secure we have same
# bad: [291b13f025250e2fa3b5e2ff714aaaa227dff02c] of: WARN on deprecated #address-cells/#size-cells handling
git bisect start 'HEAD'
# status: waiting for good commit(s), bad commit known
# good: [bfc64d9b7e8cac82be6b8629865e137d962578f8] Merge tag 'net-6.12-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net
git bisect good bfc64d9b7e8cac82be6b8629865e137d962578f8
# bad: [5090ed9c92a1ba84f8563486550c6bf0b39954f2] Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git
git bisect bad 5090ed9c92a1ba84f8563486550c6bf0b39954f2
# bad: [dbaafa9b8d4a351fb925efb44f4177cabc95d26d] Merge branch 'fs-next' of linux-next
git bisect bad dbaafa9b8d4a351fb925efb44f4177cabc95d26d
# bad: [d81b3235857fe7abd24ab2928a36626a0b4734b1] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/qcom/linux.git
git bisect bad d81b3235857fe7abd24ab2928a36626a0b4734b1
# bad: [cc030679964c0cf8e2217fa57935c19d851aa9ea] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/rmk/linux.git
git bisect bad cc030679964c0cf8e2217fa57935c19d851aa9ea
# good: [5d2ae3246a2d15e2d384637ee55fc0320546be63] foo
git bisect good 5d2ae3246a2d15e2d384637ee55fc0320546be63
# bad: [10540b9bb270cbffbc56ca2f828439675abbdccc] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git
git bisect bad 10540b9bb270cbffbc56ca2f828439675abbdccc
# good: [e038e395a05e3a1cf2f5450bb2d08adcffca80b4] Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6.git
git bisect good e038e395a05e3a1cf2f5450bb2d08adcffca80b4
# good: [aded6a2e0817d76cdd8010ea7c0b217b55cbe78b] Merge branch 'for-linux-next-fixes' of https://gitlab.freedesktop.org/drm/misc/kernel.git
git bisect good aded6a2e0817d76cdd8010ea7c0b217b55cbe78b
# good: [375a4f4ea719ad68e305373cfe0f77ecd1378531] kconfig: qconf: remove unnecessary lastWindowClosed() signal connection
git bisect good 375a4f4ea719ad68e305373cfe0f77ecd1378531
# good: [397a479b511df4e6e7c665d7d8991943645b4cab] kbuild: simplify rustfmt target
git bisect good 397a479b511df4e6e7c665d7d8991943645b4cab
# bad: [84712ea5d9b003d298b0df6f957d06bbcac99ef5] AutoFDO: Enable -ffunction-sections for the AutoFDO build
git bisect bad 84712ea5d9b003d298b0df6f957d06bbcac99ef5
# good: [18e885099f1c52755f054202525cb60d3edcda44] objtool: Fix unreachable instruction warnings for weak functions
git bisect good 18e885099f1c52755f054202525cb60d3edcda44
# bad: [9a92584c8ef545cf92299e4cadbe2148b93dafa1] vmlinux.lds.h: Add markers for text_unlikely and text_hot sections
git bisect bad 9a92584c8ef545cf92299e4cadbe2148b93dafa1
# bad: [622240ea8d71a75055399fd4b3cc2b190e44d2e2] vmlinux.lds.h: Adjust symbol ordering in text output section
git bisect bad 622240ea8d71a75055399fd4b3cc2b190e44d2e2
# first bad commit: [622240ea8d71a75055399fd4b3cc2b190e44d2e2] vmlinux.lds.h: Adjust symbol ordering in text output section

Attachment: er6p.dts.gz
Description: application/gzip

Attachment: er6p-boot-hang_console.log.gz
Description: application/gzip

Attachment: config.gz
Description: application/gzip

Attachment: er6p-working_dmesg.log.gz
Description: application/gzip


[Index of Archives]     [Kernel Development]     [DCCP]     [Linux ARM Development]     [Linux]     [Photo]     [Yosemite Help]     [Linux ARM Kernel]     [Linux SCSI]     [Linux x86_64]     [Linux Hams]

  Powered by Linux