diff mbox

[05/15] Compile the entire dynamic linker with -fno-stack-protector.

Message ID 20161219111528.14969-6-nix@esperi.org.uk
State New
Headers show

Commit Message

Nix Dec. 19, 2016, 11:15 a.m. UTC
From: Nick Alcock <nick.alcock@oracle.com>

Also compile corresponding routines in the static libc.a with the same
flag.

v3: Use $(no-stack-protector).
    Introduce $(elide-stack-protector) and use it to reduce redundancy.
    Bring all the elisions together textually.
v9: Adapt to no-sse adjustments in sysdeps/i386/Makefile.

	* elf/Makefile (elide-stack-protector): New.
	(CFLAGS-.os): Use it, eliding $(all-rtld-routines).
	(CFLAGS-.oX): Likewise, eliding $(elide-routines.os).
	(rtld-CFLAGS): Likewise.
	sysdeps/i386/Makefile (rtld-CFLAGS): Use +=, not =.
---
 elf/Makefile          | 13 +++++++++++++
 elf/rtld-Rules        |  2 ++
 sysdeps/i386/Makefile |  2 +-
 3 files changed, 16 insertions(+), 1 deletion(-)

Comments

Florian Weimer Dec. 21, 2016, 2:18 p.m. UTC | #1
On 12/19/2016 12:15 PM, Nix wrote:
> +CFLAGS-.o += $(call elide-stack-protector,.o,$(elide-routines.os))
> +CFLAGS-.op += $(call elide-stack-protector,.op,$(elide-routines.os))
> +CFLAGS-.og += $(call elide-stack-protector,.og,$(elide-routines.os))
> +CFLAGS-.os += $(call elide-stack-protector,.os,$(all-rtld-routines))

.og is gone, as mentioned before.

I think .op is a shared build and thus needs to be linked the same way 
as .os.

Thanks,
Florian
Szabolcs Nagy Dec. 21, 2016, 2:25 p.m. UTC | #2
On 21/12/16 14:18, Florian Weimer wrote:
> On 12/19/2016 12:15 PM, Nix wrote:
>> +CFLAGS-.o += $(call elide-stack-protector,.o,$(elide-routines.os))
>> +CFLAGS-.op += $(call elide-stack-protector,.op,$(elide-routines.os))
>> +CFLAGS-.og += $(call elide-stack-protector,.og,$(elide-routines.os))
>> +CFLAGS-.os += $(call elide-stack-protector,.os,$(all-rtld-routines))
> 
> .og is gone, as mentioned before.
> 
> I think .op is a shared build and thus needs to be linked the same way as .os.

Makeconfig seems to set up .op like .o (other than -DPROF and -pg flags)
and unlike .os (which has -DPIC -DSHARED -fPIC)
Florian Weimer Dec. 21, 2016, 2:56 p.m. UTC | #3
On 12/21/2016 03:25 PM, Szabolcs Nagy wrote:
> On 21/12/16 14:18, Florian Weimer wrote:
>> On 12/19/2016 12:15 PM, Nix wrote:
>>> +CFLAGS-.o += $(call elide-stack-protector,.o,$(elide-routines.os))
>>> +CFLAGS-.op += $(call elide-stack-protector,.op,$(elide-routines.os))
>>> +CFLAGS-.og += $(call elide-stack-protector,.og,$(elide-routines.os))
>>> +CFLAGS-.os += $(call elide-stack-protector,.os,$(all-rtld-routines))
>>
>> .og is gone, as mentioned before.
>>
>> I think .op is a shared build and thus needs to be linked the same way as .os.
>
> Makeconfig seems to set up .op like .o (other than -DPROF and -pg flags)
> and unlike .os (which has -DPIC -DSHARED -fPIC)

Right, I reverted the .op part.

Thanks,
Florian
diff mbox

Patch

diff --git a/elf/Makefile b/elf/Makefile
index 82c7e05..d14d48d 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -50,6 +50,19 @@  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 ld.so 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-.og += $(call elide-stack-protector,.og,$(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 c1bb506..84d9387 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 e94f2cb..e30e133 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))