From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24820 invoked by alias); 11 May 2011 15:21:36 -0000 Received: (qmail 24804 invoked by uid 22791); 11 May 2011 15:21:36 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,TW_FN,TW_PW,TW_TP,TW_WU,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 11 May 2011 15:21:16 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p4BFLGWK012284 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 11 May 2011 11:21:16 -0400 Received: from hase (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p4BFLEf8012678 for ; Wed, 11 May 2011 11:21:15 -0400 From: Andreas Schwab To: libc-hacker@sourceware.org Subject: [PATCH] Add support for generated PIE link rules X-Yow: Didn't I buy a 1951 Packard from you last March in Cairo? Date: Wed, 11 May 2011 15:21:00 -0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2011-05/txt/msg00006.txt.bz2 2011-05-11 Andreas Schwab * Makeconfig (+link-pie): Indent. * Rules (binaries-pie): Define if $(have-fpie) and $(build-shared). (binaries-shared): Also filter out $(binaries-pie). ($(addprefix $(objpfx),$(binaries-pie))): New rule. * nscd/Makefile (others-pie): Add nscd. (LDFLAGS-nscd): Set this instead of relro-LDFLAGS. ($(objpfx)nscd): Remove command override. * login/Makefile (others-pie): Add pt_chown. ($(objpfx)pt_chown): Remove command override. * elf/Makefile: Add PIE tests to tests and tests-pie variables and remove command overrides. --- Makeconfig | 6 ++-- Rules | 18 ++++++++++- elf/Makefile | 90 ++++++------------------------------------------------- login/Makefile | 4 +-- nscd/Makefile | 10 ++---- 5 files changed, 33 insertions(+), 95 deletions(-) diff --git a/Makeconfig b/Makeconfig index 4d91458..3c51498 100644 --- a/Makeconfig +++ b/Makeconfig @@ -450,9 +450,9 @@ ifndef +link-pie $(addprefix $(csu-objpfx),S$(start-installed-name)) \ $(+preinit) $(+prectorS) \ $(filter-out $(addprefix $(csu-objpfx),start.o \ - S$(start-installed-name))\ - $(+preinit) $(link-extra-libs) \ - $(common-objpfx)libc% $(+postinit),$^) \ + S$(start-installed-name))\ + $(+preinit) $(link-extra-libs) \ + $(common-objpfx)libc% $(+postinit),$^) \ $(link-extra-libs) $(link-libc) $(+postctorS) $(+postinit) endif # Command for statically linking programs with the C library. diff --git a/Rules b/Rules index 5ace24c..00f03df 100644 --- a/Rules +++ b/Rules @@ -1,4 +1,4 @@ -# Copyright (C) 1991-2000,2002,2003,2004,2005,2006 +# Copyright (C) 1991-2000,2002,2003,2004,2005,2006,2011 # Free Software Foundation, Inc. # This file is part of the GNU C Library. @@ -106,12 +106,19 @@ endif ifeq ($(build-programs),yes) binaries-all = $(others) $(sysdep-others) $(tests) $(xtests) $(test-srcs) binaries-static = $(others-static) $(tests-static) $(xtests-static) +ifeq (yesyes,$(have-fpie)$(build-shared)) +binaries-pie = $(others-pie) $(tests-pie) $(xtests-pie) +else +binaries-pie = +endif else binaries-all = $(tests) $(xtests) $(test-srcs) binaries-static = +binaries-pie = endif -binaries-shared = $(filter-out $(binaries-static), $(binaries-all)) +binaries-shared = $(filter-out $(binaries-pie) $(binaries-static), \ + $(binaries-all)) ifneq "$(strip $(binaries-shared))" "" $(addprefix $(objpfx),$(binaries-shared)): %: %.o \ @@ -120,6 +127,13 @@ $(addprefix $(objpfx),$(binaries-shared)): %: %.o \ $(+link) endif +ifneq "$(strip $(binaries-pie))" "" +$(addprefix $(objpfx),$(binaries-pie)): %: %.o \ + $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \ + $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit) + $(+link-pie) +endif + ifneq "$(strip $(binaries-static))" "" $(addprefix $(objpfx),$(binaries-static)): %: %.o \ $(sort $(filter $(common-objpfx)lib%,$(link-libc-static))) \ diff --git a/elf/Makefile b/elf/Makefile index 56cb1b1..bfc8552 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -213,9 +213,6 @@ ifeq (x86_64,$(config-machine)) tests += tst-audit3 tst-audit4 tst-audit5 tst-audit6 tst-audit7 endif endif -ifeq (yesyes,$(have-fpie)$(build-shared)) -tests: $(objpfx)tst-pie1.out -endif tests: $(objpfx)tst-leaks1-mem $(objpfx)noload-mem tlsmod17a-suffixes = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 tlsmod18a-suffixes = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 @@ -267,8 +264,8 @@ modules-names += tst-array2dep tst-array5dep endif ifeq (yesyes,$(have-fpie)$(build-shared)) modules-names += tst-piemod1 -extra-test-objs += tst-pie1.o -test-extras += tst-pie1 +tests += tst-pie1 +tests-pie += tst-pie1 endif ifeq (x86_64,$(config-machine)) modules-names += tst-auditmod3a tst-auditmod3b \ @@ -305,9 +302,8 @@ test-extras += $(ifunc-test-modules) ifeq (yes,$(have-fpie)) ifunc-pie-tests = ifuncmain1pie ifuncmain1vispie ifuncmain1staticpie \ ifuncmain5pie ifuncmain6pie ifuncmain7pie -tests: $(patsubst %,$(objpfx)%.out, $(ifunc-pie-tests)) -extra-test-objs += $(ifunc-pie-tests:=.o) -test-extras += $(ifunc-pie-tests) +tests += $(ifunc-pie-tests) +tests-pie += $(ifunc-pie-tests) endif modules-names += ifuncmod1 ifuncmod3 ifuncmod5 ifuncmod6 endif @@ -910,19 +906,9 @@ $(objpfx)tst-array5-static.out: $(objpfx)tst-array5-static $(objpfx)tst-array5-static > $@ cmp $@ tst-array5-static.exp > /dev/null -ifeq (yesyes,$(have-fpie)$(build-shared)) CFLAGS-tst-pie1.c += $(pie-ccflag) -$(objpfx)tst-pie1.out: $(objpfx)tst-pie1 - $(elf-objpfx)$(rtld-installed-name) \ - --library-path $(rpath-link)$(patsubst %,:%,$(sysdep-library-path)) \ - $< > $@ - -$(objpfx)tst-pie1: $(objpfx)tst-pie1.o $(objpfx)tst-piemod1.so - $(+link-pie) - -generated += tst-pie1 tst-pie1.out tst-pie1.o -endif +$(objpfx)tst-pie1: $(objpfx)tst-piemod1.so check-textrel-CFLAGS = -O -Wall -D_XOPEN_SOURCE=600 -D_BSD_SOURCE $(objpfx)check-textrel: check-textrel.c @@ -1085,7 +1071,6 @@ CFLAGS-ifuncmain7picstatic.c += $(pic-ccflag) LDFLAGS-ifuncmain3 = -Wl,-export-dynamic -ifeq (yesyes,$(have-fpie)$(build-shared)) CFLAGS-ifuncmain1pie.c += $(pie-ccflag) CFLAGS-ifuncmain1vispie.c += $(pie-ccflag) CFLAGS-ifuncmain1staticpie.c += $(pie-ccflag) @@ -1093,66 +1078,11 @@ CFLAGS-ifuncmain5pie.c += $(pie-ccflag) CFLAGS-ifuncmain6pie.c += $(pie-ccflag) CFLAGS-ifuncmain7pie.c += $(pie-ccflag) -$(objpfx)ifuncmain1pie.out: $(objpfx)ifuncmain1pie - $(elf-objpfx)$(rtld-installed-name) \ - --library-path $(rpath-link)$(patsubst %,:%,$(sysdep-library-path)) \ - $< > $@ - -$(objpfx)ifuncmain1pie: $(objpfx)ifuncmain1pie.o $(objpfx)ifuncmod1.so - $(+link-pie) - -generated += ifuncmain1pie ifuncmain1pie.out - -$(objpfx)ifuncmain1staticpie.out: $(objpfx)ifuncmain1staticpie - $(elf-objpfx)$(rtld-installed-name) \ - --library-path $(rpath-link)$(patsubst %,:%,$(sysdep-library-path)) \ - $< > $@ - -$(objpfx)ifuncmain1staticpie: $(objpfx)ifuncmain1staticpie.o $(objpfx)ifuncdep1pic.o - $(+link-pie) - -generated += ifuncmain1staticpie ifuncmain1staticpie.out - -$(objpfx)ifuncmain1vispie.out: $(objpfx)ifuncmain1vispie - $(elf-objpfx)$(rtld-installed-name) \ - --library-path $(rpath-link)$(patsubst %,:%,$(sysdep-library-path)) \ - $< > $@ - -$(objpfx)ifuncmain1vispie: $(objpfx)ifuncmain1vispie.o $(objpfx)ifuncmod1.so - $(+link-pie) - -generated += ifuncmain1vispie ifuncmain1vispie.out - -$(objpfx)ifuncmain5pie.out: $(objpfx)ifuncmain5pie - $(elf-objpfx)$(rtld-installed-name) \ - --library-path $(rpath-link)$(patsubst %,:%,$(sysdep-library-path)) \ - $< > $@ - -$(objpfx)ifuncmain5pie: $(objpfx)ifuncmain5pie.o $(objpfx)ifuncmod5.so - $(+link-pie) - -generated += ifuncmain5pie ifuncmain5pie.out - -$(objpfx)ifuncmain6pie.out: $(objpfx)ifuncmain6pie - $(elf-objpfx)$(rtld-installed-name) \ - --library-path $(rpath-link)$(patsubst %,:%,$(sysdep-library-path)) \ - $< > $@ - -$(objpfx)ifuncmain6pie: $(objpfx)ifuncmain6pie.o $(objpfx)ifuncmod6.so - $(+link-pie) - -generated += ifuncmain6pie ifuncmain6pie.out - -$(objpfx)ifuncmain7pie.out: $(objpfx)ifuncmain7pie - $(elf-objpfx)$(rtld-installed-name) \ - --library-path $(rpath-link)$(patsubst %,:%,$(sysdep-library-path)) \ - $< > $@ - -$(objpfx)ifuncmain7pie: $(objpfx)ifuncmain7pie.o - $(+link-pie) - -generated += ifuncmain7pie ifuncmain7pie.out -endif +$(objpfx)ifuncmain1pie: $(objpfx)ifuncmod1.so +$(objpfx)ifuncmain1staticpie: $(objpfx)ifuncdep1pic.o +$(objpfx)ifuncmain1vispie: $(objpfx)ifuncmod1.so +$(objpfx)ifuncmain5pie: $(objpfx)ifuncmod5.so +$(objpfx)ifuncmain6pie: $(objpfx)ifuncmod6.so $(objpfx)ifuncmain1: $(addprefix $(objpfx),ifuncmod1.so) $(objpfx)ifuncmain1pic: $(addprefix $(objpfx),ifuncmod1.so) diff --git a/login/Makefile b/login/Makefile index beb2a5c..46bde13 100644 --- a/login/Makefile +++ b/login/Makefile @@ -30,6 +30,7 @@ routines := getutent getutent_r getutid getutline getutid_r getutline_r \ CFLAGS-grantpt.c = -DLIBEXECDIR='"$(libexecdir)"' others = utmpdump pt_chown +others-pie = pt_chown install-others-programs = $(inst_libexecdir)/pt_chown distribute := utmp-private.h utmp-equal.h pty-private.h @@ -67,9 +68,6 @@ CFLAGS-pt_chown.c = $(pt_chown-cflags) LDLIBS-pt_chown = $(libcap) ifeq (yesyes,$(have-fpie)$(build-shared)) LDFLAGS-pt_chown = -Wl,-z,now - -$(objpfx)pt_chown: $(objpfx)pt_chown.o - $(+link-pie) endif # pt_chown needs to be setuid root. diff --git a/nscd/Makefile b/nscd/Makefile index 4abae8c..097e6f0 100644 --- a/nscd/Makefile +++ b/nscd/Makefile @@ -1,4 +1,4 @@ -# Copyright (C) 1998,2000,2002-2009 Free Software Foundation, Inc. +# Copyright (C) 1998,2000,2002-2009,2011 Free Software Foundation, Inc. # This file is part of the GNU C Library. # The GNU C Library is free software; you can redistribute it and/or @@ -38,9 +38,8 @@ nscd-modules := nscd connections pwdcache getpwnam_r getpwuid_r grpcache \ ifeq ($(have-thread-library),yes) -ifneq (yesyes,$(have-fpie)$(build-shared)) others += nscd -endif +others-pie += nscd install-sbin := nscd extra-objs := $(nscd-modules:=.o) @@ -124,10 +123,7 @@ CFLAGS-getsrvbypt_r.c += $(nscd-cflags) CFLAGS-res_hconf.c += $(nscd-cflags) ifeq (yesyes,$(have-fpie)$(build-shared)) -relro-LDFLAGS += -Wl,-z,now - -$(objpfx)nscd: $(addprefix $(objpfx),$(nscd-modules:=.o)) - $(+link-pie) +LDFLAGS-nscd = -Wl,-z,now endif # This makes sure -DNOT_IN_libc is passed for all these modules. -- 1.7.4.4 -- Andreas Schwab, schwab@redhat.com GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84 5EC7 45C6 250E 6F00 984E "And now for something completely different."