From nobody Fri Oct 18 23:50:28 2024 X-Original-To: dev-commits-src-main@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 4XVhKJ3Q1nz5ZMXM; Fri, 18 Oct 2024 23:50:28 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XVhKJ2v5Mz4YNb; Fri, 18 Oct 2024 23:50:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729295428; 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=GKXsUrQBbYUpDj7eDT+SHlZSpW2iP3uF3t8b8jQ4gsg=; b=K2P3GQGkPFEM4FXMu1viAeg1ZTbNa22fFS7gzSVjIcufI28jLraF8lMXG/pASArYks2VLb Cp46IRXbrtVgft/mKC3xbRGjMfy1Cm+Fdc54PgtF8NtmHJ4UyJZK9WoSaFLMFNI2oyhb7P 21w3ikVzYReNdDolUC359o2GZJ/sEPYuslPln/IAA49P44FlNdT/nL5LxWiq5GqJA0942v wNg0yhccfeaZWU8XMOTsbVMLPdlkI9gup00f5MgZXwPQIkBuPB0n83HDutzKd5/y2EKWZe a5WV/oQemlHyEXgYrSI+wT4RQg6auQNvukDfyQC9V/20o+Ir4HpmZa/JsYTjmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729295428; 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=GKXsUrQBbYUpDj7eDT+SHlZSpW2iP3uF3t8b8jQ4gsg=; b=t5WWVZ5URH+qK5180lNTolTQWwsrOIhJKsxeMCjYeH4jrUrSTwHW4neYEJ2FG3BALLKK++ Cf6AzSuKy6PqeAWksbh7kqd7r/e3wQihkWCbT50mvJPNb5L/FZPPBxfDeY6xsu8qWAZIDE Dm6ufuR8ZPjCoeCdwO0wsccXIzJqbWFbaEuFLH/0cQ/8YGt+P0Y9/2QVqgf6m86uA2idq3 T3RwuqbUqQChQYAJWbdNGSSX+9+4CYYqhnokk9b6E/r3gYEwWIgCTcBF7DNig/wNuWgT3R py21A/N3nm2cH9dyv5ANfgD7hVxf5y/uIWbb2rGxOiQ/lorqhA0YE+rvzNnYUA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1729295428; a=rsa-sha256; cv=none; b=SSyT41eBLwmKppNOEFhOKTYsb7CKvekttjWs8lYp5luXDNx+Afwd5ccopEhRb3aQw7sWIy xNf+EmRa0Vz1AUBGPDUTSObYqesE7bht2ssl2yx1M0IzyFcZWjrbtnopATygN/YX2HIvnO ec3ib3wOIiokkijVZhcHg8sYmUWwSCL8xoT98BugoUvCbmmA+F5PBvIgijcgt+y/DExS/s tQwmaoFxrPiB59kIfJNls6wJfKtahz5h0AQ4YAXMQ3FH8PZ1NKSTUnO6KIK4v4EXlqLIP8 RElRSfTH/aU/xa7zPkKWhi6Hh2XZ3/p5wRPCM07iGSR3TzEpr21HzJEdpp35Jw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XVhKJ2VPmztB1; Fri, 18 Oct 2024 23:50:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 49INoScd025588; Fri, 18 Oct 2024 23:50:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49INoSgV025585; Fri, 18 Oct 2024 23:50:28 GMT (envelope-from git) Date: Fri, 18 Oct 2024 23:50:28 GMT Message-Id: <202410182350.49INoSgV025585@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Jessica Clarke Subject: git: 9684658e35ab - main - libc/csu: Unify INIT_RELOCS across architectures List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 9684658e35ab033c79e0519e3681d9a194976b71 Auto-Submitted: auto-generated The branch main has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=9684658e35ab033c79e0519e3681d9a194976b71 commit 9684658e35ab033c79e0519e3681d9a194976b71 Author: Jessica Clarke AuthorDate: 2024-10-18 23:48:52 +0000 Commit: Jessica Clarke CommitDate: 2024-10-18 23:48:52 +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 --- lib/libc/csu/aarch64/Makefile.inc | 3 +-- lib/libc/csu/aarch64/reloc.c | 7 +++++++ lib/libc/csu/amd64/Makefile.inc | 3 +-- lib/libc/csu/amd64/reloc.c | 4 +++- lib/libc/csu/arm/Makefile.inc | 3 +-- lib/libc/csu/i386/Makefile.inc | 3 +-- lib/libc/csu/i386/reloc.c | 4 +++- lib/libc/csu/libc_start1.c | 28 ++++++++++++++++++++-------- 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 +-------- 14 files changed, 43 insertions(+), 42 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 ead48a8ad4fb..4ba7920bcb07 100644 --- a/lib/libc/csu/aarch64/reloc.c +++ b/lib/libc/csu/aarch64/reloc.c @@ -24,6 +24,13 @@ * SUCH DAMAGE. */ +#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 6424d69fbd5c..f1f83db9a391 100644 --- a/lib/libc/csu/amd64/reloc.c +++ b/lib/libc/csu/amd64/reloc.c @@ -23,6 +23,8 @@ * SUCH DAMAGE. */ +#include + #include #include @@ -30,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 1c9ec173facc..7097f58d8f26 100644 --- a/lib/libc/csu/i386/reloc.c +++ b/lib/libc/csu/i386/reloc.c @@ -23,6 +23,8 @@ * SUCH DAMAGE. */ +#include + #include #include @@ -30,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 f0e708e405ce..045ea1e68141 100644 --- a/lib/libc/csu/libc_start1.c +++ b/lib/libc/csu/libc_start1.c @@ -137,6 +137,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 *[])) @@ -146,10 +164,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(); } @@ -171,10 +186,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/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 41419bf0e6c2..5637e6534197 100644 --- a/lib/libc/csu/powerpc64/reloc.c +++ b/lib/libc/csu/powerpc64/reloc.c @@ -24,15 +24,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) {