Different Go packages can have the same package name, but the sorting done when generating export data was only sorting by package name. This could cause nondeterministic output. This patch fixes the problem by extending the sort comparison function. Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed to mainline.
Ian
Index: gcc/go/gofrontend/MERGE =================================================================== --- gcc/go/gofrontend/MERGE (revision 270214) +++ gcc/go/gofrontend/MERGE (working copy) @@ -1,4 +1,4 @@ -a69f7c05f1880bb90544fb0c3577109cb1d7f3ab +8822487ed776d55eafed44de7d89ee54bbfbab47 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. Index: gcc/go/gofrontend/export.cc =================================================================== --- gcc/go/gofrontend/export.cc (revision 270212) +++ gcc/go/gofrontend/export.cc (working copy) @@ -509,7 +509,24 @@ Export::set_type_index(Type* type) static bool packages_compare(const Package* a, const Package* b) { - return a->package_name() < b->package_name(); + if (a->package_name() < b->package_name()) + return true; + else if (a->package_name() > b->package_name()) + return false; + + if (a->pkgpath() < b->pkgpath()) + return true; + else if (a->pkgpath() > b->pkgpath()) + return false; + + // In principle if we get here then a == b. Try to do something sensible + // even if the import information is inconsistent. + if (a->pkgpath_symbol() < b->pkgpath_symbol()) + return true; + else if (a->pkgpath_symbol() > b->pkgpath_symbol()) + return false; + + return a < b; } // Write out all the known packages whose pkgpath symbol is not a