From patchwork Tue Jul 23 07:22:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 33777 Received: (qmail 72769 invoked by alias); 23 Jul 2019 07:22:18 -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 72760 invoked by uid 89); 23 Jul 2019 07:22:17 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=interpreted X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 23 Jul 2019 07:22:16 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 5F3C0B030 for ; Tue, 23 Jul 2019 07:22:14 +0000 (UTC) Date: Tue, 23 Jul 2019 09:22:12 +0200 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH][gdb/testsuite] Fail in gdb_compile if nopie results in PIE executable Message-ID: <20190723072210.GA24180@delia> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-IsSubscribed: yes Hi, When running gdb.base/dump.exp with --target_board=unix/-fPIE/-pie, we get: ... Running gdb/testsuite/gdb.base/dump.exp ... FAIL: gdb.base/dump.exp: dump array as value, intel hex ... The FAIL happens because although the test specifies nopie, the exec is in fact compiled as PIE. The "-fPIE -pie" options specified using the target_board are interpreted by dejagnu as multilib_flags, and end up overriding the nopie flags. Fix this by checking in gdb_compile if the resulting exec is PIE despite of a nopie setting, and if so return an error: ... Running gdb/testsuite/gdb.base/dump.exp ... gdb compile failed, nopie failed to prevent PIE executable === gdb Summary === nr of untested testcases 1 ... Tested on x86_64-linux. OK for trunk? Thanks, - Tom [gdb/testsuite] Fail in gdb_compile if nopie results in PIE executable 2019-07-23 Tom de Vries PR testsuite/24834 * lib/gdb.exp (gdb_compile): Fail if nopie results in PIE executable. (exec_is_pie): New proc. --- gdb/testsuite/lib/gdb.exp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 49ec8b2a55..5ec0912325 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -3760,6 +3760,12 @@ proc gdb_compile {source dest type options} { regsub "\[\r\n\]*$" "$result" "" result regsub "^\[\r\n\]*" "$result" "" result + if { $type == "executable" && $result == "" && $nopie != -1 } { + if { [exec_is_pie "$dest"] } { + set result "nopie failed to prevent PIE executable" + } + } + if {[lsearch $options quiet] < 0} { # We shall update this on a per language basis, to avoid # changing the entire testsuite in one go. @@ -5160,6 +5166,18 @@ proc exec_has_index_section { executable } { return 0 } +# Return true if EXECUTABLE is a Position Independent Executable. + +proc exec_is_pie { executable } { + set readelf_program [gdb_find_readelf] + set res [catch {exec $readelf_program -d $executable \ + | grep -E "(FLAGS_1).*Flags:.* PIE($| )" }] + if { $res == 0 } { + return 1 + } + return 0 +} + # Return true if a test should be skipped due to lack of floating # point support or GDB can't fetch the contents from floating point # registers.