[gdb/testsuite] Fail in gdb_compile if nopie results in PIE executable
authorTom de Vries <tdevries@suse.de>
Tue, 30 Jul 2019 07:42:07 +0000 (09:42 +0200)
committerTom de Vries <tdevries@suse.de>
Tue, 30 Jul 2019 07:42:07 +0000 (09:42 +0200)
When running gdb.base/dump.exp with --target_board=unix/-fPIE/-pie, we get:
...
Running gdb/testsuite/gdb.base/dump.exp ...
FAIL: gdb.base/dump.exp: dump array as value, intel hex
...

The FAIL happens because although the test specifies nopie, the exec is
in fact compiled as PIE.  The "-fPIE -pie" options specified using the
target_board are interpreted by dejagnu as multilib_flags, and end up
overriding the nopie flags.

Fix this by checking in gdb_compile if the resulting exec is PIE despite of
a nopie setting, and if so return an error:
...
Running gdb/testsuite/gdb.base/dump.exp ...
gdb compile failed, nopie failed to prevent PIE executable

                === gdb Summary ===

nr of untested testcases         1
...

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

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

PR testsuite/24834
* lib/gdb.exp (gdb_compile): Fail if nopie results in PIE executable.
(exec_is_pie): New proc.

gdb/testsuite/ChangeLog
gdb/testsuite/lib/gdb.exp

index b2551063fe8f90a63cf2bdc08776a264d3a5d857..3476d7f46f27d3bd73e10e03e86ce481f15127be 100644 (file)
@@ -1,3 +1,9 @@
+2019-07-30  Tom de Vries  <tdevries@suse.de>
+
+       PR testsuite/24834
+       * lib/gdb.exp (gdb_compile): Fail if nopie results in PIE executable.
+       (exec_is_pie): New proc.
+
 2019-07-29  Christian Biesinger  <cbiesinger@google.com>
 
        * gdb.python/py-objfile.c: Add global and static vars.
index 14b9601122b2e9c3640c278f642fd8b6eca3e93d..68e94346dee8f50b862756fabcd26feb3fed6c07 100644 (file)
@@ -3771,6 +3771,12 @@ proc gdb_compile {source dest type options} {
     regsub "\[\r\n\]*$" "$result" "" result
     regsub "^\[\r\n\]*" "$result" "" result
     
+    if { $type == "executable" && $result == "" && $nopie != -1 } {
+       if { [exec_is_pie "$dest"] } {
+           set result "nopie failed to prevent PIE executable"
+       }
+    }
+
     if {[lsearch $options quiet] < 0} {
        # We shall update this on a per language basis, to avoid
        # changing the entire testsuite in one go.
@@ -5171,6 +5177,18 @@ proc exec_has_index_section { executable } {
     return 0
 }
 
+# Return true if EXECUTABLE is a Position Independent Executable.
+
+proc exec_is_pie { executable } {
+    set readelf_program [gdb_find_readelf]
+    set res [catch {exec $readelf_program -d $executable \
+                       | grep -E "(FLAGS_1).*Flags:.* PIE($| )" }]
+    if { $res == 0 } {
+       return 1
+    }
+    return 0
+}
+
 # Return true if a test should be skipped due to lack of floating
 # point support or GDB can't fetch the contents from floating point
 # registers.
This page took 0.032757 seconds and 4 git commands to generate.