From: Lewis Hyatt Date: Sat, 11 Jul 2026 18:21:12 +0000 (-0400) Subject: testsuite: Add { dg-lto-do incr-link } option X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=230b58158e2bee20d02d4c94ecdbf87c4afd8c21;p=thirdparty%2Fgcc.git testsuite: Add { dg-lto-do incr-link } option 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. --- diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi index 6c0a3a4c74f..31265ddd28b 100644 --- a/gcc/doc/sourcebuild.texi +++ b/gcc/doc/sourcebuild.texi @@ -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. diff --git a/gcc/testsuite/gcc.dg/lto/README b/gcc/testsuite/gcc.dg/lto/README index 1ee8b00dee8..04c05a2ee1d 100644 --- a/gcc/testsuite/gcc.dg/lto/README +++ b/gcc/testsuite/gcc.dg/lto/README @@ -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'. diff --git a/gcc/testsuite/lib/lto.exp b/gcc/testsuite/lib/lto.exp index 2cff54b699d..7243547a52d 100644 --- a/gcc/testsuite/lib/lto.exp +++ b/gcc/testsuite/lib/lto.exp @@ -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 } }