Patchwork [gdb/testsuite] Fix ada tests with -fPIE/-pie

login
register
mail settings
Submitter Tom de Vries
Date Aug. 7, 2019, 11:07 a.m.
Message ID <20190807110713.GA23000@delia>
Download mbox | patch
Permalink /patch/33987/
State New
Headers show

Comments

Tom de Vries - Aug. 7, 2019, 11:07 a.m.
Hi,

When running the gdb testsuite with target board unix/-fPIE/-pie, the
resulting ada executables are not PIE executables, because gnatmake doesn't
recognize -pie, and consequently doesn't pass it to gnatlink.

Fix this by replacing "-pie" with "-largs -pie -margs" for ada test-cases in
gdb_default_target_compile, and doing the same for -no-pie.

Tested on x86_64-linux.

OK for trunk?

Thanks,
- Tom

[gdb/testsuite] Fix ada tests with -fPIE/-pie

gdb/testsuite/ChangeLog:

2019-08-07  Tom de Vries  <tdevries@suse.de>

	PR testsuite/24888
	* lib/future.exp (gdb_default_target_compile): Route -pie/-no-pie to
	gnatlink for ada.

---
 gdb/testsuite/lib/future.exp | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
Tom Tromey - Aug. 7, 2019, 2:18 p.m.
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:

Tom> When running the gdb testsuite with target board unix/-fPIE/-pie, the
Tom> resulting ada executables are not PIE executables, because gnatmake doesn't
Tom> recognize -pie, and consequently doesn't pass it to gnatlink.

Tom> Fix this by replacing "-pie" with "-largs -pie -margs" for ada test-cases in
Tom> gdb_default_target_compile, and doing the same for -no-pie.

I think this is a good idea overall.

However, is gdb_default_target_compile still used?  And if so, by what
path?  My understanding is that with a "new enough" dejagnu, it won't be
used -- so some users might still see the old behavior.

Basically gdb_default_target_compile is all a big monkeypatching hack
and it would be way better to have some kind of more principled approach
upstream.  I don't know what that would look like.  And of course to get
there we'd probably need even more monkeypatching.

Tom

Patch

diff --git a/gdb/testsuite/lib/future.exp b/gdb/testsuite/lib/future.exp
index 122e652858..e26e49af91 100644
--- a/gdb/testsuite/lib/future.exp
+++ b/gdb/testsuite/lib/future.exp
@@ -530,7 +530,19 @@  proc gdb_default_target_compile {source destfile type options} {
     }
 
     if {[board_info $dest exists multilib_flags]} {
-	append add_flags " [board_info $dest multilib_flags]"
+	if { $compiler_type == "ada" } {
+	    foreach op [board_info $dest multilib_flags] {
+		if { $op == "-pie" || $op == "-no-pie" } {
+		    # Pretend gnatmake supports -pie/-no-pie, route it to
+		    # linker.
+		    append add_flags " -largs $op -margs"
+		} else {
+		    append add_flags " $op"
+		}
+	    }
+	} else {
+	    append add_flags " [board_info $dest multilib_flags]"
+	}
     }
 
     verbose "doing compile"