From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id i2m2GGHySmFjZwAAWB0awg (envelope-from ) for ; Wed, 22 Sep 2021 05:07:45 -0400 Received: by simark.ca (Postfix, from userid 112) id 530DC1EE25; Wed, 22 Sep 2021 05:07:45 -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 38C041EDDB for ; Wed, 22 Sep 2021 05:07:44 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0433D385842A for ; Wed, 22 Sep 2021 09:07:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0433D385842A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1632301663; bh=g2uz6MZm+yqq0ZoBu27D0cuE0DCktKmZ/w6rkAIotQk=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=gMa70QfMYC/+g0BQx6GwCBxZ8ml7pHY+7Cq0U+CH3cihhRHp1rxpAtF7jT8Sn/yMt WVXGCrVq69r6GMzXtveM0ykRUhQaFpHFb6Bc6G83pZqMtgIg3Uwr64xElLs9MLk7bH mpfj+qJUnjLC1SvoP2uYF8ltWvaot4SniwF15W6Q= Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 2EA083858D39 for ; Wed, 22 Sep 2021 09:07:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2EA083858D39 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 690F12228E; Wed, 22 Sep 2021 09:07:22 +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 5450D13D6E; Wed, 22 Sep 2021 09:07:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id QruOE0rySmEnJQAAMHmgww (envelope-from ); Wed, 22 Sep 2021 09:07:22 +0000 Date: Wed, 22 Sep 2021 11:07:20 +0200 To: gdb-patches@sourceware.org Subject: [PATCH][gdb/testsuite] Support -fPIE/-fno-PIE/-pie/-no-pie in gdb_compile_rust Message-ID: <20210922090715.GA6660@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) 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 Cc: Tom Tromey Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Hi, When running gdb.rust/*.exp test-cases with target board unix/-fPIE/-pie, I run into: ... builtin_spawn -ignore SIGHUP rustc --color never gdb.rust/watch.rs \ -g -lm -fPIE -pie -o outputs/gdb.rust/watch/watch^M error: Unrecognized option: 'f'^M ^M compiler exited with status 1 ... The problem is that -fPIE and -fpie are gcc options, but for rust we use rustc, which has different compilation options. Fix this by translating the gcc options to rustc options in gdb_compile_rust, similar to how that is done for ada in target_compile_ada_from_dir. Likewise for unix/-fno-PIE/-no-pie. Tested on x86_64-linux, with: - native - unix/-fPIE/-pie - unix/-fno-PIE/-no-pie specifically, on openSUSE Leap 15.2 both with package gcc-PIE: - installed (making gcc default to PIE) - uninstalled (making gcc default to non-PIE). and rustc 1.52.1. Any comments? Thanks, - Tom [gdb/testsuite] Support -fPIE/-fno-PIE/-pie/-no-pie in gdb_compile_rust --- gdb/testsuite/lib/rust-support.exp | 47 +++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/gdb/testsuite/lib/rust-support.exp b/gdb/testsuite/lib/rust-support.exp index 2896ac82453..7e6315878d2 100644 --- a/gdb/testsuite/lib/rust-support.exp +++ b/gdb/testsuite/lib/rust-support.exp @@ -27,13 +27,54 @@ proc set_lang_rust {} { } proc gdb_compile_rust {sources dest options} { + set res -1 + if {[llength $sources] > 1} { error "gdb rust setup can only compile one source file at a time" } - if {[gdb_compile [lindex $sources 0] $dest executable $options] != ""} { - return -1 + + global board + set board [target_info name] + set multilib_flags_orig [board_info $board multilib_flags] + set multilib_flags "" + foreach op $multilib_flags_orig { + # Pretend rustc supports -pie/-no-pie/-fPIE/-fno-PIE. + switch $op { + "-pie" - "-no-pie" { + # Pass it to linker. + append multilib_flags " -C link-arg=$op" + } + "-fno-PIE" { + # Translate to rustc codegen equivalent. + + # The rustc documentation insists that we should use static + # here, but that causes segfaults leading to: + # UNTESTED: gdb.rust/rawids.exp: could not run to breakpoint + # UNTESTED: gdb.rust/pp.exp: could not run to breakpoint + # Instead, we use dynamic-no-pic which does seem to work. + append multilib_flags " -C relocation-model=dynamic-no-pic" + } + "-fPIE" { + # Translate to rustc codegen equivalent. + append multilib_flags " -C relocation-model=pic" + } + default { + # Pass unmodified. + append multilib_flags " $op" + } + } + } + + save_target_board_info { multilib_flags } { + unset_board_info multilib_flags + set_board_info multilib_flags "$multilib_flags" + if {[gdb_compile [lindex $sources 0] $dest executable \ + $options] == ""} { + set res "" + } } - return "" + + return $res } # Return the version of LLVM used by the Rust compiler. Note that