From 995635f95b707488c23bba07be8016c9682d4045 Mon Sep 17 00:00:00 2001 From: Nick Alcock Date: Mon, 26 Dec 2016 10:08:48 +0100 Subject: [PATCH] Compile the dynamic linker without stack protection [BZ #7065] Also compile corresponding routines in the static libc.a with the same flag. --- ChangeLog | 10 ++++++++++ elf/Makefile | 12 ++++++++++++ elf/rtld-Rules | 2 ++ sysdeps/i386/Makefile | 2 +- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 64ccdf7ca0..82fc4e29d3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2016-12-26 Nick Alcock + + [BZ #7065] + Compile the dynamic linker without stack protection. + * elf/Makefile (elide-stack-protector): New. + (CFLAGS-.os): Use it, eliding $(all-rtld-routines). + (CFLAGS-.o, CFLAGS-.op): Likewise, but for $(elide-routines.os). + * elf/rtld-Rules (rtld-CFLAGS): Add $(no-stack-protector). + * sysdeps/i386/Makefile (rtld-CFLAGS): Use +=, not =. + 2016-12-26 Nick Alcock [BZ #7065] diff --git a/elf/Makefile b/elf/Makefile index cd26e16558..1e7d7240ef 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -51,6 +51,18 @@ CFLAGS-dl-runtime.c = -fexceptions -fasynchronous-unwind-tables CFLAGS-dl-lookup.c = -fexceptions -fasynchronous-unwind-tables CFLAGS-dl-iterate-phdr.c = $(uses-callbacks) +# Compile rtld itself without stack protection. +# Also compile all routines in the static library that are elided from +# the shared libc because they are in libc.a in the same way. + +define elide-stack-protector +$(if $(filter $(@F),$(patsubst %,%$(1),$(2))), $(no-stack-protector)) +endef + +CFLAGS-.o += $(call elide-stack-protector,.o,$(elide-routines.os)) +CFLAGS-.op += $(call elide-stack-protector,.op,$(elide-routines.os)) +CFLAGS-.os += $(call elide-stack-protector,.os,$(all-rtld-routines)) + ifeq ($(unwind-find-fde),yes) routines += unwind-dw2-fde-glibc shared-only-routines += unwind-dw2-fde-glibc diff --git a/elf/rtld-Rules b/elf/rtld-Rules index c1bb50687e..84d9387746 100644 --- a/elf/rtld-Rules +++ b/elf/rtld-Rules @@ -144,4 +144,6 @@ cpp-srcs-left := $(rtld-modules:%.os=%) lib := rtld include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left)) +rtld-CFLAGS += $(no-stack-protector) + endif diff --git a/sysdeps/i386/Makefile b/sysdeps/i386/Makefile index e94f2cbd66..e30e1339f0 100644 --- a/sysdeps/i386/Makefile +++ b/sysdeps/i386/Makefile @@ -88,7 +88,7 @@ endif # the first 3 mm/xmm/ymm/zmm registers are used to pass vector parameters # which must be preserved. # With SSE disabled, ensure -fpmath is not set to use sse either. -rtld-CFLAGS = -mno-sse -mno-mmx -mfpmath=387 +rtld-CFLAGS += -mno-sse -mno-mmx -mfpmath=387 ifeq ($(subdir),elf) CFLAGS-.os += $(if $(filter $(@F),$(patsubst %,%.os,$(all-rtld-routines))),\ $(rtld-CFLAGS)) -- 2.43.5