public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] LoongArch: Prepare static PIE support
@ 2022-09-13 15:32 Xi Ruoyao
  2022-09-15  3:44 ` Lulu Cheng
  0 siblings, 1 reply; 2+ messages in thread
From: Xi Ruoyao @ 2022-09-13 15:32 UTC (permalink / raw)
  To: gcc-patches; +Cc: Lulu Cheng, Wang Xuerui, Chenghua Xu, liuzhensong, Xi Ruoyao

Static PIE allows us to extend the ASLR to cover static executables and
it's not too difficult to support it.  On GCC side, we just pass a group
of options to the linker, like other ports with static PIE support.

The real implementation of static PIE (rcrt1.o) will be added into Glibc
later.

gcc/ChangeLog:

	* config/loongarch/gnu-user.h (GNU_USER_TARGET_LINK_SPEC): For
	-static-pie, pass -static -pie --no-dynamic-linker -z text to
	the linker, and do not pass --dynamic-linker.
---
 gcc/config/loongarch/gnu-user.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gcc/config/loongarch/gnu-user.h b/gcc/config/loongarch/gnu-user.h
index 664dc9206ad..c5b1afe530d 100644
--- a/gcc/config/loongarch/gnu-user.h
+++ b/gcc/config/loongarch/gnu-user.h
@@ -40,8 +40,10 @@ along with GCC; see the file COPYING3.  If not see
 #undef GNU_USER_TARGET_LINK_SPEC
 #define GNU_USER_TARGET_LINK_SPEC \
   "%{G*} %{shared} -m " GNU_USER_LINK_EMULATION \
-  "%{!shared: %{static} %{!static: %{rdynamic:-export-dynamic} " \
-  "-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}"
+  "%{!shared: %{static} " \
+  "%{!static: %{!static-pie: %{rdynamic:-export-dynamic} " \
+  "-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}} " \
+  "%{static-pie: -static -pie --no-dynamic-linker -z text}}"
 
 
 /* Similar to standard Linux, but adding -ffast-math support.  */
-- 
2.37.3


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

* Re: [PATCH] LoongArch: Prepare static PIE support
  2022-09-13 15:32 [PATCH] LoongArch: Prepare static PIE support Xi Ruoyao
@ 2022-09-15  3:44 ` Lulu Cheng
  0 siblings, 0 replies; 2+ messages in thread
From: Lulu Cheng @ 2022-09-15  3:44 UTC (permalink / raw)
  To: Xi Ruoyao, gcc-patches; +Cc: Wang Xuerui, Chenghua Xu, liuzhensong

LGTM!

Thanks.

在 2022/9/13 下午11:32, Xi Ruoyao 写道:
> Static PIE allows us to extend the ASLR to cover static executables and
> it's not too difficult to support it.  On GCC side, we just pass a group
> of options to the linker, like other ports with static PIE support.
>
> The real implementation of static PIE (rcrt1.o) will be added into Glibc
> later.
>
> gcc/ChangeLog:
>
> 	* config/loongarch/gnu-user.h (GNU_USER_TARGET_LINK_SPEC): For
> 	-static-pie, pass -static -pie --no-dynamic-linker -z text to
> 	the linker, and do not pass --dynamic-linker.
> ---
>   gcc/config/loongarch/gnu-user.h | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/gcc/config/loongarch/gnu-user.h b/gcc/config/loongarch/gnu-user.h
> index 664dc9206ad..c5b1afe530d 100644
> --- a/gcc/config/loongarch/gnu-user.h
> +++ b/gcc/config/loongarch/gnu-user.h
> @@ -40,8 +40,10 @@ along with GCC; see the file COPYING3.  If not see
>   #undef GNU_USER_TARGET_LINK_SPEC
>   #define GNU_USER_TARGET_LINK_SPEC \
>     "%{G*} %{shared} -m " GNU_USER_LINK_EMULATION \
> -  "%{!shared: %{static} %{!static: %{rdynamic:-export-dynamic} " \
> -  "-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}"
> +  "%{!shared: %{static} " \
> +  "%{!static: %{!static-pie: %{rdynamic:-export-dynamic} " \
> +  "-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}} " \
> +  "%{static-pie: -static -pie --no-dynamic-linker -z text}}"
>   
>   
>   /* Similar to standard Linux, but adding -ffast-math support.  */


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

end of thread, other threads:[~2022-09-15  3:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-13 15:32 [PATCH] LoongArch: Prepare static PIE support Xi Ruoyao
2022-09-15  3:44 ` Lulu Cheng

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