]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
testsuite: Add { dg-lto-do incr-link } option
authorLewis Hyatt <lhyatt@gmail.com>
Sat, 11 Jul 2026 18:21:12 +0000 (14:21 -0400)
committerLewis Hyatt <lhyatt@gcc.gnu.org>
Fri, 17 Jul 2026 12:46:10 +0000 (08:46 -0400)
Similar to { dg-lto-do ar-link }, which allows testing the combination of
multiple LTO objects into an archive before linking, this new directive
allows testing the incremental linking modes of the LTO front end.

gcc/ChangeLog:

* doc/sourcebuild.texi: Document ar-link and incr-link options to
dg-lto-do directive.

gcc/testsuite/ChangeLog:

* gcc.dg/lto/README: Update to document ar-link and incr-link.
* lib/lto.exp: Support incr-link directive throughout.

gcc/doc/sourcebuild.texi
gcc/testsuite/gcc.dg/lto/README
gcc/testsuite/lib/lto.exp

index 6c0a3a4c74f93e07216f9807fd9da6de76e3a490..31265ddd28b3cc96c9ec79f8ac05c055539fa6dd 100644 (file)
@@ -4119,12 +4119,19 @@ it is executed.  It is one of:
 Compile with @option{-c} to produce a relocatable object file.
 @item link
 Compile, assemble, and link to produce an executable file.
+@item ar-link
+Similar to @code{link}, but combine all but the first source file into
+an archive file before the final link.
+@item incr-link
+As with @code{ar-link}, but combine the files into an object file
+using incremental linking, rather than an archive file.  This enables
+testing the incremental linking features of the LTO front end.
 @item run
 Produce and run an executable file, which is expected to return
 an exit code of 0.
 @end table
 
-The default is @code{assemble}.  That can be overridden for a set of
+The default is @code{run}.  That can be overridden for a set of
 tests by redefining @code{dg-do-what-default} within the @code{.exp}
 file for those tests.
 
index 1ee8b00dee8fd0d2cddc4600ecc60f560da2af1e..04c05a2ee1d0cf4381c066653a51e0a746d21c62 100644 (file)
@@ -44,12 +44,15 @@ where there is a single file named 'foo_0.C'.
 
 === The dg-lto-do Directive ==
 
-The only supported dg-lto-do options are 'assemble', 'run' and 'link'.
-Additionally, these can only be used in the main file.  If
-'assemble' is used, only the individual object files are
-generated.  If 'link' is used, the final executable is generated
-but not executed (in this case, function main() needs to exist
-but it does not need to do anything).  If 'run' is used, the
-final executable is generated and the resulting binary executed.
+The supported dg-lto-do options are 'assemble', 'run', 'link', 'ar-link',
+and 'incr-link'.  This option can only be used in the main file.  If
+'assemble' is used, only the individual object files are generated.  If
+'link' is used, the final executable is generated but not executed (in
+this case, function main() needs to exist but it does not need to do
+anything).  If 'run' is used, the final executable is generated and the
+resulting binary executed.  'ar-link' and 'incr-link' are similar to
+'link', except that the non-main object files are combined together before
+the final link, into either an archive, in the former case, or an object
+file via incremental linking, in the latter.
 
 The default value for dg-lto-do is 'run'.
index 2cff54b699d060dd58116ea43521f17fa5bd9df2..7243547a52d8c8eeaf25ecaf985e8c9d87233b03 100644 (file)
@@ -417,7 +417,9 @@ proc lto-link-and-maybe-run { testname objlist dest optall optfile optstr } {
     }
 
     # Check for diagnostics specified by directives
-    set comp_output [lto_handle_diagnostics $comp_output $optstr]
+    if { ! [string equal "incr-link" $optstr] } {
+       set comp_output [lto_handle_diagnostics $comp_output $optstr]
+    }
 
     # Prune unimportant visibility warnings before checking output.
     set comp_output [lto_prune_warns $comp_output]
@@ -432,7 +434,8 @@ proc lto-link-and-maybe-run { testname objlist dest optall optfile optstr } {
 
     # Return if we only needed to link.
     if { ![string compare "link" $compile_type] \
-        || ![string compare "ar-link" $compile_type] } {
+        || ![string compare "ar-link" $compile_type] \
+        || ![string compare "incr-link" $compile_type] } {
        return
     }
 
@@ -578,6 +581,8 @@ proc lto-get-options-main { src } {
                set compile_type "link"
            } elseif { ![string compare "ar-link" $dgdo] } {
                set compile_type "ar-link"
+           } elseif { ![string compare "incr-link" $dgdo] } {
+               set compile_type "incr-link"
            } else {
                warning "lto.exp does not support dg-lto-do $dgdo"
            }
@@ -772,8 +777,12 @@ proc lto-execute-1 { src1 sid } {
 
     # The test needs to build all but the main file into an archive and then
     # link them all together.
-    if { ![string compare "ar-link" $compile_type] } {
+    set is_incr_link [string equal "incr-link" $compile_type]
+    set is_ar_link [string equal "ar-link" $compile_type]
+    if { $is_ar_link } {
         set arname "${sid}_${base}.a"
+    } elseif { $is_incr_link } {
+        set arname "${sid}_${base}.o"
     }
 
     # Remove the $srcdir and $tmpdir prefixes from $src1.  (It would
@@ -842,13 +851,20 @@ proc lto-execute-1 { src1 sid } {
 
        # Bundle all but the main file into an archive. Update objlist to only
        # have the archive and the last file.
-       if { ![string compare "ar-link" $compile_type] } {
+       # Only attempt the incr-link mode if the linker plugin is explicitly in use.
+       set sav_compile_type $compile_type
+       set sav_obj_list $obj_list
+       if { $is_incr_link && [lsearch -exact $option "-fuse-linker-plugin"] < 0 } {
+           set compile_type "link"
+       } elseif { $is_incr_link || $is_ar_link } {
            set mainsrc [lindex $obj_list 0]
            set obj_list [lrange $obj_list 1 end]
-           lto-build-archive \
-               "[lindex $obj_list 1]-[lindex $obj_list end]" \
-               $obj_list $arname
-
+           set testname "[lindex $obj_list 1]-[lindex $obj_list end]"
+           if { $is_incr_link } {
+               lto-link-and-maybe-run $testname $obj_list $arname "-r" "" "incr-link"
+           } else {
+               lto-build-archive $testname $obj_list $arname
+           }
            set obj_list ""
            lappend obj_list $mainsrc
            lappend obj_list $arname
@@ -857,7 +873,7 @@ proc lto-execute-1 { src1 sid } {
 
        # Link (using the compiler under test), run, and clean up tests.
        if { ![string compare "run" $compile_type] \
-            || ![string compare "ar-link" $compile_type] \
+            || $is_ar_link || $is_incr_link \
             || ![string compare "link" $compile_type] } {
 
            # Filter out any link options we were asked to suppress.
@@ -874,7 +890,7 @@ proc lto-execute-1 { src1 sid } {
                $obj_list $execname $filtered "${additional-flags} ${dg-extra-ld-options}" \
                    $filtered
 
-           if (![string compare "ar-link" $compile_type]) {
+           if { $is_ar_link || $is_incr_link } {
                file_on_host delete $arname
              }
        }
@@ -923,7 +939,7 @@ proc lto-execute-1 { src1 sid } {
        unset testname_with_flags
        
        if { ![string compare "run" $compile_type] \
-            || ![string compare "ar-link" $compile_type] \
+            || $is_ar_link || $is_incr_link \
             || ![string compare "link" $compile_type] } {
            file_on_host delete $execname
        }
@@ -931,6 +947,9 @@ proc lto-execute-1 { src1 sid } {
        if {$sid eq "f_lto"} {
            cleanup-modules ""
        }
+
+       set compile_type $sav_compile_type
+       set obj_list $sav_obj_list
     }
 }