From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id fHmtIl/TXmFUZgAAWB0awg (envelope-from ) for ; Thu, 07 Oct 2021 07:00:47 -0400 Received: by simark.ca (Postfix, from userid 112) id 7C7B91EE20; Thu, 7 Oct 2021 07:00:47 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id C13961E79C for ; Thu, 7 Oct 2021 07:00:45 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2008E385800B for ; Thu, 7 Oct 2021 11:00:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2008E385800B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1633604445; bh=NJZYqyazt/L6CdhFu0thQ2xZPrf4HmkTc3WJ+ZUz1QE=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=T8a33+hF6Zz8F9IJBYBSmYBItUNzdhqNA8+jOZrb/DTg71244Mem0DXLnFyMTT0Jb GQ01/dCsJO6PiDqluFjE3q/xL9CCVZWD+xe9HlExx3ejsEk8kG0LK8uGS+YLfz0Ylf TkqtNPsS8j29OONElvlYeI9HSIa6mw3JmuZ/AFW4= Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 05FA73858C60 for ; Thu, 7 Oct 2021 11:00:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 05FA73858C60 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 1B2BD2199B; Thu, 7 Oct 2021 11:00:25 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 05EEC13B6B; Thu, 7 Oct 2021 11:00:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id HC05AEnTXmFSYwAAMHmgww (envelope-from ); Thu, 07 Oct 2021 11:00:24 +0000 Subject: [PATCH][gdb/testsuite] Prevent compilation fails with unix/-fPIE/-pie To: Tom Tromey , Tom de Vries via Gdb-patches References: <20210929135520.GA16103@delia> <87pmsq0y4m.fsf@tromey.com> <8735pfz6ax.fsf@tromey.com> <5de83135-c797-d211-467a-de12d174ae67@suse.de> Message-ID: <6339c676-579f-f841-f6ba-d3026d1a45ad@suse.de> Date: Thu, 7 Oct 2021 13:00:24 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <5de83135-c797-d211-467a-de12d174ae67@suse.de> Content-Type: multipart/mixed; boundary="------------8C06A65A385C183AC8B49311" Content-Language: en-US X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Tom de Vries via Gdb-patches Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" This is a multi-part message in MIME format. --------------8C06A65A385C183AC8B49311 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit [ was: Re: [PATCH][gdb/testsuite] Add proc require in lib/gdb.exp ] This follow-up patch uses the new proc require. Any comments? Thanks, - Tom --------------8C06A65A385C183AC8B49311 Content-Type: text/x-patch; charset=UTF-8; name="0002-gdb-testsuite-Prevent-compilation-fails-with-unix-fPIE-pie.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename*0="0002-gdb-testsuite-Prevent-compilation-fails-with-unix-fPIE-"; filename*1="pie.patch" [gdb/testsuite] Prevent compilation fails with unix/-fPIE/-pie A regular test-case will produce an executable, and depending on the compiler default, it will be a PIE or not. A test-case can force one or the other using the pie and nopie options. However, when running with target board unix/-fPIE/-pie, the nopie option will have no effect, and likewise for target board unix/-fno-PIE/-no-pie and the pie option. When say we run test-case gdb.base/attach-pie-noexec.exp, which passes the pie option with target board unix/-fno-PIE/-no-pie we get: ... Running src/gdb/testsuite/gdb.base/attach-pie-noexec.exp ... gdb compile failed, pie failed to generate PIE executable === gdb Summary === # of untested testcases 1 ... However, this works only when we actually manage to generate an executable. There are other test-cases, like f.i. gdb.arch/amd64-disp-step.exp that specify nopie, but will generate a compilation failure with target board unix/-fPIE/-pie due to using a hard-coded .S file: ... Running src/gdb/testsuite/gdb.arch/amd64-disp-step.exp ... gdb compile failed, ld: outputs/gdb.arch/amd64-disp-step/amd64-disp-step0.o: \ relocation R_X86_64_32S against `.text' can not be used when making a PIE \ object; recompile with -fPIE collect2: error: ld returned 1 exit status === gdb Summary === # of untested testcases 1 ... Hide this compilation error by: - adding a gdb_caching_proc pie_forced, and - adding "require pie_forced 0" in all affected test-cases. such that we simply have: ... UNTESTED: gdb.arch/amd64-disp-step.exp: nopie failed to prevent PIE executable ... Likewise, add nopie_forced. Tested on x86_64-linux. --- gdb/testsuite/gdb.arch/amd64-disp-step.exp | 2 ++ gdb/testsuite/gdb.arch/amd64-entry-value.exp | 2 ++ .../gdb.arch/amd64-invalid-stack-middle.exp | 2 ++ gdb/testsuite/gdb.arch/i386-float.exp | 2 ++ gdb/testsuite/gdb.arch/i386-signal.exp | 2 ++ gdb/testsuite/gdb.dwarf2/clztest.exp | 2 ++ gdb/testsuite/gdb.dwarf2/dw2-common-block.exp | 2 ++ gdb/testsuite/gdb.dwarf2/dw2-dup-frame.exp | 3 +++ gdb/testsuite/gdb.dwarf2/dw2-reg-undefined.exp | 3 +++ .../gdb.dwarf2/dw2-single-line-discriminators.exp | 2 ++ .../gdb.dwarf2/dw2-undefined-ret-addr.exp | 3 +++ gdb/testsuite/gdb.mi/mi-reg-undefined.exp | 3 +++ gdb/testsuite/lib/gdb.exp | 30 ++++++++++++++++++++++ 13 files changed, 58 insertions(+) diff --git a/gdb/testsuite/gdb.arch/amd64-disp-step.exp b/gdb/testsuite/gdb.arch/amd64-disp-step.exp index f30f29ea578..15fbcbf4051 100644 --- a/gdb/testsuite/gdb.arch/amd64-disp-step.exp +++ b/gdb/testsuite/gdb.arch/amd64-disp-step.exp @@ -23,6 +23,8 @@ if { ![istarget x86_64-*-* ] || ![is_lp64_target] } { return } +require pie_forced 0 + set newline "\[\r\n\]*" set opts {debug nopie} diff --git a/gdb/testsuite/gdb.arch/amd64-entry-value.exp b/gdb/testsuite/gdb.arch/amd64-entry-value.exp index fdfa4a01b58..b9468f04897 100644 --- a/gdb/testsuite/gdb.arch/amd64-entry-value.exp +++ b/gdb/testsuite/gdb.arch/amd64-entry-value.exp @@ -13,6 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +require pie_forced 0 + standard_testfile .s set opts {nopie} diff --git a/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp b/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp index f9e590d83bb..57bb1de9850 100644 --- a/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp +++ b/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp @@ -27,6 +27,8 @@ # run twice, and we restart gdb before testing each different command to # ensure that nothing is being cached. +require pie_forced 0 + standard_testfile .S if { ![istarget x86_64-*-* ] || ![is_lp64_target] } { diff --git a/gdb/testsuite/gdb.arch/i386-float.exp b/gdb/testsuite/gdb.arch/i386-float.exp index b96ff2ba13e..91b9142dbba 100644 --- a/gdb/testsuite/gdb.arch/i386-float.exp +++ b/gdb/testsuite/gdb.arch/i386-float.exp @@ -18,6 +18,8 @@ # Test the x87 floating point information printout. +require pie_forced 0 + if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } then { verbose "Skipping i386 tests for x87 floating point support." return diff --git a/gdb/testsuite/gdb.arch/i386-signal.exp b/gdb/testsuite/gdb.arch/i386-signal.exp index aff796325c9..4354a956d28 100644 --- a/gdb/testsuite/gdb.arch/i386-signal.exp +++ b/gdb/testsuite/gdb.arch/i386-signal.exp @@ -15,6 +15,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +require pie_forced 0 + if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } then { verbose "Skipping i386 unwinder tests." return diff --git a/gdb/testsuite/gdb.dwarf2/clztest.exp b/gdb/testsuite/gdb.dwarf2/clztest.exp index 0f6d18f2c41..a038d3546f6 100644 --- a/gdb/testsuite/gdb.dwarf2/clztest.exp +++ b/gdb/testsuite/gdb.dwarf2/clztest.exp @@ -13,6 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +require pie_forced 0 + load_lib dwarf.exp standard_testfile .S diff --git a/gdb/testsuite/gdb.dwarf2/dw2-common-block.exp b/gdb/testsuite/gdb.dwarf2/dw2-common-block.exp index 5c78f07943d..afd9c87e286 100644 --- a/gdb/testsuite/gdb.dwarf2/dw2-common-block.exp +++ b/gdb/testsuite/gdb.dwarf2/dw2-common-block.exp @@ -13,6 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +require pie_forced 0 + load_lib dwarf.exp # This test can only be run on targets which support DWARF-2 and use gas. diff --git a/gdb/testsuite/gdb.dwarf2/dw2-dup-frame.exp b/gdb/testsuite/gdb.dwarf2/dw2-dup-frame.exp index 4864658a2a1..64a8e462c73 100644 --- a/gdb/testsuite/gdb.dwarf2/dw2-dup-frame.exp +++ b/gdb/testsuite/gdb.dwarf2/dw2-dup-frame.exp @@ -12,6 +12,9 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . + +require pie_forced 0 + load_lib dwarf.exp # This test can only be run on targets which support DWARF-2 and use gas. diff --git a/gdb/testsuite/gdb.dwarf2/dw2-reg-undefined.exp b/gdb/testsuite/gdb.dwarf2/dw2-reg-undefined.exp index b1c28b2f41c..195fb683553 100644 --- a/gdb/testsuite/gdb.dwarf2/dw2-reg-undefined.exp +++ b/gdb/testsuite/gdb.dwarf2/dw2-reg-undefined.exp @@ -12,6 +12,9 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . + +require pie_forced 0 + load_lib dwarf.exp # This test can only be run on targets which support DWARF-2 and use gas. diff --git a/gdb/testsuite/gdb.dwarf2/dw2-single-line-discriminators.exp b/gdb/testsuite/gdb.dwarf2/dw2-single-line-discriminators.exp index 752c4842467..c1af8090e32 100644 --- a/gdb/testsuite/gdb.dwarf2/dw2-single-line-discriminators.exp +++ b/gdb/testsuite/gdb.dwarf2/dw2-single-line-discriminators.exp @@ -16,6 +16,8 @@ # Test gdb's coalescing of multiple line number entries for the same line # but with different discriminators. PR 17276. +require pie_forced 0 + load_lib dwarf.exp # This test can only be run on targets which support DWARF-2 and use gas. diff --git a/gdb/testsuite/gdb.dwarf2/dw2-undefined-ret-addr.exp b/gdb/testsuite/gdb.dwarf2/dw2-undefined-ret-addr.exp index f130ce784ee..d60d6da12ab 100644 --- a/gdb/testsuite/gdb.dwarf2/dw2-undefined-ret-addr.exp +++ b/gdb/testsuite/gdb.dwarf2/dw2-undefined-ret-addr.exp @@ -12,6 +12,9 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . + +require pie_forced 0 + load_lib dwarf.exp standard_testfile .S diff --git a/gdb/testsuite/gdb.mi/mi-reg-undefined.exp b/gdb/testsuite/gdb.mi/mi-reg-undefined.exp index f38e20003a3..3732f084b7a 100644 --- a/gdb/testsuite/gdb.mi/mi-reg-undefined.exp +++ b/gdb/testsuite/gdb.mi/mi-reg-undefined.exp @@ -12,6 +12,9 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . + +require pie_forced 0 + load_lib dwarf.exp load_lib mi-support.exp set MIFLAGS "-i=mi" diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 89733c59605..ad0902f5a22 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -8073,6 +8073,34 @@ gdb_caching_proc have_fuse_ld_gold { return [gdb_simple_compile $me $src executable $flags] } +# Return 1 if nopie fails to prevent a PIE, 0 if nopie prevented a PIE, +# and -1 if an error occurred. +gdb_caching_proc pie_forced { + set me "pie_forced" + set src { int main() { return 0; } } + gdb_simple_compile $me $src executable nopie + set res [exec_is_pie $obj] + if { $res == -1 } { + return -1 + } + set res [expr $res == 1] + return $res +} + +# Return 1 if pie fails to generated a PIE, 0 if pie generated a PIE, +# and -1 if an error occurred. +gdb_caching_proc nopie_forced { + set me "nopie_forced" + set src { int main() { return 0; } } + gdb_simple_compile $me $src executable pie] + set res [exec_is_pie $obj] + if { $res == -1 } { + return -1 + } + set res [expr $res == 0] + return $res +} + # Return 1 if compiler supports scalar_storage_order attribute, otherwise # return 0. gdb_caching_proc supports_scalar_storage_order_attribute { @@ -8224,6 +8252,8 @@ proc require { fn val } { switch $fn-$val { gdb_skip_xml_test-0 { set msg "missing xml support" } + pie_forced-0 { set msg "nopie failed to prevent PIE executable" } + nopie_forced-0 { set msg "pie failed to generate PIE executable" } default { set msg "$fn != $val" } } --------------8C06A65A385C183AC8B49311--