ld: Update mixed LTO and none-LTO relocatable output tests

Message ID CAMe9rOodzK_a7C7Cs8Y_mGOsK_p1FCfOgwZJCTt8h9-qbE2o6A@mail.gmail.com
State New
Headers
Series ld: Update mixed LTO and none-LTO relocatable output tests |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed

Commit Message

H.J. Lu Jan. 14, 2025, 3:59 a.m. UTC
  Since only mixed LTO and none-LTO relocatable output is only supported
on ELF platforms, limit these tests to ELF targets.  Since powerpc64
elfv1 defines a function symbol on its procedure descriptor, which is in
a data section, rather than on the code for that function, allow both D
and T for nm test on mixed object.
  

Comments

Andreas Schwab Jan. 14, 2025, 7:34 a.m. UTC | #1
s/none/non/
  
H.J. Lu Jan. 14, 2025, 12:30 p.m. UTC | #2
On Tue, Jan 14, 2025 at 3:34 PM Andreas Schwab <schwab@linux-m68k.org> wrote:
>
> s/none/non/

Fixed.

> --
> Andreas Schwab, schwab@linux-m68k.org
> GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
> "And now for something completely different."

This is the patch I am checking in.

Thanks.
  
Alan Modra Jan. 14, 2025, 12:46 p.m. UTC | #3
On Tue, Jan 14, 2025 at 08:30:29PM +0800, H.J. Lu wrote:
> On Tue, Jan 14, 2025 at 3:34 PM Andreas Schwab <schwab@linux-m68k.org> wrote:
> >
> > s/none/non/
> 
> Fixed.
> 
> > --
> > Andreas Schwab, schwab@linux-m68k.org
> > GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
> > "And now for something completely different."
> 
> This is the patch I am checking in.

Thanks.
  
Alan Modra Jan. 15, 2025, 5:49 a.m. UTC | #4
x86_64-w64-mingw32/ld
valgrind ./ld-new   -o tmpdir/pr19317-r.o  -L/home/alan/src/binutils-virgin/ld/testsuite/ld-plugin -r tmpdir/pr19317.o --no-error-execstack tmpdir/dummy.o

==1538167== 
==1538167== Invalid read of size 8
==1538167==    at 0x155A90: lang_insert_orphan (ldlang.c:1997)
==1538167==    by 0x166561: gldi386pep_place_orphan (ei386pep.c:2061)
==1538167==    by 0x15232B: ldlang_place_orphan (ldlang.c:7479)
==1538167==    by 0x15232B: lang_place_orphans (ldlang.c:7535)
==1538167==    by 0x158D53: cmdline_emit_object_only_section (ldlang.c:10872)
==1538167==    by 0x143062: main (ldmain.c:653)
==1538167==  Address 0x4b47b00 is 832 bytes inside a block of size 4,064 free'd
==1538167==    at 0x484988F: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==1538167==    by 0x2605EA: objalloc_free (objalloc.c:187)
==1538167==    by 0x18ECB0: bfd_hash_table_free (hash.c:504)
==1538167==    by 0x14F9F3: output_section_statement_table_free (ldlang.c:1361)
==1538167==    by 0x14F9F3: lang_finish (ldlang.c:1400)
==1538167==    by 0x142B48: main (ldmain.c:579)
==1538167==  Block was alloc'd at
==1538167==    at 0x4846828: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==1538167==    by 0x2604A0: objalloc_create (objalloc.c:95)
==1538167==    by 0x18EBD3: bfd_hash_table_init_n (hash.c:441)
==1538167==    by 0x150ECD: output_section_statement_table_init (ldlang.c:1351)
==1538167==    by 0x150ECD: lang_init (ldlang.c:1377)
==1538167==    by 0x142720: main (ldmain.c:397)
  
H.J. Lu Jan. 15, 2025, 11:06 a.m. UTC | #5
On Wed, Jan 15, 2025 at 1:49 PM Alan Modra <amodra@gmail.com> wrote:
>
> x86_64-w64-mingw32/ld
> valgrind ./ld-new   -o tmpdir/pr19317-r.o  -L/home/alan/src/binutils-virgin/ld/testsuite/ld-plugin -r tmpdir/pr19317.o --no-error-execstack tmpdir/dummy.o
>
> ==1538167==
> ==1538167== Invalid read of size 8
> ==1538167==    at 0x155A90: lang_insert_orphan (ldlang.c:1997)
> ==1538167==    by 0x166561: gldi386pep_place_orphan (ei386pep.c:2061)
> ==1538167==    by 0x15232B: ldlang_place_orphan (ldlang.c:7479)
> ==1538167==    by 0x15232B: lang_place_orphans (ldlang.c:7535)
> ==1538167==    by 0x158D53: cmdline_emit_object_only_section (ldlang.c:10872)
> ==1538167==    by 0x143062: main (ldmain.c:653)
> ==1538167==  Address 0x4b47b00 is 832 bytes inside a block of size 4,064 free'd
> ==1538167==    at 0x484988F: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==1538167==    by 0x2605EA: objalloc_free (objalloc.c:187)
> ==1538167==    by 0x18ECB0: bfd_hash_table_free (hash.c:504)
> ==1538167==    by 0x14F9F3: output_section_statement_table_free (ldlang.c:1361)
> ==1538167==    by 0x14F9F3: lang_finish (ldlang.c:1400)
> ==1538167==    by 0x142B48: main (ldmain.c:579)
> ==1538167==  Block was alloc'd at
> ==1538167==    at 0x4846828: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==1538167==    by 0x2604A0: objalloc_create (objalloc.c:95)
> ==1538167==    by 0x18EBD3: bfd_hash_table_init_n (hash.c:441)
> ==1538167==    by 0x150ECD: output_section_statement_table_init (ldlang.c:1351)
> ==1538167==    by 0x150ECD: lang_init (ldlang.c:1377)
> ==1538167==    by 0x142720: main (ldmain.c:397)
>
> --
> Alan Modra

Here is the patch set:

https://sourceware.org/pipermail/binutils/2025-January/138665.html
  

Patch

From 1513a020cc1722c332ecf707dad2ca759bc4d133 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Tue, 14 Jan 2025 09:09:28 +0800
Subject: [PATCH] ld: Update mixed LTO and none-LTO relocatable output tests

Since only mixed LTO and none-LTO relocatable output is only supported
on ELF platforms, limit these tests to ELF targets.  Since powerpc64
elfv1 defines a function symbol on its procedure descriptor, which is in
a data section, rather than on the code for that function, allow both D
and T for nm test on mixed object.

	* testsuite/ld-plugin/lto.exp: Limits  mixed LTO and none-LTO
	relocatable output tests to ELF targets.  Allow both D and T for
	nm test on mixed object.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
---
 ld/testsuite/ld-plugin/lto.exp | 82 +++++++++++++++++-----------------
 1 file changed, 42 insertions(+), 40 deletions(-)

diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index e454b485ed9..f3d82c834c8 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -726,29 +726,9 @@  set lto_run_tests [list \
   [list "LTO 3c" \
    "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o -Wl,--whole-archive tmpdir/liblto-3.a -Wl,--no-whole-archive tmpdir/liblto-3.a" "" \
    {dummy.c} "lto-3d.exe" "lto-3.out" "" "c"] \
-  [list "LTO 4a" \
-   "-O2 -flto -fuse-linker-plugin \
-    -Wl,--no-warn-execstack,--no-error-execstack \
-    tmpdir/lto-4r-a.o" "" \
-   {dummy.c} "lto-4a.exe" "lto-4.out" "" "c"] \
-  [list "LTO 4c" \
-   "-O2 -flto -fuse-linker-plugin \
-    -Wl,--no-warn-execstack,--no-error-execstack \
-    tmpdir/lto-4r-c.o" "" \
-   {dummy.c} "lto-4c.exe" "lto-4.out" "" "c"] \
-  [list "LTO 4d" \
-   "-O2 -flto -fuse-linker-plugin \
-    -Wl,--no-warn-execstack,--no-error-execstack \
-    tmpdir/lto-4r-d.o" "" \
-   {dummy.c} "lto-4d.exe" "lto-4.out" "" "c"] \
   [list "LTO 5" \
    "-O2 -flto -fuse-linker-plugin tmpdir/lto-5.o" "" \
    {dummy.c} "lto-5.exe" "lto-5.out" "" "c"] \
-  [list "LTO 10" \
-   "-O2 -flto -fuse-linker-plugin \
-    -Wl,--no-warn-execstack,--no-error-execstack \
-    tmpdir/lto-10.o" "" \
-   {dummy.c} "lto-10.exe" "lto-10.out" "" "c"] \
   [list "LTO 11" \
    "-O -flto -fuse-linker-plugin tmpdir/liblto-11.a" "" \
    {dummy.c} "lto-11.exe" "lto-11.out" "" "c"] \
@@ -918,6 +898,26 @@  set lto_run_elf_shared_tests [list \
 
 # LTO run-time tests for ELF
 set lto_run_elf_tests [list \
+  [list "LTO 4a" \
+   "-O2 -flto -fuse-linker-plugin \
+    -Wl,--no-warn-execstack,--no-error-execstack \
+    tmpdir/lto-4r-a.o" "" \
+   {dummy.c} "lto-4a.exe" "lto-4.out" "" "c"] \
+  [list "LTO 4c" \
+   "-O2 -flto -fuse-linker-plugin \
+    -Wl,--no-warn-execstack,--no-error-execstack \
+    tmpdir/lto-4r-c.o" "" \
+   {dummy.c} "lto-4c.exe" "lto-4.out" "" "c"] \
+  [list "LTO 4d" \
+   "-O2 -flto -fuse-linker-plugin \
+    -Wl,--no-warn-execstack,--no-error-execstack \
+    tmpdir/lto-4r-d.o" "" \
+   {dummy.c} "lto-4d.exe" "lto-4.out" "" "c"] \
+  [list "LTO 10" \
+   "-O2 -flto -fuse-linker-plugin \
+    -Wl,--no-warn-execstack,--no-error-execstack \
+    tmpdir/lto-10.o" "" \
+   {dummy.c} "lto-10.exe" "lto-10.out" "" "c"] \
   [list "LTO 8" \
    "-O2 -flto -fuse-linker-plugin tmpdir/lto-8b.o tmpdir/lto-8a.o" "" \
    {dummy.c} "lto-8.exe" "lto-8.out" "" "c"] \
@@ -1135,30 +1135,32 @@  if { [at_least_gcc_version 4 7] } {
 # Run "ld -r" to generate inputs for complex LTO tests.
 run_dump_test "lto-3r"
 remote_exec host "mv" "tmpdir/dump tmpdir/lto-3.o"
-run_dump_test "lto-4r-a"
-remote_exec host "mv" "tmpdir/dump tmpdir/lto-4r-a.o"
-run_dump_test "lto-4r-b"
-remote_exec host "mv" "tmpdir/dump tmpdir/lto-4r-b.o"
-run_dump_test "lto-4r-c"
-remote_exec host "mv" "tmpdir/dump tmpdir/lto-4r-c.o"
-run_dump_test "lto-4r-d"
-remote_exec host "mv" "tmpdir/dump tmpdir/lto-4r-d.o"
 run_dump_test "lto-5r"
 remote_exec host "mv" "tmpdir/dump tmpdir/lto-5.o"
-run_dump_test "lto-10r"
-remote_exec host "mv" "tmpdir/dump tmpdir/lto-10.o"
-set testname "nm mixed object"
-set lto_plugin [string trim [run_host_cmd "$CC_FOR_TARGET" "-print-prog-name=liblto_plugin.so"]]
-if { [ regexp "liblto_plugin.so" $lto_plugin ] } {
-    set exec_output [run_host_cmd "$NM" "--plugin $lto_plugin tmpdir/lto-10.o"]
-    if { [ regexp "T main" $exec_output ] } {
-	pass $testname
-    } {
+if { [is_elf_format] } {
+    run_dump_test "lto-4r-a"
+    remote_exec host "mv" "tmpdir/dump tmpdir/lto-4r-a.o"
+    run_dump_test "lto-4r-b"
+    remote_exec host "mv" "tmpdir/dump tmpdir/lto-4r-b.o"
+    run_dump_test "lto-4r-c"
+    remote_exec host "mv" "tmpdir/dump tmpdir/lto-4r-c.o"
+    run_dump_test "lto-4r-d"
+    remote_exec host "mv" "tmpdir/dump tmpdir/lto-4r-d.o"
+    run_dump_test "lto-10r"
+    remote_exec host "mv" "tmpdir/dump tmpdir/lto-10.o"
+    set testname "nm mixed object"
+    set lto_plugin [string trim [run_host_cmd "$CC_FOR_TARGET" "-print-prog-name=liblto_plugin.so"]]
+    if { [ regexp "liblto_plugin.so" $lto_plugin ] } {
+	set exec_output [run_host_cmd "$NM" "--plugin $lto_plugin tmpdir/lto-10.o"]
+	if { [ regexp "(D|T) main" $exec_output ] } {
+	    pass $testname
+	} else {
+	    fail $testname
+	}
+    } else {
 	fail $testname
     }
-} {
-    fail $testname
- }
+}
 
 run_cc_link_tests $lto_link_symbol_tests
 
-- 
2.47.1