From patchwork Fri Jul 5 15:18:08 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timo Teras X-Patchwork-Id: 257189 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 2FA112C0091 for ; Sat, 6 Jul 2013 01:18:01 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:mime-version :content-type:content-transfer-encoding; q=dns; s=default; b=lYP X+IwOUMlhQGwU2uNpHtWenEuVoA45ncmTMTnen8P+N9yXXBYF4tfDGVgIJfPh5l+ 0UkgMHgTmS+xWyhtJshAavCCB4NmmUDBVVoI3arEvgl1VvC8R4j1bwaTiiMzI/Ba qUBATVhe+wIvTQUzbkzf6k3SE0cGwIoy6oIXcaYI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:mime-version :content-type:content-transfer-encoding; s=default; bh=a9R+gNiE8 +QH3kDWeRDSlHFpV8U=; b=vw5MNsdOsZFmvYx/qaGP33OEYv5bmOYoa1bQ34fjZ gqGB38igwLV2I7ZuvltkRl0+TaykKHhE6tNT3UkQR2j9WonfJw6VtoPeLGBO2lIn SY/WPUA9aa0SgpEnFFP5yoi3Ab4N3MihRA1jwz60zK8Fn1CQCNP8SKthnMANlJcd 0Y= Received: (qmail 29713 invoked by alias); 5 Jul 2013 15:17:55 -0000 Mailing-List: contact crossgcc-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: crossgcc-owner@sourceware.org Delivered-To: mailing list crossgcc@sourceware.org Received: (qmail 29700 invoked by uid 89); 5 Jul 2013 15:17:53 -0000 X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, SPF_PASS, TW_CX autolearn=ham version=3.3.1 Received: from mail-ee0-f48.google.com (HELO mail-ee0-f48.google.com) (74.125.83.48) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Fri, 05 Jul 2013 15:17:51 +0000 Received: by mail-ee0-f48.google.com with SMTP id b47so1424363eek.21 for ; Fri, 05 Jul 2013 08:17:49 -0700 (PDT) X-Received: by 10.14.1.70 with SMTP id 46mr12794190eec.82.1373037469592; Fri, 05 Jul 2013 08:17:49 -0700 (PDT) Received: from vostro ([83.145.235.199]) by mx.google.com with ESMTPSA id c44sm14687030eeb.8.2013.07.05.08.17.48 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 05 Jul 2013 08:17:49 -0700 (PDT) Date: Fri, 5 Jul 2013 18:18:08 +0300 From: Timo Teras To: crossgcc@sourceware.org Subject: [RFC PATCH] PIE support Message-ID: <20130705181808.5c9a7fb4@vostro> Mime-Version: 1.0 X-IsSubscribed: yes This is also mainly for comments. The piepatches definitely need to be handled somewhat better - would be nice if CT_Patch could be called with the patches just downloaded. The config option names and description also need improvement, but not really sure how they should be named. All in all, this enables: 1. to build for host that needs PIE executables 2. to build toolchain that generates PIE executables for target This is also tested to be functional. # HG changeset patch # User Timo Teras # Date 1373036916 0 # Fri Jul 05 15:08:36 2013 +0000 # Node ID 241d803894fb9a0724edb415e8fe59b2f6473c3e # Parent ea74ae048cecafd6a9078fe9c621934bc23e39f3 RFC: PIC/PIE support --- For unsubscribe information see http://sourceware.org/lists.html#faq diff -r ea74ae048cec -r 241d803894fb config/toolchain.in --- a/config/toolchain.in Tue Jul 02 05:34:04 2013 +0000 +++ b/config/toolchain.in Fri Jul 05 15:08:36 2013 +0000 @@ -146,6 +146,13 @@ You shouldn't need to enter anything here, unless you plan to manually call the tools (autotools-based ./configure will use the standard name). +config TARGET_PIE + bool + prompt "Enable PIE" + default n + help + Enable this if target exepects PIC/PIE enabled. + comment "Toolchain type" choice @@ -245,6 +252,13 @@ for that by checking the tools without the suffix in case it can not find some of the tool. +config BUILD_PIE + bool + default n + prompt "| Enforce PIC/PIE support" + help + Check this if *build system* expects to have PIC/PIE enabled. + if CANADIAN comment "Host system" @@ -299,6 +313,13 @@ for that by checking the tools without the suffix in case it can not find some of the tool. +config HOST_PIE + bool + default n + prompt "| Enforce PIC/PIE support" + help + Check this if *host system* expects to have PIC/PIE enabled. + endif # CANADIAN comment "Misc options" diff -r ea74ae048cec -r 241d803894fb scripts/build/cc/gcc.sh --- a/scripts/build/cc/gcc.sh Tue Jul 02 05:34:04 2013 +0000 +++ b/scripts/build/cc/gcc.sh Fri Jul 05 15:08:36 2013 +0000 @@ -39,6 +39,11 @@ CT_GetFile ecj-latest .jar ftp://gcc.gnu.org/pub/java \ ftp://sourceware.org/pub/java fi + + if [ "${CT_TARGET_PIE}" = "y" ]; then + CT_GetFile "gcc-4.7.1-piepatches-v0.5.3" \ + http://distfiles.gentoo.org/distfiles/ + fi } # Extract gcc @@ -58,6 +63,17 @@ ]; then CT_DoExecLog ALL cp -v "${CT_TARBALLS_DIR}/ecj-latest.jar" "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/ecj.jar" fi + + if [ "${CT_TARGET_PIE}" = "y" ]; then + CT_Extract "gcc-4.7.1-piepatches-v0.5.3" + cd "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/" + for p in "${CT_SRC_DIR}"/gcc-4.7.1-piepatches-v0.5.3/*.patch; do + CT_DoExecLog ALL \ + patch --no-backup-if-mismatch -f -p0 -i "${p}" || + patch --no-backup-if-mismatch -f -p1 -i "${p}" || + return 1 + done + fi } #------------------------------------------------------------------------------ @@ -592,6 +608,7 @@ local prefix local complibs local cflags + local piecflags local ldflags local lang_list local build_manuals @@ -793,6 +810,8 @@ esac [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ] && extra_config+=("--disable-nls") + [ "${CT_TARGET_PIE}" = "y" ] && extra_config+=("--enable-esp") + [ "${CT_TARGET_PIE}" = "y" ] && piecflags="-DEFAULT_PIE_SSP -DEFAULT_RELRO -DEFAULT_BIND_NOW" if [ "${CT_CC_GCC_SYSTEM_ZLIB}" = "y" ]; then extra_config+=("--with-system-zlib") @@ -808,7 +827,7 @@ CT_DoExecLog CFG \ CC_FOR_BUILD="${CT_BUILD}-gcc" \ - CFLAGS="${cflags}" \ + CFLAGS="${cflags} ${piecflags}" \ LDFLAGS="${final_LDFLAGS[*]}" \ CFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}" \ CXXFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}" \ diff -r ea74ae048cec -r 241d803894fb scripts/build/companion_libs/100-gmp.sh --- a/scripts/build/companion_libs/100-gmp.sh Tue Jul 02 05:34:04 2013 +0000 +++ b/scripts/build/companion_libs/100-gmp.sh Fri Jul 05 15:08:36 2013 +0000 @@ -39,6 +39,7 @@ gmp_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" ) gmp_opts+=( "cflags=${CT_CFLAGS_FOR_BUILD}" ) gmp_opts+=( "ldflags=${CT_LDFLAGS_FOR_BUILD}" ) + gmp_opts+=( "pie=${CT_BUILD_PIE}" ) do_gmp_backend "${gmp_opts[@]}" CT_Popd @@ -56,6 +57,7 @@ gmp_opts+=( "prefix=${CT_HOST_COMPLIBS_DIR}" ) gmp_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" ) gmp_opts+=( "ldflags=${CT_LDFLAGS_FOR_HOST}" ) + gmp_opts+=( "pie=${CT_HOST_PIE}" ) do_gmp_backend "${gmp_opts[@]}" CT_Popd @@ -68,12 +70,15 @@ # prefix : prefix to install into : dir : (none) # cflags : cflags to use : string : (empty) # ldflags : ldflags to use : string : (empty) +# pie : enable pic/pie : string : (empty) do_gmp_backend() { local host local prefix local cflags local ldflags + local pie local arg + local confopts for arg in "$@"; do eval "${arg// /\\ }" @@ -81,6 +86,8 @@ CT_DoLog EXTRA "Configuring GMP" + [ "$pie" = "y" ] && confopts="$confopts --with-pic" + CT_DoExecLog CFG \ CFLAGS="${cflags} -fexceptions" \ LDFLAGS="${ldflags}" \ @@ -88,6 +95,7 @@ --build=${CT_BUILD} \ --host=${host} \ --prefix="${prefix}" \ + $confopts \ --enable-fft \ --enable-mpbsd \ --enable-cxx \ diff -r ea74ae048cec -r 241d803894fb scripts/crosstool-NG.sh.in --- a/scripts/crosstool-NG.sh.in Tue Jul 02 05:34:04 2013 +0000 +++ b/scripts/crosstool-NG.sh.in Fri Jul 05 15:08:36 2013 +0000 @@ -360,6 +360,7 @@ cross) # A cross-compiler runs on the same machine it is built on CT_HOST="${CT_BUILD}" + CT_HOST_PIE="${CT_BUILD_PIE}" build_mangle="build_" host_mangle="build_" target_mangle=""