gold patch: fix crash when -static and -shared used together
Cary Coutant
ccoutant@google.com
Tue Oct 7 23:39:00 GMT 2008
If you try to link something with both -static and -shared, gold will
crash trying to print an error message. The crash is caused by error
checking code in queue_middle_tasks that assumes that we're linking
shared because we saw at least one dynamic object, and it tries to
print the name of the first one. This patch adds a check in
General_options::finalize to make sure that -static and -shared are
not both specified, which catches that case early, so that the error
checking in queue_middle_tasks can now safely make that assumption.
Committed as trivial and obvious.
-cary
* options.c (General_options::finalize): Add check for -static and
-shared.
* gold.cc (queue_middle_tasks): Assert that list of dynamic objects
is not empty.
Index: options.cc
===================================================================
RCS file: /cvs/src/src/gold/options.cc,v
retrieving revision 1.77
diff -u -p -r1.77 options.cc
--- options.cc 19 Sep 2008 22:54:57 -0000 1.77
+++ options.cc 7 Oct 2008 23:29:36 -0000
@@ -792,6 +792,9 @@ General_options::finalize()
this->add_sysroot();
// Now that we've normalized the options, check for contradictory ones.
+ if (this->shared() && this->is_static())
+ gold_fatal(_("-shared and -static are incompatible"));
+
if (this->shared() && this->relocatable())
gold_fatal(_("-shared and -r are incompatible"));
Index: gold.cc
===================================================================
RCS file: /cvs/src/src/gold/gold.cc,v
retrieving revision 1.58
diff -u -p -r1.58 gold.cc
--- gold.cc 19 Sep 2008 22:54:57 -0000 1.58
+++ gold.cc 7 Oct 2008 23:29:36 -0000
@@ -203,6 +203,7 @@ queue_middle_tasks(const General_options
if (!doing_static_link && options.is_static())
{
// We print out just the first .so we see; there may be others.
+ gold_assert(input_objects->dynobj_begin() !=
input_objects->dynobj_end());
gold_error(_("cannot mix -static with dynamic object %s"),
(*input_objects->dynobj_begin())->name().c_str());
}
More information about the Binutils
mailing list