This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH v2] Testsuite: Ensure stack protection is off for GCC
- From: Pedro Alves <palves at redhat dot com>
- To: Alan Hayward <Alan dot Hayward at arm dot com>, "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>
- Cc: nd <nd at arm dot com>
- Date: Fri, 18 Jan 2019 19:44:14 +0000
- Subject: Re: [PATCH v2] Testsuite: Ensure stack protection is off for GCC
- References: <20190118172550.65430-1-alan.hayward@arm.com>
On 01/18/2019 05:25 PM, Alan Hayward wrote:
> Using -fstack-protector-strong will cause GDB to break on the wrong line
> when placing a breakpoint on a function. This is due to inadequate dwarf
> line numbering, and is being tracked by the GCC bug
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88432
>
> GCC (and Clang) provided by Debian/Ubuntu default to stack protector
> being enabled.
>
> Ensure that when running the GDB testsuite, stack protector is always
> turned off for GCC 4.1.0 (when stack protector was added) and above.
>
> Ensure that this does not cause infinite recursion due to
> test_compiler_info having to compile a file itself.
>
> Add a test to explicitly test breakpoints with various levels of stack
> protection on both GCC and Clang, with xfail for the known errors.
>
> Restore change in ovldbreak.exp which worked around the issue.
Thanks!
This is OK, with the nits below fixed.
>
> gdb/testsuite/ChangeLog:
>
> 2019-01-18 Alan Hayward <alan.hayward@arm.com>
>
> * gdb.base/stack-protector.c: New test.
> * gdb.base/stack-protector.exp: New file.
> * gdb.cp/ovldbreak.exp: Only allow a single break line.
> * lib/gdb.exp (get_compiler_info): Use getting_compiler_info option.
> (gdb_compile): Remove stack protector for GCC and prevent recursion.
Tabs vs spaces above.
>
> diff --git a/gdb/testsuite/gdb.base/stack-protector.c b/gdb/testsuite/gdb.base/stack-protector.c
> new file mode 100644
> index 0000000000..5e048859a7
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/stack-protector.c
> @@ -0,0 +1,27 @@
> +/* This test program is part of GDB, the GNU debugger.
> +
> + Copyright 2019 Free Software Foundation, Inc.
> +
> + This program is free software; you can redistribute it and/or modify
> + it under the terms of the GNU General Public License as published by
> + the Free Software Foundation; either version 3 of the License, or
> + (at your option) any later version.
> +
> + This program is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + GNU General Public License for more details.
> +
> + You should have received a copy of the GNU General Public License
> + along with this program. If not, see <http://www.gnu.org/licenses/>. */
> +
> +int foo (int a)
Linux break before "foo".
> +{
> + return a + 7; /* break here. */
> +}
> +
> +int
> +main ()
> +{
> + return foo (5);
> +}
> @@ -3549,11 +3550,26 @@ proc gdb_compile {source dest type options} {
> }
> } elseif { $opt == "shlib_load" && $type == "executable" } {
> set shlib_load 1
> + } elseif { $opt == "getting_compiler_info" } {
> + # If this is set, calling test_compiler_info will cause recursion.
> + set getting_compiler_info 1
> } else {
> lappend new_options $opt
> }
> }
>
> + # Ensure stack protector is disabled for GCC, as this will causes problems
s/as this will causes/as this causes/
> + # with DWARF line numbering.
> + # See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88432
> + # This option defaults to on for Debian/Ubuntu.
> + if { $getting_compiler_info == 0
> + && [test_compiler_info {gcc-*-*}]
> + && !([test_compiler_info {gcc-[0-3]-*}]
> + || [test_compiler_info {gcc-4-0-*}]) } {
> + # Put it at the front to not override any user-provided value
Missing period.
> + lappend new_options "early_flags=-fno-stack-protector"
> + }
> +
> # Because we link with libraries using their basename, we may need
> # (depending on the platform) to set a special rpath value, to allow
> # the executable to find the libraries it depends on.
>
Thanks,
Pedro Alves