[10/18] Link libc.so with libc_nonshared.a to pull in __stack_chk_fail_local.

Message ID 1457445064-7107-11-git-send-email-nix@esperi.org.uk
State New, archived
Headers

Commit Message

Nix March 8, 2016, 1:50 p.m. UTC
  From: Nick Alcock <nick.alcock@oracle.com>

With this in place, we pull in __stack_chk_fail_local, which will
be required by the next commit, and referenced by every stack-
protected function in libc.

Also prevent that function from being stack-protected itself: this
makes no sense.

v5: Better explanation.  Add no-stack-protection of
    __stack_chk_fail_local etc.

	* Makerules $(common-objpfx)libc.so,
	$(common-objpfx)linkobj/libc.so): Add
	$(common-objpfx)libc_nonshared.a.
	* debug/Makefile (CFLAGS-stack_chk_fail.c): Use $(no-stack-protector).
	(CFLAGS-stack_chk_fail_local.c): Likewise.
---
 Makerules      | 2 ++
 debug/Makefile | 6 ++++++
 2 files changed, 8 insertions(+)
  

Comments

Andreas Schwab March 8, 2016, 2:48 p.m. UTC | #1
Nix <nix@esperi.org.uk> writes:

> @@ -674,6 +674,7 @@ $(common-objpfx)linkobj/libc.so: link-libc-deps = # empty
>  # libraries.
>  $(common-objpfx)libc.so: $(elf-objpfx)soinit.os \
>  			 $(common-objpfx)libc_pic.os$(libc_pic_clean) \
> +			 $(common-objpfx)libc_nonshared.a \

Everything needed for libc.so should come from libc_pic.a.

Andreas.
  
Nix March 8, 2016, 9:50 p.m. UTC | #2
On 8 Mar 2016, Andreas Schwab verbalised:

> Nix <nix@esperi.org.uk> writes:
>
>> @@ -674,6 +674,7 @@ $(common-objpfx)linkobj/libc.so: link-libc-deps = # empty
>>  # libraries.
>>  $(common-objpfx)libc.so: $(elf-objpfx)soinit.os \
>>  			 $(common-objpfx)libc_pic.os$(libc_pic_clean) \
>> +			 $(common-objpfx)libc_nonshared.a \
>
> Everything needed for libc.so should come from libc_pic.a.

That means we have to build __stack_check_fail_local into two libraries
at once, since it also has to be in libc_nonshared.a (that's where it is
now and moving it seems likely to be problematic). How does one do that
in the glibc makefile scheme of things?
  
Andreas Schwab March 9, 2016, 8:13 a.m. UTC | #3
Nix <nix@esperi.org.uk> writes:

> That means we have to build __stack_check_fail_local into two libraries
> at once, since it also has to be in libc_nonshared.a

libc.so and libc_nonshared.a are variants of the same library.

> How does one do that in the glibc makefile scheme of things?

You can create it under a new name and put it in shared-only-routines.

Andreas.
  

Patch

diff --git a/Makerules b/Makerules
index 53eabfa..d369d78 100644
--- a/Makerules
+++ b/Makerules
@@ -674,6 +674,7 @@  $(common-objpfx)linkobj/libc.so: link-libc-deps = # empty
 # libraries.
 $(common-objpfx)libc.so: $(elf-objpfx)soinit.os \
 			 $(common-objpfx)libc_pic.os$(libc_pic_clean) \
+			 $(common-objpfx)libc_nonshared.a \
 			 $(elf-objpfx)sofini.os \
 			 $(elf-objpfx)interp.os \
 			 $(elf-objpfx)ld.so \
@@ -683,6 +684,7 @@  $(common-objpfx)libc.so: $(elf-objpfx)soinit.os \
 
 $(common-objpfx)linkobj/libc.so: $(elf-objpfx)soinit.os \
 			 $(common-objpfx)linkobj/libc_pic.a \
+			 $(common-objpfx)libc_nonshared.a \
 			 $(elf-objpfx)sofini.os \
 			 $(elf-objpfx)interp.os \
 			 $(elf-objpfx)ld.so \
diff --git a/debug/Makefile b/debug/Makefile
index 6b5f31e..2f506af 100644
--- a/debug/Makefile
+++ b/debug/Makefile
@@ -52,6 +52,12 @@  routines  = backtrace backtracesyms backtracesymsfd noophooks \
 	    $(static-only-routines)
 static-only-routines := warning-nop stack_chk_fail_local
 
+# Building the stack-protector failure routines with stack protection
+# makes no sense.
+
+CFLAGS-stack_chk_fail.c = $(no-stack-protector)
+CFLAGS-stack_chk_fail_local.c = $(no-stack-protector)
+
 CFLAGS-backtrace.c = -fno-omit-frame-pointer
 CFLAGS-sprintf_chk.c = $(libio-mtsafe)
 CFLAGS-snprintf_chk.c = $(libio-mtsafe)