[gcc r16-9448] testsuite: Make function body scans more flexible to ABI and asm syntax.
Iain D Sandoe via Gcc-cvs <[email protected]> Wed, 29 Jul 2026 21:47:50 +0000 (GMT)
| Newsgroups | gmane.comp.gcc.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://gcc.gnu.org/g:ef8247abb4eee11dba6f26b17114538a6061d2b3 commit r16-9448-gef8247abb4eee11dba6f26b17114538a6061d2b3 Author: Iain Sandoe <[email protected]> Date: Mon May 4 23:24:45 2026 +0100 testsuite: Make function body scans more flexible to ABI and asm syntax. This introduces threee customisation points into the function body scans code. This allows targets to consume regexes that are written for ABIs and asm syntax that is reasonably compatibile with that used by the target. The initial use-case here is to map from regexes specified in terms of ELF syntax and Linux ABIs, but to be consumed by Darwin ABI and mach-o binary format. gcc/testsuite/ChangeLog: * lib/scanasm.exp (target_regex_skip_line, target_regex_verbatim_line, target_substitute_func_regex): New. (check-function-bodies): use the customisation points. (configure_check-function-bodies): Populate the new customisation points for Darwin/Mach-O. * lib/target-supports.exp (add_options_for_check_function_bodies): Add Darwin criteria. Signed-off-by: Iain Sandoe <[email protected]> (cherry picked from commit 4144209d54e882dd565a229fc5593cc59d1db623) Diff: --- gcc/testsuite/lib/scanasm.exp | 111 ++++++++++++++++++++++++++++++---- gcc/testsuite/lib/target-supports.exp | 4 ++ 2 files changed, 102 insertions(+), 13 deletions(-) diff --git a/gcc/testsuite/lib/scanasm.exp b/gcc/testsuite/lib/scanasm.exp index 2fe942e404c9..a14dd9b97bfb 100644 --- a/gcc/testsuite/lib/scanasm.exp +++ b/gcc/testsuite/lib/scanasm.exp @@ -4,12 +4,12 @@ # 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 GCC; see the file COPYING3. If not see # <http://www.gnu.org/licenses/>. @@ -151,7 +151,7 @@ proc scan-assembler-not { args } { set_required_options_for scan-assembler-not -# Return the scan for the assembly for hidden visibility. +# Return the scan for the assembly for hidden visibility. proc hidden-scan-for { symbol } { @@ -576,7 +576,7 @@ proc scan-assembler-times { args } { set_required_options_for scan-assembler-times -# Call pass if pattern is present within a lower or upper bound, +# Call pass if pattern is present within a lower or upper bound, # otherwise fail. # ex /* { dg-final { scan-assembler-bound {RE} > 3 } } proc scan-assembler-bound { args } { @@ -623,7 +623,7 @@ proc scan-assembler-bound { args } { error "scan-assembler-bound: illegal argument: $bound" return } - + set fd [open $output_file r] set text [read $fd] close $fd @@ -934,7 +934,7 @@ proc configure_check-function-bodies { config } { } elseif { [istarget *-*-darwin*] } { set up_config(start) { {^_([a-zA-Z_]\S*):$} - {^LFB[0-9]+:} + {^LFS?B[0-9]+:$} } } else { set up_config(start) {{^([a-zA-Z_]\S*):$}} @@ -944,7 +944,7 @@ proc configure_check-function-bodies { config } { if { [istarget nvptx*-*-*] } { set up_config(end) {^\}$} } elseif { [istarget *-*-darwin*] } { - set up_config(end) {^LFE[0-9]+} + set up_config(end) {^LFE[0-9]+:$} } elseif { [istarget aarch64*-*-mingw32] } { set up_config(end) {seh_endproc} } else { @@ -957,7 +957,7 @@ proc configure_check-function-bodies { config } { # example). set up_config(fluff) {^\s*(?://)} } elseif { [istarget *-*-darwin*] } { - set up_config(fluff) {^\s*(?:\.|//|@)|^L[0-9ABCESV]} + set up_config(fluff) {^\s*(?:\.|//|@|#)|^L[ABCESV]} } elseif { [istarget s390*-*-*] } { # Additionally to the defaults skip lines beginning with a # resulting # from inline asm. @@ -980,6 +980,86 @@ proc configure_check-function-bodies { config } { } else { set up_config(line_prefix) {\t} } + + # Set up regex lines that should be skipped for a given object format + set up_config(skip_regex_cases) "" + if { [istarget *-*-darwin*] } { + # Darwin already matches .LF* as part of start/end. + # Currently, .cfi_xxx instructions are not used. + set up_config(skip_regex_cases) { + {^\\?\.LF.*$} + {^.*\.cfi_.*$} + } + } + + # Set up regex lines that should be copied verbatim for a given object + # format + if { [istarget *-*-darwin*] } { + # Lines starting with a label, for Darwin we accept ELF local labels + # (starting with .L) and Mach-O (starting with L). We also accept + # numeric assembler labels. + set up_config(verbatim_regex_cases) { + {^\\?\.?L\[?[0-9].*:$} + {^[0-9]+:.*$} + } + } else { + # Lines starting with a local code label ".L" (which are usually the + # only entries on a line - or numeric assembler labels, which are + # often followed by some instruction. + set up_config(verbatim_regex_cases) { + {^\\?\.L} + {^[0-9]+:.*$} + } + } + + set up_config(regex_substitutions) "" + if { [istarget *-*-darwin*] } { + # Setup substitution pairs for body regexes + # the first entry is what should be matched, the second is what should + # replace it. + set up_config(regex_substitutions) { + { {\\?\.LC} {[lL]C} } + { {\\?\.L} "L" } + } + } + +} + +# Sometimes the function match regex might include directives that are not +# used by a given binary format. Allow these to be skipped. +proc target_regex_skip_line { config line } { + upvar $config up_config + foreach check $up_config(skip_regex_cases) { + if { [regexp $check $line] } { + return 1 + } + } + return 0 +} + +# Some regex lines (mostly ones starting with a label) should be copied +# verbatim (i.e. without prepending config(line_prefix)). + +proc target_regex_verbatim_line { config line } { + upvar $config up_config + foreach check $up_config(verbatim_regex_cases) { + if { [regexp $check $line] } { + return 1 + } + } + return 0 +} + +# Apply global substitutions to the function body regex as needed by the +# target ABI / assembler syntax. + +proc target_substitute_func_regex { config func_regex } { + upvar $config up_config + upvar $func_regex up_func_regex + foreach subs $up_config(regex_substitutions) { + regsub -all [lindex $subs 0] $up_func_regex [lindex $subs 1] up_func_regex + incr item + } } # Per CONFIG, read assembly file FILENAME and store a mapping from function @@ -1015,7 +1095,7 @@ proc parse_function_bodies { config filename result } { set function_name $maybe_function_name set in_function 1 } elseif { [regexp $up_config(end) $line] } { - verbose "parse_function_bodies: $function_name:\n$function_body" + verbose "parse_function_bodies: found end marker for $function_name:\n$function_body" set up_result($function_name) $function_body set in_function 0 } elseif { $up_config(matched) ne "" \ @@ -1201,14 +1281,19 @@ proc check-function-bodies { args } { append function_regexp ")" } elseif { [string equal $line "..."] } { append function_regexp ".*" - } elseif { [regexp {^\.L} $line] } { - append function_regexp $line "\n" - } elseif { [regexp {^[0-9]+:} $line] } { - append function_regexp $line "\n" + } elseif { [target_regex_skip_line config $line] } { + # Drop this line. + continue + } elseif { [target_regex_verbatim_line config $line] } { + # Copy this through. + append function_regexp $line "\n" } else { + # Copy but with a prefix (typically \t). append function_regexp $config(line_prefix) $line "\n" } } elseif { [string equal -length $terminator_len $line $terminator] } { + # Do any global substitutions the target ABI/asm syntax needs. + target_substitute_func_regex config function_regexp if { ![string equal $selector "N"] } { if { $xfail_all || [string equal $selector "F"] } { setup_xfail "*-*-*" diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index fa2319c44695..72ad67bc996b 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -996,6 +996,10 @@ proc add_options_for_check_function_bodies { flags } { # off on Solaris/x86 with as and ld. Similarly it also expects # the .LFB/.LFE labels, which aren't emitted for 32-bit. return "-fdwarf2-cfi-asm -fasynchronous-unwind-tables $flags " + } elseif { [istarget *-*-darwin*] } { + # Darwin does not currently use .cfi_ instructions and also requires + # unwind tables to be forced on for 32bit. + return "-fno-dwarf2-cfi-asm -fasynchronous-unwind-tables $flags " } return $flags }