Re: [PATCH 5/5] lto: Support #pragma GCC diagnostic [PR80922] [PR106823] [PR107936]

Torbjorn SVENSSON <[email protected]> Thu, 6 Aug 2026 07:42:06 +0200
Newsgroups gmane.comp.gcc.patches
Message-ID <[email protected]>

On 2026-08-06 02:15, Lewis Hyatt wrote:
> On Wed, Aug 05, 2026 at 08:52:41AM +0200, Torbjorn SVENSSON wrote:
>>
>>
>> On 2026-08-05 02:06, Lewis Hyatt wrote:
>>> On Tue, Aug 04, 2026 at 02:31:51PM +0200, Torbjorn SVENSSON wrote:
>>>> Hello,
>>>>
>>>> The new gcc.dg/lto/pr80922 test appears to fail for all arm-none-eabi targets:
>>>>
>>>> Testing gcc.dg/lto/pr80922-2, -O0 -flto -flto-partition=none -fuse-linker-plugin
>>>> doing compile
>>>> Executing on host: /build/r17-2833-g32657f29f91871/bin/arm-none-eabi-gcc   -mthumb -march=armv6s-m -mcpu=cortex-m0 -mfloat-abi=soft -mfpu=auto   -fdiagnostics-plain-output  -O0 -flto -flto-partition=none -fuse-linker-plugin  -O2 -Wfree-nonheap-object -c     -o c_lto_pr80922-2_0.o /build/gcc_src/gcc/testsuite/gcc.dg/lto/pr80922-2_0.c    (timeout = 800)
>>>> spawn -ignore SIGHUP /build/r17-2833-g32657f29f91871/bin/arm-none-eabi-gcc -mthumb -march=armv6s-m -mcpu=cortex-m0 -mfloat-abi=soft -mfpu=auto -fdiagnostics-plain-output -O0 -flto -flto-partition=none -fuse-linker-plugin -O2 -Wfree-nonheap-object -c -o c_lto_pr80922-2_0.o /build/gcc_src/gcc/testsuite/gcc.dg/lto/pr80922-2_0.c
>>>> pid is 703324 -703324
>>>> pid is -1
>>>> output is  status 0
>>>> PASS: gcc.dg/lto/pr80922-2 c_lto_pr80922-2_0.o assemble, -O0 -flto -flto-partition=none -fuse-linker-plugin
>>>> doing compile
>>>> Executing on host: /build/r17-2833-g32657f29f91871/bin/arm-none-eabi-gcc   -mthumb -march=armv6s-m -mcpu=cortex-m0 -mfloat-abi=soft -mfpu=auto   -fdiagnostics-plain-output  -O0 -flto -flto-partition=none -fuse-linker-plugin  -O2 -Wfree-nonheap-object -c     -o c_lto_pr80922-2_1.o /build/gcc_src/gcc/testsuite/gcc.dg/lto/pr80922-2_1.c    (timeout = 800)
>>>> spawn -ignore SIGHUP /build/r17-2833-g32657f29f91871/bin/arm-none-eabi-gcc -mthumb -march=armv6s-m -mcpu=cortex-m0 -mfloat-abi=soft -mfpu=auto -fdiagnostics-plain-output -O0 -flto -flto-partition=none -fuse-linker-plugin -O2 -Wfree-nonheap-object -c -o c_lto_pr80922-2_1.o /build/gcc_src/gcc/testsuite/gcc.dg/lto/pr80922-2_1.c
>>>> pid is 703370 -703370
>>>> pid is -1
>>>> output is  status 0
>>>> PASS: gcc.dg/lto/pr80922-2 c_lto_pr80922-2_1.o assemble, -O0 -flto -flto-partition=none -fuse-linker-plugin
>>>> doing compile
>>>> Executing on host: /build/r17-2833-g32657f29f91871/bin/arm-none-eabi-gcc   -mthumb -march=armv6s-m -mcpu=cortex-m0 -mfloat-abi=soft -mfpu=auto   -fdiagnostics-plain-output  -O0 -flto -flto-partition=none -fuse-linker-plugin  -O2 -Wfree-nonheap-object -c     -o c_lto_pr80922-2_2.o /build/gcc_src/gcc/testsuite/gcc.dg/lto/pr80922-2_2.c    (timeout = 800)
>>>> spawn -ignore SIGHUP /build/r17-2833-g32657f29f91871/bin/arm-none-eabi-gcc -mthumb -march=armv6s-m -mcpu=cortex-m0 -mfloat-abi=soft -mfpu=auto -fdiagnostics-plain-output -O0 -flto -flto-partition=none -fuse-linker-plugin -O2 -Wfree-nonheap-object -c -o c_lto_pr80922-2_2.o /build/gcc_src/gcc/testsuite/gcc.dg/lto/pr80922-2_2.c
>>>> pid is 703406 -703406
>>>> pid is -1
>>>> output is  status 0
>>>> PASS: gcc.dg/lto/pr80922-2 c_lto_pr80922-2_2.o assemble, -O0 -flto -flto-partition=none -fuse-linker-plugin
>>>> doing compile
>>>> Executing on host: /build/r17-2833-g32657f29f91871/bin/arm-none-eabi-gcc  c_lto_pr80922-2_1.o c_lto_pr80922-2_2.o  -mthumb -march=armv6s-m -mcpu=cortex-m0 -mfloat-abi=soft -mfpu=auto   -dumpbase "" -fdiagnostics-plain-output  -r       --specs=rdimon.specs -Wl,--start-group -lc -lm -Wl,--end-group --specs=nosys.specs -Wl,--allow-multiple-definition -Wl,-u,_isatty,-u,_fstat  -Wl,-wrap,exit -Wl,-wrap,_exit -Wl,-wrap,main -Wl,-wrap,abort -Wl,gcc_tg.o    -o c_lto_pr80922-2.o    (timeout = 800)
>>>> spawn -ignore SIGHUP /build/r17-2833-g32657f29f91871/bin/arm-none-eabi-gcc c_lto_pr80922-2_1.o c_lto_pr80922-2_2.o -mthumb -march=armv6s-m -mcpu=cortex-m0 -mfloat-abi=soft -mfpu=auto -dumpbase  -fdiagnostics-plain-output -r --specs=rdimon.specs -Wl,--start-group -lc -lm -Wl,--end-group --specs=nosys.specs -Wl,--allow-multiple-definition -Wl,-u,_isatty,-u,_fstat -Wl,-wrap,exit -Wl,-wrap,_exit -Wl,-wrap,main -Wl,-wrap,abort -Wl,gcc_tg.o -o c_lto_pr80922-2.o
>>>> pid is 703440 -703440
>>>> /build/r17-2833-g32657f29f91871/arm-none-eabi/bin/ld: warning: incremental linking of LTO and non-LTO objects; using -flinker-output=nolto-rel which will bypass whole program optimization
>>>> In function 'myfree2',
>>>>       inlined from 'main' at /build/gcc_src/gcc/testsuite/gcc.dg/lto/pr80922-1_1.c:8:3:
>>>> /build/gcc_src/gcc/testsuite/gcc.dg/lto/pr80922-2_1.c:5:3: warning: '__builtin_free' called on unallocated object 'a' [-Wfree-nonheap-object]
>>>> /build/gcc_src/gcc/testsuite/gcc.dg/lto/pr80922-1_1.c: In function 'main':
>>>> /build/gcc_src/gcc/testsuite/gcc.dg/lto/pr80922-1_1.c:4:13: note: declared here
>>>> In function 'myfree2',
>>>>       inlined from 'main' at /build/gcc_src/gcc/testsuite/gcc.dg/lto/pr80922-1_1.c:8:3:
>>>> /build/gcc_src/gcc/testsuite/gcc.dg/lto/pr80922-2_1.c:10:3: warning: '__builtin_free' called on unallocated object 'c' [-Wfree-nonheap-object]
>>>> /build/gcc_src/gcc/testsuite/gcc.dg/lto/pr80922-1_1.c: In function 'main':
>>>> /build/gcc_src/gcc/testsuite/gcc.dg/lto/pr80922-1_1.c:4:19: note: declared here
>>>> pid is -1
>>>> output is /build/r17-2833-g32657f29f91871/arm-none-eabi/bin/ld: warning: incremental linking of LTO and non-LTO objects; using -flinker-output=nolto-rel which will bypass whole program optimization
>>>> In function 'myfree2',
>>>>       inlined from 'main' at /build/gcc_src/gcc/testsuite/gcc.dg/lto/pr80922-1_1.c:8:3:
>>>> /build/gcc_src/gcc/testsuite/gcc.dg/lto/pr80922-2_1.c:5:3: warning: '__builtin_free' called on unallocated object 'a' [-Wfree-nonheap-object]
>>>> /build/gcc_src/gcc/testsuite/gcc.dg/lto/pr80922-1_1.c: In function 'main':
>>>> /build/gcc_src/gcc/testsuite/gcc.dg/lto/pr80922-1_1.c:4:13: note: declared here
>>>> In function 'myfree2',
>>>>       inlined from 'main' at /build/gcc_src/gcc/testsuite/gcc.dg/lto/pr80922-1_1.c:8:3:
>>>> /build/gcc_src/gcc/testsuite/gcc.dg/lto/pr80922-2_1.c:10:3: warning: '__builtin_free' called on unallocated object 'c' [-Wfree-nonheap-object]
>>>> /build/gcc_src/gcc/testsuite/gcc.dg/lto/pr80922-1_1.c: In function 'main':
>>>> /build/gcc_src/gcc/testsuite/gcc.dg/lto/pr80922-1_1.c:4:19: note: declared here
>>>>    status 0
>>>> FAIL: gcc.dg/lto/pr80922-2 c_lto_pr80922-2_2.o-c_lto_pr80922-2_2.o link, incr-link
>>>> doing compile
>>>> Executing on host: /build/r17-2833-g32657f29f91871/bin/arm-none-eabi-gcc  c_lto_pr80922-2_0.o c_lto_pr80922-2.o  -mthumb -march=armv6s-m -mcpu=cortex-m0 -mfloat-abi=soft -mfpu=auto   -dumpbase "" -fdiagnostics-plain-output  -O0 -flto -flto-partition=none -fuse-linker-plugin -O2 -Wfree-nonheap-object       --specs=rdimon.specs -Wl,--start-group -lc -lm -Wl,--end-group --specs=nosys.specs -Wl,--allow-multiple-definition -Wl,-u,_isatty,-u,_fstat  -Wl,-wrap,exit -Wl,-wrap,_exit -Wl,-wrap,main -Wl,-wrap,abort -Wl,gcc_tg.o   -T qemu.ld -o gcc-dg-lto-pr80922-2-01.exe    (timeout = 800)
>>>> spawn -ignore SIGHUP /build/r17-2833-g32657f29f91871/bin/arm-none-eabi-gcc c_lto_pr80922-2_0.o c_lto_pr80922-2.o -mthumb -march=armv6s-m -mcpu=cortex-m0 -mfloat-abi=soft -mfpu=auto -dumpbase  -fdiagnostics-plain-output -O0 -flto -flto-partition=none -fuse-linker-plugin -O2 -Wfree-nonheap-object --specs=rdimon.specs -Wl,--start-group -lc -lm -Wl,--end-group --specs=nosys.specs -Wl,--allow-multiple-definition -Wl,-u,_isatty,-u,_fstat -Wl,-wrap,exit -Wl,-wrap,_exit -Wl,-wrap,main -Wl,-wrap,abort -Wl,gcc_tg.o -T qemu.ld -o gcc-dg-lto-pr80922-2-01.exe
>>>> pid is 703533 -703533
>>>> pid is -1
>>>> output is  status 0
>>>> FAIL: gcc.dg/lto/pr80922-2  (test for LTO warnings, pr80922-2_0.c line 10 -O0 -flto -flto-partition=none -fuse-linker-plugin)
>>>> FAIL: gcc.dg/lto/pr80922-2  (test for LTO warnings, pr80922-2_0.c line 15 -O0 -flto -flto-partition=none -fuse-linker-plugin)
>>>> FAIL: gcc.dg/lto/pr80922-2  (test for LTO warnings, pr80922-2_1.c line 5 -O0 -flto -flto-partition=none -fuse-linker-plugin)
>>>> FAIL: gcc.dg/lto/pr80922-2  (test for LTO warnings, pr80922-2_1.c line 10 -O0 -flto -flto-partition=none -fuse-linker-plugin)
>>>> PASS: gcc.dg/lto/pr80922-2 c_lto_pr80922-2_0.o-c_lto_pr80922-2.o link, -O0 -flto -flto-partition=none -fuse-linker-plugin
>>>>
>>>>
>>>> Kind regards,
>>>> Torbjörn
>>>
>>> Thanks, so the test is expecting an LTO-only partial link, and it gets
>>> tripped up because this target adds an extra non-LTO wrapper object to every
>>> link. The attached patch disables the test using
>>> check_effective_target_unwrapped, which I think is the way to go for now? It
>>> works fine on x86-64, fwiw, in that the incr-link test still runs as
>>> before. I don't think I have a way to test on arm-none-eabi myself, unless
>>> there is a cfarm machine I have not found for that...
>>
>> I've tested below patch on top of r17-2833-g32657f29f91871 and it appears to do the job. I do, however, not know if there is any better solution than disabling the incr-link.
>> What impact do you think it would have to compile the testglue.c from dejagnu with -flto? Would that be a better solution?
>> If think it's possible to add -flto when building testglue.c by adding
>>
>> set_board_info wrap_compile_flags "-flto"
>>
>> to the board definition. Perhaps, this is something that the harness in GCC should do?
>>
> 
> The incr-link step is combining two objects together into one, and then the
> combined object is later linked normally. So I think what needs to happen is
> just that the wrapper object should be omitted from the arguments when doing
> the partial link step, since it will be included on the final link. I was
> able to test the attached patch locally on x86-64 (temporarily enabling the
> test glue wrapper in unix.exp) and it works right for me -- could I trouble
> you to try it on arm-none-eabi as well please? (This is instead of the other
> patch I sent, not in addition to it.) Thanks!

Thanks for taking another look at this.
I took the new patch for a spin on top of r17-2833-g32657f29f91871 and all the tests in lto.exp is now passing for all the arm-none-eabi targets that I usually test.
I think this patch is ok, but you need someone with authority to actually approve it.

Kind regards,
Torbjörn

> 
> -Lewis
> 
> 
> 0001-lto-testsuite-Fix-incr-link-tests-on-wrapped-targets.txt
> 
> [PATCH] lto: testsuite: Fix incr-link tests on wrapped targets
> 
> For targets that use a gluefile wrapper object, the extra object should not
> be included in the link for the new LTO incr-link mode.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* lib/lto.exp (lto-link-and-maybe-run): Unset gluefile for the
> 	incremental link step, since the wrapper is not needed there and
> 	does not contain LTO sections.
> ---
>   gcc/testsuite/lib/lto.exp | 15 ++++++++++++++-
>   1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/gcc/testsuite/lib/lto.exp b/gcc/testsuite/lib/lto.exp
> index 7243547a52d..a6532e22076 100644
> --- a/gcc/testsuite/lib/lto.exp
> +++ b/gcc/testsuite/lib/lto.exp
> @@ -375,6 +375,7 @@ proc lto-link-and-maybe-run { testname objlist dest optall optfile optstr } {
>       global tool
>       global compile_type
>       global board_info
> +    global gluefile
>   
>       upvar dg-messages-by-file dg-messages-by-file
>   
> @@ -408,16 +409,28 @@ proc lto-link-and-maybe-run { testname objlist dest optall optfile optstr } {
>   	set board_info($target_board,ldscript) ""
>       }
>   
> +    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 ""
> +    }
> +
>       # Link the objects into an executable.
>       set comp_output [${tool}_target_compile "$objlist" $dest executable \
>   		     "$options"]
>   
> +    if { [info exists sav_gluefile] } {
> +	set gluefile $sav_gluefile
> +    }
> +
>       if { $relocatable } {
>   	set board_info($target_board,ldscript) $saved_ldscript
>       }
>   
>       # Check for diagnostics specified by directives
> -    if { ! [string equal "incr-link" $optstr] } {
> +    if { ! $is_incr_link } {
>   	set comp_output [lto_handle_diagnostics $comp_output $optstr]
>       }
>