* [PATCH][gdb/testsuite] Support -fPIE/-fno-PIE/-pie/-no-pie in gdb_compile_rust
@ 2021-09-22 9:07 Tom de Vries via Gdb-patches
2021-09-23 18:01 ` Tom Tromey
0 siblings, 1 reply; 3+ messages in thread
From: Tom de Vries via Gdb-patches @ 2021-09-22 9:07 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH][gdb/testsuite] Support -fPIE/-fno-PIE/-pie/-no-pie in gdb_compile_rust
2021-09-22 9:07 [PATCH][gdb/testsuite] Support -fPIE/-fno-PIE/-pie/-no-pie in gdb_compile_rust Tom de Vries via Gdb-patches
@ 2021-09-23 18:01 ` Tom Tromey
2021-09-23 21:01 ` Tom de Vries via Gdb-patches
0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2021-09-23 18:01 UTC (permalink / raw)
To: Tom de Vries via Gdb-patches; +Cc: Tom Tromey
>>>>> "Tom" == Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> writes:
Tom> Fix this by translating the gcc options to rustc options in gdb_compile_rust,
Tom> similar to how that is done for ada in target_compile_ada_from_dir.
Thanks for doing this.
Tom> + global board
Tom> + set board [target_info name]
Tom> + set multilib_flags_orig [board_info $board multilib_flags]
Tom> + set multilib_flags ""
Tom> + foreach op $multilib_flags_orig {
This iterates over the flags as if they are a list, but constructs the
new flags as if it is a string:
Tom> + append multilib_flags " -C link-arg=$op"
This could in principle cause some quoting issues, though in practice
this would only occur with relatively weird values.
If that's a concern, a fix would be to use:
set multilib_flags {} ;# this is more idiomatic, not critical
...
lappend multilib_flags -C link-arg=$op
Other than this, this seems fine to me.
Maybe even fine as-is, up to you.
Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH][gdb/testsuite] Support -fPIE/-fno-PIE/-pie/-no-pie in gdb_compile_rust
2021-09-23 18:01 ` Tom Tromey
@ 2021-09-23 21:01 ` Tom de Vries via Gdb-patches
0 siblings, 0 replies; 3+ messages in thread
From: Tom de Vries via Gdb-patches @ 2021-09-23 21:01 UTC (permalink / raw)
To: Tom Tromey, Tom de Vries via Gdb-patches
On 9/23/21 8:01 PM, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> writes:
>
> Tom> Fix this by translating the gcc options to rustc options in gdb_compile_rust,
> Tom> similar to how that is done for ada in target_compile_ada_from_dir.
>
> Thanks for doing this.
>
> Tom> + global board
> Tom> + set board [target_info name]
> Tom> + set multilib_flags_orig [board_info $board multilib_flags]
> Tom> + set multilib_flags ""
> Tom> + foreach op $multilib_flags_orig {
>
> This iterates over the flags as if they are a list, but constructs the
> new flags as if it is a string:
>
> Tom> + append multilib_flags " -C link-arg=$op"
>
> This could in principle cause some quoting issues, though in practice
> this would only occur with relatively weird values.
>
> If that's a concern, a fix would be to use:
>
> set multilib_flags {} ;# this is more idiomatic, not critical
> ...
> lappend multilib_flags -C link-arg=$op
>
>
> Other than this, this seems fine to me.
Thanks for pointing this out, fixed and committed.
Thanks,
- Tom
> Maybe even fine as-is, up to you.
>
> Tom
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-09-23 21:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-22 9:07 [PATCH][gdb/testsuite] Support -fPIE/-fno-PIE/-pie/-no-pie in gdb_compile_rust Tom de Vries via Gdb-patches
2021-09-23 18:01 ` Tom Tromey
2021-09-23 21:01 ` Tom de Vries via Gdb-patches
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox