From: Tom de Vries <tdevries@suse.de>
To: Tom Tromey <tom@tromey.com>,
Tom de Vries via Gdb-patches <gdb-patches@sourceware.org>
Subject: [PATCH][gdb/testsuite] Prevent compilation fails with unix/-fPIE/-pie
Date: Thu, 7 Oct 2021 13:00:24 +0200 [thread overview]
Message-ID: <6339c676-579f-f841-f6ba-d3026d1a45ad@suse.de> (raw)
In-Reply-To: <5de83135-c797-d211-467a-de12d174ae67@suse.de>
[-- Attachment #1: Type: text/plain, Size: 147 bytes --]
[ was: Re: [PATCH][gdb/testsuite] Add proc require in lib/gdb.exp ]
This follow-up patch uses the new proc require.
Any comments?
Thanks,
- Tom
[-- Attachment #2: 0002-gdb-testsuite-Prevent-compilation-fails-with-unix-fPIE-pie.patch --]
[-- Type: text/x-patch, Size: 10056 bytes --]
[gdb/testsuite] Prevent compilation fails with unix/-fPIE/-pie
A regular test-case will produce an executable, and depending on the compiler
default, it will be a PIE or not. A test-case can force one or the other
using the pie and nopie options.
However, when running with target board unix/-fPIE/-pie, the nopie option will
have no effect, and likewise for target board unix/-fno-PIE/-no-pie and the
pie option.
When say we run test-case gdb.base/attach-pie-noexec.exp, which passes the pie
option with target board unix/-fno-PIE/-no-pie we get:
...
Running src/gdb/testsuite/gdb.base/attach-pie-noexec.exp ...
gdb compile failed, pie failed to generate PIE executable
=== gdb Summary ===
# of untested testcases 1
...
However, this works only when we actually manage to generate an executable.
There are other test-cases, like f.i. gdb.arch/amd64-disp-step.exp that
specify nopie, but will generate a compilation failure with target board
unix/-fPIE/-pie due to using a hard-coded .S file:
...
Running src/gdb/testsuite/gdb.arch/amd64-disp-step.exp ...
gdb compile failed, ld: outputs/gdb.arch/amd64-disp-step/amd64-disp-step0.o: \
relocation R_X86_64_32S against `.text' can not be used when making a PIE \
object; recompile with -fPIE
collect2: error: ld returned 1 exit status
=== gdb Summary ===
# of untested testcases 1
...
Hide this compilation error by:
- adding a gdb_caching_proc pie_forced, and
- adding "require pie_forced 0" in all affected test-cases.
such that we simply have:
...
UNTESTED: gdb.arch/amd64-disp-step.exp: nopie failed to prevent PIE executable
...
Likewise, add nopie_forced.
Tested on x86_64-linux.
---
gdb/testsuite/gdb.arch/amd64-disp-step.exp | 2 ++
gdb/testsuite/gdb.arch/amd64-entry-value.exp | 2 ++
.../gdb.arch/amd64-invalid-stack-middle.exp | 2 ++
gdb/testsuite/gdb.arch/i386-float.exp | 2 ++
gdb/testsuite/gdb.arch/i386-signal.exp | 2 ++
gdb/testsuite/gdb.dwarf2/clztest.exp | 2 ++
gdb/testsuite/gdb.dwarf2/dw2-common-block.exp | 2 ++
gdb/testsuite/gdb.dwarf2/dw2-dup-frame.exp | 3 +++
gdb/testsuite/gdb.dwarf2/dw2-reg-undefined.exp | 3 +++
.../gdb.dwarf2/dw2-single-line-discriminators.exp | 2 ++
.../gdb.dwarf2/dw2-undefined-ret-addr.exp | 3 +++
gdb/testsuite/gdb.mi/mi-reg-undefined.exp | 3 +++
gdb/testsuite/lib/gdb.exp | 30 ++++++++++++++++++++++
13 files changed, 58 insertions(+)
diff --git a/gdb/testsuite/gdb.arch/amd64-disp-step.exp b/gdb/testsuite/gdb.arch/amd64-disp-step.exp
index f30f29ea578..15fbcbf4051 100644
--- a/gdb/testsuite/gdb.arch/amd64-disp-step.exp
+++ b/gdb/testsuite/gdb.arch/amd64-disp-step.exp
@@ -23,6 +23,8 @@ if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
return
}
+require pie_forced 0
+
set newline "\[\r\n\]*"
set opts {debug nopie}
diff --git a/gdb/testsuite/gdb.arch/amd64-entry-value.exp b/gdb/testsuite/gdb.arch/amd64-entry-value.exp
index fdfa4a01b58..b9468f04897 100644
--- a/gdb/testsuite/gdb.arch/amd64-entry-value.exp
+++ b/gdb/testsuite/gdb.arch/amd64-entry-value.exp
@@ -13,6 +13,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+require pie_forced 0
+
standard_testfile .s
set opts {nopie}
diff --git a/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp b/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp
index f9e590d83bb..57bb1de9850 100644
--- a/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp
+++ b/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp
@@ -27,6 +27,8 @@
# run twice, and we restart gdb before testing each different command to
# ensure that nothing is being cached.
+require pie_forced 0
+
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 b96ff2ba13e..91b9142dbba 100644
--- a/gdb/testsuite/gdb.arch/i386-float.exp
+++ b/gdb/testsuite/gdb.arch/i386-float.exp
@@ -18,6 +18,8 @@
# Test the x87 floating point information printout.
+require pie_forced 0
+
if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } then {
verbose "Skipping i386 tests for x87 floating point support."
return
diff --git a/gdb/testsuite/gdb.arch/i386-signal.exp b/gdb/testsuite/gdb.arch/i386-signal.exp
index aff796325c9..4354a956d28 100644
--- a/gdb/testsuite/gdb.arch/i386-signal.exp
+++ b/gdb/testsuite/gdb.arch/i386-signal.exp
@@ -15,6 +15,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+require pie_forced 0
+
if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } then {
verbose "Skipping i386 unwinder tests."
return
diff --git a/gdb/testsuite/gdb.dwarf2/clztest.exp b/gdb/testsuite/gdb.dwarf2/clztest.exp
index 0f6d18f2c41..a038d3546f6 100644
--- a/gdb/testsuite/gdb.dwarf2/clztest.exp
+++ b/gdb/testsuite/gdb.dwarf2/clztest.exp
@@ -13,6 +13,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+require pie_forced 0
+
load_lib dwarf.exp
standard_testfile .S
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-common-block.exp b/gdb/testsuite/gdb.dwarf2/dw2-common-block.exp
index 5c78f07943d..afd9c87e286 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-common-block.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-common-block.exp
@@ -13,6 +13,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+require pie_forced 0
+
load_lib dwarf.exp
# This test can only be run on targets which support DWARF-2 and use gas.
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-dup-frame.exp b/gdb/testsuite/gdb.dwarf2/dw2-dup-frame.exp
index 4864658a2a1..64a8e462c73 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-dup-frame.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-dup-frame.exp
@@ -12,6 +12,9 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+require pie_forced 0
+
load_lib dwarf.exp
# This test can only be run on targets which support DWARF-2 and use gas.
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-reg-undefined.exp b/gdb/testsuite/gdb.dwarf2/dw2-reg-undefined.exp
index b1c28b2f41c..195fb683553 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-reg-undefined.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-reg-undefined.exp
@@ -12,6 +12,9 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+require pie_forced 0
+
load_lib dwarf.exp
# This test can only be run on targets which support DWARF-2 and use gas.
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-single-line-discriminators.exp b/gdb/testsuite/gdb.dwarf2/dw2-single-line-discriminators.exp
index 752c4842467..c1af8090e32 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-single-line-discriminators.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-single-line-discriminators.exp
@@ -16,6 +16,8 @@
# Test gdb's coalescing of multiple line number entries for the same line
# but with different discriminators. PR 17276.
+require pie_forced 0
+
load_lib dwarf.exp
# This test can only be run on targets which support DWARF-2 and use gas.
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-undefined-ret-addr.exp b/gdb/testsuite/gdb.dwarf2/dw2-undefined-ret-addr.exp
index f130ce784ee..d60d6da12ab 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-undefined-ret-addr.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-undefined-ret-addr.exp
@@ -12,6 +12,9 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+require pie_forced 0
+
load_lib dwarf.exp
standard_testfile .S
diff --git a/gdb/testsuite/gdb.mi/mi-reg-undefined.exp b/gdb/testsuite/gdb.mi/mi-reg-undefined.exp
index f38e20003a3..3732f084b7a 100644
--- a/gdb/testsuite/gdb.mi/mi-reg-undefined.exp
+++ b/gdb/testsuite/gdb.mi/mi-reg-undefined.exp
@@ -12,6 +12,9 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+require pie_forced 0
+
load_lib dwarf.exp
load_lib mi-support.exp
set MIFLAGS "-i=mi"
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 89733c59605..ad0902f5a22 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -8073,6 +8073,34 @@ gdb_caching_proc have_fuse_ld_gold {
return [gdb_simple_compile $me $src executable $flags]
}
+# Return 1 if nopie fails to prevent a PIE, 0 if nopie prevented a PIE,
+# and -1 if an error occurred.
+gdb_caching_proc pie_forced {
+ set me "pie_forced"
+ set src { int main() { return 0; } }
+ gdb_simple_compile $me $src executable nopie
+ set res [exec_is_pie $obj]
+ if { $res == -1 } {
+ return -1
+ }
+ set res [expr $res == 1]
+ return $res
+}
+
+# Return 1 if pie fails to generated a PIE, 0 if pie generated a PIE,
+# and -1 if an error occurred.
+gdb_caching_proc nopie_forced {
+ set me "nopie_forced"
+ set src { int main() { return 0; } }
+ gdb_simple_compile $me $src executable pie]
+ set res [exec_is_pie $obj]
+ if { $res == -1 } {
+ return -1
+ }
+ set res [expr $res == 0]
+ return $res
+}
+
# Return 1 if compiler supports scalar_storage_order attribute, otherwise
# return 0.
gdb_caching_proc supports_scalar_storage_order_attribute {
@@ -8224,6 +8252,8 @@ proc require { fn val } {
switch $fn-$val {
gdb_skip_xml_test-0 { set msg "missing xml support" }
+ pie_forced-0 { set msg "nopie failed to prevent PIE executable" }
+ nopie_forced-0 { set msg "pie failed to generate PIE executable" }
default { set msg "$fn != $val" }
}
next prev parent reply other threads:[~2021-10-07 11:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-29 13:55 [committed][gdb/testsuite] Disable vgdb tests if xml not supported Tom de Vries
2021-09-30 17:30 ` Tom Tromey
2021-09-30 21:41 ` Tom de Vries
2021-09-30 21:47 ` Tom de Vries
2021-10-05 18:15 ` Tom Tromey
2021-10-06 7:40 ` [PATCH][gdb/testsuite] Add proc require in lib/gdb.exp Tom de Vries
2021-10-07 11:00 ` Tom de Vries [this message]
2021-10-08 14:37 ` [PATCH][gdb/testsuite] Prevent compilation fails with unix/-fPIE/-pie Tom de Vries
2021-10-11 10:28 ` [PATCH][gdb/testsuite] Add proc require in lib/gdb.exp Tom de Vries
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6339c676-579f-f841-f6ba-d3026d1a45ad@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).