From c0ccddb46c11be096ab3b843b5b48104a11a7485 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 23 Aug 2016 17:45:45 +0000 Subject: compiler: revamp scheme for ordering calls to import init fcns. Switch to a new method for determining the order in which import init functions are invoked: build an init fcn dependence DAG and walk the DAG to rewrite/adjust priorities to account for discrepancies introduced by "go test". This patch includes a change to the export data format generated by gccgo. Older versions of gccgo will not be able to read object files produced by a newer gccgo, but the new gcc will still be able to read old object files. Fixes golang/go#15738. Reviewed-on: https://go-review.googlesource.com/25301 From-SVN: r239708 --- gcc/go/gofrontend/export.h | 53 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 11 deletions(-) (limited to 'gcc/go/gofrontend/export.h') diff --git a/gcc/go/gofrontend/export.h b/gcc/go/gofrontend/export.h index c3972d8..ee61d27 100644 --- a/gcc/go/gofrontend/export.h +++ b/gcc/go/gofrontend/export.h @@ -15,6 +15,7 @@ class Import_init; class Bindings; class Type; class Package; +class Import_init_set; // Codes used for the builtin types. These are all negative to make // them easily distinct from the codes assigned by Export::write_type. @@ -47,6 +48,17 @@ enum Builtin_code SMALLEST_BUILTIN_CODE = -21 }; +// Export data version number. New export data is written with the +// "current" version, but there is support for reading files with +// older version export data (at least for now). + +enum Export_data_version { + EXPORT_FORMAT_UNKNOWN = 0, + EXPORT_FORMAT_V1 = 1, + EXPORT_FORMAT_V2 = 2, + EXPORT_FORMAT_CURRENT = EXPORT_FORMAT_V2 +}; + // This class manages exporting Go declarations. It handles the main // loop of exporting. A pointer to this class is also passed to the // various specific export implementations. @@ -103,12 +115,15 @@ class Export : public String_dump Export(Stream*); - // The magic code for version 1 export data. - static const int v1_magic_len = 4; - static const char v1_magic[v1_magic_len]; + // Size of export data magic string (which includes version number). + static const int magic_len = 4; - // The length of the v1 checksum string. - static const int v1_checksum_len = 20; + // Magic strings (current version and older v1 version). + static const char cur_magic[magic_len]; + static const char v1_magic[magic_len]; + + // The length of the checksum string. + static const int checksum_len = 20; // Register the builtin types. void @@ -119,7 +134,6 @@ class Export : public String_dump // is nothing to export, this->stream_->write will not be called. // PREFIX is the package prefix. PKGPATH is the package path. // Only one of PREFIX and PKGPATH will be non-empty. - // PACKAGE_PRIORITY is the priority to use for this package. // PACKAGES is all the packages we have seen. // IMPORTS is the explicitly imported packages. // IMPORT_INIT_FN is the name of the import initialization function @@ -130,11 +144,10 @@ class Export : public String_dump export_globals(const std::string& package_name, const std::string& prefix, const std::string& pkgpath, - int package_priority, const std::map& packages, const std::map& imports, const std::string& import_init_fn, - const std::set& imported_init_fns, + const Import_init_set& imported_init_fns, const Bindings* bindings); // Write a string to the export stream. @@ -166,6 +179,14 @@ class Export : public String_dump void write_escape(std::string* note); + // Write an integer value. + void + write_int(int); + + // Write an unsigned value. + void + write_unsigned(unsigned); + private: Export(const Export&); Export& operator=(const Export&); @@ -174,14 +195,24 @@ class Export : public String_dump void write_packages(const std::map& packages); + typedef std::map > Init_graph; + + static void + add_init_graph_edge(Init_graph* init_graph, unsigned src, unsigned sink); + + static void + populate_init_graph(Init_graph* init_graph, + const Import_init_set& imported_init_fns, + const std::map& init_idx); + // Write out the imported packages. void write_imports(const std::map& imports); - // Write out the imported initialization functions. + // Write out the imported initialization functions and init graph. void - write_imported_init_fns(const std::string& package_name, int priority, - const std::string&, const std::set&); + write_imported_init_fns(const std::string& package_name, + const std::string&, const Import_init_set&); // Register one builtin type. void -- cgit v1.1