[PATCH] gdb/testsuite: fix build-id compile option when used with clang
Andrew Burgess
aburgess@redhat.com
Fri Jul 26 13:37:45 GMT 2024
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.
---
gdb/testsuite/gdb.base/build-id-seqno.exp | 3 ++-
gdb/testsuite/gdb.base/index-cache.exp | 2 +-
gdb/testsuite/gdb.dwarf2/per-bfd-sharing.exp | 2 +-
gdb/testsuite/lib/gdb.exp | 4 ++--
4 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/gdb/testsuite/gdb.base/build-id-seqno.exp b/gdb/testsuite/gdb.base/build-id-seqno.exp
index fba8a8d1ca3..95669331d9b 100644
--- a/gdb/testsuite/gdb.base/build-id-seqno.exp
+++ b/gdb/testsuite/gdb.base/build-id-seqno.exp
@@ -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
}
diff --git a/gdb/testsuite/gdb.base/index-cache.exp b/gdb/testsuite/gdb.base/index-cache.exp
index 0e19bfb31e2..af64faa034f 100644
--- a/gdb/testsuite/gdb.base/index-cache.exp
+++ b/gdb/testsuite/gdb.base/index-cache.exp
@@ -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
}
diff --git a/gdb/testsuite/gdb.dwarf2/per-bfd-sharing.exp b/gdb/testsuite/gdb.dwarf2/per-bfd-sharing.exp
index ef1ed196951..7df68a946ac 100644
--- a/gdb/testsuite/gdb.dwarf2/per-bfd-sharing.exp
+++ b/gdb/testsuite/gdb.dwarf2/per-bfd-sharing.exp
@@ -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]
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index dfe19c9410d..e5cacefeb13 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -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
base-commit: b0056f89497ce28e88b275250099d4fab0999c0a
--
2.25.4
More information about the Gdb-patches
mailing list