public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Use crtbeginT.o and crtend.o for non-PIE static executables
@ 2024-04-05 23:42 H.J. Lu
  2024-04-08 16:23 ` Sunil Pandey
  0 siblings, 1 reply; 2+ messages in thread
From: H.J. Lu @ 2024-04-05 23:42 UTC (permalink / raw)
  To: libc-alpha

When static PIE is enabled by default, we shouldn't use crtbeginS.o and
crtendS.o for non-PIE static executables.  Check $($(@F)-no-pie) to use
crtbeginT.o and crtend.o to create non-PIE static executables.
---
 Makeconfig | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/Makeconfig b/Makeconfig
index 85e00cef94..e583765712 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -705,13 +705,15 @@ endif
 +prectorS = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbeginS.o`
 +postctorS = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtendS.o`
 # Variants of the two previous definitions for statically linking programs.
+static-prector = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbeginT.o`
+static-postctor = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtend.o`
 ifeq (yes,$(enable-static-pie))
 # Static PIE must use PIE variants.
-+prectorT = $(+prectorS)
-+postctorT = $(+postctorS)
++prectorT = $(if $($(@F)-no-pie),$(static-prector),$(+prectorS))
++postctorT = $(if $($(@F)-no-pie),$(static-postctor),$(+postctorS))
 else
-+prectorT = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbeginT.o`
-+postctorT = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtend.o`
++prectorT = $(static-prector)
++postctorT =$(static-postctor)
 endif
 csu-objpfx = $(common-objpfx)csu/
 elf-objpfx = $(common-objpfx)elf/
-- 
2.44.0


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

* Re: [PATCH] Use crtbeginT.o and crtend.o for non-PIE static executables
  2024-04-05 23:42 [PATCH] Use crtbeginT.o and crtend.o for non-PIE static executables H.J. Lu
@ 2024-04-08 16:23 ` Sunil Pandey
  0 siblings, 0 replies; 2+ messages in thread
From: Sunil Pandey @ 2024-04-08 16:23 UTC (permalink / raw)
  To: H.J. Lu; +Cc: libc-alpha

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

On Fri, Apr 5, 2024 at 4:43 PM H.J. Lu <hjl.tools@gmail.com> wrote:

> When static PIE is enabled by default, we shouldn't use crtbeginS.o and
> crtendS.o for non-PIE static executables.  Check $($(@F)-no-pie) to use
> crtbeginT.o and crtend.o to create non-PIE static executables.
> ---
>  Makeconfig | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/Makeconfig b/Makeconfig
> index 85e00cef94..e583765712 100644
> --- a/Makeconfig
> +++ b/Makeconfig
> @@ -705,13 +705,15 @@ endif
>  +prectorS = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbeginS.o`
>  +postctorS = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtendS.o`
>  # Variants of the two previous definitions for statically linking
> programs.
> +static-prector = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbeginT.o`
> +static-postctor = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtend.o`
>  ifeq (yes,$(enable-static-pie))
>  # Static PIE must use PIE variants.
> -+prectorT = $(+prectorS)
> -+postctorT = $(+postctorS)
> ++prectorT = $(if $($(@F)-no-pie),$(static-prector),$(+prectorS))
> ++postctorT = $(if $($(@F)-no-pie),$(static-postctor),$(+postctorS))
>  else
> -+prectorT = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbeginT.o`
> -+postctorT = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtend.o`
> ++prectorT = $(static-prector)
> ++postctorT =$(static-postctor)
>  endif
>  csu-objpfx = $(common-objpfx)csu/
>  elf-objpfx = $(common-objpfx)elf/
> --
> 2.44.0
>

LGTM
Reviewed-by: Sunil K Pandey <skpgkp2@gmail.com>

--Sunil

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

end of thread, other threads:[~2024-04-08 16:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-05 23:42 [PATCH] Use crtbeginT.o and crtend.o for non-PIE static executables H.J. Lu
2024-04-08 16:23 ` Sunil Pandey

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).