From patchwork Thu Sep 28 12:22:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 23194 Received: (qmail 87605 invoked by alias); 28 Sep 2017 12:22:19 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 87595 invoked by uid 89); 28 Sep 2017 12:22:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-oi0-f52.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=w9RRTSpWhA9jSPMFRObHAuufrveOfY7fMJqmhG+xFHw=; b=NIvC2j6uae8zkTWRz8GiuyNcFXrrISUSOENjLkDG2xpVMiGank+laG+uHK3Sc+BRho eijqI7v72z5u2XFrkMLwVUvILhXLV5/Q7+XkrBer8aBgV41Ck+7q3TJ6iu3MSQDk+P6R SNQpd/I5oaA7Vl2Jx4CMHnbE+5DRBPcZNCEUP0DP7hih/M77+jvOjzuyNOSs/kQhPDo9 KZS76PB49YFVp14T0bC7dBnDKcspBzthICOQxqw8eDn0udtNKSY54qhsv5Uir/glaXJ2 wCGP5AS2zeSeAtqOduPVki2Ag3kKKS05VbiA9HBAbbJNCP4M9Zq1Av9noH558OZINmIi pBMw== X-Gm-Message-State: AMCzsaVtvYDv1GBc4wiGJNrj0mdjj+GyCPfzIXpArlxLJOvdpu2I93Er VusG1fSh7ZomK3hSFRJYEdZCmTNf X-Google-Smtp-Source: AOwi7QAJiwr17d6VzlEuDCpJeix5s7sapg8YUjA0K7ZMYVULi0rIcDZXaMtrM3o0EcusqjLqJ/8KMA== X-Received: by 10.202.64.131 with SMTP id n125mr208542oia.202.1506601336013; Thu, 28 Sep 2017 05:22:16 -0700 (PDT) Date: Thu, 28 Sep 2017 05:22:07 -0700 From: "H.J. Lu" To: GNU C Library Subject: [PATCH] x86: Allow undefined _DYNAMIC in static executable Message-ID: <20170928122207.GA25931@gmail.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.8.3 (2017-05-23) When --enable-static-pie is used to build static PIE, _DYNAMIC is used to compute the load address of static PIE. But _DYNAMIC is undefined when creating static executable. This patch makes _DYNAMIC weak in PIE libc.a so that it can be undefined. Any comments? H.J. --- * sysdeps/i386/dl-machine.h (elf_machine_load_address): Allow undefined _DYNAMIC in PIE libc.a. * sysdeps/x86_64/dl-machine.h (elf_machine_load_address): Likewse. --- sysdeps/i386/dl-machine.h | 17 +++++++++++++++-- sysdeps/x86_64/dl-machine.h | 13 +++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/sysdeps/i386/dl-machine.h b/sysdeps/i386/dl-machine.h index 2e17eba5c0..0a5c83398f 100644 --- a/sysdeps/i386/dl-machine.h +++ b/sysdeps/i386/dl-machine.h @@ -54,8 +54,21 @@ 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 (); +#ifdef SHARED + extern Elf32_Dyn _DYNAMIC[] attribute_hidden; + return (Elf32_Addr) &_DYNAMIC - elf_machine_dynamic (); +#else + extern Elf32_Dyn _DYNAMIC[] __attribute__((weak, visibility ("hidden"))); + if (_DYNAMIC) + { + /* The address of dynamic must be taken as non-weak to avoid + dynamic relocation. */ + extern Elf32_Dyn dynamic[] asm ("_DYNAMIC") attribute_hidden; + return (Elf32_Addr) &dynamic - elf_machine_dynamic (); + } + else + return 0; +#endif } /* Set up the loaded object described by L so its unrelocated PLT diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h index 6a04cbcdc9..4114c798f0 100644 --- a/sysdeps/x86_64/dl-machine.h +++ b/sysdeps/x86_64/dl-machine.h @@ -55,8 +55,21 @@ 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. */ +#ifdef SHARED extern ElfW(Dyn) _DYNAMIC[] attribute_hidden; return (ElfW(Addr)) &_DYNAMIC - elf_machine_dynamic (); +#else + extern ElfW(Dyn) _DYNAMIC[] __attribute__((weak, visibility ("hidden"))); + if (_DYNAMIC) + { + /* The address of dynamic must be taken as non-weak to avoid + dynamic relocation. */ + extern ElfW(Dyn) dynamic[] asm ("_DYNAMIC") attribute_hidden; + return (ElfW(Addr)) &dynamic - elf_machine_dynamic (); + } + else + return 0; +#endif } /* Set up the loaded object described by L so its unrelocated PLT