This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb/gdb-8.3-branch] Testsuite: Ensure pie is disabled on some tests


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=3b752ac2e6e7ba7306528b3affaa3c364e30044b

commit 3b752ac2e6e7ba7306528b3affaa3c364e30044b
Author: Alan Hayward <alan.hayward@arm.com>
Date:   Wed Aug 7 18:23:49 2019 +0200

    Testsuite: Ensure pie is disabled on some tests
    
    [ Backport of master commit 968aa7ae38. ]
    
    Recent versions of Ubuntu and Debian default GCC to enable pie.
    
    In dump.exp, pie will causes addresses to be out of range for IHEX.
    
    In break-interp.exp, pie is explicitly set for some tests and assumed
    to be disabled for the remainder.
    
    Ensure pie is disabled for these tests when required.
    
    In addition, add a pie option to gdb_compile to match the nopie option
    and simplify use.
    
    gdb/testsuite/ChangeLog:
    
    	* README: Add pie options.
    	* gdb.base/break-interp.exp: Ensure pie is disabled.
    	* gdb.base/dump.exp: Likewise.
    	* lib/gdb.exp (gdb_compile): Add pie option.

Diff:
---
 gdb/testsuite/ChangeLog                 |  7 +++++++
 gdb/testsuite/README                    | 10 ++++++++++
 gdb/testsuite/gdb.base/break-interp.exp |  6 ++++--
 gdb/testsuite/gdb.base/dump.exp         |  4 ++++
 gdb/testsuite/lib/gdb.exp               | 30 ++++++++++++++++++++++++++++--
 5 files changed, 53 insertions(+), 4 deletions(-)

diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index c510361..03824fa 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2019-03-22  Alan Hayward  <alan.hayward@arm.com>
+
+	* README: Add pie options.
+	* gdb.base/break-interp.exp: Ensure pie is disabled.
+	* gdb.base/dump.exp: Likewise.
+	* lib/gdb.exp (gdb_compile): Add pie option.
+
 2019-06-27  Tom Tromey  <tromey@adacore.com>
 
 	* gdb.cp/constexpr-field.exp: Use setup_xfail.
diff --git a/gdb/testsuite/README b/gdb/testsuite/README
index b5e75b9..db90ea4 100644
--- a/gdb/testsuite/README
+++ b/gdb/testsuite/README
@@ -482,6 +482,16 @@ gdb,no_thread_names
 
   The target doesn't support thread names.
 
+gdb,pie_flag
+
+  The flag required to force the compiler to produce position-independent
+  executables.
+
+gdb,pie_ldflag
+
+  The flag required to force the linker to produce position-independent
+  executables.
+
 gdb,nopie_flag
 
   The flag required to force the compiler to produce non-position-independent
diff --git a/gdb/testsuite/gdb.base/break-interp.exp b/gdb/testsuite/gdb.base/break-interp.exp
index f85e8a6..51e31f6 100644
--- a/gdb/testsuite/gdb.base/break-interp.exp
+++ b/gdb/testsuite/gdb.base/break-interp.exp
@@ -625,8 +625,10 @@ foreach ldprelink {NO YES} {
 				lappend opts {debug}
 			    }
 			    if {$binpie != "NO"} {
-				lappend opts {additional_flags=-fPIE}
-				lappend opts {ldflags=-pie}
+				lappend opts {pie}
+			    } else {
+				# Debian9/Ubuntu16.10 onwards default to PIE enabled. Ensure it is disabled.
+				lappend opts {nopie}
 			    }
 
 			    set dir ${exec}.d
diff --git a/gdb/testsuite/gdb.base/dump.exp b/gdb/testsuite/gdb.base/dump.exp
index 44b0988..52ba5f8 100644
--- a/gdb/testsuite/gdb.base/dump.exp
+++ b/gdb/testsuite/gdb.base/dump.exp
@@ -36,6 +36,10 @@ if {[istarget "spu*-*-*"]} then {
     set is64bitonly "yes"
 }
 
+# Debian9/Ubuntu16.10 onwards default to PIE enabled. Ensure it is disabled as
+# this causes addresses to be out of range for IHEX.
+lappend options {nopie}
+
 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable ${options}] != "" } {
      untested "failed to compile"
      return -1
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 36f1673..3d5f872 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -3492,6 +3492,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.
+#   - pie: Force creation of PIE executables.
 #   - nopie: Prevent creation of PIE executables.
 #
 # And here are some of the not too obscure options understood by DejaGnu that
@@ -3630,8 +3631,33 @@ 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.
+    # Replace the "pie" option with the appropriate compiler and linker flags
+    # to enable PIE executables.
+    set pie [lsearch -exact $options pie]
+    if {$pie != -1} {
+	if [target_info exists gdb,pie_flag] {
+	    set flag "additional_flags=[target_info gdb,pie_flag]"
+	} else {
+	    # For safety, use fPIE rather than fpie. On AArch64, m68k, PowerPC
+	    # and SPARC, fpie can cause compile errors due to the GOT exceeding
+	    # a maximum size.  On other architectures the two flags are
+	    # identical (see the GCC manual). Note Debian9 and Ubuntu16.10
+	    # onwards default GCC to using fPIE.  If you do require fpie, then
+	    # it can be set using the pie_flag.
+	    set flag "additional_flags=-fPIE"
+	}
+	set options [lreplace $options $pie $pie $flag]
+
+	if [target_info exists gdb,pie_ldflag] {
+	    set flag "ldflags=[target_info gdb,pie_ldflag]"
+	} else {
+	    set flag "ldflags=-pie"
+	}
+	lappend options "$flag"
+    }
+
+    # Replace the "nopie" option with the appropriate linker flag to disable
+    # PIE executables.  There are no compiler flags for this option.
     set nopie [lsearch -exact $options nopie]
     if {$nopie != -1} {
 	if [target_info exists gdb,nopie_flag] {


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]