git: 3e76d05231b0 - main - kernel: Add defination of .init_array and .fini_array for all other platforms

From: Zhenlei Huang <zlei_at_FreeBSD.org>
Date: Mon, 02 Sep 2024 04:29:37 UTC
The branch main has been updated by zlei:

URL: https://cgit.FreeBSD.org/src/commit/?id=3e76d05231b0aa77d922bdbc9abf62d9747a91ab

commit 3e76d05231b0aa77d922bdbc9abf62d9747a91ab
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2024-09-02 04:26:48 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2024-09-02 04:26:48 +0000

    kernel: Add defination of .init_array and .fini_array for all other platforms
    
    Currently these sections are not used but defined only for amd64 and
    i386. Added them for all other platforms to keep all platforms in sync.
    There should be no functional change.
    
    This change is extracted from a bigger patch [1] of hselasky, with
    additional fix for the order of .fini_array section.
    
    1. https://reviews.freebsd.org/D40467
    
    Obtained from:  hselasky
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D45214
---
 sys/conf/ldscript.arm         | 14 ++++++++++++++
 sys/conf/ldscript.arm64       | 14 ++++++++++++++
 sys/conf/ldscript.powerpc     | 16 ++++++++++++++--
 sys/conf/ldscript.powerpc64   | 15 ++++++++++++++-
 sys/conf/ldscript.powerpc64le | 15 ++++++++++++++-
 sys/conf/ldscript.powerpcspe  | 16 ++++++++++++++--
 sys/conf/ldscript.riscv       | 14 ++++++++++++++
 7 files changed, 98 insertions(+), 6 deletions(-)

diff --git a/sys/conf/ldscript.arm b/sys/conf/ldscript.arm
index 0764c99f9042..e8d2db3f854b 100644
--- a/sys/conf/ldscript.arm
+++ b/sys/conf/ldscript.arm
@@ -83,6 +83,20 @@ SECTIONS
   }
   .data1   : { *(.data1) }
   . = ALIGN(32 / 8);
+  .init_array    :
+  {
+    PROVIDE_HIDDEN (__init_array_start = .);
+    KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*)))
+    KEEP (*(.init_array))
+    PROVIDE_HIDDEN (__init_array_end = .);
+  }
+  .fini_array    :
+  {
+    PROVIDE_HIDDEN (__fini_array_start = .);
+    KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*)))
+    KEEP (*(.fini_array))
+    PROVIDE_HIDDEN (__fini_array_end = .);
+  }
   _start_ctors = .;
   PROVIDE (start_ctors = .);
   .ctors         :
diff --git a/sys/conf/ldscript.arm64 b/sys/conf/ldscript.arm64
index 32af035105d0..0d50eef431cf 100644
--- a/sys/conf/ldscript.arm64
+++ b/sys/conf/ldscript.arm64
@@ -100,6 +100,20 @@ SECTIONS
   . = ALIGN(128);
   .data1   : { *(.data1) }
   . = ALIGN(32 / 8);
+  .init_array    :
+  {
+    PROVIDE_HIDDEN (__init_array_start = .);
+    KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*)))
+    KEEP (*(.init_array))
+    PROVIDE_HIDDEN (__init_array_end = .);
+  }
+  .fini_array    :
+  {
+    PROVIDE_HIDDEN (__fini_array_start = .);
+    KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*)))
+    KEEP (*(.fini_array))
+    PROVIDE_HIDDEN (__fini_array_end = .);
+  }
   _start_ctors = .;
   PROVIDE (start_ctors = .);
   .ctors         :
diff --git a/sys/conf/ldscript.powerpc b/sys/conf/ldscript.powerpc
index 0e11dd4459db..3a407a4dbf88 100644
--- a/sys/conf/ldscript.powerpc
+++ b/sys/conf/ldscript.powerpc
@@ -78,8 +78,20 @@ SECTIONS
   . = ALIGN(4096);
   .got            : { *(.got) }
   .got.plt        : { *(.got.plt) }
-
-
+  .init_array     :
+  {
+    PROVIDE_HIDDEN (__init_array_start = .);
+    KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*)))
+    KEEP (*(.init_array))
+    PROVIDE_HIDDEN (__init_array_end = .);
+  }
+  .fini_array     :
+  {
+    PROVIDE_HIDDEN (__fini_array_start = .);
+    KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*)))
+    KEEP (*(.fini_array))
+    PROVIDE_HIDDEN (__fini_array_end = .);
+  }
   .dynamic        : { *(.dynamic) } :kernel :dynamic
   /* Put .ctors and .dtors next to the .got2 section, so that the pointers
      get relocated with -mrelocatable. Also put in the .fixup pointers.
diff --git a/sys/conf/ldscript.powerpc64 b/sys/conf/ldscript.powerpc64
index 58a3dc69931b..a342a48b9daf 100644
--- a/sys/conf/ldscript.powerpc64
+++ b/sys/conf/ldscript.powerpc64
@@ -104,7 +104,20 @@ SECTIONS
   . = ALIGN(4096);
   .got       : ALIGN(8) { __tocbase = .; *(.got) }
   .toc       : ALIGN(8) { *(.toc) }
-
+  .init_array     :
+  {
+    PROVIDE_HIDDEN (__init_array_start = .);
+    KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*)))
+    KEEP (*(.init_array))
+    PROVIDE_HIDDEN (__init_array_end = .);
+  }
+  .fini_array     :
+  {
+    PROVIDE_HIDDEN (__fini_array_start = .);
+    KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*)))
+    KEEP (*(.fini_array))
+    PROVIDE_HIDDEN (__fini_array_end = .);
+  }
   .dynamic        : { *(.dynamic) } :kernel :dynamic
   /* Put .ctors and .dtors next to the .got2 section, so that the pointers
      get relocated with -mrelocatable. Also put in the .fixup pointers.
diff --git a/sys/conf/ldscript.powerpc64le b/sys/conf/ldscript.powerpc64le
index a65b39b3d9eb..1d5f3efe64fd 100644
--- a/sys/conf/ldscript.powerpc64le
+++ b/sys/conf/ldscript.powerpc64le
@@ -104,7 +104,20 @@ SECTIONS
   . = ALIGN(4096);
   .got       : ALIGN(8) { __tocbase = .; *(.got) }
   .toc       : ALIGN(8) { *(.toc) }
-
+  .init_array     :
+  {
+    PROVIDE_HIDDEN (__init_array_start = .);
+    KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*)))
+    KEEP (*(.init_array))
+    PROVIDE_HIDDEN (__init_array_end = .);
+  }
+  .fini_array     :
+  {
+    PROVIDE_HIDDEN (__fini_array_start = .);
+    KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*)))
+    KEEP (*(.fini_array))
+    PROVIDE_HIDDEN (__fini_array_end = .);
+  }
   .dynamic        : { *(.dynamic) } :kernel :dynamic
   /* Put .ctors and .dtors next to the .got2 section, so that the pointers
      get relocated with -mrelocatable. Also put in the .fixup pointers.
diff --git a/sys/conf/ldscript.powerpcspe b/sys/conf/ldscript.powerpcspe
index 66630aaabaae..fa82cbe8330f 100644
--- a/sys/conf/ldscript.powerpcspe
+++ b/sys/conf/ldscript.powerpcspe
@@ -79,8 +79,20 @@ SECTIONS
   . = ALIGN(4096);
   .got            : { *(.got) }
   .got.plt        : { *(.got.plt) }
-
-
+  .init_array     :
+  {
+    PROVIDE_HIDDEN (__init_array_start = .);
+    KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*)))
+    KEEP (*(.init_array))
+    PROVIDE_HIDDEN (__init_array_end = .);
+  }
+  .fini_array     :
+  {
+    PROVIDE_HIDDEN (__fini_array_start = .);
+    KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*)))
+    KEEP (*(.fini_array))
+    PROVIDE_HIDDEN (__fini_array_end = .);
+  }
   .dynamic        : { *(.dynamic) } :kernel :dynamic
   /* Put .ctors and .dtors next to the .got2 section, so that the pointers
      get relocated with -mrelocatable. Also put in the .fixup pointers.
diff --git a/sys/conf/ldscript.riscv b/sys/conf/ldscript.riscv
index b964a8739b7c..c730b423ccc2 100644
--- a/sys/conf/ldscript.riscv
+++ b/sys/conf/ldscript.riscv
@@ -71,6 +71,20 @@ SECTIONS
   }
   .data1   : { *(.data1) }
   . = ALIGN(32 / 8);
+  .init_array    :
+  {
+    PROVIDE_HIDDEN (__init_array_start = .);
+    KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*)))
+    KEEP (*(.init_array))
+    PROVIDE_HIDDEN (__init_array_end = .);
+  }
+  .fini_array    :
+  {
+    PROVIDE_HIDDEN (__fini_array_start = .);
+    KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*)))
+    KEEP (*(.fini_array))
+    PROVIDE_HIDDEN (__fini_array_end = .);
+  }
   _start_ctors = .;
   PROVIDE (start_ctors = .);
   .ctors         :