Message ID | 20170808164040.GA31184@gmail.com |
---|---|
State | Committed |
Commit | 7c41b4a1315fc4415e468bbac94f77ecdb74f4c8 |
Headers |
Received: (qmail 43118 invoked by alias); 8 Aug 2017 16:40:44 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: <libc-alpha.sourceware.org> List-Unsubscribe: <mailto:libc-alpha-unsubscribe-##L=##H@sourceware.org> List-Subscribe: <mailto:libc-alpha-subscribe@sourceware.org> List-Archive: <http://sourceware.org/ml/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-help@sourceware.org>, <http://sourceware.org/ml/#faqs> Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 42025 invoked by uid 89); 8 Aug 2017 16:40:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, NO_DNS_FOR_FROM, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mga04.intel.com X-ExtLoop1: 1 Date: Tue, 8 Aug 2017 09:40:40 -0700 From: "H.J. Lu" <hongjiu.lu@intel.com> To: GNU C Library <libc-alpha@sourceware.org> Subject: [PATCH] Enable hidden visibility in libc.a compiled with PIE Message-ID: <20170808164040.GA31184@gmail.com> Reply-To: "H.J. Lu" <hjl.tools@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.8.3 (2017-05-23) |
Commit Message
Lu, Hongjiu
Aug. 8, 2017, 4:40 p.m. UTC
When building libc.a with PIE, enable hidden visibility to allow direct access to definitions within libc.a without using GOT. Size comparison of elf/ldconfig when the compiler defaults to -fPIE: On x86-64: text data bss dec hex Before: 619206 20132 5488 644826 9d6da After : 619062 20132 5488 644682 9d64a On i686: text data bss dec hex Before: 556305 10816 3056 570177 8b341 After : 553688 10756 3056 567500 8a8cc OK for master? H.J. --- * include/libc-symbols.h (attribute_hidden): Enable hidden visibility in libc.a compiled with PIE. --- include/libc-symbols.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Comments
On Mon, Aug 14, 2017 at 5:51 AM, H.J. Lu <hjl.tools@gmail.com> wrote: > On Tue, Aug 8, 2017 at 9:40 AM, H.J. Lu <hongjiu.lu@intel.com> wrote: >> When building libc.a with PIE, enable hidden visibility to allow direct >> access to definitions within libc.a without using GOT. >> >> Size comparison of elf/ldconfig when the compiler defaults to -fPIE: >> >> On x86-64: >> text data bss dec hex >> Before: 619206 20132 5488 644826 9d6da >> After : 619062 20132 5488 644682 9d64a >> On i686: >> text data bss dec hex >> Before: 556305 10816 3056 570177 8b341 >> After : 553688 10756 3056 567500 8a8cc >> >> OK for master? >> >> H.J. >> --- >> * include/libc-symbols.h (attribute_hidden): Enable hidden >> visibility in libc.a compiled with PIE. >> --- >> include/libc-symbols.h | 3 ++- >> 1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/include/libc-symbols.h b/include/libc-symbols.h >> index fe3ab81c51..d6a1c260f6 100644 >> --- a/include/libc-symbols.h >> +++ b/include/libc-symbols.h >> @@ -363,7 +363,8 @@ for linking") >> strong_alias(real, name) >> #endif >> >> -#if defined SHARED || defined LIBC_NONSHARED >> +#if defined SHARED || defined LIBC_NONSHARED \ >> + || (BUILD_PIE_DEFAULT && IS_IN (libc)) >> # define attribute_hidden __attribute__ ((visibility ("hidden"))) >> #else >> # define attribute_hidden >> -- >> 2.13.4 >> > > Any comments or objections? > I will check it in tomorrow.
On 08/08/2017 06:40 PM, H.J. Lu wrote: > -#if defined SHARED || defined LIBC_NONSHARED > +#if defined SHARED || defined LIBC_NONSHARED \ > + || (BUILD_PIE_DEFAULT && IS_IN (libc)) > # define attribute_hidden __attribute__ ((visibility ("hidden"))) > #else > # define attribute_hidden I think this broke “make subdirs=benchtests bench-build” because json-lib.c is erroneously compiled with -DMODULE_NAME=libc. Thanks, Florian
On 08/08/17 17:40, H.J. Lu wrote: > When building libc.a with PIE, enable hidden visibility to allow direct > access to definitions within libc.a without using GOT. ... > -#if defined SHARED || defined LIBC_NONSHARED > +#if defined SHARED || defined LIBC_NONSHARED \ > + || (BUILD_PIE_DEFAULT && IS_IN (libc)) > # define attribute_hidden __attribute__ ((visibility ("hidden"))) btw what happens if this is enabled for non-pie libc.a ? i'd expect that to work too (it prevents some symbol interpositions?)
On Mon, Aug 21, 2017 at 9:31 AM, Szabolcs Nagy <szabolcs.nagy@arm.com> wrote: > On 08/08/17 17:40, H.J. Lu wrote: >> When building libc.a with PIE, enable hidden visibility to allow direct >> access to definitions within libc.a without using GOT. > ... >> -#if defined SHARED || defined LIBC_NONSHARED >> +#if defined SHARED || defined LIBC_NONSHARED \ >> + || (BUILD_PIE_DEFAULT && IS_IN (libc)) >> # define attribute_hidden __attribute__ ((visibility ("hidden"))) > > btw what happens if this is enabled for non-pie libc.a ? It makes those symbols in libc.a hidden. > i'd expect that to work too (it prevents some symbol > interpositions?) > You can't interpose any symbols in libc.a, PIE or non-PIE. What my patch does is to avoid GOT/PLT in PIE libc.a when accessing them within libc.a.
On 21/08/17 17:44, H.J. Lu wrote: > On Mon, Aug 21, 2017 at 9:31 AM, Szabolcs Nagy <szabolcs.nagy@arm.com> wrote: >> On 08/08/17 17:40, H.J. Lu wrote: >>> When building libc.a with PIE, enable hidden visibility to allow direct >>> access to definitions within libc.a without using GOT. >> ... >>> -#if defined SHARED || defined LIBC_NONSHARED >>> +#if defined SHARED || defined LIBC_NONSHARED \ >>> + || (BUILD_PIE_DEFAULT && IS_IN (libc)) >>> # define attribute_hidden __attribute__ ((visibility ("hidden"))) >> >> btw what happens if this is enabled for non-pie libc.a ? > > It makes those symbols in libc.a hidden. > >> i'd expect that to work too (it prevents some symbol >> interpositions?) >> > > You can't interpose any symbols in libc.a, PIE or non-PIE. > What my patch does is to avoid GOT/PLT in PIE libc.a when > accessing them within libc.a. > yes, but my point is that the ifdef can be simplified if it's valid for the non-pie case too.
diff --git a/include/libc-symbols.h b/include/libc-symbols.h index fe3ab81c51..d6a1c260f6 100644 --- a/include/libc-symbols.h +++ b/include/libc-symbols.h @@ -363,7 +363,8 @@ for linking") strong_alias(real, name) #endif -#if defined SHARED || defined LIBC_NONSHARED +#if defined SHARED || defined LIBC_NONSHARED \ + || (BUILD_PIE_DEFAULT && IS_IN (libc)) # define attribute_hidden __attribute__ ((visibility ("hidden"))) #else # define attribute_hidden