From patchwork Tue Jun 7 11:06:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nix X-Patchwork-Id: 12844 Received: (qmail 60803 invoked by alias); 7 Jun 2016 11:26:25 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 60791 invoked by uid 89); 7 Jun 2016 11:26:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=T, rm, lgcc, dragged X-HELO: mail.esperi.org.uk From: Nix To: libc-alpha@sourceware.org Cc: fweimer@redhat.com, Nick Alcock Subject: [PATCH 07/14 v6] Prevent the rtld mapfile computation from dragging in __stack_chk_fail*. Date: Tue, 7 Jun 2016 12:06:09 +0100 Message-Id: <1465297576-10981-8-git-send-email-nix@esperi.org.uk> In-Reply-To: <1465297576-10981-1-git-send-email-nix@esperi.org.uk> References: <1465297576-10981-1-git-send-email-nix@esperi.org.uk> X-DCC--Metrics: spindle 1282; Body=4 Fuz1=4 Fuz2=4 From: Nick Alcock The previous commit prevented rtld itself from being built with -fstack-protector, but this is not quite enough. We identify which objects belong in rtld via a test link and analysis of the resulting mapfile. That link is necessarily done against objects that are stack-protected, so drags in __stack_chk_fail_local, __stack_chk_fail, and all the libc and libio code they use. To stop this happening, use --defsym in the test librtld.map-production link to force the linker to predefine these two symbols (to 0, but it could be to anything). (In a real link, this would of course be catastrophic, but these object files are never used for anything else.) v2: New. v6: Dummy out stack_chk_fail_local too. * elf/Makefile (dummy-stack-chk-fail): New. ($(objpfx)librtld.map): Use it. --- elf/Makefile | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/elf/Makefile b/elf/Makefile index 0037cca..d1e29a58 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -349,9 +349,20 @@ $(objpfx)dl-allobjs.os: $(all-rtld-routines:%=$(objpfx)%.os) # are compiled with special flags, and puts these modules into rtld-libc.a # for us. Then we do the real link using rtld-libc.a instead of libc_pic.a. +# If the compiler can do SSP, build the mapfile with dummy __stack_chk_fail +# and __stack_chk_fail_local symbols defined, to prevent the real things +# being dragged into rtld even though rtld is never built with stack-protection. + +ifeq ($(have-ssp),yes) +dummy-stack-chk-fail := -Wl,--defsym='__stack_chk_fail=0' \ + -Wl,--defsym='__stack_chk_fail_local=0' +else +dummy-stack-chk-fail := +endif + $(objpfx)librtld.map: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a @-rm -f $@T - $(reloc-link) -o $@.o '-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T + $(reloc-link) -o $@.o $(dummy-stack-chk-fail) '-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T rm -f $@.o mv -f $@T $@