From patchwork Thu Dec 13 15:20:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Vrany X-Patchwork-Id: 30661 Received: (qmail 5699 invoked by alias); 13 Dec 2018 15:21:30 -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 5680 invoked by uid 89); 13 Dec 2018 15:21:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_PASS autolearn=ham version=3.3.2 spammy=x86_64**, 14, 7, obscure, x86_64-*-* X-HELO: relay.fit.cvut.cz Received: from relay.fit.cvut.cz (HELO relay.fit.cvut.cz) (147.32.232.237) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 13 Dec 2018 15:21:26 +0000 Received: from imap.fit.cvut.cz (imap.fit.cvut.cz [147.32.232.238]) by relay.fit.cvut.cz (8.15.2/8.15.2) with ESMTPS id wBDFLKe0062103 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Dec 2018 16:21:21 +0100 (CET) (envelope-from jan.vrany@fit.cvut.cz) Received: from localhost (02788930.bb.sky.com [2.120.137.48] (may be forged)) (authenticated bits=0 as user vranyj1) by imap.fit.cvut.cz (8.15.2/8.15.2) with ESMTPSA id wBDFLJBF015790 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Thu, 13 Dec 2018 16:21:20 +0100 (CET) (envelope-from jan.vrany@fit.cvut.cz) From: Jan Vrany To: gdb-patches@sourceware.org Cc: Jan Vrany Subject: [PATCH] Fix various tests to use -no-pie linker flag when needed Date: Thu, 13 Dec 2018 15:20:49 +0000 Message-Id: <20181213152049.7702-1-jan.vrany@fit.cvut.cz> In-Reply-To: <2985d86a6b3b9a3bef6e79bc2d130955@polymtl.ca> References: <2985d86a6b3b9a3bef6e79bc2d130955@polymtl.ca> MIME-Version: 1.0 Various test 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. 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: 2018-08-28 Jan Vrany * gdb.arch/amd64-disp-step.exp: Use -no-pie linker 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. --- gdb/testsuite/ChangeLog | 12 ++++++++++++ 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 +++++++++++++ 8 files changed, 32 insertions(+), 7 deletions(-) diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index ab3a74fffd..34e10ea3cb 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,15 @@ +2018-12-13 Jan Vrany + + * lib/gdb.exp (gdb_compile): Add new nopie flag enforce + non-PIE executables. + * 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-12 Andrew Burgess * gdb.base/annota1.exp: Update a test regexp. diff --git a/gdb/testsuite/gdb.arch/amd64-disp-step.exp b/gdb/testsuite/gdb.arch/amd64-disp-step.exp index 782b75896c..0b941e7f63 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 72700d55c2..a8d7d4e2f6 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 2bb0344052..db4d9d70bb 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 87c90c372e..f0d05f340f 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 38046a13cb..d7acb0497c 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 83abab1a0e..e7f0b54860 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 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] { + 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"]