From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by sourceware.org (Postfix) with ESMTPS id 0454D386545C for ; Fri, 13 May 2022 20:46:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0454D386545C Received: by mail-oi1-x22d.google.com with SMTP id m25so11549124oih.2 for ; Fri, 13 May 2022 13:46:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=5Nkizzz/PKQrMxz3LMVqx4vpCM8R8R6EnT/QEYHVcRE=; b=2V0zZfKICn0LV7YnkJvfmxFs9Rf6+AVN7rCGtaO9NbRR9MPWNbEssWNND8JhUv2XYQ 0jHZLygKCsGC7Ev4/74XGHae6G3TbnUMer3ie2XuwoXSuZ+UfU/6Hp+amVhNMbJI+yp9 NafIUqGwWBXtchX4tcaHxCPdHnpFTH3aVwvBhUVyztIXotD2VUl7Gi+zBC+LOX12RhVt 0lE0pYAO12Kb26pnmXRQKkKGEBuyvmVlXWs+VCEbuIpiOliVN2vgS7yK6kloTlyJQDSU d6FWUlQQArQuSKGZjvMteML/OdsqmOShiXrEtdgGf5WtIiuLBT1ayr70Ibz3CyALjzKJ OAOw== X-Gm-Message-State: AOAM533BXGO153DE7q4BJIfT+rLXQ8xJmh/FhCeX2ejSNre9lfYhV1O1 VUF9KoOWk+0SnXyVo9CAgmGYRjhSjfnmow== X-Google-Smtp-Source: ABdhPJxDEnrykQNZH/64kXBZEye0dUBprwyJ2DMscn1lo9JdgViaw/TBK6RUjapBCh+rqAPyXuIrgw== X-Received: by 2002:a05:6808:e8f:b0:2f7:6c1a:c1a with SMTP id k15-20020a0568080e8f00b002f76c1a0c1amr8247595oil.129.1652474771981; Fri, 13 May 2022 13:46:11 -0700 (PDT) Received: from ?IPV6:2804:431:c7ca:5fbd:b7af:daa5:1bf0:c543? ([2804:431:c7ca:5fbd:b7af:daa5:1bf0:c543]) by smtp.gmail.com with ESMTPSA id w11-20020a9d70cb000000b0060603221245sm1405415otj.21.2022.05.13.13.46.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 13 May 2022 13:46:11 -0700 (PDT) Message-ID: <1c1ed41a-ff57-f43f-a9c9-1d25e1babdd0@linaro.org> Date: Fri, 13 May 2022 17:46:09 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH v6 4/4] aarch64: Move ld.so _start to separate file and drop _dl_skip_args Content-Language: en-US To: Szabolcs Nagy , libc-alpha@sourceware.org References: <30ecd158a7425badc5996450816a3ca3dd86e9c9.1651757640.git.szabolcs.nagy@arm.com> From: Adhemerval Zanella In-Reply-To: <30ecd158a7425badc5996450816a3ca3dd86e9c9.1651757640.git.szabolcs.nagy@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-14.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Fri, 13 May 2022 20:46:15 -0000 On 05/05/2022 10:59, Szabolcs Nagy via Libc-alpha wrote: > A separate asm file is easier to maintain than a macro that expands to > inline asm. > > The RTLD_START macro is only needed now because _dl_start is local in > rtld.c, but _start has to call it, if _dl_start was made hidden then it > could be empty. > > _dl_skip_args is no longer needed. LGTM, thanks. Reviewed-by: Adhemerval Zanella > > --- > v4: > - adjust commit message about _dl_skip_args. > v3: > - mention _dl_skip_args > v2: > - fix typo in commit message. > --- > sysdeps/aarch64/Makefile | 1 + > sysdeps/aarch64/dl-machine.h | 77 +----------------------------------- > sysdeps/aarch64/dl-start.S | 53 +++++++++++++++++++++++++ > 3 files changed, 56 insertions(+), 75 deletions(-) > create mode 100644 sysdeps/aarch64/dl-start.S > > diff --git a/sysdeps/aarch64/Makefile b/sysdeps/aarch64/Makefile > index 7183895d04..17fb1c5b72 100644 > --- a/sysdeps/aarch64/Makefile > +++ b/sysdeps/aarch64/Makefile > @@ -33,6 +33,7 @@ tst-audit27-ENV = LD_AUDIT=$(objpfx)tst-auditmod27.so > endif > > ifeq ($(subdir),elf) > +sysdep-rtld-routines += dl-start > sysdep-dl-routines += tlsdesc dl-tlsdesc > gen-as-const-headers += dl-link.sym > > diff --git a/sysdeps/aarch64/dl-machine.h b/sysdeps/aarch64/dl-machine.h > index b40050a981..fe120bb507 100644 > --- a/sysdeps/aarch64/dl-machine.h > +++ b/sysdeps/aarch64/dl-machine.h > @@ -105,81 +105,8 @@ elf_machine_runtime_setup (struct link_map *l, struct r_scope_elem *scope[], > return lazy; > } > > -/* Initial entry point for the dynamic linker. The C function > - _dl_start is the real entry point, its return value is the user > - program's entry point */ > -#ifdef __LP64__ > -# define RTLD_START RTLD_START_1 ("x", "3", "sp") > -#else > -# define RTLD_START RTLD_START_1 ("w", "2", "wsp") > -#endif > - > - > -#define RTLD_START_1(PTR, PTR_SIZE_LOG, PTR_SP) asm ("\ > -.text \n\ > -.globl _start \n\ > -.type _start, %function \n\ > -.globl _dl_start_user \n\ > -.type _dl_start_user, %function \n\ > -_start: \n\ > - // bti c \n\ > - hint 34 \n\ > - mov " PTR "0, " PTR_SP " \n\ > - bl _dl_start \n\ > - // returns user entry point in x0 \n\ > - mov x21, x0 \n\ > -_dl_start_user: \n\ > - // get the original arg count \n\ > - ldr " PTR "1, [sp] \n\ > - // get the argv address \n\ > - add " PTR "2, " PTR_SP ", #(1<<" PTR_SIZE_LOG ") \n\ > - // get _dl_skip_args to see if we were \n\ > - // invoked as an executable \n\ > - adrp x4, _dl_skip_args \n\ > - ldr w4, [x4, #:lo12:_dl_skip_args] \n\ > - // do we need to adjust argc/argv \n\ > - cmp w4, 0 \n\ > - beq .L_done_stack_adjust \n\ > - // subtract _dl_skip_args from original arg count \n\ > - sub " PTR "1, " PTR "1, " PTR "4 \n\ > - // store adjusted argc back to stack \n\ > - str " PTR "1, [sp] \n\ > - // find the first unskipped argument \n\ > - mov " PTR "3, " PTR "2 \n\ > - add " PTR "4, " PTR "2, " PTR "4, lsl #" PTR_SIZE_LOG " \n\ > - // shuffle argv down \n\ > -1: ldr " PTR "5, [x4], #(1<<" PTR_SIZE_LOG ") \n\ > - str " PTR "5, [x3], #(1<<" PTR_SIZE_LOG ") \n\ > - cmp " PTR "5, #0 \n\ > - bne 1b \n\ > - // shuffle envp down \n\ > -1: ldr " PTR "5, [x4], #(1<<" PTR_SIZE_LOG ") \n\ > - str " PTR "5, [x3], #(1<<" PTR_SIZE_LOG ") \n\ > - cmp " PTR "5, #0 \n\ > - bne 1b \n\ > - // shuffle auxv down \n\ > -1: ldp " PTR "0, " PTR "5, [x4, #(2<<" PTR_SIZE_LOG ")]! \n\ > - stp " PTR "0, " PTR "5, [x3], #(2<<" PTR_SIZE_LOG ") \n\ > - cmp " PTR "0, #0 \n\ > - bne 1b \n\ > - // Update _dl_argv \n\ > - adrp x3, __GI__dl_argv \n\ > - str " PTR "2, [x3, #:lo12:__GI__dl_argv] \n\ > -.L_done_stack_adjust: \n\ > - // compute envp \n\ > - add " PTR "3, " PTR "2, " PTR "1, lsl #" PTR_SIZE_LOG " \n\ > - add " PTR "3, " PTR "3, #(1<<" PTR_SIZE_LOG ") \n\ > - adrp x16, _rtld_local \n\ > - add " PTR "16, " PTR "16, #:lo12:_rtld_local \n\ > - ldr " PTR "0, [x16] \n\ > - bl _dl_init \n\ > - // load the finalizer function \n\ > - adrp x0, _dl_fini \n\ > - add " PTR "0, " PTR "0, #:lo12:_dl_fini \n\ > - // jump to the user_s entry point \n\ > - mov x16, x21 \n\ > - br x16 \n\ > -"); > +/* In elf/rtld.c _dl_start should be global so dl-start.S can reference it. */ > +#define RTLD_START asm (".globl _dl_start"); > > #define elf_machine_type_class(type) \ > ((((type) == AARCH64_R(JUMP_SLOT) \ > diff --git a/sysdeps/aarch64/dl-start.S b/sysdeps/aarch64/dl-start.S > new file mode 100644 > index 0000000000..a3a57bd5a1 > --- /dev/null > +++ b/sysdeps/aarch64/dl-start.S > @@ -0,0 +1,53 @@ > +/* 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 > + . */ > + > +#include > + > +ENTRY (_start) > + /* Create an initial frame with 0 LR and FP */ > + cfi_undefined (x30) > + mov x29, #0 > + mov x30, #0 > + > + mov x0, sp > + PTR_ARG (0) > + bl _dl_start > + /* Returns user entry point in x0. */ > + mov PTR_REG (21), PTR_REG (0) > +.globl _dl_start_user > +.type _dl_start_user, %function > +_dl_start_user: > + /* Get argc. */ > + ldr PTR_REG (1), [sp] > + /* Get argv. */ > + add x2, sp, PTR_SIZE > + /* Compute envp. */ > + add PTR_REG (3), PTR_REG (2), PTR_REG (1), lsl PTR_LOG_SIZE > + add PTR_REG (3), PTR_REG (3), PTR_SIZE > + adrp x16, _rtld_local > + add PTR_REG (16), PTR_REG (16), :lo12:_rtld_local > + ldr PTR_REG (0), [x16] > + bl _dl_init > + /* Load the finalizer function. */ > + adrp x0, _dl_fini > + add PTR_REG (0), PTR_REG (0), :lo12:_dl_fini > + /* Jump to the user's entry point. */ > + mov x16, x21 > + br x16 > +END (_start)