From patchwork Fri Sep 24 04:26:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fangrui Song X-Patchwork-Id: 45406 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 4BC66385840D for ; Fri, 24 Sep 2021 04:27:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4BC66385840D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1632457640; bh=3nsARQQcnY9NwVVKv1aqLxOfQkkuyIXwWf8diqlhQTU=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=B3G+7DWYG+HGhVIPa4P3DDQkV3ZnkN////edTuaVL6gPGnoinOy/9Ode0JCP0RUPQ 7IGlS0kaQng+OZPjZTXn7YjS+MduCmlXBynINq8WEcnmW5YygU3Ck9f0OFPm9eYQpK /Rr0ciH6wfy0uCjS+MKutT0m8c4doV1JrqoqP7Yg= 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 62E57385843A for ; Fri, 24 Sep 2021 04:26:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 62E57385843A Received: by mail-yb1-xb49.google.com with SMTP id p200-20020a25d8d1000000b005a3a281bc11so1907111ybg.0 for ; Thu, 23 Sep 2021 21:26:41 -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=3nsARQQcnY9NwVVKv1aqLxOfQkkuyIXwWf8diqlhQTU=; b=v96XYClR7+mYgeH+CrncapkcK5TfPx/ng5lFd/HU7ssP8sVGiKaf9+mxPsWb/3Ehma WLp5rLlziq4TgjbxUz14LLolizH2SKFlKIksgz7FF/y0DsXBUJontB7IPBSGYJxGnS1X p7+8OD+x0QadgXF1dQwXUZ0KwFAvg2HbPP6PZC2zEnAyGFoOUBp4+NagV8RNZUqZgah/ N9lIKFnzc3/RpqIoccddZ5yEwHiWNdRSzVjLltFTzwEbwhrGvB+0fCFIEshMwFRPTPVK KAXotjN2U6imBV9sz/AG1uTptk7+qrYkhNgG1/5IVnyQW9zInyYp9va2BEtLkhHVVgFI FpYQ== X-Gm-Message-State: AOAM533EquFRKLMwzQH0LIsL6Vn1EItLLvHkCXLTn8C6/f6GuKCITQuT EhnsJCVxiJh+0CuQUM7zR+sZfe+D0uNrSA4sOalYEJIW5X/zc0RUKxhc1P9A2JgBvd8jkgYWMZh 08LKvmy4oy5RrhMvG6hLImcAFaOUQASjm49Xuybbv1PoPXxzlO3NKsr4KjznKmlzLCsDU X-Google-Smtp-Source: ABdhPJwjTcAaA9pmI/dVondHnzLJEU/jh+kPSxFRkHcw9FNQjHhBYtAmnzob8OROF755q+yFqtuc+xgeOAJi X-Received: from maskray1.svl.corp.google.com ([2620:15c:2ce:200:7876:453c:557e:a27a]) (user=maskray job=sendgmr) by 2002:a25:1d09:: with SMTP id d9mr10113224ybd.140.1632457600839; Thu, 23 Sep 2021 21:26:40 -0700 (PDT) Date: Thu, 23 Sep 2021 21:26:23 -0700 Message-Id: <20210924042623.3899762-1-maskray@google.com> Mime-Version: 1.0 Subject: [PATCH] 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. --- 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 (); } /* Set up the loaded object described by L so its unrelocated PLT