public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Don't use PLT nor GOT in libc.a [BZ #20750]
@ 2016-11-04 17:47 H.J. Lu
  2016-11-04 19:03 ` Florian Weimer
  0 siblings, 1 reply; 11+ messages in thread
From: H.J. Lu @ 2016-11-04 17:47 UTC (permalink / raw)
  To: GNU C Library

There is no need to use PLT nor GOT in libc.a to branch to a function,
regardless whether libc.a is compiled with PIC or not.

Tested on x86-64.  OK for master?

H.J.
---
	[BZ #20750]
	* sysdeps/x86_64/sysdep.h (JUMPTARGET): Check SHARED instead
	of PIC.
---
 sysdeps/x86_64/sysdep.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sysdeps/x86_64/sysdep.h b/sysdeps/x86_64/sysdep.h
index 75ac747..fd25c90 100644
--- a/sysdeps/x86_64/sysdep.h
+++ b/sysdeps/x86_64/sysdep.h
@@ -89,13 +89,14 @@ lose:									      \
   END (name)
 
 #undef JUMPTARGET
-#ifdef PIC
+#ifdef SHARED
 # ifdef BIND_NOW
 #  define JUMPTARGET(name)	*name##@GOTPCREL(%rip)
 # else
 #  define JUMPTARGET(name)	name##@PLT
 # endif
 #else
+/* For libc.a, we want to branch to target directly.  */
 # define JUMPTARGET(name)	name
 #endif
 
-- 
2.7.4

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Don't use PLT nor GOT in libc.a [BZ #20750]
  2016-11-04 17:47 [PATCH] Don't use PLT nor GOT in libc.a [BZ #20750] H.J. Lu
@ 2016-11-04 19:03 ` Florian Weimer
  2016-11-04 19:25   ` H.J. Lu
  0 siblings, 1 reply; 11+ messages in thread
From: Florian Weimer @ 2016-11-04 19:03 UTC (permalink / raw)
  To: libc-alpha

On 11/04/2016 06:47 PM, H.J. Lu wrote:
> There is no need to use PLT nor GOT in libc.a to branch to a function,
> regardless whether libc.a is compiled with PIC or not.
>
> Tested on x86-64.  OK for master?

Isn't this header file used outside of libc as well?

(And the commit message should mention that this change is specific to 
x86_64.)

Thanks,
Florian

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Don't use PLT nor GOT in libc.a [BZ #20750]
  2016-11-04 19:03 ` Florian Weimer
@ 2016-11-04 19:25   ` H.J. Lu
  2016-11-07 16:03     ` Florian Weimer
  0 siblings, 1 reply; 11+ messages in thread
From: H.J. Lu @ 2016-11-04 19:25 UTC (permalink / raw)
  To: Florian Weimer; +Cc: GNU C Library

On Fri, Nov 4, 2016 at 12:03 PM, Florian Weimer <fweimer@redhat.com> wrote:
> On 11/04/2016 06:47 PM, H.J. Lu wrote:
>>
>> There is no need to use PLT nor GOT in libc.a to branch to a function,
>> regardless whether libc.a is compiled with PIC or not.
>>
>> Tested on x86-64.  OK for master?
>
>
> Isn't this header file used outside of libc as well?

It is used for other .a files.  If they aren't used to create static binaries,
PLT/GOT may be used.  The resulting executable will work correctly.

> (And the commit message should mention that this change is specific to
> x86_64.)
>

I will update it.


-- 
H.J.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Don't use PLT nor GOT in libc.a [BZ #20750]
  2016-11-04 19:25   ` H.J. Lu
@ 2016-11-07 16:03     ` Florian Weimer
  2016-11-07 17:14       ` H.J. Lu
  0 siblings, 1 reply; 11+ messages in thread
From: Florian Weimer @ 2016-11-07 16:03 UTC (permalink / raw)
  To: H.J. Lu; +Cc: libc-alpha

On 11/04/2016 08:25 PM, H.J. Lu wrote:
> On Fri, Nov 4, 2016 at 12:03 PM, Florian Weimer <fweimer@redhat.com> wrote:
>> On 11/04/2016 06:47 PM, H.J. Lu wrote:
>>>
>>> There is no need to use PLT nor GOT in libc.a to branch to a function,
>>> regardless whether libc.a is compiled with PIC or not.
>>>
>>> Tested on x86-64.  OK for master?
>>
>>
>> Isn't this header file used outside of libc as well?
>
> It is used for other .a files.  If they aren't used to create static binaries,
> PLT/GOT may be used.  The resulting executable will work correctly.

You mean because “name” is automatically mapped to “name@plt”?

I find this comment not very illuminating:

+/* For libc.a, we want to branch to target directly.  */
  # define JUMPTARGET(name)	name

And cheating the static linker in this way seems like a future 
maintenance hazard.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Don't use PLT nor GOT in libc.a [BZ #20750]
  2016-11-07 16:03     ` Florian Weimer
@ 2016-11-07 17:14       ` H.J. Lu
  2016-11-24 11:58         ` Allan McRae
  0 siblings, 1 reply; 11+ messages in thread
From: H.J. Lu @ 2016-11-07 17:14 UTC (permalink / raw)
  To: Florian Weimer; +Cc: GNU C Library

On Mon, Nov 7, 2016 at 8:03 AM, Florian Weimer <fweimer@redhat.com> wrote:
> On 11/04/2016 08:25 PM, H.J. Lu wrote:
>>
>> On Fri, Nov 4, 2016 at 12:03 PM, Florian Weimer <fweimer@redhat.com>
>> wrote:
>>>
>>> On 11/04/2016 06:47 PM, H.J. Lu wrote:
>>>>
>>>>
>>>> There is no need to use PLT nor GOT in libc.a to branch to a function,
>>>> regardless whether libc.a is compiled with PIC or not.
>>>>
>>>> Tested on x86-64.  OK for master?
>>>
>>>
>>>
>>> Isn't this header file used outside of libc as well?
>>
>>
>> It is used for other .a files.  If they aren't used to create static
>> binaries,
>> PLT/GOT may be used.  The resulting executable will work correctly.
>
>
> You mean because “name” is automatically mapped to “name@plt”?

No.  There is no "@plt".  Linker will create a PLT entry if the function
is defined in a shared object.

> I find this comment not very illuminating:
>
> +/* For libc.a, we want to branch to target directly.  */
>  # define JUMPTARGET(name)      name
>
> And cheating the static linker in this way seems like a future maintenance
> hazard.
>

It is ok as long as those static archives aren't used to create shared
objects.

-- 
H.J.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Don't use PLT nor GOT in libc.a [BZ #20750]
  2016-11-07 17:14       ` H.J. Lu
@ 2016-11-24 11:58         ` Allan McRae
  2016-11-25  8:43           ` Florian Weimer
  2016-11-28 17:54           ` Szabolcs Nagy
  0 siblings, 2 replies; 11+ messages in thread
From: Allan McRae @ 2016-11-24 11:58 UTC (permalink / raw)
  To: H.J. Lu, Florian Weimer; +Cc: GNU C Library

Ping.  My distribution wants to enable PIE and -z,now by default and
this is required for glibc to build.

Allan

On 08/11/16 03:13, H.J. Lu wrote:
> On Mon, Nov 7, 2016 at 8:03 AM, Florian Weimer <fweimer@redhat.com> wrote:
>> On 11/04/2016 08:25 PM, H.J. Lu wrote:
>>>
>>> On Fri, Nov 4, 2016 at 12:03 PM, Florian Weimer <fweimer@redhat.com>
>>> wrote:
>>>>
>>>> On 11/04/2016 06:47 PM, H.J. Lu wrote:
>>>>>
>>>>>
>>>>> There is no need to use PLT nor GOT in libc.a to branch to a function,
>>>>> regardless whether libc.a is compiled with PIC or not.
>>>>>
>>>>> Tested on x86-64.  OK for master?
>>>>
>>>>
>>>>
>>>> Isn't this header file used outside of libc as well?
>>>
>>>
>>> It is used for other .a files.  If they aren't used to create static
>>> binaries,
>>> PLT/GOT may be used.  The resulting executable will work correctly.
>>
>>
>> You mean because “name” is automatically mapped to “name@plt”?
> 
> No.  There is no "@plt".  Linker will create a PLT entry if the function
> is defined in a shared object.
> 
>> I find this comment not very illuminating:
>>
>> +/* For libc.a, we want to branch to target directly.  */
>>  # define JUMPTARGET(name)      name
>>
>> And cheating the static linker in this way seems like a future maintenance
>> hazard.
>>
> 
> It is ok as long as those static archives aren't used to create shared
> objects.
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Don't use PLT nor GOT in libc.a [BZ #20750]
  2016-11-24 11:58         ` Allan McRae
@ 2016-11-25  8:43           ` Florian Weimer
  2016-11-28 17:46             ` H.J. Lu
  2016-11-28 17:54           ` Szabolcs Nagy
  1 sibling, 1 reply; 11+ messages in thread
From: Florian Weimer @ 2016-11-25  8:43 UTC (permalink / raw)
  To: Allan McRae, H.J. Lu; +Cc: GNU C Library

On 11/24/2016 12:58 PM, Allan McRae wrote:
> Ping.  My distribution wants to enable PIE and -z,now by default and
> this is required for glibc to build.

My question has been answered.  H.J., could you please check this in?

Thanks,
Florian

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Don't use PLT nor GOT in libc.a [BZ #20750]
  2016-11-25  8:43           ` Florian Weimer
@ 2016-11-28 17:46             ` H.J. Lu
  2016-11-28 18:27               ` Joseph Myers
  0 siblings, 1 reply; 11+ messages in thread
From: H.J. Lu @ 2016-11-28 17:46 UTC (permalink / raw)
  To: Florian Weimer; +Cc: Allan McRae, GNU C Library

[-- Attachment #1: Type: text/plain, Size: 375 bytes --]

On Fri, Nov 25, 2016 at 12:43 AM, Florian Weimer <fweimer@redhat.com> wrote:
> On 11/24/2016 12:58 PM, Allan McRae wrote:
>>
>> Ping.  My distribution wants to enable PIE and -z,now by default and
>> this is required for glibc to build.
>
>
> My question has been answered.  H.J., could you please check this in?
>
> Thanks,
> Florian
>

This is what I checked in.

-- 
H.J.

[-- Attachment #2: 0001-X86_64-Don-t-use-PLT-nor-GOT-in-static-archives-BZ-2.patch --]
[-- Type: text/x-patch, Size: 1169 bytes --]

From dddb327ef2da7dfd86aed36b4db6e2fe471ed461 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Fri, 4 Nov 2016 10:43:42 -0700
Subject: [PATCH] X86_64: Don't use PLT nor GOT in static archives [BZ #20750]

There is no need to use PLT nor GOT in static archives to branch to a
function, regardless whether static archives is compiled with PIC or
not.  When static archives are used to create dynamic executable,
PLT/GOT may be used.  The resulting executable still works correctly.

	[BZ #20750]
	* sysdeps/x86_64/sysdep.h (JUMPTARGET): Check SHARED instead
	of PIC.
---
 sysdeps/x86_64/sysdep.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sysdeps/x86_64/sysdep.h b/sysdeps/x86_64/sysdep.h
index 75ac747..4b67fa8 100644
--- a/sysdeps/x86_64/sysdep.h
+++ b/sysdeps/x86_64/sysdep.h
@@ -89,13 +89,14 @@ lose:									      \
   END (name)
 
 #undef JUMPTARGET
-#ifdef PIC
+#ifdef SHARED
 # ifdef BIND_NOW
 #  define JUMPTARGET(name)	*name##@GOTPCREL(%rip)
 # else
 #  define JUMPTARGET(name)	name##@PLT
 # endif
 #else
+/* For static archives, branch to target directly.  */
 # define JUMPTARGET(name)	name
 #endif
 
-- 
2.7.4


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Don't use PLT nor GOT in libc.a [BZ #20750]
  2016-11-24 11:58         ` Allan McRae
  2016-11-25  8:43           ` Florian Weimer
@ 2016-11-28 17:54           ` Szabolcs Nagy
  1 sibling, 0 replies; 11+ messages in thread
From: Szabolcs Nagy @ 2016-11-28 17:54 UTC (permalink / raw)
  To: Allan McRae, H.J. Lu, Florian Weimer; +Cc: nd, GNU C Library

On 24/11/16 11:58, Allan McRae wrote:
> Ping.  My distribution wants to enable PIE and -z,now by default and
> this is required for glibc to build.
> 

how does this help?

i think glibc has no static pie entry point that can
resolve relative relocs of pie code..

(i think only musl libc supports this now, used in
the alpine linux distro, which have some toolchain
patches to make it work).

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Don't use PLT nor GOT in libc.a [BZ #20750]
  2016-11-28 17:46             ` H.J. Lu
@ 2016-11-28 18:27               ` Joseph Myers
  2016-11-28 21:32                 ` H.J. Lu
  0 siblings, 1 reply; 11+ messages in thread
From: Joseph Myers @ 2016-11-28 18:27 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Florian Weimer, Allan McRae, GNU C Library

Does this fix bug 20621 or not?  (At one point 20621 and 20750 were marked 
as duplicates.)

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Don't use PLT nor GOT in libc.a [BZ #20750]
  2016-11-28 18:27               ` Joseph Myers
@ 2016-11-28 21:32                 ` H.J. Lu
  0 siblings, 0 replies; 11+ messages in thread
From: H.J. Lu @ 2016-11-28 21:32 UTC (permalink / raw)
  To: Joseph Myers; +Cc: Florian Weimer, Allan McRae, GNU C Library

On Mon, Nov 28, 2016 at 10:26 AM, Joseph Myers <joseph@codesourcery.com> wrote:
> Does this fix bug 20621 or not?  (At one point 20621 and 20750 were marked
> as duplicates.)
>

Bug 20621 compiles glibc with -fPIC -DPIC.  I don't think it is the
supported way to build glibc.


-- 
H.J.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2016-11-28 21:32 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-04 17:47 [PATCH] Don't use PLT nor GOT in libc.a [BZ #20750] H.J. Lu
2016-11-04 19:03 ` Florian Weimer
2016-11-04 19:25   ` H.J. Lu
2016-11-07 16:03     ` Florian Weimer
2016-11-07 17:14       ` H.J. Lu
2016-11-24 11:58         ` Allan McRae
2016-11-25  8:43           ` Florian Weimer
2016-11-28 17:46             ` H.J. Lu
2016-11-28 18:27               ` Joseph Myers
2016-11-28 21:32                 ` H.J. Lu
2016-11-28 17:54           ` Szabolcs Nagy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).