]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
PR32032 dwp segfaults on hello world binary
authorAlan Modra <amodra@gmail.com>
Mon, 29 Jul 2024 04:55:07 +0000 (14:25 +0930)
committerAlan Modra <amodra@gmail.com>
Mon, 29 Jul 2024 06:55:59 +0000 (16:25 +0930)
Fixing the segfault is easy with this bandaid, but further work is
needed to teach dwp about DW_AT_dwo_name and dwo id in the cu header.
At the moment dwp only handles DW_AT_GNU_dwo_name and DW_AT_GNU_dwo_id.

PR 32032
* dwp.cc (Dwp_output_file::finalize): Return immediately on
no output file.

gold/dwp.cc

index e1656d0650d1182aae7c19054a54a25a77df1278..584892c2b0c85ca9f448db2ab83b1df613ee38a4 100644 (file)
@@ -1838,6 +1838,9 @@ Dwp_output_file::finalize()
 {
   unsigned char* buf;
 
+  if (this->fd_ == NULL)
+    return;
+
   // Write the accumulated output sections.
   for (unsigned int i = 0; i < this->sections_.size(); i++)
     {
@@ -1919,11 +1922,8 @@ Dwp_output_file::finalize()
   this->write_ehdr();
 
   // Close the file.
-  if (this->fd_ != NULL)
-    {
-      if (::fclose(this->fd_) != 0)
-       gold_fatal(_("%s: %s"), this->name_, strerror(errno));
-    }
+  if (::fclose(this->fd_) != 0)
+    gold_fatal(_("%s: %s"), this->name_, strerror(errno));
   this->fd_ = NULL;
 }