From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 7B81F385E020 for ; Fri, 14 Oct 2022 11:10:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7B81F385E020 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-out2.suse.de (Postfix) with ESMTPS id B5E451F383 for ; Fri, 14 Oct 2022 11:10:40 +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 A4B7513451 for ; Fri, 14 Oct 2022 11:10:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id E7ElJ7BDSWN0WgAAMHmgww (envelope-from ) for ; Fri, 14 Oct 2022 11:10:40 +0000 Date: Fri, 14 Oct 2022 13:10:39 +0200 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [committed][gdb/testsuite] Fix nopie test-cases with target board unix/-fPIE/-pie Message-ID: <20221014111037.GA11169@delia.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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: , X-List-Received-Date: Fri, 14 Oct 2022 11:10:42 -0000 Hi, Compilers default to either PIE or no-PIE executables. 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 multilib_flags of the target board to "-fPIE -pie". Likewise, we can use target board unix/-fno-PIE/-no-pie with a compiler that produces PIE by default. The target board unix/-fno-PIE/-no-pie has a potential problem when compiling shared libs, because the multilib_flags will override the attempts of gdb_compile_shlib to compile with -fPIC. This is taken care of by running the body of gdb_compile_shlib wrapped in with_PIE_multilib_flags_filtered. 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 we find out that the resulting executable is PIE despite specifying nopie, we error out with the standard error message "nopie failed to prevent PIE executable". That however does not work for hard-coded assembly nopie test-cases, which 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 ... Fix this in gdb_compile by filtering out the PIE settings in the target board multilib_flags when pie or nopie is specified. Tested on x86_64-linux. Committed to trunk. Thanks, - Tom [gdb/testsuite] Fix nopie test-cases with target board unix/-fPIE/-pie --- 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} { } } - set result [target_compile $source $dest $type $options] + cond_wrap [expr $pie != -1 || $nopie != -1] \ + with_PIE_multilib_flags_filtered { + set result [target_compile $source $dest $type $options] + } # Prune uninteresting compiler (and linker) output. regsub "Creating library file: \[^\r\n\]*\[\r\n\]+" $result "" result