public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
* [committed] Fix ignored return value warning for link in write_dso
@ 2019-01-01  0:00 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2019-01-01  0:00 UTC (permalink / raw)
  To: dwz, jakub

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;
 	}
     }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-11-23  8:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-01  0:00 [committed] Fix ignored return value warning for link in write_dso Tom de Vries

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).