From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x231.google.com (mail-oi1-x231.google.com [IPv6:2607:f8b0:4864:20::231]) by sourceware.org (Postfix) with ESMTPS id 27BE2386F002 for ; Thu, 7 Jan 2021 21:04:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 27BE2386F002 Received: by mail-oi1-x231.google.com with SMTP id f132so8878400oib.12 for ; Thu, 07 Jan 2021 13:04:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=I5lEH4otx1GiqkWnsfEsh+aPblFNVQajZSvFJV+wIRI=; b=dqExJDkPN7p71RZm96DpgYbvmGayxTU3NiXKi6GhCU7Dw9GNz335JqRGM69TSr80FX 7UdTOdILUTyjOWC6wG7RuCjbgYnQc2Ae+QqTV2rochfEjhJD5OrE5WRoX/XNSBUIiZvs /N+cpgE7ewvy2a7jJokCUasETgzWSN0nrIVCdP2hZwdIOUn+Z3DNPAnjeJD3CjtFvJpD sq9q2DLLpYjvyoYx7DRzs/zxf76mOqqHUya2SMQPVNHJ76TQ9Ua6k6q7Da3ebcQSpvVB sjBvjWEJ970bQmu7fQp3SBddonyMJHMN6zad7W2zFx727swPx8SldPWh2htdvLVsrBH1 GwDA== X-Gm-Message-State: AOAM533IGiB1IzakyTj0RDbu/7dxc4d1sKhGzCTdubVFdQyXWcFXIx/0 bSa0kCO3Wr+bymfG7AxE365rtTnSyhcOrRwQk95Rx9C9/WQ= X-Google-Smtp-Source: ABdhPJwf7oIF2doy2MbPBXAUt8PIIPisV3zow7hANvi4O81WwAw6FUL8Vw85xVy4YrFaG/2eW6BF61cBk2wRNwxglgo= X-Received: by 2002:aca:f456:: with SMTP id s83mr338911oih.58.1610053456620; Thu, 07 Jan 2021 13:04:16 -0800 (PST) MIME-Version: 1.0 References: <1bfa01e6e92073b30c02cb76a209656b9d97b675.1610016590.git.szabolcs.nagy@arm.com> In-Reply-To: <1bfa01e6e92073b30c02cb76a209656b9d97b675.1610016590.git.szabolcs.nagy@arm.com> From: "H.J. Lu" Date: Thu, 7 Jan 2021 13:03:40 -0800 Message-ID: Subject: Re: [PATCH 3/3] csu: Move static pie self relocation later [BZ #27072] To: Szabolcs Nagy Cc: GNU C Library Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3036.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Thu, 07 Jan 2021 21:04:21 -0000 On Thu, Jan 7, 2021 at 3:04 AM Szabolcs Nagy via Libc-alpha wrote: > > On targets where hidden symbol access does not need RELATIVE > relocs, move the static pie self relocation after tunables and > cpu features are set up. This allows processing IRELATIVE > relocs with correct ifunc dispatch logic. > > Unfortunately it is hard to guarantee that there will be no > dynamic relocations in the early start up code, so this is a > bit fragile. Ideally the RELATIVE relocs would be processed as > early as possible and IRELATIVE relocs after cpu features are > setup, but in glibc it is hard to separate them into two steps. > --- > csu/libc-start.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/csu/libc-start.c b/csu/libc-start.c > index db859c3bed..b8d22bd59e 100644 > --- a/csu/libc-start.c > +++ b/csu/libc-start.c > @@ -142,7 +142,10 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL), > int result; > > #ifndef SHARED > +# ifndef PI_STATIC_AND_HIDDEN > + /* Do static pie self relocation as early as possible. */ > _dl_relocate_static_pie (); > +# endif It should be simply removed. PI_STATIC_AND_HIDDEN should be required for static PIE. > char **ev = &argv[argc + 1]; > > @@ -191,6 +194,13 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL), Does { /* Starting from binutils-2.23, the linker will define the magic symbol __ehdr_start to point to our own ELF header if it is visible in a segment that also includes the phdrs. So we can set up _dl_phdr and _dl_phnum even without any information from auxv. */ extern const ElfW(Ehdr) __ehdr_start __attribute__ ((weak, visibility ("hidden"))); if (&__ehdr_start != NULL) { assert (__ehdr_start.e_phentsize == sizeof *GL(dl_phdr)); GL(dl_phdr) = (const void *) &__ehdr_start + __ehdr_start.e_phoff; GL(dl_phnum) = __ehdr_start.e_phnum; } } here require RELATIVE relocation? > ARCH_INIT_CPU_FEATURES (); > > +# ifdef PI_STATIC_AND_HIDDEN > + /* Do static pie self relocation after cpu features are setup. > + Code before this point must avoid relocations, which in practice > + means no initialized global pointer or ifunc symbol access. */ > + _dl_relocate_static_pie (); > +# endif > + > /* Perform IREL{,A} relocations. */ > ARCH_SETUP_IREL (); > > -- > 2.17.1 > -- H.J.