[klibc] [PATCH klibc 2/3] Kbuild: Add a per-architecture option to disable exectable stacks

Ben Hutchings ben at decadent.org.uk
Wed Apr 29 15:06:06 PDT 2020


We still want to avoid executable stacks, but now we will only do so
for architectures where we know we can avoid stack trampolines for
signal return.

Disable executable stacks only if KLIBCEXECSTACK is set to 'n' by the
architecture's MCONFIG.

Signed-off-by: Ben Hutchings <ben at decadent.org.uk>
---
 scripts/Kbuild.klibc | 5 ++++-
 usr/klibc/Kbuild     | 1 +
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/scripts/Kbuild.klibc b/scripts/Kbuild.klibc
index b7e99b56..a9a2a40e 100644
--- a/scripts/Kbuild.klibc
+++ b/scripts/Kbuild.klibc
@@ -118,13 +118,16 @@ KLIBCCPPFLAGS    += -I$(KLIBCKERNELSRC)/include		\
                      $(if $(KBUILD_SRC),-I$(srctree)/include)  \
 		     $(KLIBCARCHINCFLAGS)
 
+# compiler/assembler option for whether we want an executable stack
+KLIBCSTACKFLAGS  := -Wa,$(if $(filter n,$(KLIBCEXECSTACK)),no)execstack
+
 # klibc definitions
 KLIBCDEFS        += -D__KLIBC__=$(KLIBCMAJOR)          \
 		    -D__KLIBC_MINOR__=$(KLIBCMINOR)    \
 		    -D_BITSIZE=$(KLIBCBITSIZE)
 KLIBCCPPFLAGS    += $(KLIBCDEFS)
 KLIBCCFLAGS      += $(KLIBCCPPFLAGS) $(KLIBCREQFLAGS) $(KLIBCARCHREQFLAGS)  \
-                    $(KLIBCOPTFLAGS) $(KLIBCWARNFLAGS)
+                    $(KLIBCOPTFLAGS) $(KLIBCSTACKFLGS) $(KLIBCWARNFLAGS)
 KLIBCAFLAGS      += -D__ASSEMBLY__ $(KLIBCCFLAGS)
 KLIBCSTRIPFLAGS  += --strip-all -R .comment -R .note
 
diff --git a/usr/klibc/Kbuild b/usr/klibc/Kbuild
index bec9cdb4..c6338851 100644
--- a/usr/klibc/Kbuild
+++ b/usr/klibc/Kbuild
@@ -185,6 +185,7 @@ quiet_cmd_interp = BUILD   $@
       cmd_interp = $(KLIBCCC) $(klibccflags) -D__ASSEMBLY__     \
                              -DLIBDIR=\"$(SHLIBDIR)\"         \
 			     -DSOHASH=\"$(SOLIBHASH)\" \
+                             $(KLIBCSTACKFLAGS) \
 			     -c -o $@ $<
 
 $(INTERP_O): $(obj)/interp.S $(SOLIB).hash

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.zytor.com/archives/klibc/attachments/20200429/ff06c8ef/attachment.sig>


More information about the klibc mailing list