From patchwork Tue Aug 17 06:05:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fangrui Song X-Patchwork-Id: 44677 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 A75683838003 for ; Tue, 17 Aug 2021 06:24:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A75683838003 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1629181457; bh=SFJHmdCzXYf13Ff/hu1QntvkzVEgMznrXfiuOzX//Zo=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ORgxdUhfSceWL7mCTjvmgltPGKULS8n9VFSNZ1rz5EdIsCq7QVCR44iwb8FWsJzd1 9CfR+4dqQZwFbNIWXLn9T5hz8FSdgCnY6dNTLW70UXe8Y2RJUEkImDCU9cUcX2Hahv ab64npIkbJ1ywbWUSeJ9Ur20aL+DLAhEAlesty1o= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by sourceware.org (Postfix) with ESMTPS id 783243839C6D for ; Tue, 17 Aug 2021 06:23:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 783243839C6D Received: by mail-qt1-x849.google.com with SMTP id s39-20020a05622a1aa700b00298bbc58d2fso2890217qtc.12 for ; Mon, 16 Aug 2021 23:23:56 -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=SFJHmdCzXYf13Ff/hu1QntvkzVEgMznrXfiuOzX//Zo=; b=fyzBfyrJVHZzD3LfHZCvfuKkxnEJwnJUg8d+ajkPlTtmYXYYxVCWPCNRyLRPAWhv0Q y5MoHcAHnOVXrXYrCns+egRSleq9t6ZnGZpLEoNf1/m6oT9XdxroecIS5vF7PV04ubFu CdpIkIqvrrUZe3+PZMH7HSCHi8ceoNS7qg+uz9HZZE+zhS62kfaUmTvQxbDXgNM/hp1+ 9fL7flZpMKMrjK7QbXDt8XdCGyqW25RvgN7lPFroF0MofojcQAyGN9vd/Ky3ktdQDUiR JCfhM2GT4DC9WSmH2hr+su6AEa2myipUGg78tnlNpqfQen8P2zT/qdtLKp+/8xDZx2EC h1wA== X-Gm-Message-State: AOAM530dPF7Z10ouN035o6JFDuWKTcgrLBck/va0+c2en1EDyPTc8BN9 G3grW6oPX/25tMhxiTKnpHvxWQZutMifff3SqBGSf0UgJoKPuELccFbP6FT2Bp8jbFPROtIUqO5 tzpq6/y4xpYc4K9GhRS5Boqzn2UiYmJ+MhF5YMjdV0SwD7eWmyW4ELc/rKqqjeaTX/fJe X-Google-Smtp-Source: ABdhPJy1bacy2ZXMQKmdq4EAONMIIyiQ6/KZMW2J8XrZY6zUCFDg16f4lkhY4ryv2z+qZG8cXIEpzeV4XF27 X-Received: from maskray1.svl.corp.google.com ([2620:15c:2ce:200:e30a:fd5e:699:fa1c]) (user=maskray job=sendgmr) by 2002:a05:6214:5185:: with SMTP id kl5mr1764499qvb.47.1629181436037; Mon, 16 Aug 2021 23:23:56 -0700 (PDT) Date: Mon, 16 Aug 2021 23:05:32 -0700 Message-Id: <20210817060532.1210408-1-maskray@google.com> Mime-Version: 1.0 Subject: [PATCH] x86_64: Simplify elf_machine_{load_address,dynamic} To: libc-alpha@sourceware.org X-Spam-Status: No, score=-19.2 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]. &__ehdr_start is a better way to get the load address. Reviewed-by: H.J. Lu --- sysdeps/x86_64/dl-machine.h | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h index a8596aa3fa..ceee50734e 100644 --- a/sysdeps/x86_64/dl-machine.h +++ b/sysdeps/x86_64/dl-machine.h @@ -35,27 +35,20 @@ elf_machine_matches_host (const ElfW(Ehdr) *ehdr) } -/* Return the link-time address of _DYNAMIC. Conveniently, this is the - first element of the GOT. This must be inlined in a function which - uses global data. */ -static inline ElfW(Addr) __attribute__ ((unused)) -elf_machine_dynamic (void) -{ - /* This produces an IP-relative reloc which is resolved at link time. */ - extern const ElfW(Addr) _GLOBAL_OFFSET_TABLE_[] attribute_hidden; - return _GLOBAL_OFFSET_TABLE_[0]; -} - - /* Return the run-time load address of the shared object. */ static inline ElfW(Addr) __attribute__ ((unused)) elf_machine_load_address (void) { - /* Compute the difference between the runtime address of _DYNAMIC as seen - by an IP-relative reference, and the link-time address found in the - special unrelocated first GOT entry. */ + 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_dynamic (); + return (ElfW(Addr)) _DYNAMIC - elf_machine_load_address (); } /* Set up the loaded object described by L so its unrelocated PLT