From: Alan Hayward <Alan.Hayward@arm.com>
To: Tom de Vries <tdevries@suse.de>
Cc: "gdb-patches\\@sourceware.org" <gdb-patches@sourceware.org>,
nd <nd@arm.com>
Subject: Re: [PATCH][gdb/testsuite] Fail in gdb_compile if nopie results in PIE executable
Date: Mon, 29 Jul 2019 09:57:00 -0000 [thread overview]
Message-ID: <A2400412-6B41-41FF-A70B-75AD0A269BE9@arm.com> (raw)
In-Reply-To: <20190723072210.GA24180@delia>
> On 23 Jul 2019, at 08:22, Tom de Vries <tdevries@suse.de> wrote:
>
> Hi,
>
> 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.
>
> OK for trunk?
LGTM (but I’m not a global maintainer).
I tried this on an Ubuntu18.04 (which defaults gcc to use PIE), and everything
looks fine.
>
> Thanks,
> - Tom
>
> [gdb/testsuite] Fail in gdb_compile if nopie results in PIE executable
>
> 2019-07-23 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/lib/gdb.exp | 18 ++++++++++++++++++
> 1 file changed, 18 insertions(+)
>
> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
> index 49ec8b2a55..5ec0912325 100644
> --- a/gdb/testsuite/lib/gdb.exp
> +++ b/gdb/testsuite/lib/gdb.exp
> @@ -3760,6 +3760,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"
> + }
> + }
> +
As a side point, I just spotted that if a script specifies both pie and nopie, then
I think it ends up as nopie because the nopie flag gets set second.
Maybe it should error if both options are sent to gdb_compile.
Not something that needs fixing with this patch though.
> if {[lsearch $options quiet] < 0} {
> # We shall update this on a per language basis, to avoid
> # changing the entire testsuite in one go.
> @@ -5160,6 +5166,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.
next prev parent reply other threads:[~2019-07-29 9:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-23 7:22 Tom de Vries
2019-07-29 9:57 ` Alan Hayward [this message]
2019-07-30 1:20 ` Simon Marchi
2019-08-05 10:57 ` [committed][gdb/testsuite] Fail in gdb_compile if pie results in non-PIE executable Tom de Vries
2019-08-16 18:49 ` [PATCH][gdb/testsuite] Fail in gdb_compile if nopie results in PIE executable Pedro Alves
2019-08-17 7:09 ` 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=A2400412-6B41-41FF-A70B-75AD0A269BE9@arm.com \
--to=alan.hayward@arm.com \
--cc=gdb-patches@sourceware.org \
--cc=nd@arm.com \
--cc=tdevries@suse.de \
/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