From patchwork Fri Sep 24 16:09:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fangrui Song X-Patchwork-Id: 45422 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 CE4B43858024 for ; Fri, 24 Sep 2021 16:11:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CE4B43858024 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1632499870; bh=Imx40YRwLFG5U8nsxJ4jMwsOcSVy3JzqCixxIXhcw+E=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=eU8ZUIVocGHteC+7tcpbKplZQjQtUfNdj0nSK+9ipffSd2n/J3ll1MAUrTi97mX+t WeUGD/asU3UzwM5q8iUoYL9SOTG3yYNJiDI9/pqHDlZagfLiTmM9DIXhD2OxJLGThz YzZeaa8DGPryl1nOaTsipOYVYyGuHlnNH4zf6lNY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by sourceware.org (Postfix) with ESMTPS id 129A13858423 for ; Fri, 24 Sep 2021 16:10:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 129A13858423 Received: by mail-yb1-xb49.google.com with SMTP id y134-20020a25dc8c000000b0059f0301df0fso3930427ybe.21 for ; Fri, 24 Sep 2021 09:10:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=Imx40YRwLFG5U8nsxJ4jMwsOcSVy3JzqCixxIXhcw+E=; b=WMruxI0l3G9HbC/QZYMugUe35iPIcqbr7nGlz94zcZdD5vPya08mpdlrKva+wJyW2r 4pqc0GtNbCscKpEo7+FmgXwt87DuKW0SGSeF/YBro3z/6J8jmXvB1wSpHH+9TSDXt6hu 6KZU2+P/Wf9V9DWuHcF0yLCEtMZnRUsEyIWT0owqOewZPUDq3kKN1/DfYMwlE1qO4e3S IEaA4e/wQkd29bkyUmELkbzz6Nmi3TYi+N92bmRWSA8Yd448mruxopQCHjlo0USePStG ZTXFbMAO3WTHb1IrsQZKu/DCXbw9q1flRpgcxSv9kvJNfSzkExA0MZpF3GpNcCc2o6D8 BvAQ== X-Gm-Message-State: AOAM533CuOYfVAWURmpMgLbltBijjeULuc7H1O3LM+V0Ypg2fQDFW3TB txGw+Z5junDiURIh+YXii2ngmU0txcFjRatR4x2E3F8l3aPQ9gqs66XGuzR0NFvwFGu2/VsVO/M h1l7Uuq4lUB5PwjSV8uG9FdJNp1z/4Jih4VQYJJIbsADJCbJClM8OH5bPqtVFUAw6fB2j X-Google-Smtp-Source: ABdhPJy45AJ5HZsYPAiZdiyqlP+JXLuQt0O7PQdWhNYXhJhAteFSFD36MHhYoNxz2CXizLNRxXDspF5gaF7b X-Received: from maskray1.svl.corp.google.com ([2620:15c:2ce:200:7876:453c:557e:a27a]) (user=maskray job=sendgmr) by 2002:a25:a2cf:: with SMTP id c15mr14219130ybn.392.1632499838648; Fri, 24 Sep 2021 09:10:38 -0700 (PDT) Date: Fri, 24 Sep 2021 09:09:48 -0700 Message-Id: <20210924160948.4123839-1-maskray@google.com> Mime-Version: 1.0 Subject: [PATCH v2] i386: Port elf_machine_{load_address,dynamic} from x86-64 To: libc-alpha@sourceware.org, "H.J. Lu" X-Spam-Status: No, score=-19.7 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, 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" This drops reliance on _GLOBAL_OFFSET_TABLE_[0] being the link-time address of _DYNAMIC. The code sequence length does not change. Reviewed-by: H.J. Lu --- Changes from v1: * Change ElfW(xxx) to Elf32_xxx --- sysdeps/i386/dl-machine.h | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/sysdeps/i386/dl-machine.h b/sysdeps/i386/dl-machine.h index 590b41d8d7..0401888508 100644 --- a/sysdeps/i386/dl-machine.h +++ b/sysdeps/i386/dl-machine.h @@ -34,27 +34,20 @@ elf_machine_matches_host (const Elf32_Ehdr *ehdr) } -/* Return the link-time address of _DYNAMIC. Conveniently, this is the - first element of the GOT, a special entry that is never relocated. */ -static inline Elf32_Addr __attribute__ ((unused, const)) -elf_machine_dynamic (void) -{ - /* This produces a GOTOFF reloc that resolves to zero at link time, so in - fact just loads from the GOT register directly. By doing it without - an asm we can let the compiler choose any register. */ - 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)) elf_machine_load_address (void) { - /* Compute the difference between the runtime address of _DYNAMIC as seen - by a GOTOFF reference, and the link-time address found in the special - unrelocated first GOT entry. */ - extern Elf32_Dyn bygotoff[] asm ("_DYNAMIC") attribute_hidden; - return (Elf32_Addr) &bygotoff - elf_machine_dynamic (); + extern const Elf32_Ehdr __ehdr_start attribute_hidden; + return (Elf32_Addr) &__ehdr_start; +} + +/* Return the link-time address of _DYNAMIC. */ +static inline Elf32_Addr __attribute__ ((unused)) +elf_machine_dynamic (void) +{ + extern Elf32_Dyn _DYNAMIC[] attribute_hidden; + return (Elf32_Addr) _DYNAMIC - elf_machine_load_address (); } /* Set up the loaded object described by L so its unrelocated PLT