From patchwork Wed Aug 18 05:55:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fangrui Song X-Patchwork-Id: 44689 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5B592388803F for ; Wed, 18 Aug 2021 05:56:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5B592388803F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1629266181; bh=jJILnabWw5GN6WfZnqDAOpJP1TC6yhRGXdl2jXcefgQ=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=xzfB9gNvDcojl6y1eW8bz79s+rW60CLhebb9SAQa36CavElwZ5ePdCiOMMC24Wq6s j+k8Tvj6RukyG4H6CfGVFTxhWuItY3iqO1qKQOrXQ+m2Q4+P8yHiLTMjWqH8roSmHQ WlpeWFnL8rIjPedE7SytkA8cdyyMWVnZZplp72AI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by sourceware.org (Postfix) with ESMTPS id 55317388881F for ; Wed, 18 Aug 2021 05:56:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 55317388881F Received: by mail-yb1-xb4a.google.com with SMTP id x5-20020a0569020505b0290592c25b8c59so1698664ybs.18 for ; Tue, 17 Aug 2021 22:56:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=jJILnabWw5GN6WfZnqDAOpJP1TC6yhRGXdl2jXcefgQ=; b=OytotBbHDQHjocMsVncO/tFQVQviT9BaCbyR2gXtIOS75d/+ArJNlfJf0DIUrLfA7h ApoFsAXhjTuDlKdh/6SZPHIOon4q6PBJl25eIRtEHd0BUlGlLIh5DMnj9ubT95FkmRut XTgG8wwjLwReac5dJBqbnyqnwJnAGjjA8uEFMepASvdNkt885id5etimWbD+IzSmtOJi fKPmMvWKa+9Ot7SCkaY2MD1I/rdZ7GuC0Veb0U6cyepdLNaWbShKL40XqCoeh0L2aBYu qh2QEMxgoUkmnVp/5P5RU2DRidG11tZxy0/OMnGAXp0GSHEte/0biuYkXGaJVzi1EIPU LesQ== X-Gm-Message-State: AOAM53043lU3Fa8OqW4JeDJs8s5FsMAzT5nWS2Z84y77/mTOEciP6wL1 oINk96WbymvpBVIlylTIiKmhYuNtlPUmx0I3rh5cojpfr9AXslSlX3dQt2c3FvksIYm0+z7EwC1 vx/xAOU2M+vsvC3NsDSG+0DPmPrt+N89Ro5RkLd4h361TNilOmzuW1c8U2yKoj/KxhCJt X-Google-Smtp-Source: ABdhPJw+qWVtqRpWITL3SySLnKKLeSQCqJnHQd87oZ+Y/Zsv6Jy+p9dAOztkwbni+2eufhmHDCujAArh3RAa X-Received: from maskray1.svl.corp.google.com ([2620:15c:2ce:200:3873:27e4:f574:ca40]) (user=maskray job=sendgmr) by 2002:a25:c2:: with SMTP id 185mr9991890yba.148.1629266159848; Tue, 17 Aug 2021 22:55:59 -0700 (PDT) Date: Tue, 17 Aug 2021 22:55:56 -0700 Message-Id: <20210818055556.2119205-1-maskray@google.com> Mime-Version: 1.0 Subject: [PATCH] arm: Simplify elf_machine_{load_address,dynamic} To: libc-alpha@sourceware.org, Joseph Myers X-Spam-Status: No, score=-19.6 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL 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: Fangrui Song via Libc-alpha From: Fangrui Song Reply-To: Fangrui Song Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" and drop reliance on _GLOBAL_OFFSET_TABLE_[0] being the link-time address of _DYNAMIC. &__ehdr_start is a better way to get the load address. This is similar to commits b37b75d269883a2c553bb7019a813094eb4e2dd1 (x86-64) and 43d06ed218fc8be58987bdfd00e21e5720f0b862 (aarch64). --- sysdeps/arm/dl-machine.h | 47 +++++++++------------------------------- 1 file changed, 10 insertions(+), 37 deletions(-) diff --git a/sysdeps/arm/dl-machine.h b/sysdeps/arm/dl-machine.h index ff5e09e207..eb13cb8b57 100644 --- a/sysdeps/arm/dl-machine.h +++ b/sysdeps/arm/dl-machine.h @@ -37,48 +37,21 @@ elf_machine_matches_host (const Elf32_Ehdr *ehdr) return ehdr->e_machine == EM_ARM; } - -/* Return the link-time address of _DYNAMIC. Conveniently, this is the - first element of the GOT. */ -static inline Elf32_Addr __attribute__ ((unused)) -elf_machine_dynamic (void) -{ - /* Declaring this hidden ensures that a PC-relative reference is used. */ - extern const Elf32_Addr _GLOBAL_OFFSET_TABLE_[] attribute_hidden; - return _GLOBAL_OFFSET_TABLE_[0]; -} - - /* Return the run-time load address of the shared object. */ -static inline Elf32_Addr __attribute__ ((unused)) +static inline ElfW(Addr) __attribute__ ((unused)) elf_machine_load_address (void) { - Elf32_Addr pcrel_addr; -#ifdef SHARED - extern Elf32_Addr __dl_start (void *) asm ("_dl_start"); - Elf32_Addr got_addr = (Elf32_Addr) &__dl_start; - asm ("adr %0, _dl_start" : "=r" (pcrel_addr)); -#else - extern Elf32_Addr __dl_relocate_static_pie (void *) - asm ("_dl_relocate_static_pie") attribute_hidden; - Elf32_Addr got_addr = (Elf32_Addr) &__dl_relocate_static_pie; - asm ("adr %0, _dl_relocate_static_pie" : "=r" (pcrel_addr)); -#endif -#ifdef __thumb__ - /* Clear the low bit of the function address. - - NOTE: got_addr is from GOT table whose lsb is always set by linker if it's - Thumb function address. PCREL_ADDR comes from PC-relative calculation - which will finish during assembling. GAS assembler before the fix for - PR gas/21458 was not setting the lsb but does after that. Always do the - strip for both, so the code works with various combinations of glibc and - Binutils. */ - got_addr &= ~(Elf32_Addr) 1; - pcrel_addr &= ~(Elf32_Addr) 1; -#endif - return pcrel_addr - got_addr; + extern const ElfW(Ehdr) __ehdr_start attribute_hidden; + return (ElfW(Addr)) &__ehdr_start; } +/* Return the link-time address of _DYNAMIC. */ +static inline ElfW(Addr) __attribute__ ((unused)) +elf_machine_dynamic (void) +{ + extern ElfW(Dyn) _DYNAMIC[] attribute_hidden; + return (ElfW(Addr)) _DYNAMIC - elf_machine_load_address (); +} /* Set up the loaded object described by L so its unrelocated PLT entries will jump to the on-demand fixup code in dl-runtime.c. */