Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 15 Dec 2025 18:18:41 +0000
From:      Jessica Clarke <jrtc27@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 3d292b9ee8cf - stable/13 - libc/csu: Unify INIT_RELOCS across architectures
Message-ID:  <69405101.25a36.142e428e@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch stable/13 has been updated by jrtc27:

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

commit 3d292b9ee8cf4efc35c07f69bb9aae41a3f36ef8
Author:     Jessica Clarke <jrtc27@FreeBSD.org>
AuthorDate: 2024-10-18 23:48:52 +0000
Commit:     Jessica Clarke <jrtc27@FreeBSD.org>
CommitDate: 2025-12-15 17:56:35 +0000

    libc/csu: Unify INIT_RELOCS across architectures
    
    Some architectures don't need any arguments, whilst others need auxargs,
    which they get by passing in env thanks to INIT_RELOCS referencing the
    local variable in __libc_start1(_gcrt) by name. This is unnecessarily
    confusing, fragile (one has to look at INIT_IRELOCS's definition to see
    that it uses env) and duplicates code between architectures.
    
    Instead, implement it more like rtld-elf. Each architecture provides an
    ifunc_init that takes the auxargs directly, and those that don't need it
    can just ignore it.
    
    Reviewed by:    kib
    MFC after:      1 month
    Differential Revision:  https://reviews.freebsd.org/D47188
    
    (cherry picked from commit 9684658e35ab033c79e0519e3681d9a194976b71)
---
 lib/libc/csu/aarch64/Makefile.inc    |  3 +--
 lib/libc/csu/aarch64/reloc.c         |  6 ++++++
 lib/libc/csu/amd64/Makefile.inc      |  3 +--
 lib/libc/csu/amd64/reloc.c           |  3 ++-
 lib/libc/csu/arm/Makefile.inc        |  3 +--
 lib/libc/csu/i386/Makefile.inc       |  3 +--
 lib/libc/csu/i386/reloc.c            |  3 ++-
 lib/libc/csu/libc_start1.c           | 28 ++++++++++++++++++++--------
 lib/libc/csu/mips/Makefile.inc       |  3 +--
 lib/libc/csu/powerpc/Makefile.inc    |  3 +--
 lib/libc/csu/powerpc64/Makefile.inc  |  3 +--
 lib/libc/csu/powerpc64/reloc.c       |  9 +--------
 lib/libc/csu/powerpcspe/Makefile.inc |  3 +--
 lib/libc/csu/riscv/Makefile.inc      |  3 +--
 lib/libc/csu/riscv/reloc.c           |  9 +--------
 15 files changed, 41 insertions(+), 44 deletions(-)

diff --git a/lib/libc/csu/aarch64/Makefile.inc b/lib/libc/csu/aarch64/Makefile.inc
index b3420a638164..6c315c5e2624 100644
--- a/lib/libc/csu/aarch64/Makefile.inc
+++ b/lib/libc/csu/aarch64/Makefile.inc
@@ -1,4 +1,3 @@
 #
 
-CFLAGS+=	-DCRT_IRELOC_RELA \
-		-DINIT_IRELOCS=""
+CFLAGS+=	-DCRT_IRELOC_RELA
diff --git a/lib/libc/csu/aarch64/reloc.c b/lib/libc/csu/aarch64/reloc.c
index 7f5dff497fe2..4ba7920bcb07 100644
--- a/lib/libc/csu/aarch64/reloc.c
+++ b/lib/libc/csu/aarch64/reloc.c
@@ -25,6 +25,12 @@
  */
 
 #include <sys/cdefs.h>
+
+static void
+ifunc_init(const Elf_Auxinfo *aux __unused)
+{
+}
+
 static void
 crt1_handle_rela(const Elf_Rela *r)
 {
diff --git a/lib/libc/csu/amd64/Makefile.inc b/lib/libc/csu/amd64/Makefile.inc
index f14033217580..6c315c5e2624 100644
--- a/lib/libc/csu/amd64/Makefile.inc
+++ b/lib/libc/csu/amd64/Makefile.inc
@@ -1,4 +1,3 @@
 #
 
-CFLAGS+=	-DCRT_IRELOC_RELA \
-		-DINIT_IRELOCS="init_cpu_features()"
+CFLAGS+=	-DCRT_IRELOC_RELA
diff --git a/lib/libc/csu/amd64/reloc.c b/lib/libc/csu/amd64/reloc.c
index 654958819271..f1f83db9a391 100644
--- a/lib/libc/csu/amd64/reloc.c
+++ b/lib/libc/csu/amd64/reloc.c
@@ -24,6 +24,7 @@
  */
 
 #include <sys/cdefs.h>
+
 #include <machine/specialreg.h>
 #include <machine/cpufunc.h>
 
@@ -31,7 +32,7 @@ static uint32_t cpu_feature, cpu_feature2;
 static uint32_t cpu_stdext_feature, cpu_stdext_feature2;
 
 static void
-init_cpu_features(void)
+ifunc_init(const Elf_Auxinfo *aux __unused)
 {
 	u_int p[4];
 
diff --git a/lib/libc/csu/arm/Makefile.inc b/lib/libc/csu/arm/Makefile.inc
index 2534e6579f38..ddead75f874d 100644
--- a/lib/libc/csu/arm/Makefile.inc
+++ b/lib/libc/csu/arm/Makefile.inc
@@ -1,4 +1,3 @@
 #
 
-CFLAGS+=	-DCRT_IRELOC_SUPPRESS \
-		-DINIT_IRELOCS=""
+CFLAGS+=	-DCRT_IRELOC_SUPPRESS
diff --git a/lib/libc/csu/i386/Makefile.inc b/lib/libc/csu/i386/Makefile.inc
index f3f8c2b176ce..32018000e1f2 100644
--- a/lib/libc/csu/i386/Makefile.inc
+++ b/lib/libc/csu/i386/Makefile.inc
@@ -1,4 +1,3 @@
 #
 
-CFLAGS+=	-DCRT_IRELOC_REL \
-		-DINIT_IRELOCS="init_cpu_features()"
+CFLAGS+=	-DCRT_IRELOC_REL
diff --git a/lib/libc/csu/i386/reloc.c b/lib/libc/csu/i386/reloc.c
index d617f35dc665..7097f58d8f26 100644
--- a/lib/libc/csu/i386/reloc.c
+++ b/lib/libc/csu/i386/reloc.c
@@ -24,6 +24,7 @@
  */
 
 #include <sys/cdefs.h>
+
 #include <machine/specialreg.h>
 #include <machine/cpufunc.h>
 
@@ -31,7 +32,7 @@ static uint32_t cpu_feature, cpu_feature2;
 static uint32_t cpu_stdext_feature, cpu_stdext_feature2;
 
 static void
-init_cpu_features(void)
+ifunc_init(const Elf_Auxinfo *aux __unused)
 {
 	u_int cpuid_supported, p[4];
 
diff --git a/lib/libc/csu/libc_start1.c b/lib/libc/csu/libc_start1.c
index d6a973bf0fe0..7296893efd57 100644
--- a/lib/libc/csu/libc_start1.c
+++ b/lib/libc/csu/libc_start1.c
@@ -135,6 +135,24 @@ handle_argv(int argc, char *argv[], char **env)
 	}
 }
 
+static void
+handle_irelocs(char *env[])
+{
+#ifndef CRT_IRELOC_SUPPRESS
+	const Elf_Auxinfo *aux;
+
+	/* Find the auxiliary vector on the stack. */
+	while (*env++ != 0)	/* Skip over environment, and NULL terminator */
+		;
+	aux = (const Elf_Auxinfo *)env;
+
+	ifunc_init(aux);
+	process_irelocs();
+#else
+	(void)env;
+#endif
+}
+
 void
 __libc_start1(int argc, char *argv[], char *env[], void (*cleanup)(void),
     int (*mainX)(int, char *[], char *[]))
@@ -144,10 +162,7 @@ __libc_start1(int argc, char *argv[], char *env[], void (*cleanup)(void),
 	if (&_DYNAMIC != NULL) {
 		atexit(cleanup);
 	} else {
-#ifndef CRT_IRELOC_SUPPRESS
-		INIT_IRELOCS;
-		process_irelocs();
-#endif
+		handle_irelocs(env);
 		_init_tls();
 	}
 
@@ -169,10 +184,7 @@ __libc_start1_gcrt(int argc, char *argv[], char *env[],
 	if (&_DYNAMIC != NULL) {
 		atexit(cleanup);
 	} else {
-#ifndef CRT_IRELOC_SUPPRESS
-		INIT_IRELOCS;
-		process_irelocs();
-#endif
+		handle_irelocs(env);
 		_init_tls();
 	}
 
diff --git a/lib/libc/csu/mips/Makefile.inc b/lib/libc/csu/mips/Makefile.inc
index 2534e6579f38..ddead75f874d 100644
--- a/lib/libc/csu/mips/Makefile.inc
+++ b/lib/libc/csu/mips/Makefile.inc
@@ -1,4 +1,3 @@
 #
 
-CFLAGS+=	-DCRT_IRELOC_SUPPRESS \
-		-DINIT_IRELOCS=""
+CFLAGS+=	-DCRT_IRELOC_SUPPRESS
diff --git a/lib/libc/csu/powerpc/Makefile.inc b/lib/libc/csu/powerpc/Makefile.inc
index 2534e6579f38..ddead75f874d 100644
--- a/lib/libc/csu/powerpc/Makefile.inc
+++ b/lib/libc/csu/powerpc/Makefile.inc
@@ -1,4 +1,3 @@
 #
 
-CFLAGS+=	-DCRT_IRELOC_SUPPRESS \
-		-DINIT_IRELOCS=""
+CFLAGS+=	-DCRT_IRELOC_SUPPRESS
diff --git a/lib/libc/csu/powerpc64/Makefile.inc b/lib/libc/csu/powerpc64/Makefile.inc
index 5d59d40eb393..6c315c5e2624 100644
--- a/lib/libc/csu/powerpc64/Makefile.inc
+++ b/lib/libc/csu/powerpc64/Makefile.inc
@@ -1,4 +1,3 @@
 #
 
-CFLAGS+=	-DCRT_IRELOC_RELA \
-		-DINIT_IRELOCS="init_cpu_features(env)"
+CFLAGS+=	-DCRT_IRELOC_RELA
diff --git a/lib/libc/csu/powerpc64/reloc.c b/lib/libc/csu/powerpc64/reloc.c
index 6201ba0f1fb5..5caf5ff28e4b 100644
--- a/lib/libc/csu/powerpc64/reloc.c
+++ b/lib/libc/csu/powerpc64/reloc.c
@@ -25,15 +25,8 @@ static uint32_t cpu_features;
 static uint32_t cpu_features2;
 
 static void
-init_cpu_features(char **env)
+ifunc_init(const Elf_Auxinfo *aux)
 {
-	const Elf_Auxinfo *aux;
-
-	/* Find the auxiliary vector on the stack. */
-	while (*env++ != 0)	/* Skip over environment, and NULL terminator */
-		;
-	aux = (const Elf_Auxinfo *)env;
-
 	/* Digest the auxiliary vector. */
 	for (;  aux->a_type != AT_NULL; aux++) {
 		switch (aux->a_type) {
diff --git a/lib/libc/csu/powerpcspe/Makefile.inc b/lib/libc/csu/powerpcspe/Makefile.inc
index 2534e6579f38..ddead75f874d 100644
--- a/lib/libc/csu/powerpcspe/Makefile.inc
+++ b/lib/libc/csu/powerpcspe/Makefile.inc
@@ -1,4 +1,3 @@
 #
 
-CFLAGS+=	-DCRT_IRELOC_SUPPRESS \
-		-DINIT_IRELOCS=""
+CFLAGS+=	-DCRT_IRELOC_SUPPRESS
diff --git a/lib/libc/csu/riscv/Makefile.inc b/lib/libc/csu/riscv/Makefile.inc
index 5d59d40eb393..6c315c5e2624 100644
--- a/lib/libc/csu/riscv/Makefile.inc
+++ b/lib/libc/csu/riscv/Makefile.inc
@@ -1,4 +1,3 @@
 #
 
-CFLAGS+=	-DCRT_IRELOC_RELA \
-		-DINIT_IRELOCS="init_cpu_features(env)"
+CFLAGS+=	-DCRT_IRELOC_RELA
diff --git a/lib/libc/csu/riscv/reloc.c b/lib/libc/csu/riscv/reloc.c
index 036ea3de8701..6ae85085089b 100644
--- a/lib/libc/csu/riscv/reloc.c
+++ b/lib/libc/csu/riscv/reloc.c
@@ -24,15 +24,8 @@
 static unsigned long elf_hwcap;
 
 static void
-init_cpu_features(char **env)
+ifunc_init(const Elf_Auxinfo *aux)
 {
-	const Elf_Auxinfo *aux;
-
-	/* Find the auxiliary vector on the stack. */
-	while (*env++ != 0)	/* Skip over environment, and NULL terminator */
-		;
-	aux = (const Elf_Auxinfo *)env;
-
 	/* Digest the auxiliary vector. */
 	for (; aux->a_type != AT_NULL; aux++) {
 		switch (aux->a_type) {


help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69405101.25a36.142e428e>