From: Alan Hayward <Alan.Hayward@arm.com>
To: Simon Marchi <simark@simark.ca>
Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>,
nd <nd@arm.com>
Subject: Re: [PATCH] Testsuite: Ensure pie is disabled on some tests
Date: Tue, 19 Mar 2019 15:45:00 -0000 [thread overview]
Message-ID: <260313A3-D685-4306-8DE1-080D51BAE0BE@arm.com> (raw)
In-Reply-To: <696945e9-4942-5285-0bb4-0bf899606f0a@simark.ca>
> On 19 Mar 2019, at 13:47, Simon Marchi <simark@simark.ca> wrote:
>
> On 2019-03-06 5:20 a.m., Alan Hayward wrote:
>> 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.
>> gdb/testsuite/ChangeLog:
>> 2019-03-06 Alan Hayward <alan.hayward@arm.com>
>> * gdb.base/break-interp.exp: Ensure pie is disabled.
>> * gdb.base/dump.exp: Likewise.
>
> Hi Alan,
>
> The "nopie" flag to gdb_compile has been introduced recently for this, could you use that instead? See commit 6e8b1ab2fd4c ("Fix various tests to use -no-pie linker flag when needed”).
Aha! That’s exactly what I needed.
In my mind, we should have a “pie” flag too. I’ll add this in too.
>
>> ---
>> gdb/testsuite/gdb.base/break-interp.exp | 4 ++++
>> gdb/testsuite/gdb.base/dump.exp | 4 ++++
>> 2 files changed, 8 insertions(+)
>> diff --git a/gdb/testsuite/gdb.base/break-interp.exp b/gdb/testsuite/gdb.base/break-interp.exp
>> index f85e8a650a..409c31e568 100644
>> --- a/gdb/testsuite/gdb.base/break-interp.exp
>> +++ b/gdb/testsuite/gdb.base/break-interp.exp
>> @@ -627,6 +627,10 @@ foreach ldprelink {NO YES} {
>> if {$binpie != "NO"} {
>> lappend opts {additional_flags=-fPIE}
>> lappend opts {ldflags=-pie}
>> + } else {
>> + # Recent Debian/Ubuntu defaults PIE enabled. Ensure it is disabled.
>> + lappend opts {additional_flags=-no-pie}
>> + lappend opts {ldflags=-no-pie}
>> }
>
> I believe it won't be necessary here to change CFLAGS (which additional_flags does), only ldflags, to make the final executable a non-PIE. Anyway, you'll probably end up using the "nopie" gdb_compile flag.
Agreed.
>
>> set dir ${exec}.d
>> diff --git a/gdb/testsuite/gdb.base/dump.exp b/gdb/testsuite/gdb.base/dump.exp
>> index 44b0988b80..b2d7ef938a 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"
>> }
>> +# Ensure -pie is disabled as this breaks IHEX tests.
>
> Can you just precise how it breaks the IHEX tests, as you did in the commit message (it causes the addresses to be out of range for that format)?
Done.
>
> This patch is ok with those fixed, thanks!
>
Updated. I would have pushed this new version - but - I’m a little unsure about adding the additional board flags.
Pie option adds both flag and ldflag versions to make sure it gets the cases where we’re just compiling to objects.
This version ok?
2019-03-19 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.
diff --git a/gdb/testsuite/README b/gdb/testsuite/README
index b5e75b9a79..25381cdf04 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,ldpie_flag
+
+ 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 f85e8a650a..8bb853c041 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 {
+ # Recent Debian/Ubuntu defaults 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 44b0988b80..56dcafd4cb 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"
}
+# Recent Debian/Ubuntu defaults 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 f13f909c34..259865f5fd 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -3461,6 +3461,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
@@ -3599,8 +3600,27 @@ 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 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 {
+ set flag "additional_flags=-fpie"
+ }
+ set options [lreplace $options $pie $pie $flag]
+
+ if [target_info exists gdb,ldpie_flag] {
+ set flag "ldflags=[target_info gdb,ldpie_flag]"
+ } else {
+ set flag "ldflags=-pie"
+ }
+ lappend options "$flag"
+ }
+
+ # Replace the "nopie" option with the appropriate flags to disable PIE
+ # executables.
set nopie [lsearch -exact $options nopie]
if {$nopie != -1} {
if [target_info exists gdb,nopie_flag] {
next prev parent reply other threads:[~2019-03-19 15:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-06 10:20 Alan Hayward
2019-03-19 10:45 ` [PING][PATCH] " Alan Hayward
2019-03-19 13:48 ` [PATCH] " Simon Marchi
2019-03-19 15:45 ` Alan Hayward [this message]
2019-03-19 16:07 ` Simon Marchi
2019-03-20 10:36 ` Alan Hayward
2019-03-19 16:36 ` Pedro Alves
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=260313A3-D685-4306-8DE1-080D51BAE0BE@arm.com \
--to=alan.hayward@arm.com \
--cc=gdb-patches@sourceware.org \
--cc=nd@arm.com \
--cc=simark@simark.ca \
/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