binutils-gdb/gdb/testsuite/gdb.base/step-indirect-call-thunk.exp
Tom de Vries 9d9dd861e9 [gdb/testsuite] Fix regression in step-indirect-call-thunk.exp with gcc 7
Since commit 43127ae571 ("Fix gdb.base/step-indirect-call-thunk.exp") I run
into:
...
gdb compile failed, gcc: error: unrecognized command line option \
  '-fcf-protection=none'; did you mean '-flto-partition=none'?
UNTESTED: gdb.base/step-indirect-call-thunk.exp: failed to prepare
...

The problem is that -fcf-protection is supported starting gcc 8, but I'm using
system gcc 7.5.0.

Fix this by only adding -fcf-protection=none for gcc 8 and later.

Tested on x86_64-linux, with gcc 7.5.0, 8.2.1 and 12.1.1.
2022-07-18 06:13:45 +02:00

84 lines
2.7 KiB
Plaintext

# Copyright 2018-2022 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/>.
standard_testfile
if { ![istarget "x86*"] } {
return
}
set cflags "-mindirect-branch=thunk -mfunction-return=thunk"
if { [gcc_major_version] >= 8 } {
append cflags " -fcf-protection=none"
}
if { [prepare_for_testing "failed to prepare" $testfile $srcfile \
[list debug "additional_flags=$cflags"]] } {
return -1
}
if { ![runto_main] } {
return -1
}
# Do repeated instruction steps in order to reach TARGET from CURRENT
#
# CURRENT is a string matching the current location
# TARGET is a string matching the target location
# TEST is the test name
#
# The function issues repeated "stepi" commands as long as the location
# matches CURRENT up to a maximum of 100 steps.
#
# TEST passes if the resulting location matches TARGET and fails
# otherwise.
#
proc stepi_until { current target test } {
global gdb_prompt
set count 0
gdb_test_multiple "stepi" "$test" {
-re "$current.*$gdb_prompt $" {
incr count
if { $count < 100 } {
send_gdb "stepi\n"
exp_continue
} else {
fail "$test"
}
}
-re "$target.*$gdb_prompt $" {
pass "$test"
}
}
}
# Normal stepping steps through all thunks.
gdb_test "step" "thrice\.2.*" "step into thrice"
gdb_test "next" "thrice\.3.*" "step through thunks and over inc"
gdb_test "step" "inc\.2.*" "step through call thunk into inc"
gdb_test "step" "inc\.3.*" "step inside inc"
gdb_test "step" "thrice\.4.*" "step through return thunk back into thrice"
set alphanum_re "\[a-zA-Z0-9\]"
set pic_thunk_re "__$alphanum_re*\\.get_pc_thunk\\.$alphanum_re* \\(\\)"
# We can use instruction stepping to step into thunks.
stepi_until "thrice" "indirect_thunk" "stepi into call thunk"
stepi_until "indirect_thunk" "inc." "stepi out of call thunk into inc"
stepi_until "(inc|$pic_thunk_re)" "return_thunk" "stepi into return thunk"
stepi_until "return_thunk" "thrice" \
"stepi out of return thunk back into thrice"