From patchwork Tue Jan 19 14:25:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 41759 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 E0E31393C846; Tue, 19 Jan 2021 14:26:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E0E31393C846 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611066394; bh=/VNcP8P/8/CItt74zeswc/SukBMYeil5jkbbUdXzFQ4=; h=References:In-Reply-To:Date:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=e1M0nfUCohxmBNsSRvcK7Yb1TWaUg4++X7jZyKUG181hLtcBlDUoQVaytOBo0j8qU JYmzK3pleyOD8uVdSKhyIIg8iofuu5PWLylVfDZKWdL18HH6aLbdx3LLF9zUQVwzoA eqj05YVG4RC4U3UyLol+Mp55ExfAcqnmis6oChek= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com [IPv6:2607:f8b0:4864:20::22b]) by sourceware.org (Postfix) with ESMTPS id 83CA6393C032 for ; Tue, 19 Jan 2021 14:26:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 83CA6393C032 Received: by mail-oi1-x22b.google.com with SMTP id x71so5504540oia.9 for ; Tue, 19 Jan 2021 06:26:28 -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=/VNcP8P/8/CItt74zeswc/SukBMYeil5jkbbUdXzFQ4=; b=gC4DmE3wFxf1B6djWTHdgrImnemUHvJm7NqpBRMMzQA/Vd9oJoOcUxEkni+jT0LlcG s4n1sE/HWixZzn1ddlb6+qJa8wto9to5pNcmfMQ43AD4DcArPNqbjAKaBElvsthGczEu WMSEalcCubQIf6ME/mGEszEZ4xcdLO9S/GCzKI4lAgkY3TDiHs8+qKulpgK7FxKoERp2 oItYLs2CoYQ0B1zEhH9DKxtY7XWjGe43u6mhDuctA3cpvi5Qq5zrw4sOx/PeIiv3xsRJ q17gFCb0LcPIJxPQ89bqv6NbslVgB+U/LfJ8FcRtsSpPCYLJQbKd5VYHwiazeYeR53o6 W0Eg== X-Gm-Message-State: AOAM533X5aEzDrpomsPb/xtf4CEEJaNfF50BXjx2fe2r09nQ7zXy3+T2 bIE5C12RqNOtsK2EQbtKjwA2Cv63NIKycnK8OP0= X-Google-Smtp-Source: ABdhPJxDiHhqYMqngv/ZCVvHas6yUsuxYF+Wx/ChuZz4QMTJSvhjVxUWGCKdoqe81ezMubMs8ZnhBm2zXhP1TMOYFE0= X-Received: by 2002:aca:34c2:: with SMTP id b185mr2659908oia.25.1611066387873; Tue, 19 Jan 2021 06:26:27 -0800 (PST) MIME-Version: 1.0 References: <3ed8c627e3f1353e5539b458e596c4112121b3ba.1610986541.git.szabolcs.nagy@arm.com> <10ad0f8f-804f-c298-547a-325fdbf269f3@linaro.org> In-Reply-To: <10ad0f8f-804f-c298-547a-325fdbf269f3@linaro.org> Date: Tue, 19 Jan 2021 06:25:51 -0800 Message-ID: Subject: V2 [PATCH v4 06/10] elf: Avoid RELATIVE relocation for _dl_sysinfo To: Adhemerval Zanella X-Spam-Status: No, score=-3036.4 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-Patchwork-Original-From: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Cc: GNU C Library Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" On Tue, Jan 19, 2021 at 5:51 AM Adhemerval Zanella via Libc-alpha wrote: > > > > On 18/01/2021 13:24, Szabolcs Nagy via Libc-alpha wrote: > > From: "H.J. Lu" > > > > In static PIE, set the default _dl_sysinfo in _dl_aux_init, instead of > > using the RELATIVE relocation to intialize it. > > > > This is needed for fixing bug 27072 on x86. > > --- > > elf/dl-support.c | 12 +++++++++++- > > 1 file changed, 11 insertions(+), 1 deletion(-) > > > > diff --git a/elf/dl-support.c b/elf/dl-support.c > > index 384080dd80..5acd59290f 100644 > > --- a/elf/dl-support.c > > +++ b/elf/dl-support.c > > @@ -200,7 +200,12 @@ struct dl_scope_free_list *_dl_scope_free_list; > > > > #ifdef NEED_DL_SYSINFO > > /* Needed for improved syscall handling on at least x86/Linux. */ > > -uintptr_t _dl_sysinfo = DL_SYSINFO_DEFAULT; > > +uintptr_t _dl_sysinfo > > +/* NB: Avoid RELATIVE relocation in static PIE. */ > > +# ifndef BUILD_PIE_DEFAULT > > + = DL_SYSINFO_DEFAULT > > +# endif > > +; > > #endif > > #ifdef NEED_DL_SYSINFO_DSO > > /* Address of the ELF headers in the vsyscall page. */ > > @@ -238,6 +243,11 @@ _dl_aux_init (ElfW(auxv_t) *av) > > uid_t uid = 0; > > gid_t gid = 0; > > > > +#if defined NEED_DL_SYSINFO && BUILD_PIE_DEFAULT > > + /* NB: Avoid RELATIVE relocation in static PIE. */ > > + GL(dl_sysinfo) = DL_SYSINFO_DEFAULT; > > +#endif > > + > > Couldn't we make it the default instead? > > > _dl_auxv = av; > > for (; av->a_type != AT_NULL; ++av) > > switch (av->a_type) > > Like this? Reviewed-by: Adhemerval Zanella From af3c44826b8ff07082eb5020213652e6b1fadfa4 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Mon, 18 Jan 2021 11:45:46 +0000 Subject: [PATCH] elf: Avoid RELATIVE relocation for _dl_sysinfo Set the default _dl_sysinfo in _dl_aux_init to avoid RELATIVE relocation in static PIE. This is needed for fixing bug 27072 on x86. --- elf/dl-support.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/elf/dl-support.c b/elf/dl-support.c index 384080dd80..7abb65d8e3 100644 --- a/elf/dl-support.c +++ b/elf/dl-support.c @@ -199,8 +199,9 @@ int _dl_thread_gscope_count; struct dl_scope_free_list *_dl_scope_free_list; #ifdef NEED_DL_SYSINFO -/* Needed for improved syscall handling on at least x86/Linux. */ -uintptr_t _dl_sysinfo = DL_SYSINFO_DEFAULT; +/* Needed for improved syscall handling on at least x86/Linux. NB: Don't + initialize it here to avoid RELATIVE relocation in static PIE. */ +uintptr_t _dl_sysinfo; #endif #ifdef NEED_DL_SYSINFO_DSO /* Address of the ELF headers in the vsyscall page. */ @@ -238,6 +239,11 @@ _dl_aux_init (ElfW(auxv_t) *av) uid_t uid = 0; gid_t gid = 0; +#ifdef NEED_DL_SYSINFO + /* NB: Avoid RELATIVE relocation in static PIE. */ + GL(dl_sysinfo) = DL_SYSINFO_DEFAULT; +#endif + _dl_auxv = av; for (; av->a_type != AT_NULL; ++av) switch (av->a_type) -- 2.29.2