Discussion:
[PATCH] GOLD/DWP: avoid segmentation fault for binaries without debug fission
Yunlian Jiang
2016-05-16 23:56:40 UTC
Permalink
If run dwp command on a binary built without debug fission, it will
cause segmentation
fault. This patch fixes that by exit early if no DWO files information
found inside the
input binary.

gold/
* dwp.cc: (main): exit early when no DWO files information found
in the input binary.

diff --git a/gold/dwp.cc b/gold/dwp.cc
index d8c39c6..c26f969 100644
--- a/gold/dwp.cc
+++ b/gold/dwp.cc
@@ -2436,6 +2436,11 @@ main(int argc, char** argv)
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
}

+ // If there is no DWO files information found in the input binary,
+ // return early to avoid segmentation fault.
+ if (files.size() == 0)
+ return EXIT_SUCCESS;
+
// Process each file, adding its contents to the output file.
Dwp_output_file output_file(output_filename.c_str());
for (File_list::const_iterator f = files.begin(); f != files.end(); ++f)
Sriraman Tallam
2016-05-17 17:02:30 UTC
Permalink
Post by Yunlian Jiang
If run dwp command on a binary built without debug fission, it will
cause segmentation
fault. This patch fixes that by exit early if no DWO files information
found inside the
input binary.
gold/
* dwp.cc: (main): exit early when no DWO files information found
in the input binary.
diff --git a/gold/dwp.cc b/gold/dwp.cc
index d8c39c6..c26f969 100644
--- a/gold/dwp.cc
+++ b/gold/dwp.cc
@@ -2436,6 +2436,11 @@ main(int argc, char** argv)
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
}
+ // If there is no DWO files information found in the input binary,
+ // return early to avoid segmentation fault.
Change the comment to maybe "If there are no DWO files, there is
nothing to do."
Post by Yunlian Jiang
+ if (files.size() == 0)
+ return EXIT_SUCCESS;
+
This looks fine to me but I do not have permissions to approve.

Thanks
Sri
Post by Yunlian Jiang
// Process each file, adding its contents to the output file.
Dwp_output_file output_file(output_filename.c_str());
for (File_list::const_iterator f = files.begin(); f != files.end(); ++f)
Yunlian Jiang
2016-05-17 18:51:15 UTC
Permalink
Thanks, updated the patch as follows.

diff --git a/binutils-2.25/gold/dwp.cc b/binutils-2.25/gold/dwp.cc
index 121f37b..9eef68a 100644
--- a/binutils-2.25/gold/dwp.cc
+++ b/binutils-2.25/gold/dwp.cc
@@ -2427,6 +2427,10 @@ main(int argc, char** argv)
if (exe_filename == NULL && files.empty())
gold_fatal(_("no input files and no executable specified"));

+ // If there are no DWO files, there is nothing to do.
+ if (files.empty())
+ return EXIT_SUCCESS;
+
if (verify_only)
{
// Get list of DWO files in the DWP file and compare with
Post by Sriraman Tallam
Post by Yunlian Jiang
If run dwp command on a binary built without debug fission, it will
cause segmentation
fault. This patch fixes that by exit early if no DWO files information
found inside the
input binary.
gold/
* dwp.cc: (main): exit early when no DWO files information found
in the input binary.
diff --git a/gold/dwp.cc b/gold/dwp.cc
index d8c39c6..c26f969 100644
--- a/gold/dwp.cc
+++ b/gold/dwp.cc
@@ -2436,6 +2436,11 @@ main(int argc, char** argv)
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
}
+ // If there is no DWO files information found in the input binary,
+ // return early to avoid segmentation fault.
Change the comment to maybe "If there are no DWO files, there is
nothing to do."
Post by Yunlian Jiang
+ if (files.size() == 0)
+ return EXIT_SUCCESS;
+
This looks fine to me but I do not have permissions to approve.
Thanks
Sri
Post by Yunlian Jiang
// Process each file, adding its contents to the output file.
Dwp_output_file output_file(output_filename.c_str());
for (File_list::const_iterator f = files.begin(); f != files.end(); ++f)
Sriraman Tallam
2016-05-17 18:57:59 UTC
Permalink
Post by Yunlian Jiang
Thanks, updated the patch as follows.
diff --git a/binutils-2.25/gold/dwp.cc b/binutils-2.25/gold/dwp.cc
index 121f37b..9eef68a 100644
--- a/binutils-2.25/gold/dwp.cc
+++ b/binutils-2.25/gold/dwp.cc
@@ -2427,6 +2427,10 @@ main(int argc, char** argv)
if (exe_filename == NULL && files.empty())
gold_fatal(_("no input files and no executable specified"));
+ // If there are no DWO files, there is nothing to do.
+ if (files.empty())
+ return EXIT_SUCCESS;
+
if (verify_only)
{
// Get list of DWO files in the DWP file and compare with
Sorry, I take this back. I see this line

if (exe_filename == NULL && files.empty())
gold_fatal(_("no input files and no executable specified"))

So, do you want to just do :

if (files.empty())
gold_fatal(_("no input files specified"))
Post by Yunlian Jiang
Post by Sriraman Tallam
Post by Yunlian Jiang
If run dwp command on a binary built without debug fission, it will
cause segmentation
fault. This patch fixes that by exit early if no DWO files information
found inside the
input binary.
gold/
* dwp.cc: (main): exit early when no DWO files information found
in the input binary.
diff --git a/gold/dwp.cc b/gold/dwp.cc
index d8c39c6..c26f969 100644
--- a/gold/dwp.cc
+++ b/gold/dwp.cc
@@ -2436,6 +2436,11 @@ main(int argc, char** argv)
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
}
+ // If there is no DWO files information found in the input binary,
+ // return early to avoid segmentation fault.
Change the comment to maybe "If there are no DWO files, there is
nothing to do."
Post by Yunlian Jiang
+ if (files.size() == 0)
+ return EXIT_SUCCESS;
+
This looks fine to me but I do not have permissions to approve.
Thanks
Sri
Post by Yunlian Jiang
// Process each file, adding its contents to the output file.
Dwp_output_file output_file(output_filename.c_str());
for (File_list::const_iterator f = files.begin(); f != files.end(); ++f)
Loading...