x86: Don't use apply_irel in static PIE

Message ID 20190321122445.28990-1-hjl.tools@gmail.com
State Dropped
Headers

Commit Message

H.J. Lu March 21, 2019, 12:24 p.m. UTC
  On x86, since _dl_relocate_static_pie also processes IFUNC relocations,
there is no need to call apply_irel.

Tested on i686 and x86-64.

	* csu/libc-start.c (apply_irel): Add unused attribute.
	* sysdeps/x86/libc-start.h (ARCH_SETUP_IREL): Defined as empty
	for static PIE.
---
 csu/libc-start.c         | 1 +
 sysdeps/x86/libc-start.h | 7 ++++++-
 2 files changed, 7 insertions(+), 1 deletion(-)
  

Comments

Siva Chandra Reddy March 21, 2019, 3:18 p.m. UTC | #1
On Thu, Mar 21, 2019 at 5:36 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On x86, since _dl_relocate_static_pie also processes IFUNC relocations,
> there is no need to call apply_irel.
>
> Tested on i686 and x86-64.
>
>         * csu/libc-start.c (apply_irel): Add unused attribute.
>         * sysdeps/x86/libc-start.h (ARCH_SETUP_IREL): Defined as empty
>         for static PIE.
> ---
>  csu/libc-start.c         | 1 +
>  sysdeps/x86/libc-start.h | 7 ++++++-
>  2 files changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/csu/libc-start.c b/csu/libc-start.c
> index 5d9c3675fa..07be05f1e9 100644
> --- a/csu/libc-start.c
> +++ b/csu/libc-start.c
> @@ -66,6 +66,7 @@ uintptr_t __pointer_chk_guard_local
>  # endif
>
>  static void
> +__attribute__ ((unused))
>  apply_irel (void)
>  {
>  # ifdef IREL
> diff --git a/sysdeps/x86/libc-start.h b/sysdeps/x86/libc-start.h
> index c76b1d917f..e544867c1d 100644
> --- a/sysdeps/x86/libc-start.h
> +++ b/sysdeps/x86/libc-start.h
> @@ -17,7 +17,12 @@
>     <http://www.gnu.org/licenses/>.  */
>
>  #ifndef SHARED
> -# define ARCH_SETUP_IREL() apply_irel ()
> +# if ENABLE_STATIC_PIE
> +/* NB: x86 doesn't use apply_irel in static PIE.  */
> +#  define ARCH_SETUP_IREL()

Will this break non-PIE static when glibc is configured --enable-static-pie?

> +# else
> +#  define ARCH_SETUP_IREL() apply_irel ()
> +# endif
>  # define ARCH_APPLY_IREL()
>  # ifndef ARCH_SETUP_TLS
>  #  define ARCH_SETUP_TLS() __libc_setup_tls ()
> --
> 2.20.1
>
  
H.J. Lu March 21, 2019, 9:27 p.m. UTC | #2
On 3/21/19, Siva Chandra <sivachandra@google.com> wrote:
> On Thu, Mar 21, 2019 at 5:36 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>>
>> On x86, sinceelf/ifuncmain1static-non-pie _dl_relocate_static_pie also processes IFUNC relocations,
>> there is no need to call apply_irel.
>>
>> Tested on i686 and x86-64.
>>
>>         * csu/libc-start.c (apply_irel): Add unused attribute.
>>         * sysdeps/x86/libc-start.h (ARCH_SETUP_IREL): Defined as empty
>>         for static PIE.
>> ---
>>  csu/libc-start.c         | 1 +
>>  sysdeps/x86/libc-start.h | 7 ++++++-
>>  2 files changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/csu/libc-start.c b/csu/libc-start.c
>> index 5d9c3675fa..07be05f1e9 100644
>> --- a/csu/libc-start.c
>> +++ b/csu/libc-start.c
>> @@ -66,6 +66,7 @@ uintptr_t __pointer_chk_guard_local
>>  # endif
>>
>>  static void
>> +__attribute__ ((unused))
>>  apply_irel (void)
>>  {
>>  # ifdef IREL
>> diff --git a/sysdeps/x86/libc-start.h b/sysdeps/x86/libc-start.h
>> index c76b1d917f..e544867c1d 100644
>> --- a/sysdeps/x86/libc-start.h
>> +++ b/sysdeps/x86/libc-start.h
>> @@ -17,7 +17,12 @@
>>     <http://www.gnu.org/licenses/>.  */
>>
>>  #ifndef SHARED
>> -# define ARCH_SETUP_IREL() apply_irel ()
>> +# if ENABLE_STATIC_PIE
>> +/* NB: x86 doesn't use apply_irel in static PIE.  */
>> +#  define ARCH_SETUP_IREL()
>
> Will this break non-PIE static when glibc is configured
> --enable-static-pie?

You are right.  I withdrew my patch.

>> +# else
>> +#  define ARCH_SETUP_IREL() apply_irel ()
>> +# endif
>>  # define ARCH_APPLY_IREL()
>>  # ifndef ARCH_SETUP_TLS
>>  #  define ARCH_SETUP_TLS() __libc_setup_tls ()
>> --
>> 2.20.1
>>
>

Thanks.
  

Patch

diff --git a/csu/libc-start.c b/csu/libc-start.c
index 5d9c3675fa..07be05f1e9 100644
--- a/csu/libc-start.c
+++ b/csu/libc-start.c
@@ -66,6 +66,7 @@  uintptr_t __pointer_chk_guard_local
 # endif
 
 static void
+__attribute__ ((unused))
 apply_irel (void)
 {
 # ifdef IREL
diff --git a/sysdeps/x86/libc-start.h b/sysdeps/x86/libc-start.h
index c76b1d917f..e544867c1d 100644
--- a/sysdeps/x86/libc-start.h
+++ b/sysdeps/x86/libc-start.h
@@ -17,7 +17,12 @@ 
    <http://www.gnu.org/licenses/>.  */
 
 #ifndef SHARED
-# define ARCH_SETUP_IREL() apply_irel ()
+# if ENABLE_STATIC_PIE
+/* NB: x86 doesn't use apply_irel in static PIE.  */
+#  define ARCH_SETUP_IREL()
+# else
+#  define ARCH_SETUP_IREL() apply_irel ()
+# endif
 # define ARCH_APPLY_IREL()
 # ifndef ARCH_SETUP_TLS
 #  define ARCH_SETUP_TLS() __libc_setup_tls ()