From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id A55643858C41 for ; Thu, 26 Oct 2023 19:49:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A55643858C41 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A55643858C41 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698349757; cv=none; b=mP+N8+rqASxHBUszXHiFY0bvmgetMoRRWlqPqZgKrtbrMnLrmVGLKLwV/fig0MV6rIiP5IFgg4kYaRpQ48kMHMXxGqEt5VSC+XRbxPQK+obzeGYyR2ERqtpOHN1uB5+v9z14ktmpsjV7znX6ux261sOHdQVyWrbm1vCZvGMsKkU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698349757; c=relaxed/simple; bh=+GransARfOb3GNZace4vgan21y//cAP3AJx/nluDVtw=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=A1VdbSPTtxLK/N5zVmIyBOCTE11Z81ZwTamsq4dr0PQKwPJHbTNRnQtcZ7Qod4nkyX/8YA5JK9FQi1xFEEoTqwj510N5Ghi/91HSBZkczIlAfTKJl6OS+Itp4809XmxW32Ykf2gFCOA3DZy62Sl+YIrEdjjC+G58Y4cWc3WA8eo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F1E171424; Thu, 26 Oct 2023 12:49:56 -0700 (PDT) Received: from localhost (e121540-lin.manchester.arm.com [10.32.110.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B59823F738; Thu, 26 Oct 2023 12:49:14 -0700 (PDT) From: Richard Sandiford To: Iain Sandoe Mail-Followup-To: Iain Sandoe ,gcc-patches@gcc.gnu.org, iain@sandoe.co.uk, thomas@codesourcery.com, richard.sandiford@arm.com Cc: gcc-patches@gcc.gnu.org, iain@sandoe.co.uk, thomas@codesourcery.com Subject: Re: [PATCH] testsuite, Darwin: Add support for Mach-O function body scans. References: <20231026192301.58329-1-iain@sandoe.co.uk> Date: Thu, 26 Oct 2023 20:49:13 +0100 In-Reply-To: <20231026192301.58329-1-iain@sandoe.co.uk> (Iain Sandoe's message of "Thu, 26 Oct 2023 20:23:01 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-23.5 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Iain Sandoe writes: > This was written before Thomas' modification to the ELF-handling to allow > a config-based change for target details. I did consider updating this > to try and use that scheme, but I think that it would sit a little > awkwardly, since there are some differences in the start-up scanning for > Mach-O. I would say that in all probability we could improve things but > I'd like to put this forward as a well-tested initial implementation. Sorry, I would prefer to extend the existing function instead. E.g. there's already some divergence between the Mach-O version and the default version, in that the Mach-O version doesn't print verbose messages. I also don't think that the current default code is so watertight that it'll never need to be updated in future. Some questions/suggestions below. > It has been in use for more than 2 years on the aarch64 Darwin devt. > branch. Tested also in configurations on x86_64-linux and > aarch64-linux. Obviously, this is not aarch64-specific but that is > out initial use-case. OK for trunk? > thanks > Iain > > --- 8< --- > > We need to process the source slightly differently from ELF, especially > in that we have __USER_LABEL_PREFIX__ and there are no function start > and end assembler directives. This means we cannot delineate functions > when frame output is switched off. > > TODO: consider adding -mtest-markers or something similar to inject > assembler comments that can be scanned for. > > gcc/testsuite/ChangeLog: > > * lib/scanasm.exp: Initial handling for Mach-O function body scans. > > Signed-off-by: Iain Sandoe > --- > gcc/testsuite/lib/scanasm.exp | 55 ++++++++++++++++++++++++++++++++++- > 1 file changed, 54 insertions(+), 1 deletion(-) > > diff --git a/gcc/testsuite/lib/scanasm.exp b/gcc/testsuite/lib/scanasm.exp > index 5df80325dff..fab4b0669ec 100644 > --- a/gcc/testsuite/lib/scanasm.exp > +++ b/gcc/testsuite/lib/scanasm.exp > @@ -851,6 +851,44 @@ proc parse_function_bodies { config filename result } { > close $fd > } > > +proc parse_MACHO_function_bodies { filename result } { > + upvar $result up_result > + > + # Regexp for the start of a function definition (name in \1). > + set label {^(_[a-zA-Z_]\S+):$} > + set start {^LFB[0-9]+} Do you need to single out the start label like this? Couldn't we just skip LFB labels, by extending the fluff regexp? > + > + # Regexp for the end of a function definition. > + set terminator {^LFE[0-9]+} > + > + # Regexp for lines that aren't interesting. > + set fluff {^\s*(?:\.|//|@)} > + set fluff3 {^L[0-9ACESV]} Is there any need for two regexps here? It looks like we could combine them as: {^\s*(?:\.|//|@)|^L[0-9ACESV]} Or, with the above suggestion too: {^\s*(?:\.|//|@)|^L[0-9ACESV]|^LFB[0-9]} If that works, it seems to fit within the existing config scheme. Thanks, Richard > + > + set fd [open $filename r] > + set in_function 0 > + while { [gets $fd line] >= 0 } { > + if { !$in_function && [regexp $label $line dummy function_name] } { > + set in_function 1 > + set function_body "" > + } elseif { $in_function == 1 } { > + if { [regexp $start $line] } { > + set in_function 2 > + } else { > + set in_function 0 > + } > + } elseif { $in_function == 2 } { > + if { [regexp $terminator $line] } { > + set up_result($function_name) $function_body > + set in_function 0 > + } elseif { ![regexp $fluff $line] && ![regexp $fluff3 $line] } { > + append function_body $line "\n" > + } > + } > + } > + close $fd > +} > + > # FUNCTIONS is an array that maps function names to function bodies. > # Return true if it contains a definition of function NAME and if > # that definition matches BODY_REGEXP. > @@ -883,6 +921,14 @@ proc check-function-bodies { args } { > error "too many arguments to check-function-bodies" > } > > + set isELF 1 > + # some targets have a __USER_LABEL_PREFIX__ > + set needsULP 0 > + if { [istarget *-*-darwin*] } { > + set isELF 0 > + set needsULP 1 > + } > + > if { [llength $args] >= 3 } { > set required_flags [lindex $args 2] > > @@ -944,7 +990,11 @@ proc check-function-bodies { args } { > remote_upload host "$filename" > } > if { [file exists $output_filename] } { > - parse_function_bodies config $output_filename functions > + if { $isELF } { > + parse_function_bodies config $output_filename functions > + } else { > + parse_MACHO_function_bodies $output_filename functions > + } > set have_bodies 1 > } else { > verbose -log "$testcase: output file does not exist" > @@ -988,6 +1038,9 @@ proc check-function-bodies { args } { > if { $xfail_all || [string equal $selector "F"] } { > setup_xfail "*-*-*" > } > + if { $needsULP } { > + set function_name "_$function_name" > + } > set testname "$testcase check-function-bodies $function_name" > if { !$have_bodies } { > unresolved $testname