From: Tom de Vries via Gdb-patches <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH][gdb/testsuite] Support -fPIE/-fno-PIE/-pie/-no-pie in gdb_compile_rust
Date: Wed, 22 Sep 2021 11:07:20 +0200 [thread overview]
Message-ID: <20210922090715.GA6660@delia> (raw)
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
next reply other threads:[~2021-09-22 9:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-22 9:07 Tom de Vries via Gdb-patches [this message]
2021-09-23 18:01 ` Tom Tromey
2021-09-23 21:01 ` Tom de Vries via Gdb-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210922090715.GA6660@delia \
--to=gdb-patches@sourceware.org \
--cc=tdevries@suse.de \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox