From patchwork Wed Apr 13 13:00:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1616752 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=SMJN9+MS; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KdjQc1wBPz9s09 for ; Wed, 13 Apr 2022 23:01:28 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3233B3857419 for ; Wed, 13 Apr 2022 13:01:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3233B3857419 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1649854886; bh=PU9uWdG5PN+8CVamUl+w7cjdU0wR0+lM0tJlkccPpcQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=SMJN9+MSOwFDS/VcYytRHEWrdsPhMsLz55LOTXYfUogZNtXguRjjURCuwWBAFsSsD 9JZirZ4jVrrurDfxIrZ+kqwUOlAhDfhaXcyONpqay+RPO/pJLLow6pM59HReG+x0jD OKvyhdR6Jzjo3dSJ+igh67Hx76t17raZCs5L04V4= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-eopbgr40077.outbound.protection.outlook.com [40.107.4.77]) by sourceware.org (Postfix) with ESMTPS id 647B93858430 for ; Wed, 13 Apr 2022 13:00:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 647B93858430 Received: from AM0PR02CA0192.eurprd02.prod.outlook.com (2603:10a6:20b:28e::29) by HE1PR0802MB2396.eurprd08.prod.outlook.com (2603:10a6:3:dc::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Wed, 13 Apr 2022 13:00:34 +0000 Received: from VE1EUR03FT060.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:28e:cafe::b6) by AM0PR02CA0192.outlook.office365.com (2603:10a6:20b:28e::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20 via Frontend Transport; Wed, 13 Apr 2022 13:00:34 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT060.mail.protection.outlook.com (10.152.19.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.19 via Frontend Transport; Wed, 13 Apr 2022 13:00:34 +0000 Received: ("Tessian outbound 9613c00560a5:v118"); Wed, 13 Apr 2022 13:00:33 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 69c5287c1dc01af0 X-CR-MTA-TID: 64aa7808 Received: from de155937144a.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id CFA22A1D-0585-4C74-AACB-6D45190EE84B.1; Wed, 13 Apr 2022 13:00:27 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id de155937144a.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 13 Apr 2022 13:00:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gQnmcNWOLyeMmP0ZXuN2Y0XCjz6oWJjbE/P3SGWx/lS0j49ODh2ZAC8/aHAIz8A07nRrX3DZeMwKGubPZFMR+d5JrHceItnO3idn1zHKWrMwO/CIDWzMroknlLrQWhz/YE/eLYNTjBLHK8H9iJMt7OMVfN/y6n34Y4kKsVGRYV2L27sue/liFGy2G6lgmLu3RVNUhZEO0F0cA8HICGPVByRL5UTUjNMQ7Fu/YOV1X7ythVDXDyGSuWl02WXGVPeIQLC4A0rnIEr1uWo4MslWF+aMUYHr/94NKvRyGhdx5ciBIsCC2CiPdzZrz9ruD0GztDaN10/ppFYwXOn1tUpcWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=PU9uWdG5PN+8CVamUl+w7cjdU0wR0+lM0tJlkccPpcQ=; b=dBm4QJHsDL6CnaCuEeSC8dhUBdZAmXdJx+Ry7bMzM+T9xrAWtXh9HoeMnmjdRihQdAfEFfOlBfMtAA95ZfwYlt/RXCXwJOniDhX6XlIX6J4NC8sQgFJ4bhsZVsdTxFgomanss2b9k7nhpmNql74cmLAas1qrgRDrDFN+gg4gjiUc8FMcbfbnDvqUVasU6NohK5Xcac+8yGXSWrl3E7qAFEK7TAx6lwu2k8Urif5NQmyMLNF1X3VQ8jbXrJwgZXdRtiWl08Q8dzgls8LdyrtMEfEe8CfWRqZtUmxcjDJsmD6vwOh6DwOkmyYRedD/F52xKIJpi23U3qYmy+M5HDYz3Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none Received: from DB6PR07CA0010.eurprd07.prod.outlook.com (2603:10a6:6:2d::20) by VI1PR08MB3887.eurprd08.prod.outlook.com (2603:10a6:803:c2::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Wed, 13 Apr 2022 13:00:24 +0000 Received: from DB5EUR03FT035.eop-EUR03.prod.protection.outlook.com (2603:10a6:6:2d:cafe::d2) by DB6PR07CA0010.outlook.office365.com (2603:10a6:6:2d::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20 via Frontend Transport; Wed, 13 Apr 2022 13:00:24 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; Received: from nebula.arm.com (40.67.248.234) by DB5EUR03FT035.mail.protection.outlook.com (10.152.20.65) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5164.19 via Frontend Transport; Wed, 13 Apr 2022 13:00:24 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Wed, 13 Apr 2022 13:00:30 +0000 Received: from armchair.cambridge.arm.com (10.2.80.71) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.2308.27 via Frontend Transport; Wed, 13 Apr 2022 13:00:30 +0000 To: Subject: [PATCH v3 1/2] aarch64: Use generic argv adjustment in ld.so [BZ #23293] Date: Wed, 13 Apr 2022 14:00:22 +0100 Message-ID: <4a157fa95462503bd1b6c3218644a0334ae52325.1649854695.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: 302d1841-9416-4b2d-91a1-08da1d4d98e1 X-MS-TrafficTypeDiagnostic: VI1PR08MB3887:EE_|VE1EUR03FT060:EE_|HE1PR0802MB2396:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: JI3zS2BaWs1hWTzVmPI+e/MfLT0nLooYp7ka9V455ln/StyZHprtcKpAgKD25euuRxr4XJBInwuneoIA7oMAWN+txNCIUvJiaTj8Os4PDb09yKoFGS375H35LkPM6QfarYIx2/Dcss4NYsjbtebBd431bGfpZa7K6ul/BgRP8iFbyNhO6PjFYW+tRhKIQJXdGcdhKeEeqViMQW1Nmdie3dKZSnqM/FffpaSLJNU4Zuq19KUQPhGOLIee8h8PpqMvAOe+lgFKSZ3lAKnnVMfk9MjWhYbv/fDDVLnsAsdQEykgijceCPAieJ781uEJ3GjQLh+RyQIEppg6NAt+I7T8JxPgKKtbZPp+nnAuwRdbGnY1NGgl7IPhgsXd+BPmu3BXZIDZs08Aa1l136+Det+CNcPdqEV3lZi+EHkm033pDOPTvI5Pifb7ConMmg6AUIitDRHUVs7AwbVfbGfJqSC8qJwr0qkkShARxg2EFbxCn/pzh3Srg6p7GtEzLxZYYJeYT86WYjTBfqUBZ0MKifBvvzkyXTnyMv4MmkU2dx4NQE+7SPVCcsdomi8P/bFSm3R2Ha/6jXZfIaHEsE7HVswRXxK77+dYAtK1XDo2uusBTn+STX8BliZBQJUMd0DUAl34KlJhPSWgvZTVCixpFVhnmlQHhCmV3ENFaRFtxugDltbKQ3l0HaOfle2X6KJNpMJ7e/6Q0Sgu/iTgeVNZ8NuDXe3N/uVqg5xLF/NG+ntxE24= X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:nebula.arm.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(426003)(336012)(6916009)(83380400001)(2616005)(70206006)(36756003)(70586007)(81166007)(5660300002)(82310400005)(8676002)(8936002)(44832011)(6666004)(2906002)(7696005)(86362001)(498600001)(47076005)(186003)(356005)(26005)(40460700003)(36860700001)(41533002)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB3887 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT060.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 0cf0df09-9b51-4117-5d4a-08da1d4d92ec X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lcNDYwC1QYmfhBq5V9ufbyoXEVrDoY4iZabZX54mUW46Su6oGJnHDUXP7vLghsWPgnJo3OGOpGyxme88EhQu4+33WaC3Ieo3QJpA75w8QuCC5Xxn+0FduJ//qw3tsOIsDLVpmOU3rC1Oo5aEShCH99j5uk5zovnEqV2A2lAnEvOBdl6zne00or1/K0U4E8vt1ycSXWhrbvYDDMBu/R7a0RzAErbPgTz95sJj/xuSEafc8DC7yI2qBWZbz3SQcNICrA1HSBJ92XVApYgYMfmfXmg586L7zX2GvZIc0fsoShmiqSFOYHOmntaLclEofJ+hrZ49Vl+HwkRPkeNW5IvJRdq+k/KddaOTfPPZkeQwls4WZE6gd92CKJ7f2EGouQAI08wkBQjO4zjIZi+UhfbraHuOvDaZEvR5gv5OSKNcOaPBeeExBlZx/pYVbQ2wTsSvY91bFM/tNVZKGdmN+a6g5c67KbFFDsj5AdAnbFKd6rTdXFb4GUgcz1vAQTuE9wwFodHg3bAihtshl1IlB5w4XkIdvFPJ0cmjFZTOBUkApQwaDur79BsJOW1IMmoceDdKIswA72FlQGQxTKjUEVz2QnBbKGNXG2kdYS2uDoviMkoF9EUr9G0pMe+WoNoVh5a/HtcAbHLnFfJSO+QpJYUWhpPv8tdBLiPz6q+d2YByBsdkC1EEtXr1szJSjl33fGbKEBS3OmpDsV+Ui9T/8KosCQ== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(8676002)(8936002)(70206006)(2616005)(6916009)(47076005)(186003)(82310400005)(5660300002)(26005)(336012)(2906002)(40460700003)(36756003)(36860700001)(426003)(83380400001)(70586007)(86362001)(498600001)(44832011)(7696005)(6666004)(81166007)(41533002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Apr 2022 13:00:34.0016 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 302d1841-9416-4b2d-91a1-08da1d4d98e1 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: VE1EUR03FT060.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0802MB2396 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY 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-Patchwork-Original-From: Szabolcs Nagy via Libc-alpha From: Szabolcs Nagy Reply-To: Szabolcs Nagy Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" When an executable is invoked as ./ld.so [ld.so-args] ./exe [exe-args] then the argv is adujusted in ld.so before calling the entry point of the executable so ld.so args are not visible to it. On most targets this requires moving argv, env and auxv on the stack to ensure correct stack alignment at the entry point. This had several issues: - The code for this adjustment on the stack is written in asm as part of the target specific ld.so _start code which is hard to maintain. - The adjustment is done after _dl_start returns, where it's too late to update GLRO(dl_auxv), as it is already readonly, so it points to memory that was clobbered by the adjustment. This is bug 23293. - _environ is also wrong in ld.so after the adjustment, but it is likely not used after _dl_start returns so this is not user visible. - _dl_argv was updated, but for this it was moved out of relro, which changes security properties across targets unnecessarily. This patch introduces a generic _dl_start_args_adjust function that handles the argument adjustments after ld.so processed its own args and before relro protection is applied. It sets _dl_skip_args to 0 so the existing adjustment in asm is not invoked. Each target has to opt-in to use this new adjustment since some targets don't need it. Once all targets are updated, _dl_argv declaration can be simplified. A new _dl_start_argptr was introduced because the original sp is not passed to dl_main which now has to do the adjustments. Reviewed-by: Florian Weimer --- v2: - use p != NULL, and a_type != AT_NULL - remove the confusing paragraph from the commit message. --- elf/rtld.c | 58 +++++++++++++++++++++++++++++ sysdeps/aarch64/dl-sysdep.h | 2 +- sysdeps/generic/ldsodefs.h | 3 ++ sysdeps/unix/sysv/linux/dl-sysdep.c | 10 +++++ 4 files changed, 72 insertions(+), 1 deletion(-) diff --git a/elf/rtld.c b/elf/rtld.c index 19e328f89e..bc4d59f5d6 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -1311,6 +1311,60 @@ 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 != NULL); + + /* Shuffle envp down. */ + do + *++sp = *++p; + while (*p != NULL); + + auxv = (ElfW(auxv_t) *) (sp + 1); /* Necessary aliasing violation. */ + /* Shuffle auxv down. */ + void *a, *b; /* Use a pair of pointers for an auxv entry. */ + unsigned long a_type; + do + { + a_type = ((ElfW(auxv_t) *) (p + 1))->a_type; + a = *++p; + b = *++p; + *++sp = a; + *++sp = b; + } + while (a_type != AT_NULL); + + /* 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 + static void dl_main (const ElfW(Phdr) *phdr, ElfW(Word) phnum, @@ -1615,6 +1669,10 @@ dl_main (const ElfW(Phdr) *phdr, /* Set the argv[0] string now that we've processed the executable. */ if (argv0 != NULL) _dl_argv[0] = argv0; +#ifdef DL_NEED_START_ARGS_ADJUST + /* Adjust arguments for the application entry point. */ + _dl_start_args_adjust (); +#endif } else { diff --git a/sysdeps/aarch64/dl-sysdep.h b/sysdeps/aarch64/dl-sysdep.h index 667786671c..1df4c2c528 100644 --- a/sysdeps/aarch64/dl-sysdep.h +++ b/sysdeps/aarch64/dl-sysdep.h @@ -20,6 +20,6 @@ /* _dl_argv cannot be attribute_relro, because _dl_start_user might write into it after _dl_start returns. */ -#define DL_ARGV_NOT_RELRO 1 +#define DL_NEED_START_ARGS_ADJUST 1 #define DL_EXTERN_PROTECTED_DATA diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index 29f005499b..f322d36570 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -785,6 +785,9 @@ extern unsigned int _dl_skip_args attribute_hidden attribute_relro # endif ; +# ifdef DL_NEED_START_ARGS_ADJUST +extern void **_dl_start_argptr attribute_hidden attribute_relro; +# endif #endif #define rtld_progname _dl_argv[0] diff --git a/sysdeps/unix/sysv/linux/dl-sysdep.c b/sysdeps/unix/sysv/linux/dl-sysdep.c index c90f109b11..66f003e2a3 100644 --- a/sysdeps/unix/sysv/linux/dl-sysdep.c +++ b/sysdeps/unix/sysv/linux/dl-sysdep.c @@ -58,6 +58,12 @@ void *__libc_stack_end attribute_relro = NULL; rtld_hidden_data_def(__libc_stack_end) void *_dl_random attribute_relro = NULL; +#ifdef DL_NEED_START_ARGS_ADJUST +/* Original sp at ELF entry, used when rtld is executed explicitly + and needs to adjust arg components for the actual application. */ +void **_dl_start_argptr attribute_hidden attribute_relro = NULL; +#endif + #ifndef DL_STACK_END # define DL_STACK_END(cookie) ((void *) (cookie)) #endif @@ -114,6 +120,10 @@ _dl_sysdep_start (void **start_argptr, __brk (0); /* Initialize the break. */ +#ifdef DL_NEED_START_ARGS_ADJUST + _dl_start_argptr = start_argptr; +#endif + #ifdef DL_PLATFORM_INIT DL_PLATFORM_INIT; #endif From patchwork Wed Apr 13 13:00:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1616753 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=hMW9Sn/4; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KdjRZ5Wrzz9s09 for ; Wed, 13 Apr 2022 23:02:18 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B26D13857404 for ; Wed, 13 Apr 2022 13:02:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B26D13857404 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1649854935; bh=jjiy9wTZJee2SpwDEI1fS7R0ZXAfngIOg3E3EpVoKBs=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=hMW9Sn/4x14jNNg9Xrk39sqbfgiXKIiZvMwN2GWP9sKE/LyasdsFd4Q8JfXRMqOFp D8tMBFNiv+cCjQ9GXRhTgkRvsyfKdEV/ych0ljHrSMnsJBCxIgODitwiebDb//nvEe fJX9HU5U8QpmjWThmI7sBeyzw3rEhZlfwEPMAPEw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-eopbgr150053.outbound.protection.outlook.com [40.107.15.53]) by sourceware.org (Postfix) with ESMTPS id 623C63857418 for ; Wed, 13 Apr 2022 13:00:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 623C63857418 Received: from AM6P192CA0017.EURP192.PROD.OUTLOOK.COM (2603:10a6:209:83::30) by AS4PR08MB7478.eurprd08.prod.outlook.com (2603:10a6:20b:4e5::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Wed, 13 Apr 2022 13:00:43 +0000 Received: from AM5EUR03FT039.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:83:cafe::22) by AM6P192CA0017.outlook.office365.com (2603:10a6:209:83::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.19 via Frontend Transport; Wed, 13 Apr 2022 13:00:43 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT039.mail.protection.outlook.com (10.152.17.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.19 via Frontend Transport; Wed, 13 Apr 2022 13:00:43 +0000 Received: ("Tessian outbound ab7864ef57f2:v118"); Wed, 13 Apr 2022 13:00:43 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: e5fa19f59867d09e X-CR-MTA-TID: 64aa7808 Received: from 9c1b978c4a64.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 225AF38E-B90F-473E-884F-980F5BAFE9D3.1; Wed, 13 Apr 2022 13:00:36 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 9c1b978c4a64.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 13 Apr 2022 13:00:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MtEccnoIjgbHSlstWzvyCIBdTmB+FMahs99bADzg7wk4dcnQwzCrOura98gITl1HB/QqVj95qH4IwCo4XZOrtiLgtQSga6MhaxLeDOUscUjZYeh2Xr5gTYxMWovb29R5ZRcBLJdnWRqBwTU+OMgfshySYRv1JsitxvHRS9gTbVb8ME94zqdxuqgZScpQ7p+lWObgm/Vd0vgHvTwHXB62Be7XSPLVusQWIvqobMMCzpgkNzMohPoJe9SS3HCST/n6mkBwqJ3A9Ztmbm+mVShutZzVMZFOFouPLtrnbpDD4ugJAH33ErLupNR6zOyxPXrKHCmNBPCPtcmMXd49U4Ku0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jjiy9wTZJee2SpwDEI1fS7R0ZXAfngIOg3E3EpVoKBs=; b=bKOIZy60C0Au/cyq6vNrGpy+S7StI9oqdZTcmSC5800ic8OfEjAt6QkUmbzZ8eWkO+lRazf6ESTnVEpGV0TWZCYyteqHMyBDELeUrmwyhnnqorQV3TsTBFWCvDe1G/msDszZ9ewCIQEK386fLod7g27yXTVw5YptQ+4WhNlKJZyC+2lBMeMAZ/8D19+kN0zoIq1EXc2c0d9rDMIWjPD3LhL24Zl4LUkPnTAZR5W0pFo7fnBceYmydxc3TjtqPjgnPT1VDZtjVKha9qIE3Sz5MJuxLryCK9OJXXRfl0VPA/3f+TipnAGWSjova3WidlBwBkvGpMYEcnnsQ1+ia+xLpQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none Received: from DB6PR0501CA0011.eurprd05.prod.outlook.com (2603:10a6:4:8f::21) by DB6PR0802MB2440.eurprd08.prod.outlook.com (2603:10a6:4:a1::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Wed, 13 Apr 2022 13:00:34 +0000 Received: from DB5EUR03FT035.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:8f:cafe::84) by DB6PR0501CA0011.outlook.office365.com (2603:10a6:4:8f::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.30 via Frontend Transport; Wed, 13 Apr 2022 13:00:34 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; Received: from nebula.arm.com (40.67.248.234) by DB5EUR03FT035.mail.protection.outlook.com (10.152.20.65) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5164.19 via Frontend Transport; Wed, 13 Apr 2022 13:00:34 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Wed, 13 Apr 2022 13:00:41 +0000 Received: from armchair.cambridge.arm.com (10.2.80.71) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.2308.27 via Frontend Transport; Wed, 13 Apr 2022 13:00:41 +0000 To: Subject: [PATCH v3 2/2] aarch64: Move ld.so _start to separate file and drop _dl_skip_args Date: Wed, 13 Apr 2022 14:00:33 +0100 Message-ID: <6ff5facd3d1dedce53da3df77d025d2f0b6cc31b.1649854695.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: 92ec0be2-f9a9-45ae-1f80-08da1d4d9e7d X-MS-TrafficTypeDiagnostic: DB6PR0802MB2440:EE_|AM5EUR03FT039:EE_|AS4PR08MB7478:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 65FPdZc0JYgkHiCbo0RAswzwbnJqg/ygBVxd12KJ7eeKXAoKSMJ8ml+E+lNWgd4XC9w6RpzaaipkQkYLX06Nhw7Vp4Or4ciqqqZ93mru1sIrFpvIjaGF8yQWqTs8CDEoXJIMWqupmZ3rl5FaiZvMYdAfKKu9edpS45u3/ZLb0VdEt9NfpxyatsDoMmTiuHfDa3TwvpTiBnsOVKGOkCfV3d2EHPNOR3UtTfG1HUv8ItzmysZ/TlebPnRy7rWbjxFZ0aKCemYxyKVQL1ws5mYWJL8mm5ibpSdpfktDpGX6gUwJxff/XqU6MQc1RZXO44TvFiepQeKLy7vqkfLm2RYejjXtk8qVNiDAel4eHDZpuFRkLv04vPOTpnAu8o6s1yk6fryYKPJiFqohoB14jvnj4UyvUSLKm1JaW5sZx/ILv9dRtpaXLjO6AlOrAogd7g9pL46sdVz+NgMnzY+FEYMvW7kEUfIXn37ROlov1Nx475aIn64Zl9ahF6KytH+c+SMyCXoAFrKvx9FnrAORSEjf8D7nMXRS/pxfDqNbms780Dd8bVKskYD7HHrbzwh8mxjFnZMNytFSgc6wK73lL9lr70Q2fG2ZYrIdISTW95X8XjGFVbg7rh7PbMISyQTVvKp0fmciPtDfATKZ+2p2HH1YCwg9lhqwSSIqPAHAF5QRNZbH4mEzzblJ38eSgbr2f2CS9vnHElsQbASvN9Xnp7Q9jzhovasggd7v3eDGVEp7EZVjylnS485fdY0Fkd324pNK/RLbSiJQvARILc5mr0QXBTCJG3005ycvFmdNLCkLX+r4+BqrYUy0yq9OqZkZbRJ8 X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:nebula.arm.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(86362001)(6666004)(186003)(26005)(426003)(2906002)(336012)(5660300002)(44832011)(82310400005)(36860700001)(2616005)(47076005)(70586007)(70206006)(6916009)(8676002)(8936002)(7696005)(81166007)(356005)(36756003)(83380400001)(498600001)(40460700003)(2004002)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0802MB2440 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT039.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: e0efd6b8-5f43-44b3-66e9-08da1d4d9953 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DyBu4vSyvfg79aArP/XUOS3/WPKMcppEfK2rrOZHxZDD5dLor5OJtaVbQHkUgQD+jQqMEj+0LaPgp9k0r1ww0kPMqV0HZW06H7ikEgThKMzbJrtSXozhGD+UbHKwszUg+8vgZWLMR4YGEc8Hx1NioCsiQplRHVcQ4N5ku1lLj5cxH0DDW32mAlLry3RqvZRGVhNXLJytV6oeDqHlusYn6Nd60iyAinMNHuZ3RoN/0MHdzqaOKrl7DkF3zEJvvQ0eMOvndCGv5yYO8ISA4nQnMuIO1h1U1anvzy3QBA/YDyPo0VFrpY9OY2X62laNo4Og3Vh9JXcz2Zu+IkA/jj7gw3NJz43LwKNOjuRrSZgKbu8BZdhEZTDZQI6QiYAPpSOCgqnbp9x8zbqwa26Rms4Gs+Ew+zMV3RU0yDsTILvJ5p5G3Rb5giu/h2BNIvzpT0NNcK5SutMrIWudXsVtAyMZgecwEo6jsva2l8wzxamKwFIuTjIR2piAaUaihdKriiboSA0u1Gh4viKVmU+e1b/BuLQOoJioX2VydEwuWlMrU8FxA1aNHbKMrcBw13ZjCrBG7cVLuBQ5TvskRXXNbVhQOzivoNyXQDUSys6I4klGcmNZzu9OCJvx6lV1vcrZNSvAu5R7oNn1BmM1P6Y8R4x+8Z9wA0XiDlCNykB7jhkGSukibFMiHGNbSXR29IFP58AXKVB2xnW7RcEH6VGIti+hRPUfYgCrwMFsMTRcqrtMrp3yizTw573jVhD6l4Fcr9WG98pzpsFPBG7eynnA2agPBA== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(7696005)(5660300002)(86362001)(82310400005)(6916009)(2906002)(40460700003)(426003)(8936002)(47076005)(336012)(26005)(186003)(6666004)(81166007)(83380400001)(2616005)(498600001)(36860700001)(44832011)(70206006)(70586007)(36756003)(8676002)(2004002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Apr 2022 13:00:43.4408 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 92ec0be2-f9a9-45ae-1f80-08da1d4d9e7d X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT039.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS4PR08MB7478 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY 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-Patchwork-Original-From: Szabolcs Nagy via Libc-alpha From: Szabolcs Nagy Reply-To: Szabolcs Nagy Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" 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 handled in the _start asm, instead we rely on DL_NEED_START_ARGS_ADJUST. Reviewed-by: Florian Weimer --- 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)