Enable hidden visibility in libc.a compiled with PIE
Commit Message
On Mon, Aug 21, 2017 at 9:50 AM, Szabolcs Nagy <szabolcs.nagy@arm.com> wrote:
> 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.
Here is the patch. Tested with PIE and non-PIE libc.a.
Any comments?
From d301c3c02e70ee9ff50d173da7d4d9626767bc4c Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Mon, 21 Aug 2017 10:27:57 -0700
Subject: [PATCH] Always hide symbols referenced internally within libc.a
Since none of internal symbols within libc.a, PIE or non-PIE, can be
interposed, we can always hide symbols referenced internally within
libc.a.
* include/libc-symbols.h (attribute_hidden): Remove
BUILD_PIE_DEFAULT check.
---
include/libc-symbols.h | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
@@ -363,8 +363,7 @@ 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 || IS_IN (libc)
# define attribute_hidden __attribute__ ((visibility ("hidden")))
#else
# define attribute_hidden
--
2.13.5