From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id 17DFE3850408 for ; Wed, 13 Jan 2021 00:03:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 17DFE3850408 Received: by mail-ot1-x32c.google.com with SMTP id x13so228343oto.8 for ; Tue, 12 Jan 2021 16:03:10 -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=ZFvS/prfirOrdbSjrRf9QgP4H3ih/7x3Qm9nzBz2SP4=; b=JNEIIqMflcqc7uVDgUR0GvUS9XscliXAdN3Nukk49Bufy2W0c7FQ9e35Ed2MgN4Rih uQS1VtPHmq5iT3i7THhU6ygiqjcpRnr/8TKaRXUpjFmBlmOiyUt35YKmFTEX85oNb8vp LJ8CC7URmdKYGph+bYr/P66LXpOIvEr09A7npOSB5/Evx3HzR3go0WwWturOAHvmCp0i wjHFDc8mJGfVjzyilNNgtN9dPTMxrEoUJLdnJU7j+SePeE59ERIcri6sP5g6/xXsMyfJ 9lKR5+P4YKfP35ldMN3l+OO8EyqYbfnGxKjxbTZUAwHESliNkH5ilvL6A0ctBcPM396X LSiw== X-Gm-Message-State: AOAM530dS1rm8//zwyonMwmfJOrBWP8Pll81XkYrKyoWM5Vw7lOsoXdg cCxEkOK7HxIBltYUjmQUhDiN1FwqW4lGpK2niqFHQOGxveU= X-Google-Smtp-Source: ABdhPJxJLdTzy5vX1IiesDCgG4Jt8xhhSyHUuWHMFCGg3x4/2dSraDLnd3mtGXumCwLssRWMbnFq2PEqfnla1Det7UI= X-Received: by 2002:a05:6830:10d2:: with SMTP id z18mr1263378oto.90.1610496189505; Tue, 12 Jan 2021 16:03:09 -0800 (PST) MIME-Version: 1.0 References: <27498bbc768372541e4379794656ac2778d33035.1610471272.git.szabolcs.nagy@arm.com> In-Reply-To: From: "H.J. Lu" Date: Tue, 12 Jan 2021 16:02:33 -0800 Message-ID: Subject: Re: [PATCH v3 2/5] Make libc symbols hidden in static PIE To: Szabolcs Nagy Cc: GNU C Library Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3037.0 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: Wed, 13 Jan 2021 00:03:11 -0000 On Tue, Jan 12, 2021 at 3:09 PM H.J. Lu wrote: > > On Tue, Jan 12, 2021 at 9:26 AM Szabolcs Nagy via Libc-alpha > wrote: > > > > Hidden matters with static PIE: extern symbol access in position > > independent code usually involves GOT indirections which needs > > RELATIVE relocs in a static linked PIE. Using So hidden avoids > > indirections and RELATIVE relocs on targets that can access symbols > > pc-relative. > > > > The check should use IS_IN_LIB instead of IS_IN(libc) since all > > static libraries can use hidden visibility to avoid indirections, > > however the test system links objects from libcrypt.a into dynamic > > linked test binaries so hidden does not work there. I think mixing > > static and shared libc components in the same binary should not be > > supported usage, but to be safe only use hidden in libc.a. > > > > From -static-pie linked 'int main(){}' this shaves off 73 relative > > relocs on aarch64 and reduces code size too. > > --- > > include/libc-symbols.h | 8 ++++++-- > > 1 file changed, 6 insertions(+), 2 deletions(-) > > > > diff --git a/include/libc-symbols.h b/include/libc-symbols.h > > index ea126ae70c..93e63ee889 100644 > > --- a/include/libc-symbols.h > > +++ b/include/libc-symbols.h > > @@ -434,13 +434,17 @@ for linking") > > strong_alias(real, name) > > #endif > > > > -#if defined SHARED || defined LIBC_NONSHARED \ > > - || (BUILD_PIE_DEFAULT && IS_IN (libc)) > > +#if defined SHARED || defined LIBC_NONSHARED > > # define attribute_hidden __attribute__ ((visibility ("hidden"))) > > #else > > # define attribute_hidden > > #endif > > > > +/* Mark all symbols hidden in static PIE libc to avoid GOT indirections. */ > > +#if BUILD_PIE_DEFAULT && IS_IN (libc) && !defined LIBC_NONSHARED > > +# pragma GCC visibility push(hidden) > > +#endif > > + > > #define attribute_tls_model_ie __attribute__ ((tls_model ("initial-exec"))) > > > > #define attribute_relro __attribute__ ((section (".data.rel.ro"))) > > -- > > 2.17.1 > > > > Unfortunately it doesn't work on i686 with --enable-static-pie: > > /usr/local/bin/ld: > /export/build/gnu/tools-build/glibc-32bit-static-pie-gitlab/build-i686-linux/libc.a(dl-lookup-direct.o): > unsupported non-PIC call to IFUNC `strcmp' > > Please make it opt-out. > See: https://sourceware.org/bugzilla/show_bug.cgi?id=14961 -- H.J.