Index: common.cc =================================================================== RCS file: /cvs/src/src/gold/common.cc,v retrieving revision 1.28 diff -u -r1.28 common.cc --- common.cc 8 Jun 2011 04:43:28 -0000 1.28 +++ common.cc 27 Sep 2011 22:11:53 -0000 @@ -253,10 +253,6 @@ if (!any) return; - // Sort the common symbols. - std::sort(commons->begin(), commons->end(), - Sort_commons(this, sort_order)); - // Place them in a newly allocated BSS section. elfcpp::Elf_Xword flags = elfcpp::SHF_WRITE | elfcpp::SHF_ALLOC; const char* name; @@ -303,14 +299,23 @@ os = layout->find_output_section(name); } - if (os != NULL) + // Do not allocate the common symbols if the output section has been + // discarded. + if (os == NULL) { - if (commons_section_type == COMMONS_SMALL) - os->set_is_small_section(); - else if (commons_section_type == COMMONS_LARGE) - os->set_is_large_section(); + commons->clear(); + return; } + if (commons_section_type == COMMONS_SMALL) + os->set_is_small_section(); + else if (commons_section_type == COMMONS_LARGE) + os->set_is_large_section(); + + // Sort the common symbols. + std::sort(commons->begin(), commons->end(), + Sort_commons(this, sort_order)); + // Allocate them all. off_t off = 0;