From patchwork Fri Dec 21 20:56:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 30810 Received: (qmail 109311 invoked by alias); 21 Dec 2018 20:56:13 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 109300 invoked by uid 89); 21 Dec 2018 20:56:12 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, MIME_BASE64_BLANKS autolearn=ham version=3.3.2 spammy= X-HELO: sessmg23.ericsson.net Received: from sessmg23.ericsson.net (HELO sessmg23.ericsson.net) (193.180.251.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 21 Dec 2018 20:56:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; d=ericsson.com; s=mailgw201801; c=relaxed/relaxed; q=dns/txt; i=@ericsson.com; t=1545425765; x=1548017765; h=From:Sender:Reply-To:Subject:Date:Message-ID:To:CC:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=gGTrbFI9hptlidprZJFmldZLi11IS9O5OVeEcA8BtQ0=; b=PDop/zE0CJzXT3KpEbRT7JlL9jYJ8UJMuBUehw+C+vUGiMd2kzF1uj1krd+/f4Is k35Xs7tS6yzQY8mJCH+qZVJze/RxtOX5WB1IppXW3bBKFTvAHWLgRJ3D/d3l/GKf LWC02ZQDTDgl33mM1KAgOCiPkKW7bb3SFjMJTmK27Ds=; Received: from ESESSMB502.ericsson.se (Unknown_Domain [153.88.183.120]) by sessmg23.ericsson.net (Symantec Mail Security) with SMTP id CE.DE.01583.5635D1C5; Fri, 21 Dec 2018 21:56:05 +0100 (CET) Received: from ESESSMB501.ericsson.se (153.88.183.162) by ESESSMB502.ericsson.se (153.88.183.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Fri, 21 Dec 2018 21:56:05 +0100 Received: from NAM02-CY1-obe.outbound.protection.outlook.com (153.88.183.157) by ESESSMB501.ericsson.se (153.88.183.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3 via Frontend Transport; Fri, 21 Dec 2018 21:56:05 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericsson.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gGTrbFI9hptlidprZJFmldZLi11IS9O5OVeEcA8BtQ0=; b=AiyEsLk6lUrOIlxQGWViQQUAXeZCbzELYczmBwofJV4MD4EUFq4NeEuBgrO/aN32mD5Y0XzqxhDnYWT6QfGKSBophbUfzep2vNpJmnUSmb8Ojw7x5IKvIR5pV+b+7kycTiNFLM1C7epnzYqbA65uZnxqpk37W3tFi5NuGEus1xQ= Received: from BYAPR15MB2390.namprd15.prod.outlook.com (52.135.198.30) by BYAPR15MB2248.namprd15.prod.outlook.com (52.135.197.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1446.23; Fri, 21 Dec 2018 20:56:02 +0000 Received: from BYAPR15MB2390.namprd15.prod.outlook.com ([fe80::a143:f30c:dd42:3af9]) by BYAPR15MB2390.namprd15.prod.outlook.com ([fe80::a143:f30c:dd42:3af9%4]) with mapi id 15.20.1425.025; Fri, 21 Dec 2018 20:56:02 +0000 From: Simon Marchi To: Simon Marchi , Jan Vrany CC: "gdb-patches@sourceware.org" , Pedro Alves Subject: Re: [PATCH] Fix various tests to use -no-pie linker flag when needed Date: Fri, 21 Dec 2018 20:56:02 +0000 Message-ID: <2b21bf75-f450-97db-2875-f69d0939c03e@ericsson.com> References: <2985d86a6b3b9a3bef6e79bc2d130955@polymtl.ca> <20181213152049.7702-1-jan.vrany@fit.cvut.cz> <98c5b4d58f5413502ce9ee519923b5a8@polymtl.ca> In-Reply-To: <98c5b4d58f5413502ce9ee519923b5a8@polymtl.ca> authentication-results: spf=none (sender IP is ) smtp.mailfrom=simon.marchi@ericsson.com; received-spf: None (protection.outlook.com: ericsson.com does not designate permitted sender hosts) Content-ID: <0A5F2D4EB703EF44B58614756412D879@namprd15.prod.outlook.com> MIME-Version: 1.0 Return-Path: simon.marchi@ericsson.com X-IsSubscribed: yes On 2018-12-13 12:13 p.m., Simon Marchi wrote: > On 2018-12-13 10:20, Jan Vrany wrote: >> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp >> index 5a5713b114..f25df0a772 100644 >> --- a/gdb/testsuite/lib/gdb.exp >> +++ b/gdb/testsuite/lib/gdb.exp >> @@ -3482,6 +3482,7 @@ set gdb_saved_set_unbuffered_mode_obj "" >>  #     dynamically load libraries at runtime.  For example, on Linux, this adds >>  #     -ldl so that the test can use dlopen. >>  #   - nowarnings:  Inhibit all compiler warnings. >> +#   - nopie: Prevent creation of PIE executables. >>  # >>  # And here are some of the not too obscure options understood by DejaGnu that >>  # influence the compilation: >> @@ -3603,6 +3604,18 @@ proc gdb_compile {source dest type options} { >>      set options [lreplace $options $nowarnings $nowarnings $flag] >>      } >> >> +    # Replace the "nopie" option with the appropriate additional_flags >> +    # to disable PIE executables. >> +    set nopie [lsearch -exact $options nopie] >> +    if {$nopie != -1} { >> +    if [target_info exists gdb,nowarnings_flag] { > > s/nowarnings_flag/nopie_flag/ > >> +        set flag "ldflags=[target_info gdb,nopie_flag]" >> +    } else { >> +        set flag "ldflags=-no-pie" >> +    } >> +    set options [lreplace $options $nopie $nopie $flag] >> +    } >> + > > With this, people who run tests against gcc 4.8 will be forced to create a specific board file to override the nopie_flag, whereas currently it's possible to do it all from the command line: > > $ make check TESTS="gdb.arch/amd64-disp-step.exp" RUNTESTFLAGS='CC_FOR_TARGET="gcc-4.8"' > > One way to avoid that would be to auto-detect whether the toolchain generates PIE executables by default.  If the nopie option is requested but the toolchain generates non-PIE by default, we would not pass any additional flags.  On Linux, we can generate an executable and use "readelf -h" to check for the type of ELF artifact generated. > > Another way would be to check whether the toolchain knows the -no-pie flag, and assume that if it doesn't, it's because it probably generates non-PIE by default, so we don't need to pass anything.  That would break with toolchains that generate PIE by default but use another flag to disable PIE (I am not aware of any that fits in this category), but people would still have the possibiliy of overriding it with a board file. > > Or maybe this just fine, and we can require the few people who test against gcc 4.8 to use a board file. > > Simon Hi Jan, I adjusted the "nowarnings_flag" copy-pasto, added an entry in testsuite/README and pushed your patch (as below). Thanks! Simon From 6e8b1ab2fd4c692146eb14295866920f83dc5403 Mon Sep 17 00:00:00 2001 From: Jan Vrany Date: Thu, 13 Dec 2018 15:20:49 +0000 Subject: [PATCH] Fix various tests to use -no-pie linker flag when needed Various tests use test code written in i386 / x86_64 assembly that cannot be used to create PIE executables. Therefore compilation of test programs failed on systems where the compiler default is to create PIE executable. The solution is to use -no-pie linker flag, however, such flag may not (is not) supported by all compilers GDB needs to support (e.g. gcc 4.8). To handle this, introduce a new flag to gdb_compile - nopie - which inserts -no-pie linker flag where supported and is no-op where it is not. By default, -no-pie flag is inserted since most modern compiler do support it. --- gdb/testsuite/ChangeLog | 13 +++++++++++++ gdb/testsuite/README | 5 +++++ gdb/testsuite/gdb.arch/amd64-disp-step.exp | 3 ++- gdb/testsuite/gdb.arch/amd64-entry-value.exp | 2 +- .../gdb.arch/amd64-invalid-stack-middle.exp | 3 +-- gdb/testsuite/gdb.arch/i386-float.exp | 2 +- gdb/testsuite/gdb.arch/i386-signal.exp | 2 +- gdb/testsuite/gdb.mi/mi-reg-undefined.exp | 2 +- gdb/testsuite/lib/gdb.exp | 13 +++++++++++++ 9 files changed, 38 insertions(+), 7 deletions(-) -- 2.20.1 diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index f3224d4b4e4..1ac687e17d0 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,16 @@ +2018-12-21 Jan Vrany + + * lib/gdb.exp (gdb_compile): Add new nopie flag enforce + non-PIE executables. + * README: Mention the gdb,nopie_flag board setting. + * gdb.arch/amd64-disp-step.exp: Use nopie flag to enforce + non-PIE executable. + * gdb.arch/amd64-entry-value.exp: Likewise. + * gdb.arch/amd64-invalid-stack-middle.exp: Likewise. + * gdb.arch/i386-float.exp: Likewise. + * gdb.arch/i386-signal.exp: Likewise. + * gdb.mi/mi-reg-undefined.exp: Likewise. + 2018-12-21 Paul Marechal PR gdb/23974 diff --git a/gdb/testsuite/README b/gdb/testsuite/README index 723d8ba5eb5..b5e75b9a79a 100644 --- a/gdb/testsuite/README +++ b/gdb/testsuite/README @@ -482,6 +482,11 @@ gdb,no_thread_names The target doesn't support thread names. +gdb,nopie_flag + + The flag required to force the compiler to produce non-position-independent + executables. + Testsuite Organization ********************** diff --git a/gdb/testsuite/gdb.arch/amd64-disp-step.exp b/gdb/testsuite/gdb.arch/amd64-disp-step.exp index 782b75896cc..0b941e7f63f 100644 --- a/gdb/testsuite/gdb.arch/amd64-disp-step.exp +++ b/gdb/testsuite/gdb.arch/amd64-disp-step.exp @@ -25,9 +25,10 @@ if { ![istarget x86_64-*-* ] || ![is_lp64_target] } { set newline "\[\r\n\]*" +set opts {debug nopie} standard_testfile .S -if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } { +if { [prepare_for_testing "failed to prepare" $testfile $srcfile $opts] } { return -1 } diff --git a/gdb/testsuite/gdb.arch/amd64-entry-value.exp b/gdb/testsuite/gdb.arch/amd64-entry-value.exp index 72700d55c23..a8d7d4e2f6c 100644 --- a/gdb/testsuite/gdb.arch/amd64-entry-value.exp +++ b/gdb/testsuite/gdb.arch/amd64-entry-value.exp @@ -14,7 +14,7 @@ # along with this program. If not, see . standard_testfile .s -set opts {} +set opts {nopie} if [info exists COMPILE] { # make check RUNTESTFLAGS="gdb.arch/amd64-entry-value.exp COMPILE=1" diff --git a/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp b/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp index 2bb0344052f..db4d9d70bbb 100644 --- a/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp +++ b/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp @@ -27,7 +27,6 @@ # run twice, and we restart gdb before testing each different command to # ensure that nothing is being cached. -set opts {} standard_testfile .S if { ![istarget x86_64-*-* ] || ![is_lp64_target] } { @@ -35,7 +34,7 @@ if { ![istarget x86_64-*-* ] || ![is_lp64_target] } { return } -if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} $opts] } { +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} {nopie}] } { return -1 } diff --git a/gdb/testsuite/gdb.arch/i386-float.exp b/gdb/testsuite/gdb.arch/i386-float.exp index 87c90c372ee..f0d05f340f3 100644 --- a/gdb/testsuite/gdb.arch/i386-float.exp +++ b/gdb/testsuite/gdb.arch/i386-float.exp @@ -28,7 +28,7 @@ standard_testfile .S # some targets have leading underscores on assembly symbols. set additional_flags [gdb_target_symbol_prefix_flags_asm] -if { [prepare_for_testing "failed to prepare" $testfile $srcfile [list debug $additional_flags]] } { +if { [prepare_for_testing "failed to prepare" $testfile $srcfile [list debug nopie $additional_flags]] } { return -1 } diff --git a/gdb/testsuite/gdb.arch/i386-signal.exp b/gdb/testsuite/gdb.arch/i386-signal.exp index 38046a13cb4..d7acb0497c0 100644 --- a/gdb/testsuite/gdb.arch/i386-signal.exp +++ b/gdb/testsuite/gdb.arch/i386-signal.exp @@ -23,7 +23,7 @@ if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } then { standard_testfile if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \ - executable { debug }] != "" } { + executable { debug nopie }] != "" } { untested "failed to compile" return -1 } diff --git a/gdb/testsuite/gdb.mi/mi-reg-undefined.exp b/gdb/testsuite/gdb.mi/mi-reg-undefined.exp index 83abab1a0e3..e7f0b548604 100644 --- a/gdb/testsuite/gdb.mi/mi-reg-undefined.exp +++ b/gdb/testsuite/gdb.mi/mi-reg-undefined.exp @@ -33,7 +33,7 @@ if [mi_gdb_start] { standard_testfile .S -if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nopie}] != "" } { untested "failed to compile" return -1 } diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 5a5713b1148..c5fda7477e0 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -3482,6 +3482,7 @@ set gdb_saved_set_unbuffered_mode_obj "" # dynamically load libraries at runtime. For example, on Linux, this adds # -ldl so that the test can use dlopen. # - nowarnings: Inhibit all compiler warnings. +# - nopie: Prevent creation of PIE executables. # # And here are some of the not too obscure options understood by DejaGnu that # influence the compilation: @@ -3603,6 +3604,18 @@ proc gdb_compile {source dest type options} { set options [lreplace $options $nowarnings $nowarnings $flag] } + # Replace the "nopie" option with the appropriate additional_flags + # to disable PIE executables. + set nopie [lsearch -exact $options nopie] + if {$nopie != -1} { + if [target_info exists gdb,nopie_flag] { + set flag "ldflags=[target_info gdb,nopie_flag]" + } else { + set flag "ldflags=-no-pie" + } + set options [lreplace $options $nopie $nopie $flag] + } + if { $type == "executable" } { if { ([istarget "*-*-mingw*"] || [istarget "*-*-*djgpp"]