]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/testsuite: fix build-id compile option when used with clang
authorAndrew Burgess <aburgess@redhat.com>
Fri, 26 Jul 2024 13:26:29 +0000 (14:26 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Fri, 26 Jul 2024 14:36:29 +0000 (15:36 +0100)
It was pointed out in this message:

  https://inbox.sourceware.org/gdb-patches/5d7a514b-5dad-446f-a021-444ea88ecf07@redhat.com

That the test gdb.base/build-id-seqno.exp I added recently was FAILing
when using Clang as the compiler.

The problem was that I had failed to add 'build-id' as a compile
option in the call to build_executable within the test script.  For
GCC this is fine as build-ids are included by default.  For Clang
though this meant the build-id was not included and the test would
fail.

So I added build-id to the compiler options.... and the test still
didn't pass!  Now the test fails to compile and I see this error from
the compiler:

  gdb compile failed, clang-15: warning: -Wl,--build-id: 'linker' \
        input unused [-Wunused-command-line-argument]

It turns out that the build-id compile option causes our gdb.exp to
add the '-Wl,--build-id' option into the compiler flags, which means
its used when building the object file AND during the final link.
However this option is unnecessary when creating the object file and
Clang warns about this, which causes the build to fail.

The solution is to change gdb.exp, instead of adding the build-id
flags like this:

  lappend new_options "additional_flags=-Wl,--build-id"

we should instead add them like:

  lappend new_options "ldflags=-Wl,--build-id"

Now the flag is only appended during the link phase and Clang is
happy.  The gdb.base/build-id-seqno.exp test now passes with Clang.

The same problem (adding to additional_flags instead of ldflags)
exists for the no-build-id compile option, so I've fixed that too.

While investigating this I also spotted two test scripts,
gdb.base/index-cache.exp and gdb.dwarf2/per-bfd-sharing.exp which were
setting ldflag directly rather than using the build-id compile option
so I've updated these two tests to use the compile option which I
think is neater.

I've checked that all these tests still pass with both GCC and Clang.

There should be no changes in what is actually tested after this
commit.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
gdb/testsuite/gdb.base/build-id-seqno.exp
gdb/testsuite/gdb.base/index-cache.exp
gdb/testsuite/gdb.dwarf2/per-bfd-sharing.exp
gdb/testsuite/lib/gdb.exp

index fba8a8d1ca3061fd0f15c3277d437f590e5f1bc7..95669331d9bf86c98d40d450e06d0934b21a49ab 100644 (file)
@@ -29,7 +29,8 @@ require {!is_remote host}
 
 standard_testfile
 
-if {[build_executable "failed to prepare" $testfile $srcfile] == -1} {
+if {[build_executable "failed to prepare" $testfile $srcfile \
+        {debug build-id}] == -1} {
     return -1
 }
 
index 0e19bfb31e2878bd754ce5c1c1cf1b2b81d1a325..af64faa034ff4591ccd32fde4c7e4277475aaa73 100644 (file)
@@ -19,7 +19,7 @@
 standard_testfile .c -2.c
 
 if { [build_executable "failed to prepare" $testfile [list $srcfile $srcfile2] \
-         {debug ldflags=-Wl,--build-id}] } {
+         {debug build-id}] } {
     return
 }
 
index ef1ed1969512e140e75c5b2c6f5b849542728924..7df68a946ac137eb6fbdedbbd68d857791dc1193 100644 (file)
@@ -19,7 +19,7 @@
 standard_testfile
 
 if { [build_executable "failed to prepare" $testfile $srcfile \
-         {debug ldflags=-Wl,--build-id}] == -1 } {
+         {debug build-id}] == -1 } {
     return
 }
 set host_binfile [gdb_remote_download host $binfile]
index dfe19c9410d9722737e21fc7c9df9a411bcbc0a3..e5cacefeb134787eab3959e6c1631fa8819acb77 100644 (file)
@@ -5469,12 +5469,12 @@ proc gdb_compile {source dest type options} {
     # enable it now.
     if {[lsearch -exact $options build-id] > 0
        && [test_compiler_info "clang-*"]} {
-       lappend new_options "additional_flags=-Wl,--build-id"
+       lappend new_options "ldflags=-Wl,--build-id"
     }
 
     # If the 'no-build-id' option is used then disable the build-id.
     if {[lsearch -exact $options no-build-id] > 0} {
-       lappend new_options "additional_flags=-Wl,--build-id=none"
+       lappend new_options "ldflags=-Wl,--build-id=none"
     }
 
     # Sanity check.  If both 'build-id' and 'no-build-id' are used