rust: Fix rust modules test

Message ID 20200704035953.849933-1-dxu@dxuuu.xyz
State Superseded
Headers show
Series
  • rust: Fix rust modules test
Related show

Commit Message

Daniel Xu July 4, 2020, 3:59 a.m.
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(-)

-- 
2.27.0

Comments

Daniel Xu July 4, 2020, 6:44 a.m. | #1
On Fri Jul 3, 2020 at 8:59 PM PDT, Daniel Xu wrote:
> 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:


This should have been a "Changes from V1".

And this patch should have veen a V2. Sorry.

[...]


Daniel
Tom Tromey July 11, 2020, 10:14 p.m. | #2
>>>>> "Daniel" == Daniel Xu <dxu@dxuuu.xyz> writes:


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

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

I added the PR, as suggested by Tom, and checked this in.
Thank you for doing this.

Tom

Patch

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();