public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] rust: Fix rust modules test
@ 2020-07-04  3:59 Daniel Xu
  2020-07-04  6:44 ` Daniel Xu
  2020-07-11 22:14 ` Tom Tromey
  0 siblings, 2 replies; 6+ messages in thread
From: Daniel Xu @ 2020-07-04  3:59 UTC (permalink / raw)
  To: gdb-patches, tom

I noticed that the modules test was failing. Some choice use of `nm`
revealed `TWENTY_THREE` was not in the final binary. Fix by taking a
pointer to the global, forcing the linker to keep the symbol in.

gdb/testsuite/
        * gdb.rust/modules.rs: Prevent linker from discarding test
          symbol

Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
---
Changes from V0:
  * Take pointer to global instead. Should be more reliable than using
    the global twice.

 gdb/testsuite/gdb.rust/modules.rs | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gdb/testsuite/gdb.rust/modules.rs b/gdb/testsuite/gdb.rust/modules.rs
index 6db082817b..479e6529cd 100644
--- a/gdb/testsuite/gdb.rust/modules.rs
+++ b/gdb/testsuite/gdb.rust/modules.rs
@@ -60,7 +60,8 @@ pub mod mod1 {
 
                 let f2 = || println!("lambda f2");
 
-                let copy = ::TWENTY_THREE;
+                // Prevent linker from discarding symbol
+                let ptr: *const u16 = &::TWENTY_THREE;
 
                 f2();           // set breakpoint here
                 f3();
-- 
2.27.0


^ permalink raw reply	[flat|nested] 6+ messages in thread
* [PATCH] rust: Fix rust modules test
@ 2020-07-04  3:27 Daniel Xu
  2020-07-06  9:32 ` Tom de Vries
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Xu @ 2020-07-04  3:27 UTC (permalink / raw)
  To: gdb-patches, tom

I noticed that the modules test was failing. Some choice use of `nm`
revealed `TWENTY_THREE` was not in the final binary. Rather than trying
to trick the compiler/linker by using magic flags, simply `println!()`
the global.

gdb/testsuite/
        * gdb.rust/modules.rs: Prevent linker from discarding test
          symbol

Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
---
 gdb/testsuite/gdb.rust/modules.rs | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gdb/testsuite/gdb.rust/modules.rs b/gdb/testsuite/gdb.rust/modules.rs
index 6db082817b..dc2a469b2f 100644
--- a/gdb/testsuite/gdb.rust/modules.rs
+++ b/gdb/testsuite/gdb.rust/modules.rs
@@ -93,4 +93,7 @@ pub mod mod1 {
 
 fn main () {
     mod1::inner::innest::f1();
+
+    // Prevent linker from discarding `TWENTY_THREE`
+    println!("{}", TWENTY_THREE);
 }
-- 
2.27.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-07-11 22:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-04  3:59 [PATCH] rust: Fix rust modules test Daniel Xu
2020-07-04  6:44 ` Daniel Xu
2020-07-11 22:14 ` Tom Tromey
  -- strict thread matches above, loose matches on Subject: below --
2020-07-04  3:27 Daniel Xu
2020-07-06  9:32 ` Tom de Vries
2020-07-07  5:16   ` Daniel Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).