]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
testsuite, darwin: Handle Darwin LTO section names.
authorIain Sandoe <iain@sandoe.co.uk>
Sun, 5 May 2024 23:01:36 +0000 (00:01 +0100)
committerIain Sandoe <iain@sandoe.co.uk>
Sat, 20 Jun 2026 16:12:24 +0000 (17:12 +0100)
This recognises the .section __GNU_LTO, segment prefix used by Darwin
to skip LTO sections there and splits this into a separate function
since it is used several times.

PR testsuite/112728

gcc/testsuite/ChangeLog:

* lib/scanasm.exp (remove_lto_sections): New.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
gcc/testsuite/lib/scanasm.exp

index 422d874ca4ce495c363cd5c0d0f8e2b9d5117b8d..897ce76eae5451caf5d24e1c6f436be324abc017 100644 (file)
@@ -37,6 +37,21 @@ proc append_encoding_arg { args enc } {
     return $args
 }
 
+# Remove LTO-prefixed sections from TEXT.
+
+proc remove_lto_sections { text } {
+    set p1 {(^|\n)[[:space:]]*\.section[[:space:]]*"?}
+    set lto_sect_prefix {\.gnu\.lto_}
+    set p3 {(?:[^\n]*\n(?![[:space:]]*\.(section|text|data|bss)))*[^\n]*\n}
+    if { [istarget *-*-darwin*] } {
+        # Darwin/Mach-O LTO sections are in the __GNU_LTO segment.
+        set lto_sect_prefix {__GNU_LTO}
+    }
+    set patt ${p1}${lto_sect_prefix}${p3}
+    regsub -all ${patt} $text {\1} text
+    return $text
+}
+
 # Scan the OUTPUT_FILE for a pattern.  If it is present and POSITIVE
 # is non-zero, or it is not present and POSITIVE is zero, the test
 # passes.  The ORIG_ARGS is the list of arguments provided by dg-final
@@ -80,10 +95,8 @@ proc dg-scan { name positive testcase output_file orig_args } {
     set text [read $fd]
     close $fd
     if { [string compare -length 14 $name scan-assembler] == 0 } {
-      # Remove LTO sections.
-      # ??? Somehow, .*? is still greedy.
-      # regsub -all {(^|\n)[[:space:]]*\.section[[:space:]]*"?\.gnu\.lto_.*?\n(?=[[:space:]]*\.text\n)} $text {\1} text
-      regsub -all {(^|\n)[[:space:]]*\.section[[:space:]]*"?\.gnu\.lto_(?:[^\n]*\n(?![[:space:]]*\.(section|text|data|bss)))*[^\n]*\n} $text {\1} text
+        # Remove LTO sections.
+        set text [remove_lto_sections $text]
     }
 
     set match [regexp -- $pattern $text]
@@ -550,8 +563,8 @@ proc scan-assembler-times { args } {
     set fd [open $output_file r]
     set text [read $fd]
     close $fd
-    regsub -all {(^|\n)[[:space:]]*\.section[[:space:]]*"?\.gnu\.lto_(?:[^\n]*\n(?![[:space:]]*\.(section|text|data|bss)))*[^\n]*\n} $text {\1} text
-
+    # Remove LTO sections.
+    set text [remove_lto_sections $text]
     set result_count [regexp -all -- $pattern $text]
     if {$result_count == $times} {
        pass "$testcase scan-assembler-times $pp_pattern $times"
@@ -614,7 +627,7 @@ proc scan-assembler-bound { args } {
     set fd [open $output_file r]
     set text [read $fd]
     close $fd
-    regsub -all {(^|\n)[[:space:]]*\.section[[:space:]]*"?\.gnu\.lto_(?:[^\n]*\n(?![[:space:]]*\.(section|text|data|bss)))*[^\n]*\n} $text {\1} text
+    set text [remove_lto_sections $text]
 
     set result_count [regexp -all -- $pattern $text]
     if [expr $result_count $cmp $bound] {
@@ -676,7 +689,7 @@ proc scan-assembler-dem { args } {
 
     set output [remote_exec host "$cxxfilt" "" "$output_file"]
     set text [lindex $output 1]
-    regsub -all {(^|\n)[[:space:]]*\.section[[:space:]]*"?\.gnu\.lto_(?:[^\n]*\n(?![[:space:]]*\.(section|text|data|bss)))*[^\n]*\n} $text {\1} text
+    set text [remove_lto_sections $text]
 
     if [regexp -- $pattern $text] {
        pass "$testcase scan-assembler-dem $pp_pattern"
@@ -733,7 +746,7 @@ proc scan-assembler-dem-not { args } {
 
     set output [remote_exec host "$cxxfilt" "" "$output_file"]
     set text [lindex $output 1]
-    regsub -all {(^|\n)[[:space:]]*\.section[[:space:]]*"?\.gnu\.lto_(?:[^\n]*\n(?![[:space:]]*\.(section|text|data|bss)))*[^\n]*\n} $text {\1} text
+    set text [remove_lto_sections $text]
 
     if ![regexp -- $pattern $text] {
        pass "$testcase scan-assembler-dem-not $pp_pattern"