public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: dwz@sourceware.org, jakub@redhat.com
Subject: [committed] Fix ignored return value warning for link in write_dso
Date: Tue, 01 Jan 2019 00:00:00 -0000	[thread overview]
Message-ID: <20191123080339.GA29178@delia> (raw)

Hi,

When compiled on ubuntu 18.04, we run into this warning:
...
dwz.c: In function ‘write_dso’:
dwz.c:11055:7: warning: ignoring return value of ‘link’, declared with \
  attribute warn_unused_result [-Wunused-result]
       link (dso->filename, buf);
...
in the --devel-save-temps code.

When fixing this warning by erroring out if the link call fails, we run into
the problem that the code containing the link call is called twice:
- once after regular mode, to save the resulting file, and
- once in multifile_finalize mode, which is unnecessary.

After fixing the code not to run in multifile_finalize mode, we run into the
problem that the link target may already exist, so remove it before calling
link.

Committed to trunk.

Thanks,
- Tom

Fix ignored return value warning for link in write_dso

2019-11-23  Tom de Vries  <tdevries@suse.de>

	* dwz.c (write_dso): Add and use save_to_temp parameter.  Unlink before
	linking.  Test result of link call.
	(dwz): Add arg to write_dso call.

---
 dwz.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/dwz.c b/dwz.c
index 945eae9..157b3a8 100644
--- a/dwz.c
+++ b/dwz.c
@@ -10658,7 +10658,7 @@ calculate_section_distance (DSO *dso, unsigned int *sorted_section_numbers,
 /* Store new ELF into FILE.  debug_sections array contains
    new_data/new_size pairs where needed.  */
 static int
-write_dso (DSO *dso, const char *file, struct stat *st)
+write_dso (DSO *dso, const char *file, struct stat *st, bool save_to_temp)
 {
   Elf *elf = NULL;
   GElf_Ehdr ehdr;
@@ -11040,7 +11040,7 @@ write_dso (DSO *dso, const char *file, struct stat *st)
       /* | (ret & 1) to silence up __wur warning for fchown.  */
       return 1 | (ret & 1);
     }
-  if (save_temps && multifile)
+  if (save_to_temp)
     {
       const char *prefix = "dwz.";
       size_t buf_len = strlen (prefix) + strlen (dso->filename) + 1;
@@ -11052,7 +11052,12 @@ write_dso (DSO *dso, const char *file, struct stat *st)
       offset += strlen (dso->filename);
       assert (offset == buf_len - 1);
       assert (buf[offset] == '\0');
-      link (dso->filename, buf);
+      unlink (buf);
+      if (link (dso->filename, buf) != 0)
+	{
+	  error (0, errno, "Failed to link file: %s\n", dso->filename);
+	  return 1;
+	}
     }
   return 0;
 }
@@ -12083,9 +12088,10 @@ dwz (const char *file, const char *outfile, struct file_result *res,
 	  if (multifile && !fi_multifile && !low_mem)
 	    write_multifile (dso);
 
+	  bool save_to_temp = save_temps && multifile && multifile_mode == 0;
 	  cleanup ();
 
-	  if (write_dso (dso, outfile, &st))
+	  if (write_dso (dso, outfile, &st, save_to_temp))
 	    ret = 1;
 	}
     }

                 reply	other threads:[~2019-11-23  8:03 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20191123080339.GA29178@delia \
    --to=tdevries@suse.de \
    --cc=dwz@sourceware.org \
    --cc=jakub@redhat.com \
    /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).