public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCH 4/6] gdb/testsuite: add (and use) a new build-id compile option
Date: Fri, 11 Nov 2022 16:36:23 +0000	[thread overview]
Message-ID: <1d74d73394e4c2b97ea6a0009ace830ac7399db7.1668184173.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1668184173.git.aburgess@redhat.com>

I noticed that the gdb.debuginfod/fetch_src_and_symbols.exp test was
failing when run with Clang as the compiler.

This test relies on the compiled binaries having a build-id within
them.  For GCC, really GNU ld, the default is to always include a
build-id.

When compiling with Clang though, the default is for no build-id.

I did consider *always* turning on the build-id feature when the
compiler is Clang, but that felt a little weird.

Instead, I propose that we add a new 'build-id' compiler option to
gdb_compile, this flag indicates that the test _requires_ a build-id.
In gcc_compile we can then add the required flags if the compiler is
Clang so that we do get a build-id.

With this change the gdb.debuginfod/fetch_src_and_symbols.exp test
now (mostly) passes with Clang 9.0.1 and 15.0.2, and still passes with
gcc.  The 'mostly' part is an unrelated issue, and will be addressed
in a later commit in this series.
---
 gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp | 4 ++--
 gdb/testsuite/lib/gdb.exp                              | 9 +++++++++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp b/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp
index 9bffb3397ec..b57b3201cf7 100644
--- a/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp
+++ b/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp
@@ -32,12 +32,12 @@ if { [catch {file copy -force ${srcdir}/${subdir}/${srcfile} \
     return -1
 }
 
-if { [gdb_compile "$sourcetmp" "$binfile" executable {debug}] != "" } {
+if { [gdb_compile "$sourcetmp" "$binfile" executable {debug build-id}] != "" } {
     untested "failed to compile"
     return -1
 }
 
-if { [gdb_compile "$sourcetmp" "${binfile}2" executable {debug}] != "" } {
+if { [gdb_compile "$sourcetmp" "${binfile}2" executable {debug build-id}] != "" } {
     fail "compile"
     return -1
 }
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 3e0a46445ca..b006d0fe855 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -4684,6 +4684,7 @@ set gdb_saved_set_unbuffered_mode_obj ""
 #   - macros: Add the required compiler flag to include macro information in
 #     debug information
 #   - text_segment=addr: Tell the linker to place the text segment at ADDR.
+#   - build-id: Ensure the final binary includes a build-id.
 #
 # And here are some of the not too obscure options understood by DejaGnu that
 # influence the compilation:
@@ -4746,6 +4747,14 @@ proc gdb_compile {source dest type options} {
 	}
     }
 
+    # If the 'build-id' option is used, then ensure that we generate a
+    # build-id.  GCC does this by default, but Clang does not, so
+    # enable it now.
+    if {[lsearch -exact $options build-id] > 0
+	&& [test_compiler_info "clang-*"]} {
+	lappend new_options "additional_flags=-Wl,--build-id"
+    }
+
     # Treating .c input files as C++ is deprecated in Clang, so
     # explicitly force C++ language.
     if { !$getting_compiler_info
-- 
2.25.4


  parent reply	other threads:[~2022-11-11 16:36 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-11 16:36 [PATCH 0/6] The DWARF assembler and Clang Andrew Burgess
2022-11-11 16:36 ` [PATCH 1/6] gdb/testsuite: don't avoid DWARF assembler tests with Clang Andrew Burgess
2022-11-11 16:36 ` [PATCH 2/6] gdb/testsuite: fix gdb.trace/unavailable-dwarf-piece.exp " Andrew Burgess
2022-11-16 14:41   ` Bruno Larsen
2022-11-17 11:06     ` Andrew Burgess
2022-12-12 17:55   ` Tom Tromey
2022-12-13 15:39     ` Andrew Burgess
2022-11-11 16:36 ` [PATCH 3/6] gdb/testsuite: fix gdb.compile/compile-ops.exp with clang Andrew Burgess
2022-11-16 16:27   ` Tom Tromey
2022-11-11 16:36 ` Andrew Burgess [this message]
2022-11-11 16:36 ` [PATCH 5/6] gdb/testsuite: fix gdb.debuginfod/fetch_src_and_symbols.exp with Clang Andrew Burgess
2022-11-16 16:29   ` Tom Tromey
2022-11-17 11:38     ` [PATCHv2 0/2] Fix " Andrew Burgess
2022-11-17 11:38       ` [PATCHv2 1/2] gdb/testsuite: rename source file gdb.debuginfod/main.c Andrew Burgess
2022-11-17 11:38       ` [PATCHv2 2/2] gdb/testsuite: fix gdb.debuginfod/fetch_src_and_symbols.exp with Clang Andrew Burgess
2022-11-17 19:29       ` [PATCHv2 0/2] Fix " Tom Tromey
2022-11-11 16:36 ` [PATCH 6/6] gdb/testsuite: rewrite gdb.cp/call-method-register.exp with dwarf assembler Andrew Burgess
2022-11-16 11:59   ` Lancelot SIX
2022-11-16 16:32 ` [PATCH 0/6] The DWARF assembler and Clang Tom Tromey
2022-11-18 11:48   ` Andrew Burgess

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1d74d73394e4c2b97ea6a0009ace830ac7399db7.1668184173.git.aburgess@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).