]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
testsuite: Make function body scans more flexible to ABI and asm syntax.
authorIain Sandoe <iain@sandoe.co.uk>
Mon, 4 May 2026 22:24:45 +0000 (23:24 +0100)
committerIain Sandoe <iain@sandoe.co.uk>
Wed, 10 Jun 2026 18:44:41 +0000 (19:44 +0100)
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 <iain@sandoe.co.uk>
gcc/testsuite/lib/scanasm.exp
gcc/testsuite/lib/target-supports.exp

index 08dbf1a8118dc0e5690529b14ac2bf8008b3b51b..422d874ca4ce495c363cd5c0d0f8e2b9d5117b8d 100644 (file)
@@ -921,7 +921,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*):$}}
@@ -931,7 +931,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 *-*-mingw32] } {
        set up_config(end) {seh_endproc}
     } else {
@@ -944,7 +944,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.
@@ -967,6 +967,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
@@ -1002,7 +1082,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 "" \
@@ -1188,14 +1268,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 "*-*-*"
index 009f22f9b30b92e8bb042625dfd25135b1228682..dcfa5923c8b2fc58d0cae34ca9a610321281fdb1 100644 (file)
@@ -982,6 +982,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
 }