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.
=== 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'.
}
# 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]
# 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
}
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"
}
# 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
# 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
# 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.
$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
}
}
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
}
if {$sid eq "f_lto"} {
cleanup-modules ""
}
+
+ set compile_type $sav_compile_type
+ set obj_list $sav_obj_list
}
}