public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] testsuite, Darwin: Add support for Mach-O function body scans.
@ 2023-10-26 19:23 Iain Sandoe
  2023-10-26 19:49 ` Richard Sandiford
  0 siblings, 1 reply; 11+ messages in thread
From: Iain Sandoe @ 2023-10-26 19:23 UTC (permalink / raw)
  To: gcc-patches; +Cc: richard.sandiford, thomas

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.

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 <iain@sandoe.co.uk>
---
 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]+}
+
+    # 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]}
+
+    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
-- 
2.39.2 (Apple Git-143)


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2023-11-23  9:22 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-26 19:23 [PATCH] testsuite, Darwin: Add support for Mach-O function body scans Iain Sandoe
2023-10-26 19:49 ` Richard Sandiford
2023-10-26 20:00   ` Iain Sandoe
2023-10-27 11:00     ` Iain Sandoe
2023-10-27 22:44       ` Andrew Pinski
2023-11-05 22:11       ` Richard Sandiford
2023-11-06  7:59         ` Iain Sandoe
2023-11-06 10:57           ` Richard Sandiford
2023-11-23  9:02             ` Christophe Lyon
2023-11-23  9:09               ` Iain Sandoe
2023-11-23  9:22                 ` Christophe Lyon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).