From: Torbjörn SVENSSON <[email protected]>
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]>
---
Similar to r17-3275-g1b9420378621b9, the board ldflags and libs can cause the
incr link to fail.
This patch temporarily disables board defined ldflags and libs during incr link.
Regtested with arm-none-eabi on r17-4804-gf7094fe5ff882f.
Ok for trunk?
--
This is a forge pull request published on the gcc-patches mailing list mailing
list
as requested by Torbjörn Svensson via Sourceware Forge
<[email protected]>.
Forge discussion: https://forge.sourceware.org/gcc/gcc/pulls/242
Get it locally using:
```
git fetch forge-upstream "+refs/versioned_pull/242/*:refs/versioned_pull/242/*"
git switch -c "pr-242-v1" "refs/versioned_pull/242/1/head"
```
Or, download the patch at: https://forge.sourceware.org/gcc/gcc/pulls/242.diff
Created on: 2026-10-06 17:16:26+00:00
Latest update: 2026-10-06 17:19:07+00:00
Changes: 1 changed files, 24 additions, 5 deletions
Head revision: azoff/gcc ref pr/lto-incr-link commit
85144ff03fdfbd1b78e30e8d10da9ccdb7974728
Base revision: gcc/gcc ref trunk commit
f7094fe5ff882f0c206d51ebe93f33f0193ce636 r17-4804-gf7094fe5ff882f
Merge base: f7094fe5ff882f0c206d51ebe93f33f0193ce636
Requested Reviewers:
Changed files:
- M: gcc/testsuite/lib/lto.exp
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 a6532e2207603..e23a90a8637b3 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
}
--
2.54.0