https://gcc.gnu.org/g:13ecbd80dbfce33f443950c593c9c6be0766f410
commit r17-4976-g13ecbd80dbfce33f443950c593c9c6be0766f410 Author: Torbjörn SVENSSON <[email protected]> Date: Tue Oct 6 16:26:46 2026 +0200 testsuite: Isolate incremental LTO links from board link settings Use -nostdlib and temporarily clear board ldflags and libs for incremental LTO links, then restore the board settings. This was discovered while testing newlib built without --disable-newlib-supplied-syscalls. In this case, the libc.a contains semihosting function that, due to ldflags for the board definition, will be pulled in, that contain non-LTO object files. This was discovered while testing newlib built without --disable-newlib-supplied-syscalls. In this configuration, the board’s linker flags pull in a semihosting function from libc.a, and that function is compiled into a non-LTO object file. gcc/testsuite/ChangeLog: * lib/lto.exp (lto-link-and-maybe-run): Disable board provided ldflags during incremental link. Signed-off-by: Torbjörn SVENSSON <[email protected]> Diff: --- gcc/testsuite/lib/lto.exp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/gcc/testsuite/lib/lto.exp b/gcc/testsuite/lib/lto.exp index a6532e220760..e23a90a8637b 100644 --- a/gcc/testsuite/lib/lto.exp +++ b/gcc/testsuite/lib/lto.exp @@ -410,11 +410,23 @@ proc lto-link-and-maybe-run { testname objlist dest optall optfile optstr } { } set is_incr_link [string equal "incr-link" $optstr] - if { $is_incr_link && [info exists gluefile] } { - set sav_gluefile $gluefile - # Setting gluefile to an empty string arranges that we still pass the needed - # -wrap flags to the linker, but we don't include the object file. - set gluefile "" + if { $is_incr_link } { + # An incremental LTO link must contain only the test's LTO objects. + lappend options "additional_flags=-nostdlib" + foreach property {ldflags libs} { + if { [board_info $target_board exists $property] } { + set saved_board_info($property) \ + [board_info $target_board $property] + set board_info($target_board,$property) "" + } + } + + if { [info exists gluefile] } { + set sav_gluefile $gluefile + # Setting gluefile to an empty string arranges that we still pass + # the needed -wrap flags to the linker, but not the object file. + set gluefile "" + } } # Link the objects into an executable. @@ -425,6 +437,13 @@ proc lto-link-and-maybe-run { testname objlist dest optall optfile optstr } { set gluefile $sav_gluefile } + foreach property {ldflags libs} { + if { [info exists saved_board_info($property)] } { + set board_info($target_board,$property) \ + $saved_board_info($property) + } + } + if { $relocatable } { set board_info($target_board,ldscript) $saved_ldscript }
