public inbox for glibc-cvs@sourceware.org help / color / mirror / Atom feed
From: Szabolcs Nagy <nsz@sourceware.org> To: glibc-cvs@sourceware.org Subject: [glibc/arm/morello/main] aarch64: morello: add purecap ld.so _start code Date: Wed, 23 Nov 2022 14:47:30 +0000 (GMT) [thread overview] Message-ID: <20221123144730.06EF93852C64@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=b2b6a773fecd30e2404157c04f4c25ce025297b3 commit b2b6a773fecd30e2404157c04f4c25ce025297b3 Author: Szabolcs Nagy <szabolcs.nagy@arm.com> Date: Thu Oct 20 13:05:19 2022 +0100 aarch64: morello: add purecap ld.so _start code The purecap version of aarch64 dl-start.S. Note: self relocation of ld.so is handled by the rtld bootstrap code. The ldso internal _dl_start still expects continuous argc, argv, envp, auxv, so that's emulated (since the purecap ELF entry passes them in separate registers). Diff: --- sysdeps/aarch64/morello/dl-start.c | 110 +++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/sysdeps/aarch64/morello/dl-start.c b/sysdeps/aarch64/morello/dl-start.c new file mode 100644 index 0000000000..f1b792d957 --- /dev/null +++ b/sysdeps/aarch64/morello/dl-start.c @@ -0,0 +1,110 @@ +/* ld.so _start code. + Copyright (C) 2022 Free Software Foundation, Inc. + + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#include <assert.h> +#include <ldsodefs.h> + +asm("" +".global _start\n" +".type _start, %function\n" +"_start:\n" +" .cfi_startproc\n" +" .cfi_undefined c30\n" +" mov c29, czr\n" +" mov c30, czr\n" +" b __real_start\n" +" .cfi_endproc\n" +" .size _start, .-_start\n"); + +typedef void (entry_t) (int, char **, char **, void *, void (*)(void)); + +__attribute__ ((noinline, noreturn)) +void +_dl_start_user (uintptr_t *args, entry_t *entry) +{ + /* Setup argv, envp, auxv for the application. */ + uintptr_t *p; + long n; + int argc = args[0]; + p = args + 1; + n = argc + 1; + char **argv = (char **) __builtin_cheri_bounds_set (p, n * sizeof *p); + p += n; + for (n = 0; p[n]; n++); + n++; + char **envp = (char **) __builtin_cheri_bounds_set (p, n * sizeof *p); + p += n; + for (n = 0; p[n] != AT_NULL; n += 2); + n += 2; + uintptr_t *auxv = __builtin_cheri_bounds_set (p, n * sizeof *p); + + _dl_init (GL(dl_ns)[LM_ID_BASE]._ns_loaded, argc, argv, envp); + entry (argc, argv, envp, auxv, _dl_fini); + __builtin_trap (); +} + +/* Count the array length needed for traditional ELF entry. */ +static inline long +count_args (int argc, char **argv, char **envp, uintptr_t *auxv) +{ + char **p; + uintptr_t *q; + long nargs = argc + 2; + for (p = envp; *p != NULL; p++); + nargs += p - envp + 1; + for (q = auxv; *q != AT_NULL; q += 2); + nargs += q - auxv + 2; + return nargs; +} + +/* Generic ld.so start code in rtld.c. */ +uintptr_t +_dl_start (void *) attribute_hidden; + +/* ld.so entry point. */ +void +__real_start (int argc, char **argv, char **envp, void *auxv) +{ + long nargs = count_args (argc, argv, envp, auxv); + { + /* _dl_start requires continuous argv, envp, auxv. */ + uintptr_t args[nargs]; + long i = 0, j; + args[i++] = argc; + for (j = 0; argv[j] != NULL; j++) + args[i++] = (uintptr_t) argv[j]; + args[i++] = 0; + for (j = 0; envp[j] != NULL; j++) + args[i++] = (uintptr_t) envp[j]; + args[i++] = 0; + uintptr_t *a = auxv; + for (j = 0; a[j] != AT_NULL; j += 2) + { + args[i++] = a[j]; + args[i++] = a[j+1]; + } + args[i++] = AT_NULL; + args[i++] = 0; + assert (i == nargs); + + /* Run ls.so setup. */ + entry_t *entry = (entry_t *) _dl_start (args); + _dl_start_user (args, entry); + } +}
next reply other threads:[~2022-11-23 14:47 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-11-23 14:47 Szabolcs Nagy [this message] -- strict thread matches above, loose matches on Subject: below -- 2022-10-27 13:57 Szabolcs Nagy 2022-10-26 15:19 Szabolcs Nagy
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20221123144730.06EF93852C64@sourceware.org \ --to=nsz@sourceware.org \ --cc=glibc-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).