From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by sourceware.org (Postfix) with ESMTPS id 7DB173858402 for ; Fri, 24 Sep 2021 16:05:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7DB173858402 Received: by mail-pl1-x629.google.com with SMTP id x8so3962605plv.8 for ; Fri, 24 Sep 2021 09:05:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7LlkRT22AmWEQWRmRSmDbnrVEjK0UAeQxmbAAQimbDk=; b=Fhbu8wbTL/1+L+7yrv75HHGmZpV+oIxmUgMEVuiFXWdAzWydLtTnG+W+ahJP+9VSYm /PiZPdJwuuPO1A8l+nZvtwPyMxf/Y6isgJWoSIKj15+lHtvO9iRQZSw426ObseeiBvjz iFIrqH+xLZpNCQ9A3hq0o0NpMRXxHvChXeeIc2TqZ7jK4017o6iIfEWTqI2PwGFeY0n8 x2ppn2rB7CmCkevUtjo/2JFVLywR9qHy0mndfP5FWfGzI2KOOMnGF21eXj2MIqbQQZMu +cHq3TMXHsA4POsYJdK29X+kCUy1JeYAl7uy2P4HBLpH19l4yTwYIX67cgDsPLLNCVcI uXaw== X-Gm-Message-State: AOAM531bwdU7c4VcDt062ziEb3HF59yLYbtVi0RcYjXY7kYAerxLojQ2 gGWqWwCIZgDzTNKYo8nMSYrPJGTI9X2FTd9hTZE= X-Google-Smtp-Source: ABdhPJxPFedOHlV+0tohN+4/gkr+Rv70TYrLh7m4I8MvT+ZWK4of71ydIes6Z6NgRjSteP9b9Sw3GLAc8L5CzRsswLg= X-Received: by 2002:a17:902:8547:b0:13d:ebc2:44ba with SMTP id d7-20020a170902854700b0013debc244bamr2917004plo.85.1632499553546; Fri, 24 Sep 2021 09:05:53 -0700 (PDT) MIME-Version: 1.0 References: <20210924042623.3899762-1-maskray@google.com> In-Reply-To: <20210924042623.3899762-1-maskray@google.com> From: "H.J. Lu" Date: Fri, 24 Sep 2021 09:05:17 -0700 Message-ID: Subject: Re: [PATCH] i386: Port elf_machine_{load_address, dynamic} from x86-64 To: Fangrui Song Cc: GNU C Library Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3030.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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-List-Received-Date: Fri, 24 Sep 2021 16:05:55 -0000 On Thu, Sep 23, 2021 at 9:26 PM Fangrui Song wrote: > > This drops reliance on _GLOBAL_OFFSET_TABLE_[0] being the link-time > address of _DYNAMIC. > > The code sequence length does not change. > --- > sysdeps/i386/dl-machine.h | 29 +++++++++++------------------ > 1 file changed, 11 insertions(+), 18 deletions(-) > > diff --git a/sysdeps/i386/dl-machine.h b/sysdeps/i386/dl-machine.h > index 590b41d8d7..9f0eeaf66e 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)) > +static inline ElfW(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 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 (); > } Please use Elf32 instead of ElfW. > /* Set up the loaded object described by L so its unrelocated PLT > -- > 2.33.0.685.g46640cef36-goog > -- H.J.