]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
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)
commit4a2b9808fc8e6d7baf400b0ab7a7d180f9493e36
treeb185d626510ee30c013e847447e3a0021b8dc6c6
parentb8b1a4388835bf2899bb0cc148db42a2c32e2af6
gdb/testsuite: fix build-id compile option when used with clang

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