public inbox for debugedit@sourceware.org
 help / color / mirror / Atom feed
From: "lersek at redhat dot com" <sourceware-bugzilla@sourceware.org>
To: debugedit@sourceware.org
Subject: [Bug find-debuginfo/30505] New: unchecked "gdb-add-index" invocation
Date: Thu, 01 Jun 2023 11:04:29 +0000	[thread overview]
Message-ID: <bug-30505-13298@http.sourceware.org/bugzilla/> (raw)

https://sourceware.org/bugzilla/show_bug.cgi?id=30505

            Bug ID: 30505
           Summary: unchecked "gdb-add-index" invocation
           Product: debugedit
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: find-debuginfo
          Assignee: unassigned at sourceware dot org
          Reporter: lersek at redhat dot com
                CC: debugedit at sourceware dot org
  Target Milestone: ---

As of commit 5bade25a11b5, "scripts/find-debuginfo.in" contains:

>|   # Add .gdb_index if requested.
>|   if $include_gdb_index; then
>|     if type gdb-add-index >/dev/null 2>&1; then
>|       gdb-add-index "$f"
>|     else
>|       echo >&2 "*** ERROR: GDB index requested, but no gdb-add-index installed"
>|       exit 2
>|     fi
>|   fi

If the objcopy invocation underlying "gdb-add-index" fails, then
"gdb-add-index" propagates that issue through its exit status; however,
"find-debuginfo" ignores it (see above).

This allows RPM builds to succeed if debuginfo extraction is started
with "-i" (i.e., GDB index is being requested), gdb-add-index is
available, but gdb-add-index fails for some reason.

One example is a shared library object that contains Perl bindings for a
C-language library. Perl's ExtUtils::Install module installs artifacts
in read-only mode. On a read-only .so, objcopy fails, hence
gdb-add-index fails. Yet the RPM build succeeds, resulting in such
debuginfo (*.so.debug) files that lack the .gdb_index section. The
expected behavior is that the RPM build fail, similarly to how it
currently fails if "-i" is passed to "find-debuginfo", but
"gdb-add-index" is unavailable (see the"exit 2" statement in the quote).

Installing files in read-only mode is arguably a bug in
ExtUtils::Install itself
<https://rt.cpan.org/Public/Bug/Display.html?id=40976>; however, that
does not mean "find-debuginfo" should ignore "gdb-add-index" failures.

I figure something like the following might work:

>| diff --git a/scripts/find-debuginfo.in b/scripts/find-debuginfo.in
>| index 7dec3c3bfdc5..e0d931175cd9 100755
>| --- a/scripts/find-debuginfo.in
>| +++ b/scripts/find-debuginfo.in
>| @@ -470,6 +470,10 @@ do_file()
>|    if $include_gdb_index; then
>|      if type gdb-add-index >/dev/null 2>&1; then
>|        gdb-add-index "$f"
>| +      exit_status=$?
>| +      if test $exit_status -ne 0; then
>| +        exit $exit_status
>| +      fi
>|      else
>|        echo >&2 "*** ERROR: GDB index requested, but no gdb-add-index installed"
>|        exit 2

However, "find-debuginfo" seems to have an (undocumented) convention
where it uses only exit statuses 1 and 2. In that case, propagating the
exit status from gdb-add-index may not be right. Then one alternative
would be:

>| diff --git a/scripts/find-debuginfo.in b/scripts/find-debuginfo.in
>| index 7dec3c3bfdc5..99cb3b906a00 100755
>| --- a/scripts/find-debuginfo.in
>| +++ b/scripts/find-debuginfo.in
>| @@ -469,7 +469,7 @@ do_file()
>|    # Add .gdb_index if requested.
>|    if $include_gdb_index; then
>|      if type gdb-add-index >/dev/null 2>&1; then
>| -      gdb-add-index "$f"
>| +      gdb-add-index "$f" || exit 1
>|      else
>|        echo >&2 "*** ERROR: GDB index requested, but no gdb-add-index installed"
>|        exit 2

Note that the problem (not checking the exit status of gdb-add-index)
dates back to the original introduction of gdb-add-index to
find-debuginfo:

  https://github.com/rpm-software-management/rpm/commit/9570a7f6af15
  https://github.com/rpm-software-management/rpm/commit/41c4dcf507e2
  https://github.com/rpm-software-management/rpm/commit/67d3df338875
  https://github.com/rpm-software-management/rpm/commit/04b0805a756c

-- 
You are receiving this mail because:
You are on the CC list for the bug.

             reply	other threads:[~2023-06-01 11:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-01 11:04 lersek at redhat dot com [this message]
2023-06-01 11:27 ` [Bug find-debuginfo/30505] " mark at klomp dot org
2023-12-10 22:16 ` mark at klomp dot org

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=bug-30505-13298@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=debugedit@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).