[06/14] Compile the entire dynamic linker with -fno-stack-protector.
Commit Message
From: Nick Alcock <nick.alcock@oracle.com>
Also compile corresponding routines in the static libc.a with the same
flag.
---
elf/Makefile | 13 +++++++++++++
elf/rtld-Rules | 4 ++++
2 files changed, 17 insertions(+)
@@ -50,6 +50,16 @@ CFLAGS-dl-runtime.c = -fexceptions -fasynchronous-unwind-tables
CFLAGS-dl-lookup.c = -fexceptions -fasynchronous-unwind-tables
CFLAGS-dl-iterate-phdr.c = $(uses-callbacks)
+ifeq ($(have-ssp),yes)
+# In the dynamic loader, some routines (which include routines called before
+# the stack guard is initialized) are compiled without stack protection.
+# Do the same when those routines are found in the static library.
+
+CFLAGS-.o += $(if $(filter $(@F),$(patsubst %,%.o,$(elide-routines.os))),-fno-stack-protector)
+CFLAGS-.op += $(if $(filter $(@F),$(patsubst %,%.op,$(elide-routines.os))),-fno-stack-protector)
+CFLAGS-.og += $(if $(filter $(@F),$(patsubst %,%.og,$(elide-routines.os))),-fno-stack-protector)
+endif
+
ifeq ($(unwind-find-fde),yes)
routines += unwind-dw2-fde-glibc
shared-only-routines += unwind-dw2-fde-glibc
@@ -468,6 +478,9 @@ libof-ldconfig = ldconfig
CFLAGS-dl-cache.c = $(SYSCONF-FLAGS)
CFLAGS-cache.c = $(SYSCONF-FLAGS)
CFLAGS-rtld.c = $(SYSCONF-FLAGS)
+ifeq ($(have-ssp),yes)
+CFLAGS-.os += $(if $(filter $(@F),$(patsubst %,%.os,$(all-rtld-routines))),-fno-stack-protector)
+endif
cpp-srcs-left := $(all-rtld-routines:=.os)
lib := rtld
@@ -144,4 +144,8 @@ cpp-srcs-left := $(rtld-modules:%.os=%)
lib := rtld
include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
+ifeq ($(have-ssp),yes)
+rtld-CFLAGS := -fno-stack-protector
+endif
+
endif