From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id 17C4738582A0; Fri, 14 Oct 2022 11:10:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 17C4738582A0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1665745811; bh=sMtc5LAPBZeJZpjQJ6uOvJq6veF4UkX6Y+/A8MG2DN8=; h=From:To:Subject:Date:From; b=FS+SQReBuPKF3ESrClF7q4geFcrgsQztWfD/jTSJiA4i4JK7ASbhQK65yr0YYHMhB Ky+B69Oaa/SPrXYnbtPBFNsM4Q3PyWiHlJoPoM1AuuGuSCWI5iIVOh67dniwoR4OGn vBNcb505D99+aTNCiQ0NwyeXsT93Oq7wKI4lxGp4= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom de Vries To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdb/testsuite] Fix nopie test-cases with target board unix/-fPIE/-pie X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: 1806054393e033dfac661fe4f68683a23646cb61 X-Git-Newrev: 68f7bda9b1c32920ce4a2fe65129525bc0b05bf7 Message-Id: <20221014111011.17C4738582A0@sourceware.org> Date: Fri, 14 Oct 2022 11:10:10 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D68f7bda9b1c3= 2920ce4a2fe65129525bc0b05bf7 commit 68f7bda9b1c32920ce4a2fe65129525bc0b05bf7 Author: Tom de Vries Date: Fri Oct 14 13:09:50 2022 +0200 [gdb/testsuite] Fix nopie test-cases with target board unix/-fPIE/-pie =20 Compilers default to either PIE or no-PIE executables. =20 In order to test PIE executables with a compiler that produces non-PIE = by default, we can use target board unix/-fPIE/-pie, which set the multili= b_flags of the target board to "-fPIE -pie". =20 Likewise, we can use target board unix/-fno-PIE/-no-pie with a compiler= that produces PIE by default. =20 The target board unix/-fno-PIE/-no-pie has a potential problem when com= piling shared libs, because the multilib_flags will override the attempts of gdb_compile_shlib to compile with -fPIC. This is taken care of by runn= ing the body of gdb_compile_shlib wrapped in with_PIE_multilib_flags_filtered. =20 The target board unix/-fPIE/-pie has a problem with nopie compilations.= The current approach is to do the compilation hoping for the best, and if w= e find out that the resulting executable is PIE despite specifying nopie, we e= rror out with the standard error message "nopie failed to prevent PIE execut= able". =20 That however does not work for hard-coded assembly nopie test-cases, wh= ich will just noisily refuse to compile: ... ld: amd64-disp-step0.o: relocation R_X86_64_32S against `.text' can not= be \ used when making a PIE object; recompile with -fPIE^M ... =20 Fix this in gdb_compile by filtering out the PIE settings in the target= board multilib_flags when pie or nopie is specified. =20 Tested on x86_64-linux. Diff: --- gdb/testsuite/lib/gdb.exp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 7de8bb60c19..1167aa73e2c 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -4783,7 +4783,10 @@ proc gdb_compile {source dest type options} { } } =20 - set result [target_compile $source $dest $type $options] + cond_wrap [expr $pie !=3D -1 || $nopie !=3D -1] \ + with_PIE_multilib_flags_filtered { + set result [target_compile $source $dest $type $options] + } =20 # Prune uninteresting compiler (and linker) output. regsub "Creating library file: \[^\r\n\]*\[\r\n\]+" $result "" result