public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix various tests to use -no-pie linker flag when needed
@ 2018-08-28 19:37 Jan Vrany
  2018-09-07 20:43 ` Tom Tromey
  0 siblings, 1 reply; 16+ messages in thread
From: Jan Vrany @ 2018-08-28 19:37 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany

Various test use test code written in i385 / x86_64 assembly that cannot
be used to create PIE executables. Therefore compilation of test programs
failed on systems where the compiler default is to create PIE executable.

To fix this, force -no-pie linker flag.

gdb/testsuite/ChangeLog:
2018-08-28  Jan Vrany  <jan.vrany@fit.cvut.cz>

	* gdb.arch/amd64-disp-step.exp: Use -no-pie linker flag
	to enforce non-PIE executable.
	* gdb.arch/amd64-entry-value.exp: Likewise.
	* gdb.arch/amd64-invalid-stack-middle.exp: Likewise.
	* gdb.arch/i386-float.exp: Likewise.
	* gdb.arch/i386-signal.exp: Likewise.
	* gdb.mi/mi-reg-undefined.exp: Likewise.
---
 gdb/testsuite/ChangeLog                               | 10 ++++++++++
 gdb/testsuite/gdb.arch/amd64-disp-step.exp            |  3 ++-
 gdb/testsuite/gdb.arch/amd64-entry-value.exp          |  2 +-
 gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp |  3 ++-
 gdb/testsuite/gdb.arch/i386-float.exp                 |  2 +-
 gdb/testsuite/gdb.arch/i386-signal.exp                |  2 +-
 gdb/testsuite/gdb.mi/mi-reg-undefined.exp             |  2 +-
 7 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 6b5275a4cb..409843ff27 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,13 @@
+2018-08-28  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* gdb.arch/amd64-disp-step.exp: Use -no-pie linker flag
+	to enforce non-PIE executable.
+	* gdb.arch/amd64-entry-value.exp: Likewise.
+	* gdb.arch/amd64-invalid-stack-middle.exp: Likewise.
+	* gdb.arch/i386-float.exp: Likewise.
+	* gdb.arch/i386-signal.exp: Likewise.
+	* gdb.mi/mi-reg-undefined.exp: Likewise.
+
 2018-08-23  Kevin Buettner  <kevinb@redhat.com>
 
 	* gdb.dwarf2/dw2-ranges-func.c: New file.
diff --git a/gdb/testsuite/gdb.arch/amd64-disp-step.exp b/gdb/testsuite/gdb.arch/amd64-disp-step.exp
index 782b75896c..8ddd48a1e8 100644
--- a/gdb/testsuite/gdb.arch/amd64-disp-step.exp
+++ b/gdb/testsuite/gdb.arch/amd64-disp-step.exp
@@ -25,9 +25,10 @@ if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
 
 set newline "\[\r\n\]*"
 
+set opts {ldflags=-no-pie}
 standard_testfile .S
 
-if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
+if { [prepare_for_testing "failed to prepare" $testfile $srcfile $opts] } {
     return -1
 }
 
diff --git a/gdb/testsuite/gdb.arch/amd64-entry-value.exp b/gdb/testsuite/gdb.arch/amd64-entry-value.exp
index 72700d55c2..eeb22c8066 100644
--- a/gdb/testsuite/gdb.arch/amd64-entry-value.exp
+++ b/gdb/testsuite/gdb.arch/amd64-entry-value.exp
@@ -14,7 +14,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 standard_testfile .s
-set opts {}
+set opts {ldflags=-no-pie}
 
 if [info exists COMPILE] {
     # make check RUNTESTFLAGS="gdb.arch/amd64-entry-value.exp COMPILE=1"
diff --git a/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp b/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp
index c00bfa10bd..b63fec9a1f 100644
--- a/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp
+++ b/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp
@@ -27,7 +27,8 @@
 # run twice, and we restart gdb before testing each different command to
 # ensure that nothing is being cached.
 
-set opts {}
+set opts {ldflags=-no-pie}
+
 standard_testfile .S
 
 if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
diff --git a/gdb/testsuite/gdb.arch/i386-float.exp b/gdb/testsuite/gdb.arch/i386-float.exp
index 87c90c372e..3fccf5e81b 100644
--- a/gdb/testsuite/gdb.arch/i386-float.exp
+++ b/gdb/testsuite/gdb.arch/i386-float.exp
@@ -28,7 +28,7 @@ standard_testfile .S
 # some targets have leading underscores on assembly symbols.
 set additional_flags [gdb_target_symbol_prefix_flags_asm]
 
-if { [prepare_for_testing "failed to prepare" $testfile $srcfile [list debug $additional_flags]] } {
+if { [prepare_for_testing "failed to prepare" $testfile $srcfile [list debug ldflags=-no-pie $additional_flags]] } {
     return -1
 }
 
diff --git a/gdb/testsuite/gdb.arch/i386-signal.exp b/gdb/testsuite/gdb.arch/i386-signal.exp
index 38046a13cb..a046c06c9d 100644
--- a/gdb/testsuite/gdb.arch/i386-signal.exp
+++ b/gdb/testsuite/gdb.arch/i386-signal.exp
@@ -23,7 +23,7 @@ if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } then {
 standard_testfile
 
 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
-	  executable { debug }] != "" } {
+	  executable { debug ldflags=-no-pie }] != "" } {
     untested "failed to compile"
     return -1
 }
diff --git a/gdb/testsuite/gdb.mi/mi-reg-undefined.exp b/gdb/testsuite/gdb.mi/mi-reg-undefined.exp
index 83abab1a0e..bc560ad9e5 100644
--- a/gdb/testsuite/gdb.mi/mi-reg-undefined.exp
+++ b/gdb/testsuite/gdb.mi/mi-reg-undefined.exp
@@ -33,7 +33,7 @@ if [mi_gdb_start] {
 
 standard_testfile .S
 
-if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug ldflags=-no-pie}] != "" } {
      untested "failed to compile"
      return -1
 }
-- 
2.18.0

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

* Re: [PATCH] Fix various tests to use -no-pie linker flag when needed
  2018-08-28 19:37 [PATCH] Fix various tests to use -no-pie linker flag when needed Jan Vrany
@ 2018-09-07 20:43 ` Tom Tromey
  2018-09-07 22:18   ` Simon Marchi
  0 siblings, 1 reply; 16+ messages in thread
From: Tom Tromey @ 2018-09-07 20:43 UTC (permalink / raw)
  To: Jan Vrany; +Cc: gdb-patches

>>>>> "Jan" == Jan Vrany <jan.vrany@fit.cvut.cz> writes:

Jan> Various test use test code written in i385 / x86_64 assembly that cannot
Jan> be used to create PIE executables. Therefore compilation of test programs
Jan> failed on systems where the compiler default is to create PIE executable.

Jan> To fix this, force -no-pie linker flag.

I guess you're on an OS that enables PIE by default?

These tests don't seem to be linux- or gcc-specific.
Do you know how universal -no-pie is?  My worry is that this would fix
the test for some people but break it for others.

Tom

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

* Re: [PATCH] Fix various tests to use -no-pie linker flag when needed
  2018-09-07 20:43 ` Tom Tromey
@ 2018-09-07 22:18   ` Simon Marchi
  2018-10-14  9:59     ` Jan Vrany
  0 siblings, 1 reply; 16+ messages in thread
From: Simon Marchi @ 2018-09-07 22:18 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Jan Vrany, gdb-patches

On 2018-09-07 21:43, Tom Tromey wrote:
>>>>>> "Jan" == Jan Vrany <jan.vrany@fit.cvut.cz> writes:
> 
> Jan> Various test use test code written in i385 / x86_64 assembly that 
> cannot
> Jan> be used to create PIE executables. Therefore compilation of test 
> programs
> Jan> failed on systems where the compiler default is to create PIE 
> executable.
> 
> Jan> To fix this, force -no-pie linker flag.
> 
> I guess you're on an OS that enables PIE by default?

I know recent-ish Ubuntus do that, I don't know if it's a patch specific 
to that distro or if it's the default value in gcc that changed.

> These tests don't seem to be linux- or gcc-specific.
> Do you know how universal -no-pie is?  My worry is that this would fix
> the test for some people but break it for others.
> 
> Tom

If needed, we could add a new option understood by gdb_compile that adds 
the right flag to achieve the result of -no-pie.

Simon

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

* Re: [PATCH] Fix various tests to use -no-pie linker flag when needed
  2018-09-07 22:18   ` Simon Marchi
@ 2018-10-14  9:59     ` Jan Vrany
  2018-10-16 22:18       ` Simon Marchi
  0 siblings, 1 reply; 16+ messages in thread
From: Jan Vrany @ 2018-10-14  9:59 UTC (permalink / raw)
  To: Simon Marchi, Tom Tromey; +Cc: gdb-patches

Hi, 

I'm sorry for a long delay, I've been very, very busy lately.
Hopefully I'd have more time for GDB now...


On Fri, 2018-09-07 at 23:18 +0100, Simon Marchi wrote:
> On 2018-09-07 21:43, Tom Tromey wrote:
> > > > > > > "Jan" == Jan Vrany <jan.vrany@fit.cvut.cz> writes:
> > 
> > Jan> Various test use test code written in i385 / x86_64 assembly that 
> > cannot
> > Jan> be used to create PIE executables. Therefore compilation of test 
> > programs
> > Jan> failed on systems where the compiler default is to create PIE 
> > executable.
> > 
> > Jan> To fix this, force -no-pie linker flag.
> > 
> > I guess you're on an OS that enables PIE by default?
> 
> I know recent-ish Ubuntus do that, I don't know if it's a patch specific 
> to that distro or if it's the default value in gcc that changed.

Neither I know. I'm using Debian Buster which seems to have -no-pie 
by default too. 

> 
> > These tests don't seem to be linux- or gcc-specific.
> > Do you know how universal -no-pie is?  My worry is that this would fix
> > the test for some people but break it for others.
> > 

No, I don't know how universal -no-pie is. From what I have understood
from Simon (https://sourceware.org/ml/gdb-patches/2018-08/msg00662.html),
out of the options available -no-pie is still the best bet. 

> > Tom
> 
> If needed, we could add a new option understood by gdb_compile that adds 
> the right flag to achieve the result of -no-pie.

Indeed we can. Tom, would that be OK with you? 

Best Jan

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

* Re: [PATCH] Fix various tests to use -no-pie linker flag when needed
  2018-10-14  9:59     ` Jan Vrany
@ 2018-10-16 22:18       ` Simon Marchi
  2018-10-17 13:55         ` Tom Tromey
  2018-10-17 15:47         ` Pedro Alves
  0 siblings, 2 replies; 16+ messages in thread
From: Simon Marchi @ 2018-10-16 22:18 UTC (permalink / raw)
  To: Jan Vrany; +Cc: Tom Tromey, gdb-patches

On 2018-10-14 05:59, Jan Vrany wrote:
> Hi,
> 
> I'm sorry for a long delay, I've been very, very busy lately.
> Hopefully I'd have more time for GDB now...
> 
> 
> On Fri, 2018-09-07 at 23:18 +0100, Simon Marchi wrote:
>> On 2018-09-07 21:43, Tom Tromey wrote:
>> > > > > > > "Jan" == Jan Vrany <jan.vrany@fit.cvut.cz> writes:
>> >
>> > Jan> Various test use test code written in i385 / x86_64 assembly that
>> > cannot
>> > Jan> be used to create PIE executables. Therefore compilation of test
>> > programs
>> > Jan> failed on systems where the compiler default is to create PIE
>> > executable.
>> >
>> > Jan> To fix this, force -no-pie linker flag.
>> >
>> > I guess you're on an OS that enables PIE by default?
>> 
>> I know recent-ish Ubuntus do that, I don't know if it's a patch 
>> specific
>> to that distro or if it's the default value in gcc that changed.
> 
> Neither I know. I'm using Debian Buster which seems to have -no-pie
> by default too.
> 
>> 
>> > These tests don't seem to be linux- or gcc-specific.
>> > Do you know how universal -no-pie is?  My worry is that this would fix
>> > the test for some people but break it for others.
>> >
> 
> No, I don't know how universal -no-pie is. From what I have understood
> from Simon 
> (https://sourceware.org/ml/gdb-patches/2018-08/msg00662.html),
> out of the options available -no-pie is still the best bet.

gcc supports it, icc supports it [1], clang supports it starting at 
version 6 according to my testing.  I think this is universal enough 
that we can use it.  If somebody stumbles on a compiler that does not 
understand -no-pie and they really need to use it for their testing, 
they can quite easily add an option for gdb_compile.  But for now, I 
don't think it's worth the extra work.

[1] https://software.intel.com/en-us/node/523278

I tested the patch and amd64-disp-step.exp fails for me.  When you 
specify options to prepare_for_testing explicitly, you have to include 
the "debug" option (if you do want debug symbols).

With this fix the patch LGTM.

Simon

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

* Re: [PATCH] Fix various tests to use -no-pie linker flag when needed
  2018-10-16 22:18       ` Simon Marchi
@ 2018-10-17 13:55         ` Tom Tromey
  2018-10-17 14:56           ` [PATCH v2] " Jan Vrany
  2018-10-17 15:47         ` Pedro Alves
  1 sibling, 1 reply; 16+ messages in thread
From: Tom Tromey @ 2018-10-17 13:55 UTC (permalink / raw)
  To: Simon Marchi; +Cc: Jan Vrany, Tom Tromey, gdb-patches

>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:

>> No, I don't know how universal -no-pie is. From what I have understood
>> from Simon
>> (https://sourceware.org/ml/gdb-patches/2018-08/msg00662.html),
>> out of the options available -no-pie is still the best bet.

Simon> gcc supports it, icc supports it [1], clang supports it starting at
Simon> version 6 according to my testing.  I think this is universal enough
Simon> that we can use it.

Sounds reasonable to me.

Tom

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

* [PATCH v2] Fix various tests to use -no-pie linker flag when needed
  2018-10-17 13:55         ` Tom Tromey
@ 2018-10-17 14:56           ` Jan Vrany
  2018-10-17 15:12             ` [PATCH v3] " Jan Vrany
  0 siblings, 1 reply; 16+ messages in thread
From: Jan Vrany @ 2018-10-17 14:56 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany

Various test use test code written in i385 / x86_64 assembly that cannot
be used to create PIE executables. Therefore compilation of test programs
failed on systems where the compiler default is to create PIE executable.

To fix this, force -no-pie linker flag.

gdb/testsuite/ChangeLog:
2018-08-28  Jan Vrany  <jan.vrany@fit.cvut.cz>

	* gdb.arch/amd64-disp-step.exp: Use -no-pie linker flag
	to enforce non-PIE executable.
	* gdb.arch/amd64-entry-value.exp: Likewise.
	* gdb.arch/amd64-invalid-stack-middle.exp: Likewise.
	* gdb.arch/i386-float.exp: Likewise.
	* gdb.arch/i386-signal.exp: Likewise.
	* gdb.mi/mi-reg-undefined.exp: Likewise.
---
 gdb/testsuite/ChangeLog                               | 10 ++++++++++
 gdb/testsuite/gdb.arch/amd64-disp-step.exp            |  3 ++-
 gdb/testsuite/gdb.arch/amd64-entry-value.exp          |  2 +-
 gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp |  3 ++-
 gdb/testsuite/gdb.arch/i386-float.exp                 |  2 +-
 gdb/testsuite/gdb.arch/i386-signal.exp                |  2 +-
 gdb/testsuite/gdb.mi/mi-reg-undefined.exp             |  2 +-
 7 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 90ce8af3ae..4cd0b03f39 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,13 @@
+2018-08-28  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* gdb.arch/amd64-disp-step.exp: Use -no-pie linker flag
+	to enforce non-PIE executable.
+	* gdb.arch/amd64-entry-value.exp: Likewise.
+	* gdb.arch/amd64-invalid-stack-middle.exp: Likewise.
+	* gdb.arch/i386-float.exp: Likewise.
+	* gdb.arch/i386-signal.exp: Likewise.
+	* gdb.mi/mi-reg-undefined.exp: Likewise.
+
 2018-10-16  Tom de Vries  <tdevries@suse.de>
 
 	PR gdb/23730
diff --git a/gdb/testsuite/gdb.arch/amd64-disp-step.exp b/gdb/testsuite/gdb.arch/amd64-disp-step.exp
index 782b75896c..8ddd48a1e8 100644
--- a/gdb/testsuite/gdb.arch/amd64-disp-step.exp
+++ b/gdb/testsuite/gdb.arch/amd64-disp-step.exp
@@ -25,9 +25,10 @@ if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
 
 set newline "\[\r\n\]*"
 
+set opts {ldflags=-no-pie}
 standard_testfile .S
 
-if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
+if { [prepare_for_testing "failed to prepare" $testfile $srcfile $opts] } {
     return -1
 }
 
diff --git a/gdb/testsuite/gdb.arch/amd64-entry-value.exp b/gdb/testsuite/gdb.arch/amd64-entry-value.exp
index 72700d55c2..eeb22c8066 100644
--- a/gdb/testsuite/gdb.arch/amd64-entry-value.exp
+++ b/gdb/testsuite/gdb.arch/amd64-entry-value.exp
@@ -14,7 +14,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 standard_testfile .s
-set opts {}
+set opts {ldflags=-no-pie}
 
 if [info exists COMPILE] {
     # make check RUNTESTFLAGS="gdb.arch/amd64-entry-value.exp COMPILE=1"
diff --git a/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp b/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp
index 2bb0344052..1694b955c5 100644
--- a/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp
+++ b/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp
@@ -27,7 +27,8 @@
 # run twice, and we restart gdb before testing each different command to
 # ensure that nothing is being cached.
 
-set opts {}
+set opts {ldflags=-no-pie}
+
 standard_testfile .S
 
 if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
diff --git a/gdb/testsuite/gdb.arch/i386-float.exp b/gdb/testsuite/gdb.arch/i386-float.exp
index 87c90c372e..3fccf5e81b 100644
--- a/gdb/testsuite/gdb.arch/i386-float.exp
+++ b/gdb/testsuite/gdb.arch/i386-float.exp
@@ -28,7 +28,7 @@ standard_testfile .S
 # some targets have leading underscores on assembly symbols.
 set additional_flags [gdb_target_symbol_prefix_flags_asm]
 
-if { [prepare_for_testing "failed to prepare" $testfile $srcfile [list debug $additional_flags]] } {
+if { [prepare_for_testing "failed to prepare" $testfile $srcfile [list debug ldflags=-no-pie $additional_flags]] } {
     return -1
 }
 
diff --git a/gdb/testsuite/gdb.arch/i386-signal.exp b/gdb/testsuite/gdb.arch/i386-signal.exp
index 38046a13cb..a046c06c9d 100644
--- a/gdb/testsuite/gdb.arch/i386-signal.exp
+++ b/gdb/testsuite/gdb.arch/i386-signal.exp
@@ -23,7 +23,7 @@ if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } then {
 standard_testfile
 
 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
-	  executable { debug }] != "" } {
+	  executable { debug ldflags=-no-pie }] != "" } {
     untested "failed to compile"
     return -1
 }
diff --git a/gdb/testsuite/gdb.mi/mi-reg-undefined.exp b/gdb/testsuite/gdb.mi/mi-reg-undefined.exp
index 83abab1a0e..bc560ad9e5 100644
--- a/gdb/testsuite/gdb.mi/mi-reg-undefined.exp
+++ b/gdb/testsuite/gdb.mi/mi-reg-undefined.exp
@@ -33,7 +33,7 @@ if [mi_gdb_start] {
 
 standard_testfile .S
 
-if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug ldflags=-no-pie}] != "" } {
      untested "failed to compile"
      return -1
 }
-- 
2.19.1

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

* [PATCH v3] Fix various tests to use -no-pie linker flag when needed
  2018-10-17 14:56           ` [PATCH v2] " Jan Vrany
@ 2018-10-17 15:12             ` Jan Vrany
  2018-10-17 15:44               ` Simon Marchi
  0 siblings, 1 reply; 16+ messages in thread
From: Jan Vrany @ 2018-10-17 15:12 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany

Various test use test code written in i385 / x86_64 assembly that cannot
be used to create PIE executables. Therefore compilation of test programs
failed on systems where the compiler default is to create PIE executable.

To fix this, force -no-pie linker flag.

gdb/testsuite/ChangeLog:
2018-08-28  Jan Vrany  <jan.vrany@fit.cvut.cz>

	* gdb.arch/amd64-disp-step.exp: Use -no-pie linker flag
	to enforce non-PIE executable.
	* gdb.arch/amd64-entry-value.exp: Likewise.
	* gdb.arch/amd64-invalid-stack-middle.exp: Likewise.
	* gdb.arch/i386-float.exp: Likewise.
	* gdb.arch/i386-signal.exp: Likewise.
	* gdb.mi/mi-reg-undefined.exp: Likewise.
---
 gdb/testsuite/ChangeLog                               | 10 ++++++++++
 gdb/testsuite/gdb.arch/amd64-disp-step.exp            |  3 ++-
 gdb/testsuite/gdb.arch/amd64-entry-value.exp          |  2 +-
 gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp |  3 ++-
 gdb/testsuite/gdb.arch/i386-float.exp                 |  2 +-
 gdb/testsuite/gdb.arch/i386-signal.exp                |  2 +-
 gdb/testsuite/gdb.mi/mi-reg-undefined.exp             |  2 +-
 7 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 90ce8af3ae..4cd0b03f39 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,13 @@
+2018-08-28  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* gdb.arch/amd64-disp-step.exp: Use -no-pie linker flag
+	to enforce non-PIE executable.
+	* gdb.arch/amd64-entry-value.exp: Likewise.
+	* gdb.arch/amd64-invalid-stack-middle.exp: Likewise.
+	* gdb.arch/i386-float.exp: Likewise.
+	* gdb.arch/i386-signal.exp: Likewise.
+	* gdb.mi/mi-reg-undefined.exp: Likewise.
+
 2018-10-16  Tom de Vries  <tdevries@suse.de>
 
 	PR gdb/23730
diff --git a/gdb/testsuite/gdb.arch/amd64-disp-step.exp b/gdb/testsuite/gdb.arch/amd64-disp-step.exp
index 782b75896c..83ca38830d 100644
--- a/gdb/testsuite/gdb.arch/amd64-disp-step.exp
+++ b/gdb/testsuite/gdb.arch/amd64-disp-step.exp
@@ -25,9 +25,10 @@ if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
 
 set newline "\[\r\n\]*"
 
+set opts {debug ldflags=-no-pie}
 standard_testfile .S
 
-if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
+if { [prepare_for_testing "failed to prepare" $testfile $srcfile $opts] } {
     return -1
 }
 
diff --git a/gdb/testsuite/gdb.arch/amd64-entry-value.exp b/gdb/testsuite/gdb.arch/amd64-entry-value.exp
index 72700d55c2..eeb22c8066 100644
--- a/gdb/testsuite/gdb.arch/amd64-entry-value.exp
+++ b/gdb/testsuite/gdb.arch/amd64-entry-value.exp
@@ -14,7 +14,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 standard_testfile .s
-set opts {}
+set opts {ldflags=-no-pie}
 
 if [info exists COMPILE] {
     # make check RUNTESTFLAGS="gdb.arch/amd64-entry-value.exp COMPILE=1"
diff --git a/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp b/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp
index 2bb0344052..1694b955c5 100644
--- a/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp
+++ b/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp
@@ -27,7 +27,8 @@
 # run twice, and we restart gdb before testing each different command to
 # ensure that nothing is being cached.
 
-set opts {}
+set opts {ldflags=-no-pie}
+
 standard_testfile .S
 
 if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
diff --git a/gdb/testsuite/gdb.arch/i386-float.exp b/gdb/testsuite/gdb.arch/i386-float.exp
index 87c90c372e..3fccf5e81b 100644
--- a/gdb/testsuite/gdb.arch/i386-float.exp
+++ b/gdb/testsuite/gdb.arch/i386-float.exp
@@ -28,7 +28,7 @@ standard_testfile .S
 # some targets have leading underscores on assembly symbols.
 set additional_flags [gdb_target_symbol_prefix_flags_asm]
 
-if { [prepare_for_testing "failed to prepare" $testfile $srcfile [list debug $additional_flags]] } {
+if { [prepare_for_testing "failed to prepare" $testfile $srcfile [list debug ldflags=-no-pie $additional_flags]] } {
     return -1
 }
 
diff --git a/gdb/testsuite/gdb.arch/i386-signal.exp b/gdb/testsuite/gdb.arch/i386-signal.exp
index 38046a13cb..a046c06c9d 100644
--- a/gdb/testsuite/gdb.arch/i386-signal.exp
+++ b/gdb/testsuite/gdb.arch/i386-signal.exp
@@ -23,7 +23,7 @@ if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } then {
 standard_testfile
 
 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
-	  executable { debug }] != "" } {
+	  executable { debug ldflags=-no-pie }] != "" } {
     untested "failed to compile"
     return -1
 }
diff --git a/gdb/testsuite/gdb.mi/mi-reg-undefined.exp b/gdb/testsuite/gdb.mi/mi-reg-undefined.exp
index 83abab1a0e..bc560ad9e5 100644
--- a/gdb/testsuite/gdb.mi/mi-reg-undefined.exp
+++ b/gdb/testsuite/gdb.mi/mi-reg-undefined.exp
@@ -33,7 +33,7 @@ if [mi_gdb_start] {
 
 standard_testfile .S
 
-if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug ldflags=-no-pie}] != "" } {
      untested "failed to compile"
      return -1
 }
-- 
2.19.1

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

* Re: [PATCH v3] Fix various tests to use -no-pie linker flag when needed
  2018-10-17 15:12             ` [PATCH v3] " Jan Vrany
@ 2018-10-17 15:44               ` Simon Marchi
  2018-10-17 15:53                 ` Simon Marchi
  0 siblings, 1 reply; 16+ messages in thread
From: Simon Marchi @ 2018-10-17 15:44 UTC (permalink / raw)
  To: Jan Vrany; +Cc: gdb-patches

On 2018-10-17 11:12, Jan Vrany wrote:
> Various test use test code written in i385 / x86_64 assembly that 
> cannot

typo, "i385"

> be used to create PIE executables. Therefore compilation of test 
> programs
> failed on systems where the compiler default is to create PIE 
> executable.
> 
> To fix this, force -no-pie linker flag.

LGTM, thanks!

Simon

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

* Re: [PATCH] Fix various tests to use -no-pie linker flag when needed
  2018-10-16 22:18       ` Simon Marchi
  2018-10-17 13:55         ` Tom Tromey
@ 2018-10-17 15:47         ` Pedro Alves
  2018-10-17 15:51           ` Simon Marchi
  1 sibling, 1 reply; 16+ messages in thread
From: Pedro Alves @ 2018-10-17 15:47 UTC (permalink / raw)
  To: Simon Marchi, Jan Vrany; +Cc: Tom Tromey, gdb-patches

On 10/16/2018 11:18 PM, Simon Marchi wrote:
> On 2018-10-14 05:59, Jan Vrany wrote:

>> No, I don't know how universal -no-pie is. From what I have understood
>> from Simon (https://sourceware.org/ml/gdb-patches/2018-08/msg00662.html),
>> out of the options available -no-pie is still the best bet.
> 
> gcc supports it, icc supports it [1], clang supports it starting at version 6 according to my testing.  I think this is universal 
> enough that we can use it.  If somebody stumbles on a compiler that does not understand -no-pie and they really need to use it for 
> their testing, they can quite easily add an option for gdb_compile.  

Not sure it's that universal.  See:

  https://github.com/xd009642/tarpaulin/issues/7#issuecomment-317180523

For example, the gcc 4.8 I have handy (our minimum supported version) does
not support it:

 $ /opt/gcc-4.8/bin/gcc /home/pedro/gdb/tests/main.c -o main -no-pie
 gcc: error: unrecognized command line option ‘-no-pie’

> But for now, I don't think it's worth the extra work.

I disagree.

Thanks,
Pedro Alves

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

* Re: [PATCH] Fix various tests to use -no-pie linker flag when needed
  2018-10-17 15:47         ` Pedro Alves
@ 2018-10-17 15:51           ` Simon Marchi
  0 siblings, 0 replies; 16+ messages in thread
From: Simon Marchi @ 2018-10-17 15:51 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Jan Vrany, Tom Tromey, gdb-patches

On 2018-10-17 11:47, Pedro Alves wrote:
> On 10/16/2018 11:18 PM, Simon Marchi wrote:
>> On 2018-10-14 05:59, Jan Vrany wrote:
> 
>>> No, I don't know how universal -no-pie is. From what I have 
>>> understood
>>> from Simon 
>>> (https://sourceware.org/ml/gdb-patches/2018-08/msg00662.html),
>>> out of the options available -no-pie is still the best bet.
>> 
>> gcc supports it, icc supports it [1], clang supports it starting at 
>> version 6 according to my testing.  I think this is universal
>> enough that we can use it.  If somebody stumbles on a compiler that 
>> does not understand -no-pie and they really need to use it for
>> their testing, they can quite easily add an option for gdb_compile.
> 
> Not sure it's that universal.  See:
> 
>   https://github.com/xd009642/tarpaulin/issues/7#issuecomment-317180523
> 
> For example, the gcc 4.8 I have handy (our minimum supported version) 
> does
> not support it:
> 
>  $ /opt/gcc-4.8/bin/gcc /home/pedro/gdb/tests/main.c -o main -no-pie
>  gcc: error: unrecognized command line option ‘-no-pie’

Ah, I just assumed that gcc supported it since virtually forever, but 
no.

>> But for now, I don't think it's worth the extra work.
> 
> I disagree.

Given that new information, I agree with you disagreeing.

Simon

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

* Re: [PATCH v3] Fix various tests to use -no-pie linker flag when needed
  2018-10-17 15:44               ` Simon Marchi
@ 2018-10-17 15:53                 ` Simon Marchi
  2018-10-17 19:33                   ` Jan Vrany
  2018-12-13 15:21                   ` [PATCH] " Jan Vrany
  0 siblings, 2 replies; 16+ messages in thread
From: Simon Marchi @ 2018-10-17 15:53 UTC (permalink / raw)
  To: Jan Vrany; +Cc: gdb-patches

On 2018-10-17 11:43, Simon Marchi wrote:
> On 2018-10-17 11:12, Jan Vrany wrote:
>> Various test use test code written in i385 / x86_64 assembly that 
>> cannot
> 
> typo, "i385"
> 
>> be used to create PIE executables. Therefore compilation of test 
>> programs
>> failed on systems where the compiler default is to create PIE 
>> executable.
>> 
>> To fix this, force -no-pie linker flag.
> 
> LGTM, thanks!

Actually, see the message from Pedro.  gcc 4.8 doesn't know about this 
flag, and we probably want to support that for a while... so we'll have 
to implement that gdb_compile flag.

Simon

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

* Re: [PATCH v3] Fix various tests to use -no-pie linker flag when needed
  2018-10-17 15:53                 ` Simon Marchi
@ 2018-10-17 19:33                   ` Jan Vrany
  2018-12-13 15:21                   ` [PATCH] " Jan Vrany
  1 sibling, 0 replies; 16+ messages in thread
From: Jan Vrany @ 2018-10-17 19:33 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

On Wed, 2018-10-17 at 11:52 -0400, Simon Marchi wrote:
> On 2018-10-17 11:43, Simon Marchi wrote:
> > On 2018-10-17 11:12, Jan Vrany wrote:
> > > Various test use test code written in i385 / x86_64 assembly that 
> > > cannot
> > 
> > typo, "i385"
> > 
> > > be used to create PIE executables. Therefore compilation of test 
> > > programs
> > > failed on systems where the compiler default is to create PIE 
> > > executable.
> > > 
> > > To fix this, force -no-pie linker flag.
> > 
> > LGTM, thanks!
> 
> Actually, see the message from Pedro.  gcc 4.8 doesn't know about this 
> flag, and we probably want to support that for a while... so we'll have 
> to implement that gdb_compile flag.
> 

Yeah, I saw it. I'll update the patch later. 

Jan

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

* [PATCH] Fix various tests to use -no-pie linker flag when needed
  2018-10-17 15:53                 ` Simon Marchi
  2018-10-17 19:33                   ` Jan Vrany
@ 2018-12-13 15:21                   ` Jan Vrany
  2018-12-13 17:13                     ` Simon Marchi
  1 sibling, 1 reply; 16+ messages in thread
From: Jan Vrany @ 2018-12-13 15:21 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany

Various test use test code written in i386 / x86_64 assembly that cannot
be used to create PIE executables. Therefore compilation of test programs
failed on systems where the compiler default is to create PIE executable.

The solution is to use -no-pie linker flag, however, such flag may not
(is not) supported by all compilers GDB needs to support. To handle this,
introduce a new flag to gdb_compile - nopie - which inserts -no-pie linker
flag where supported and is no-op where it is not. By default, -no-pie flag
is inserted since most modern compiler do support it.

gdb/testsuite/ChangeLog:
2018-08-28  Jan Vrany  <jan.vrany@fit.cvut.cz>

	* gdb.arch/amd64-disp-step.exp: Use -no-pie linker flag
	to enforce non-PIE executable.
	* gdb.arch/amd64-entry-value.exp: Likewise.
	* gdb.arch/amd64-invalid-stack-middle.exp: Likewise.
	* gdb.arch/i386-float.exp: Likewise.
	* gdb.arch/i386-signal.exp: Likewise.
	* gdb.mi/mi-reg-undefined.exp: Likewise.
---
 gdb/testsuite/ChangeLog                             | 12 ++++++++++++
 gdb/testsuite/gdb.arch/amd64-disp-step.exp          |  3 ++-
 gdb/testsuite/gdb.arch/amd64-entry-value.exp        |  2 +-
 .../gdb.arch/amd64-invalid-stack-middle.exp         |  3 +--
 gdb/testsuite/gdb.arch/i386-float.exp               |  2 +-
 gdb/testsuite/gdb.arch/i386-signal.exp              |  2 +-
 gdb/testsuite/gdb.mi/mi-reg-undefined.exp           |  2 +-
 gdb/testsuite/lib/gdb.exp                           | 13 +++++++++++++
 8 files changed, 32 insertions(+), 7 deletions(-)

diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index ab3a74fffd..34e10ea3cb 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,15 @@
+2018-12-13  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* lib/gdb.exp (gdb_compile): Add new nopie flag enforce
+	non-PIE executables.
+	* gdb.arch/amd64-disp-step.exp: Use nopie flag to enforce
+	non-PIE executable.
+	* gdb.arch/amd64-entry-value.exp: Likewise.
+	* gdb.arch/amd64-invalid-stack-middle.exp: Likewise.
+	* gdb.arch/i386-float.exp: Likewise.
+	* gdb.arch/i386-signal.exp: Likewise.
+	* gdb.mi/mi-reg-undefined.exp: Likewise.
+
 2018-12-12  Andrew Burgess  <andrew.burgess@embecosm.com>
 
 	* gdb.base/annota1.exp: Update a test regexp.
diff --git a/gdb/testsuite/gdb.arch/amd64-disp-step.exp b/gdb/testsuite/gdb.arch/amd64-disp-step.exp
index 782b75896c..0b941e7f63 100644
--- a/gdb/testsuite/gdb.arch/amd64-disp-step.exp
+++ b/gdb/testsuite/gdb.arch/amd64-disp-step.exp
@@ -25,9 +25,10 @@ if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
 
 set newline "\[\r\n\]*"
 
+set opts {debug nopie}
 standard_testfile .S
 
-if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
+if { [prepare_for_testing "failed to prepare" $testfile $srcfile $opts] } {
     return -1
 }
 
diff --git a/gdb/testsuite/gdb.arch/amd64-entry-value.exp b/gdb/testsuite/gdb.arch/amd64-entry-value.exp
index 72700d55c2..a8d7d4e2f6 100644
--- a/gdb/testsuite/gdb.arch/amd64-entry-value.exp
+++ b/gdb/testsuite/gdb.arch/amd64-entry-value.exp
@@ -14,7 +14,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 standard_testfile .s
-set opts {}
+set opts {nopie}
 
 if [info exists COMPILE] {
     # make check RUNTESTFLAGS="gdb.arch/amd64-entry-value.exp COMPILE=1"
diff --git a/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp b/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp
index 2bb0344052..db4d9d70bb 100644
--- a/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp
+++ b/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp
@@ -27,7 +27,6 @@
 # run twice, and we restart gdb before testing each different command to
 # ensure that nothing is being cached.
 
-set opts {}
 standard_testfile .S
 
 if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
@@ -35,7 +34,7 @@ if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
     return
 }
 
-if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} $opts] } {
+if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} {nopie}] } {
     return -1
 }
 
diff --git a/gdb/testsuite/gdb.arch/i386-float.exp b/gdb/testsuite/gdb.arch/i386-float.exp
index 87c90c372e..f0d05f340f 100644
--- a/gdb/testsuite/gdb.arch/i386-float.exp
+++ b/gdb/testsuite/gdb.arch/i386-float.exp
@@ -28,7 +28,7 @@ standard_testfile .S
 # some targets have leading underscores on assembly symbols.
 set additional_flags [gdb_target_symbol_prefix_flags_asm]
 
-if { [prepare_for_testing "failed to prepare" $testfile $srcfile [list debug $additional_flags]] } {
+if { [prepare_for_testing "failed to prepare" $testfile $srcfile [list debug nopie $additional_flags]] } {
     return -1
 }
 
diff --git a/gdb/testsuite/gdb.arch/i386-signal.exp b/gdb/testsuite/gdb.arch/i386-signal.exp
index 38046a13cb..d7acb0497c 100644
--- a/gdb/testsuite/gdb.arch/i386-signal.exp
+++ b/gdb/testsuite/gdb.arch/i386-signal.exp
@@ -23,7 +23,7 @@ if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } then {
 standard_testfile
 
 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
-	  executable { debug }] != "" } {
+	  executable { debug nopie }] != "" } {
     untested "failed to compile"
     return -1
 }
diff --git a/gdb/testsuite/gdb.mi/mi-reg-undefined.exp b/gdb/testsuite/gdb.mi/mi-reg-undefined.exp
index 83abab1a0e..e7f0b54860 100644
--- a/gdb/testsuite/gdb.mi/mi-reg-undefined.exp
+++ b/gdb/testsuite/gdb.mi/mi-reg-undefined.exp
@@ -33,7 +33,7 @@ if [mi_gdb_start] {
 
 standard_testfile .S
 
-if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nopie}] != "" } {
      untested "failed to compile"
      return -1
 }
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 5a5713b114..f25df0a772 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -3482,6 +3482,7 @@ set gdb_saved_set_unbuffered_mode_obj ""
 #     dynamically load libraries at runtime.  For example, on Linux, this adds
 #     -ldl so that the test can use dlopen.
 #   - nowarnings:  Inhibit all compiler warnings.
+#   - nopie: Prevent creation of PIE executables.
 #
 # And here are some of the not too obscure options understood by DejaGnu that
 # influence the compilation:
@@ -3603,6 +3604,18 @@ proc gdb_compile {source dest type options} {
 	set options [lreplace $options $nowarnings $nowarnings $flag]
     }
 
+    # Replace the "nopie" option with the appropriate additional_flags
+    # to disable PIE executables.
+    set nopie [lsearch -exact $options nopie]
+    if {$nopie != -1} {
+	if [target_info exists gdb,nowarnings_flag] {
+	    set flag "ldflags=[target_info gdb,nopie_flag]"
+	} else {
+	    set flag "ldflags=-no-pie"
+	}
+	set options [lreplace $options $nopie $nopie $flag]
+    }
+
     if { $type == "executable" } {
 	if { ([istarget "*-*-mingw*"]
 	      || [istarget "*-*-*djgpp"]
-- 
2.19.2

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

* Re: [PATCH] Fix various tests to use -no-pie linker flag when needed
  2018-12-13 15:21                   ` [PATCH] " Jan Vrany
@ 2018-12-13 17:13                     ` Simon Marchi
  2018-12-21 20:56                       ` Simon Marchi
  0 siblings, 1 reply; 16+ messages in thread
From: Simon Marchi @ 2018-12-13 17:13 UTC (permalink / raw)
  To: Jan Vrany; +Cc: gdb-patches, Pedro Alves

On 2018-12-13 10:20, Jan Vrany wrote:
> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
> index 5a5713b114..f25df0a772 100644
> --- a/gdb/testsuite/lib/gdb.exp
> +++ b/gdb/testsuite/lib/gdb.exp
> @@ -3482,6 +3482,7 @@ set gdb_saved_set_unbuffered_mode_obj ""
>  #     dynamically load libraries at runtime.  For example, on Linux, 
> this adds
>  #     -ldl so that the test can use dlopen.
>  #   - nowarnings:  Inhibit all compiler warnings.
> +#   - nopie: Prevent creation of PIE executables.
>  #
>  # And here are some of the not too obscure options understood by 
> DejaGnu that
>  # influence the compilation:
> @@ -3603,6 +3604,18 @@ proc gdb_compile {source dest type options} {
>  	set options [lreplace $options $nowarnings $nowarnings $flag]
>      }
> 
> +    # Replace the "nopie" option with the appropriate additional_flags
> +    # to disable PIE executables.
> +    set nopie [lsearch -exact $options nopie]
> +    if {$nopie != -1} {
> +	if [target_info exists gdb,nowarnings_flag] {

s/nowarnings_flag/nopie_flag/

> +	    set flag "ldflags=[target_info gdb,nopie_flag]"
> +	} else {
> +	    set flag "ldflags=-no-pie"
> +	}
> +	set options [lreplace $options $nopie $nopie $flag]
> +    }
> +

With this, people who run tests against gcc 4.8 will be forced to create 
a specific board file to override the nopie_flag, whereas currently it's 
possible to do it all from the command line:

$ make check TESTS="gdb.arch/amd64-disp-step.exp" 
RUNTESTFLAGS='CC_FOR_TARGET="gcc-4.8"'

One way to avoid that would be to auto-detect whether the toolchain 
generates PIE executables by default.  If the nopie option is requested 
but the toolchain generates non-PIE by default, we would not pass any 
additional flags.  On Linux, we can generate an executable and use 
"readelf -h" to check for the type of ELF artifact generated.

Another way would be to check whether the toolchain knows the -no-pie 
flag, and assume that if it doesn't, it's because it probably generates 
non-PIE by default, so we don't need to pass anything.  That would break 
with toolchains that generate PIE by default but use another flag to 
disable PIE (I am not aware of any that fits in this category), but 
people would still have the possibiliy of overriding it with a board 
file.

Or maybe this just fine, and we can require the few people who test 
against gcc 4.8 to use a board file.

Simon

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

* Re: [PATCH] Fix various tests to use -no-pie linker flag when needed
  2018-12-13 17:13                     ` Simon Marchi
@ 2018-12-21 20:56                       ` Simon Marchi
  0 siblings, 0 replies; 16+ messages in thread
From: Simon Marchi @ 2018-12-21 20:56 UTC (permalink / raw)
  To: Simon Marchi, Jan Vrany; +Cc: gdb-patches, Pedro Alves

On 2018-12-13 12:13 p.m., Simon Marchi wrote:
> On 2018-12-13 10:20, Jan Vrany wrote:
>> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
>> index 5a5713b114..f25df0a772 100644
>> --- a/gdb/testsuite/lib/gdb.exp
>> +++ b/gdb/testsuite/lib/gdb.exp
>> @@ -3482,6 +3482,7 @@ set gdb_saved_set_unbuffered_mode_obj ""
>>  #     dynamically load libraries at runtime.  For example, on Linux, this adds
>>  #     -ldl so that the test can use dlopen.
>>  #   - nowarnings:  Inhibit all compiler warnings.
>> +#   - nopie: Prevent creation of PIE executables.
>>  #
>>  # And here are some of the not too obscure options understood by DejaGnu that
>>  # influence the compilation:
>> @@ -3603,6 +3604,18 @@ proc gdb_compile {source dest type options} {
>>      set options [lreplace $options $nowarnings $nowarnings $flag]
>>      }
>>
>> +    # Replace the "nopie" option with the appropriate additional_flags
>> +    # to disable PIE executables.
>> +    set nopie [lsearch -exact $options nopie]
>> +    if {$nopie != -1} {
>> +    if [target_info exists gdb,nowarnings_flag] {
> 
> s/nowarnings_flag/nopie_flag/
> 
>> +        set flag "ldflags=[target_info gdb,nopie_flag]"
>> +    } else {
>> +        set flag "ldflags=-no-pie"
>> +    }
>> +    set options [lreplace $options $nopie $nopie $flag]
>> +    }
>> +
> 
> With this, people who run tests against gcc 4.8 will be forced to create a specific board file to override the nopie_flag, whereas currently it's possible to do it all from the command line:
> 
> $ make check TESTS="gdb.arch/amd64-disp-step.exp" RUNTESTFLAGS='CC_FOR_TARGET="gcc-4.8"'
> 
> One way to avoid that would be to auto-detect whether the toolchain generates PIE executables by default.  If the nopie option is requested but the toolchain generates non-PIE by default, we would not pass any additional flags.  On Linux, we can generate an executable and use "readelf -h" to check for the type of ELF artifact generated.
> 
> Another way would be to check whether the toolchain knows the -no-pie flag, and assume that if it doesn't, it's because it probably generates non-PIE by default, so we don't need to pass anything.  That would break with toolchains that generate PIE by default but use another flag to disable PIE (I am not aware of any that fits in this category), but people would still have the possibiliy of overriding it with a board file.
> 
> Or maybe this just fine, and we can require the few people who test against gcc 4.8 to use a board file.
> 
> Simon

Hi Jan,

I adjusted the "nowarnings_flag" copy-pasto, added an entry in testsuite/README
and pushed your patch (as below).

Thanks!

Simon

From 6e8b1ab2fd4c692146eb14295866920f83dc5403 Mon Sep 17 00:00:00 2001
From: Jan Vrany <jan.vrany@fit.cvut.cz>
Date: Thu, 13 Dec 2018 15:20:49 +0000
Subject: [PATCH] Fix various tests to use -no-pie linker flag when needed

Various tests use test code written in i386 / x86_64 assembly that cannot
be used to create PIE executables. Therefore compilation of test programs
failed on systems where the compiler default is to create PIE executable.

The solution is to use -no-pie linker flag, however, such flag may not
(is not) supported by all compilers GDB needs to support (e.g. gcc 4.8).
To handle this, introduce a new flag to gdb_compile - nopie - which
inserts -no-pie linker flag where supported and is no-op where it is
not. By default, -no-pie flag is inserted since most modern compiler do
support it.
---
 gdb/testsuite/ChangeLog                             | 13 +++++++++++++
 gdb/testsuite/README                                |  5 +++++
 gdb/testsuite/gdb.arch/amd64-disp-step.exp          |  3 ++-
 gdb/testsuite/gdb.arch/amd64-entry-value.exp        |  2 +-
 .../gdb.arch/amd64-invalid-stack-middle.exp         |  3 +--
 gdb/testsuite/gdb.arch/i386-float.exp               |  2 +-
 gdb/testsuite/gdb.arch/i386-signal.exp              |  2 +-
 gdb/testsuite/gdb.mi/mi-reg-undefined.exp           |  2 +-
 gdb/testsuite/lib/gdb.exp                           | 13 +++++++++++++
 9 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index f3224d4b4e4..1ac687e17d0 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,16 @@
+2018-12-21  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* lib/gdb.exp (gdb_compile): Add new nopie flag enforce
+	non-PIE executables.
+	* README: Mention the gdb,nopie_flag board setting.
+	* gdb.arch/amd64-disp-step.exp: Use nopie flag to enforce
+	non-PIE executable.
+	* gdb.arch/amd64-entry-value.exp: Likewise.
+	* gdb.arch/amd64-invalid-stack-middle.exp: Likewise.
+	* gdb.arch/i386-float.exp: Likewise.
+	* gdb.arch/i386-signal.exp: Likewise.
+	* gdb.mi/mi-reg-undefined.exp: Likewise.
+
 2018-12-21  Paul Marechal  <paul.marechal@ericsson.com>

 	PR gdb/23974
diff --git a/gdb/testsuite/README b/gdb/testsuite/README
index 723d8ba5eb5..b5e75b9a79a 100644
--- a/gdb/testsuite/README
+++ b/gdb/testsuite/README
@@ -482,6 +482,11 @@ gdb,no_thread_names

   The target doesn't support thread names.

+gdb,nopie_flag
+
+  The flag required to force the compiler to produce non-position-independent
+  executables.
+
 Testsuite Organization
 **********************

diff --git a/gdb/testsuite/gdb.arch/amd64-disp-step.exp b/gdb/testsuite/gdb.arch/amd64-disp-step.exp
index 782b75896cc..0b941e7f63f 100644
--- a/gdb/testsuite/gdb.arch/amd64-disp-step.exp
+++ b/gdb/testsuite/gdb.arch/amd64-disp-step.exp
@@ -25,9 +25,10 @@ if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {

 set newline "\[\r\n\]*"

+set opts {debug nopie}
 standard_testfile .S

-if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
+if { [prepare_for_testing "failed to prepare" $testfile $srcfile $opts] } {
     return -1
 }

diff --git a/gdb/testsuite/gdb.arch/amd64-entry-value.exp b/gdb/testsuite/gdb.arch/amd64-entry-value.exp
index 72700d55c23..a8d7d4e2f6c 100644
--- a/gdb/testsuite/gdb.arch/amd64-entry-value.exp
+++ b/gdb/testsuite/gdb.arch/amd64-entry-value.exp
@@ -14,7 +14,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.

 standard_testfile .s
-set opts {}
+set opts {nopie}

 if [info exists COMPILE] {
     # make check RUNTESTFLAGS="gdb.arch/amd64-entry-value.exp COMPILE=1"
diff --git a/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp b/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp
index 2bb0344052f..db4d9d70bbb 100644
--- a/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp
+++ b/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp
@@ -27,7 +27,6 @@
 # run twice, and we restart gdb before testing each different command to
 # ensure that nothing is being cached.

-set opts {}
 standard_testfile .S

 if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
@@ -35,7 +34,7 @@ if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
     return
 }

-if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} $opts] } {
+if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} {nopie}] } {
     return -1
 }

diff --git a/gdb/testsuite/gdb.arch/i386-float.exp b/gdb/testsuite/gdb.arch/i386-float.exp
index 87c90c372ee..f0d05f340f3 100644
--- a/gdb/testsuite/gdb.arch/i386-float.exp
+++ b/gdb/testsuite/gdb.arch/i386-float.exp
@@ -28,7 +28,7 @@ standard_testfile .S
 # some targets have leading underscores on assembly symbols.
 set additional_flags [gdb_target_symbol_prefix_flags_asm]

-if { [prepare_for_testing "failed to prepare" $testfile $srcfile [list debug $additional_flags]] } {
+if { [prepare_for_testing "failed to prepare" $testfile $srcfile [list debug nopie $additional_flags]] } {
     return -1
 }

diff --git a/gdb/testsuite/gdb.arch/i386-signal.exp b/gdb/testsuite/gdb.arch/i386-signal.exp
index 38046a13cb4..d7acb0497c0 100644
--- a/gdb/testsuite/gdb.arch/i386-signal.exp
+++ b/gdb/testsuite/gdb.arch/i386-signal.exp
@@ -23,7 +23,7 @@ if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } then {
 standard_testfile

 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
-	  executable { debug }] != "" } {
+	  executable { debug nopie }] != "" } {
     untested "failed to compile"
     return -1
 }
diff --git a/gdb/testsuite/gdb.mi/mi-reg-undefined.exp b/gdb/testsuite/gdb.mi/mi-reg-undefined.exp
index 83abab1a0e3..e7f0b548604 100644
--- a/gdb/testsuite/gdb.mi/mi-reg-undefined.exp
+++ b/gdb/testsuite/gdb.mi/mi-reg-undefined.exp
@@ -33,7 +33,7 @@ if [mi_gdb_start] {

 standard_testfile .S

-if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nopie}] != "" } {
      untested "failed to compile"
      return -1
 }
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 5a5713b1148..c5fda7477e0 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -3482,6 +3482,7 @@ set gdb_saved_set_unbuffered_mode_obj ""
 #     dynamically load libraries at runtime.  For example, on Linux, this adds
 #     -ldl so that the test can use dlopen.
 #   - nowarnings:  Inhibit all compiler warnings.
+#   - nopie: Prevent creation of PIE executables.
 #
 # And here are some of the not too obscure options understood by DejaGnu that
 # influence the compilation:
@@ -3603,6 +3604,18 @@ proc gdb_compile {source dest type options} {
 	set options [lreplace $options $nowarnings $nowarnings $flag]
     }

+    # Replace the "nopie" option with the appropriate additional_flags
+    # to disable PIE executables.
+    set nopie [lsearch -exact $options nopie]
+    if {$nopie != -1} {
+	if [target_info exists gdb,nopie_flag] {
+	    set flag "ldflags=[target_info gdb,nopie_flag]"
+	} else {
+	    set flag "ldflags=-no-pie"
+	}
+	set options [lreplace $options $nopie $nopie $flag]
+    }
+
     if { $type == "executable" } {
 	if { ([istarget "*-*-mingw*"]
 	      || [istarget "*-*-*djgpp"]
-- 
2.20.1


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

end of thread, other threads:[~2018-12-21 20:56 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-28 19:37 [PATCH] Fix various tests to use -no-pie linker flag when needed Jan Vrany
2018-09-07 20:43 ` Tom Tromey
2018-09-07 22:18   ` Simon Marchi
2018-10-14  9:59     ` Jan Vrany
2018-10-16 22:18       ` Simon Marchi
2018-10-17 13:55         ` Tom Tromey
2018-10-17 14:56           ` [PATCH v2] " Jan Vrany
2018-10-17 15:12             ` [PATCH v3] " Jan Vrany
2018-10-17 15:44               ` Simon Marchi
2018-10-17 15:53                 ` Simon Marchi
2018-10-17 19:33                   ` Jan Vrany
2018-12-13 15:21                   ` [PATCH] " Jan Vrany
2018-12-13 17:13                     ` Simon Marchi
2018-12-21 20:56                       ` Simon Marchi
2018-10-17 15:47         ` Pedro Alves
2018-10-17 15:51           ` Simon Marchi

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).