From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id BB5293858002 for ; Tue, 12 Apr 2022 14:12:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BB5293858002 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-540-VRhVtm3bNTWc8skthf0GVA-1; Tue, 12 Apr 2022 10:12:14 -0400 X-MC-Unique: VRhVtm3bNTWc8skthf0GVA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 138AC1C1C521; Tue, 12 Apr 2022 14:12:14 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.193.61]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5F418402187; Tue, 12 Apr 2022 14:12:13 +0000 (UTC) From: Florian Weimer To: Szabolcs Nagy via Libc-alpha Cc: Szabolcs Nagy Subject: Re: [PATCH 2/3] aarch64: Use generic argv adjustment in ld.so [BZ #23293] References: <6b8ed2f8c240e8d2ee4386e423a4765c39aa56ef.1649767418.git.szabolcs.nagy@arm.com> Date: Tue, 12 Apr 2022 16:12:11 +0200 In-Reply-To: <6b8ed2f8c240e8d2ee4386e423a4765c39aa56ef.1649767418.git.szabolcs.nagy@arm.com> (Szabolcs Nagy via Libc-alpha's message of "Tue, 12 Apr 2022 13:55:30 +0100") Message-ID: <877d7u75ms.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Apr 2022 14:12:16 -0000 * Szabolcs Nagy via Libc-alpha: > A seemingly simpler approach is to deal with unaligned sp in crt1.o, > i.e. align sp in the entry point of the exe before __libc_start_main > and pass unaligned sp from ld.so after updating argc (like it is done > on x86), however this is not a backward compatible solution, new ld.so > would not work with old exe on targets where old crt1 does not align. I do not understand this comment. Main executable crt1 runs after this code in ld.so. ld.so has a custom crt1 equivalent in a assembler fragment. > diff --git a/elf/rtld.c b/elf/rtld.c > index 19e328f89e..c08f7ed9e2 100644 > --- a/elf/rtld.c > +++ b/elf/rtld.c > @@ -1311,6 +1311,58 @@ rtld_setup_main_map (struct link_map *main_map) > return has_interp; > } > > +#ifdef DL_NEED_START_ARGS_ADJUST > +static void > +_dl_start_args_adjust (void) > +{ > + void **sp; > + void **p; > + long argc; > + char **argv; > + ElfW(auxv_t) *auxv; > + > + if (_dl_skip_args == 0) > + return; > + > + sp = _dl_start_argptr; > + > + /* Adjust argc on stack. */ > + argc = (long) sp[0] - _dl_skip_args; > + sp[0] = (void *) argc; > + > + argv = (char **) (sp + 1); /* Necessary aliasing violation. */ > + p = sp + _dl_skip_args; > + /* Shuffle argv down. */ > + do > + *++sp = *++p; > + while (*p); *p != NULL? This looks like a memmove. Maybe this will need -fno-tree-loop-distribute-patterns in the future? > + /* Shuffle envp down. */ > + do > + *++sp = *++p; > + while (*p); Likewise. > + auxv = (ElfW(auxv_t) *) (sp + 1); /* Necessary aliasing violation. */ > + /* Shuffle auxv down. */ > + void *a, *b; /* Use a pair of pointers for an auxv entry. */ > + do > + { > + a = *++p; > + b = *++p; > + *++sp = a; > + *++sp = b; > + } > + while (a); Likewise. > + > + /* Update globals in rtld. */ > + _dl_argv = argv; > + _environ = argv + argc + 1; > + GLRO(dl_auxv) = auxv; > + /* No longer need to skip args. */ > + _dl_skip_args = 0; > +} > +#endif Maybe we can remove _dl_skip_args completely? Thanks, Florian