> On 7 Jun 2026, at 10:33, Richard Sandiford <[email protected]> wrote:
> 
> Iain Sandoe <[email protected]> writes:
>> 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]>
>> ---
>> gcc/testsuite/lib/scanasm.exp         | 107 ++++++++++++++++++++++++--
>> gcc/testsuite/lib/target-supports.exp |   4 +
>> 2 files changed, 103 insertions(+), 8 deletions(-)
>> 
>> diff --git a/gcc/testsuite/lib/scanasm.exp b/gcc/testsuite/lib/scanasm.exp
>> index 08dbf1a8118..9e7a5896475 100644
>> --- a/gcc/testsuite/lib/scanasm.exp
>> +++ b/gcc/testsuite/lib/scanasm.exp
>> @@ -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,92 @@ 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]+:.*$}
> 
> The comment led me to expect :$ for the .L case.  Is not having the
> : deliberate?  .*$ might as well be dropped, as in the original regexp.

I was not 100% confident that there might not be code like
L123:   instruction
I don’t  think the compiler will produce that, but hand-generated might

— I reveted to the original match.

> This is admittedly partly pre-existing, but: here and in the
> substitutions below, I think it'd be worth allowing an optional "\"
> before the ".", to handle cases where the check-function-bodies regexp
> itself escapes the ".".  I suppose that would make it:
> 
>   (?:\\)?\.

These are just in match clauses .. so I think that expecting an optional \ is 
enough  i.e. \\?
> 
> (untested).
> 
>> + }
>> +    }
>> +
>> +    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
>> +    set item 0
>> +    while { $item < [llength $up_config(skip_regex_cases)] } {
>> +        if { [regexp [lindex $up_config(skip_regex_cases) $item] $line] } {
>> +            return 1
>> +        }
>> +        incr item
>> +    }
>> +    return 0
> 
> This loop would be simpler with foreach.  Same for the functions below.

done.

> 
> LGTM otherwise.

Thanks, committed with those changes, and a re-test on x86_64/aarch64 linux,
as attached,

Iain

Attachment: 0001-testsuite-Make-function-body-scans-more-flexible-to-.patch
Description: Binary data

> 
> Thanks,
> Richard

Reply via email to