Fix various tests to use -no-pie linker flag when needed
authorJan Vrany <jan.vrany@fit.cvut.cz>
Thu, 13 Dec 2018 15:20:49 +0000 (15:20 +0000)
committerSimon Marchi <simon.marchi@ericsson.com>
Fri, 21 Dec 2018 20:53:08 +0000 (15:53 -0500)
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
gdb/testsuite/README
gdb/testsuite/gdb.arch/amd64-disp-step.exp
gdb/testsuite/gdb.arch/amd64-entry-value.exp
gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp
gdb/testsuite/gdb.arch/i386-float.exp
gdb/testsuite/gdb.arch/i386-signal.exp
gdb/testsuite/gdb.mi/mi-reg-undefined.exp
gdb/testsuite/lib/gdb.exp

index f3224d4b4e41c4b4bca3fac50d24f8c9b32d37e0..1ac687e17d09f78340af7b81b82047ad46061007 100644 (file)
@@ -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
index 723d8ba5eb53e387b4d11ee99372ce0be8a91781..b5e75b9a79a56ef3380d81068c11515dcfe0fdd1 100644 (file)
@@ -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
 **********************
 
index 782b75896ccc9c664861692060ceb52f1935ba75..0b941e7f63fd2c8fbe02e8ad2706d61fb4c0425a 100644 (file)
@@ -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
 }
 
index 72700d55c2327b971a5150bdee79e1696b89775e..a8d7d4e2f6c61b3b8c9e6902ce655a92e9826c16 100644 (file)
@@ -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"
index 2bb0344052fce14f03e89a77bc21a1f08b3bc729..db4d9d70bbb1785af5c5f7b450f3ca82cd5ab361 100644 (file)
@@ -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
 }
 
index 87c90c372eedba2f6a0a9ddb1d5ef0d0c6cf8fc1..f0d05f340f32b49a1ae01b3883074f7b4297a30a 100644 (file)
@@ -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
 }
 
index 38046a13cb4ea8aa7da56faea52d556dd282e582..d7acb0497c024e39d995e1a2ba031901284eb638 100644 (file)
@@ -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
 }
index 83abab1a0e3b74cd093ea23ceb920a66c51cfe0e..e7f0b548604fbdc291c32bdfe6fd61104dedccbf 100644 (file)
@@ -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
 }
index 5a5713b1148201cd2cf55349990767466ea4e7d9..c5fda7477e063a9cf073d25d4466c5d024a17094 100644 (file)
@@ -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"]
This page took 0.035869 seconds and 4 git commands to generate.