From nobody Mon Dec 15 18:18:41 2025 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4dVSxG0GwVz6L7Rl for ; Mon, 15 Dec 2025 18:18:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dVSxF5M3bz4L72 for ; Mon, 15 Dec 2025 18:18:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1765822721; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=5N5C+0ITa87SFS/4nLMleez5CBpVyTV2yfvIZNwzTAM=; b=FjYxgtt9ZOAlQfYHZuRZ5mdUBnzz9cF1KLGB5sy5EGnzqE8IBi7NgoUR1gDrSpGEbb7pYG TVB5kUpT6k1gsvFIZEbjk4c5177URew/DHCX5F4i+XAQk4OJU3RpMuprJvtT4JIBWjovI1 WDZirJqmc+T/jQsj6lVEZz52KYFLkjs/V2mK7e9KPOUCefJPoyMaYh+PXhDYdIiqQEIm6W YVLzTfi/2C1wMp+08Ha1VzwKEIhjKCXGvH+X0lXGiNAw8TxIQ3HsF2ojKue0ttuIsTJm7y 7z+UPVCnTfdo/MefNoBiQnVByr9BVe8oLMSYre2qvTOjXW6c0ivPEui8jNsqLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1765822721; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=5N5C+0ITa87SFS/4nLMleez5CBpVyTV2yfvIZNwzTAM=; b=Iw+L9mF+aspjR94O1y0z+eUcNWoG6fH8zpTqLYpvVDOgg7EJevvvIyfotfQmeZ38yQ/6ee RDgeDK8VHfJBEf0zyhDgraL4m/bAS/wa2CtYudbfSXvRZTxP1emI0pHDyMkvgHWtU3UHy9 LFWR7s/PUf1ALmjsbHeqeL/y6b0rdELYKf1MDPBEuEB6t84+36cYRBPrVlRcyhDAUltBXd o3Lz7eB8o/+bNGDGg+YN13gkRLYEY2sWsfqY/Ie2lKona2kwByHfp8Qn5YvSBY0mhc2hzG yCgVZqIaa9XpqWMy7w4lR9S0iZ4e7j1p9rFPRXvgtH43Uvvx5toRJyX9TgGeww== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1765822721; a=rsa-sha256; cv=none; b=Y4R8RjxHqtjalp7SgmqiHe+1dNxB02wEOeQBnzsDo3Lnn0ghYEiXDGUiXcVsGM6xonD2up MehaKOR+UCGR/u9vCIJlhHRpU52wKVlUiVhBNiQ4+CHhEjnDqFN5RrO8ra5OwG0JbUIzmg PuVmFHY6uKVVgkPiCMsMRM7yOyAKpcB6rlYQCSvagTvUgnL0U0IWNrqJujjBb2kTzf+dLZ aXjl5jFezUmkRJN9XIOjvOzwRsxO2kg3JEgxsK4NfUP9RTuwYaERQH0ZANM652wWiyo/CU iuVxPNxlIfElbiyYmmRK4UrmXEtiD5KkKmWQT3qtkvv6SuSnqJoztYH6e0MewA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dVSxF4fhWzVhS for ; Mon, 15 Dec 2025 18:18:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 25a36 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 15 Dec 2025 18:18:41 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Jessica Clarke Subject: git: 3d292b9ee8cf - stable/13 - libc/csu: Unify INIT_RELOCS across architectures List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jrtc27 X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 3d292b9ee8cf4efc35c07f69bb9aae41a3f36ef8 Auto-Submitted: auto-generated Date: Mon, 15 Dec 2025 18:18:41 +0000 Message-Id: <69405101.25a36.142e428e@gitrepo.freebsd.org> The branch stable/13 has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=3d292b9ee8cf4efc35c07f69bb9aae41a3f36ef8 commit 3d292b9ee8cf4efc35c07f69bb9aae41a3f36ef8 Author: Jessica Clarke AuthorDate: 2024-10-18 23:48:52 +0000 Commit: Jessica Clarke 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 + +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 + #include #include @@ -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 + #include #include @@ -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) {