[gappa] Add patch to fix order of execution of static initializers.

Jerry James jjames at fedoraproject.org
Fri Mar 18 20:34:41 UTC 2011


commit 560e940374ab7229fbcdf60a5a914fb679100108
Author: Jerry James <loganjerry at gmail.com>
Date:   Fri Mar 18 14:33:58 2011 -0600

    Add patch to fix order of execution of static initializers.

 gappa-init-order.patch |  241 ++++++++++++++++++++++++++++++++++++++++++++++++
 gappa.spec             |    8 ++
 2 files changed, 249 insertions(+), 0 deletions(-)
---
diff --git a/gappa-init-order.patch b/gappa-init-order.patch
new file mode 100644
index 0000000..756317f
--- /dev/null
+++ b/gappa-init-order.patch
@@ -0,0 +1,241 @@
+--- ./src/backends/backend.cpp.orig	2010-04-20 10:12:33.000000000 -0600
++++ ./src/backends/backend.cpp	2011-03-18 14:00:10.041737295 -0600
+@@ -14,7 +14,7 @@
+ std::ostream *out;
+ 
+ typedef std::map< std::string, backend * > backend_map;
+-static backend_map backends;
++static backend_map backends __attribute__((init_priority(110)));
+ 
+ backend::backend(std::string const &name) {
+   backends[name] = this;
+--- ./src/backends/holl.cpp.orig	2010-04-20 10:12:49.000000000 -0600
++++ ./src/backends/holl.cpp	2011-03-18 14:00:10.042737330 -0600
+@@ -410,4 +410,4 @@
+   return name.str();
+ }
+ 
+-static struct holl_backend dummy;
++static struct holl_backend dummy __attribute__((init_priority(120)));
+--- ./src/backends/coq.cpp.orig	2010-10-05 09:30:19.000000000 -0600
++++ ./src/backends/coq.cpp	2011-03-18 14:00:10.042737330 -0600
+@@ -541,4 +541,4 @@
+   return name;
+ }
+ 
+-static struct coq_backend dummy;
++static struct coq_backend dummy __attribute__((init_priority(120)));
+--- ./src/backends/coq_lambda.cpp.orig	2010-10-05 05:03:34.000000000 -0600
++++ ./src/backends/coq_lambda.cpp	2011-03-18 14:00:10.043737363 -0600
+@@ -766,4 +766,4 @@
+   return s;
+ }
+ 
+-static struct coq_lambda_backend dummy;
++static struct coq_lambda_backend dummy __attribute__((init_priority(120)));
+--- ./src/proofs/schemes.cpp.orig	2010-04-20 10:14:32.000000000 -0600
++++ ./src/proofs/schemes.cpp	2011-03-18 14:00:10.044737394 -0600
+@@ -30,7 +30,7 @@
+ struct scheme_factories: std::vector< scheme_factory const * > {
+   ~scheme_factories() { for(iterator i = begin(), i_end = end(); i != i_end; ++i) delete *i; }
+ };
+-static scheme_factories factories;
++static scheme_factories factories __attribute__((init_priority(110)));
+ 
+ scheme_factory::scheme_factory(predicated_real const &r): target(r) {
+   factories.push_back(this);
+--- ./src/proofs/rewriting.cpp.orig	2010-04-20 10:14:26.000000000 -0600
++++ ./src/proofs/rewriting.cpp	2011-03-18 14:00:10.044737394 -0600
+@@ -169,7 +169,7 @@
+ }
+ 
+ // REWRITING_RULE
+-rewriting_vect rewriting_rules;
++rewriting_vect rewriting_rules __attribute__((init_priority(110)));
+ 
+ rewriting_rule::rewriting_rule
+   (ast_real const *r1, ast_real const *r2, std::string const &n,
+@@ -204,7 +204,7 @@
+   return res;
+ }
+ 
+-static pattern a(0), b(1), c(2), d(3), a_b(-1), one(token_one);
++static pattern __attribute__((init_priority(130))) a(0), b(1), c(2), d(3), a_b(-1), one(token_one);
+ 
+ #define abs pattern::abs
+ #define sqrt pattern::sqrt
+@@ -213,16 +213,16 @@
+ #define REWRITING_NAME BOOST_PP_CAT(rewriting_rule_,__LINE__)
+ 
+ #define REWRITE(name,lhs,rhs) \
+-  static rewriting_rule REWRITING_NAME \
++  static rewriting_rule __attribute__((init_priority(140))) REWRITING_NAME \
+   (lhs, rhs, #name, pattern_cond_vect(), pattern_excl_vect())
+ #define REWRIT3(name,lhs,rhs,cond) \
+-  static rewriting_rule REWRITING_NAME \
++  static rewriting_rule __attribute__((init_priority(140))) REWRITING_NAME \
+   (lhs, rhs, #name, pattern_cond_vect() && cond, pattern_excl_vect())
+ #define REWRITe(name,lhs,rhs,excl) \
+-  static rewriting_rule REWRITING_NAME \
++  static rewriting_rule __attribute__((init_priority(140))) REWRITING_NAME \
+   (lhs, rhs, #name, pattern_cond_vect(), pattern_excl_vect() && excl)
+ #define REWRIT9(name,lhs,rhs,cond,excl) \
+-  static rewriting_rule REWRITING_NAME \
++  static rewriting_rule __attribute__((init_priority(140))) REWRITING_NAME \
+   (lhs, rhs, #name, pattern_cond_vect() && cond, pattern_excl_vect() && excl)
+ 
+ /*
+--- ./src/utils.hpp.orig	2010-04-20 10:12:16.000000000 -0600
++++ ./src/utils.hpp	2011-03-18 14:01:05.967744860 -0600
+@@ -17,4 +17,9 @@
+   static class_##name dummy_##name; \
+   class_##name::class_##name()
+ 
++#define RUN_ONCE_PRI(name,pri) \
++  struct class_##name { class_##name(); }; \
++  static class_##name dummy_##name __attribute__((init_priority(pri))); \
++  class_##name::class_##name()
++
+ #endif // UTILS_HPP
+--- ./src/parser/ast.cpp.orig	2010-04-20 10:13:16.000000000 -0600
++++ ./src/parser/ast.cpp	2011-03-18 14:01:27.727745964 -0600
+@@ -22,7 +22,8 @@
+ 
+ extern std::string get_real_split(number const &f, int &exp, bool &zero);
+ extern bool parameter_rfma;
+-link_map accurates, approximates;
++link_map accurates __attribute__((init_priority(110)));
++link_map approximates __attribute__((init_priority(110)));
+ 
+ template< class T >
+ class cache {
+@@ -102,11 +103,11 @@
+   }  
+ }
+ 
+-static cache< ast_ident > ast_ident_cache;
++static cache< ast_ident > ast_ident_cache __attribute__((init_priority(110)));
+ ast_ident *ast_ident::find(std::string const &s) { return ast_ident_cache.find(ast_ident(s)); }
+-static cache< ast_number > ast_number_cache;
++static cache< ast_number > ast_number_cache __attribute__((init_priority(110)));
+ ast_number *normalize(ast_number const &v) { return ast_number_cache.find(v); }
+-static cache< ast_real > ast_real_cache;
++static cache< ast_real > ast_real_cache __attribute__((init_priority(110)));
+ ast_real *normalize(ast_real const &v) {
+   bool b;
+   ast_real *p = ast_real_cache.find(v, &b);
+@@ -121,7 +122,7 @@
+ 
+ ast_number const *token_zero, *token_one;
+ 
+-RUN_ONCE(load_numbers) {
++RUN_ONCE_PRI(load_numbers,120) {
+   ast_number num;
+   num.base = 0;
+   num.exponent = 0;
+--- ./src/arithmetic/relative.cpp.orig	2010-04-20 10:12:30.000000000 -0600
++++ ./src/arithmetic/relative.cpp	2011-03-18 14:00:10.045737423 -0600
+@@ -107,7 +107,7 @@
+   return &j->second;
+ }
+ 
+-static relative_function_generator dummy_add("add_rel", BOP_ADD);
+-static relative_function_generator dummy_sub("sub_rel", BOP_SUB);
+-static relative_function_generator dummy_mul("mul_rel", BOP_MUL);
+-static relative_function_generator dummy_fma("fma_rel", COP_FMA);
++static relative_function_generator __attribute__((init_priority(120))) dummy_add("add_rel", BOP_ADD);
++static relative_function_generator __attribute__((init_priority(120))) dummy_sub("sub_rel", BOP_SUB);
++static relative_function_generator __attribute__((init_priority(120))) dummy_mul("mul_rel", BOP_MUL);
++static relative_function_generator __attribute__((init_priority(120))) dummy_fma("fma_rel", COP_FMA);
+--- ./src/arithmetic/homogen.cpp.orig	2010-04-20 10:12:26.000000000 -0600
++++ ./src/arithmetic/homogen.cpp	2011-03-18 14:00:10.046737450 -0600
+@@ -35,7 +35,7 @@
+   return i * he;
+ }
+ 
+-static homogen_rounding_class dummy;
++static homogen_rounding_class dummy __attribute__((init_priority(120)));
+ 
+ struct homogen_init_rounding_class: function_class
+ {
+@@ -57,7 +57,7 @@
+   return i * he;
+ }
+ 
+-static homogen_init_rounding_class dummy_init;
++static homogen_init_rounding_class dummy_init __attribute__((init_priority(120)));
+ 
+ struct floatx_rounding_class: function_class {
+   default_function_generator generator;
+@@ -83,4 +83,4 @@
+   return interval(a, b);
+ }
+ 
+-static floatx_rounding_class dummy2;
++static floatx_rounding_class dummy2 __attribute__((init_priority(120)));
+--- ./src/arithmetic/fixed.cpp.orig	2010-10-05 09:20:24.000000000 -0600
++++ ./src/arithmetic/fixed.cpp	2011-03-18 14:00:10.046737450 -0600
+@@ -100,7 +100,7 @@
+   return generate(get_direction(p[1]), min_exp);
+ }
+ 
+-static fixed_rounding_generator dummy;
++static fixed_rounding_generator dummy __attribute__((init_priority(120)));
+ 
+ struct int_rounding_generator: function_generator {
+   int_rounding_generator(): function_generator("int") {}
+@@ -112,7 +112,7 @@
+   return fixed_rounding_generator::generate(get_direction(p[0]), 0);
+ }
+ 
+-static int_rounding_generator dummy2;
++static int_rounding_generator dummy2 __attribute__((init_priority(120)));
+ 
+ // FIX_OF_FIXED
+ REGISTER_SCHEME_BEGIN(fix_of_fixed);
+--- ./src/arithmetic/float.cpp.orig	2010-10-05 09:20:07.000000000 -0600
++++ ./src/arithmetic/float.cpp	2011-03-18 14:01:46.458748085 -0600
+@@ -31,12 +31,12 @@
+ };
+ 
+ typedef std::map< ast_ident const *, float_format > float_formats;
+-static float_formats formats;
++static float_formats formats __attribute__((init_priority(110)));
+ 
+ #define REGISTER_FORMAT(name, e, p) \
+   formats.insert(std::make_pair(ast_ident::find(#name), float_format(e, p)))
+ 
+-RUN_ONCE(register_formats) {
++RUN_ONCE_PRI(register_formats,120) {
+   REGISTER_FORMAT(ieee_32 ,   -149,  24);
+   REGISTER_FORMAT(ieee_64 ,  -1074,  53);
+   REGISTER_FORMAT(ieee_128, -16494, 113);
+@@ -100,7 +100,7 @@
+   return &j->second;
+ }
+ 
+-static float_rounding_generator dummy;
++static float_rounding_generator dummy __attribute__((init_priority(120)));
+ 
+ interval float_rounding_class::enforce(interval const &i, std::string &name) const {
+   number a = round_number(lower(i), &format, &float_format::roundUP);
+--- ./src/numbers/round.cpp.orig	2010-04-20 10:13:12.000000000 -0600
++++ ./src/numbers/round.cpp	2011-03-18 14:02:34.687752043 -0600
+@@ -113,7 +113,7 @@
+ }
+ 
+ typedef std::map< ast_ident const *, direction_type > rounding_directions;
+-static rounding_directions directions;
++static rounding_directions directions __attribute__((init_priority(110)));
+ rounding_fun direction_functions[nb_directions];
+ char const *direction_names[nb_directions];
+ 
+@@ -122,7 +122,7 @@
+   direction_functions[ROUND_##type] = &gs_rounding::round##type; \
+   direction_names[ROUND_##type] = #name
+ 
+-RUN_ONCE(register_directions) {
++RUN_ONCE_PRI(register_directions,120) {
+   REGISTER_DIRECTION(up, UP);
+   REGISTER_DIRECTION(dn, DN);
+   REGISTER_DIRECTION(zr, ZR);
diff --git a/gappa.spec b/gappa.spec
index 3c3ff59..98dd3aa 100644
--- a/gappa.spec
+++ b/gappa.spec
@@ -10,6 +10,8 @@ Source0:	https://gforge.inria.fr/frs/download.php/27654/gappa-%{version}.tar.gz
 Source1:	http://gappa.gforge.inria.fr/gappa.pdf
 # Tell flex not to generate the unused unput() function.
 Patch0:         gappa-nounput.patch
+# Fix an order-of-initialization bug with static initializers
+Patch1:         gappa-init-order.patch
 
 BuildRequires:	gmp-devel, mpfr-devel, boost-devel, flex, bison
 
@@ -28,10 +30,16 @@ written by Guillaume Melquiond.
 %setup -q
 cp -p %SOURCE1 .
 %patch0
+%patch1
 
 # Regenerate the flex and bison files
 rm -f src/parser/lexer.cpp src/parser/parser.cpp src/parser/parser.h
 
+# Help the debuginfo generator find the flex and bison files
+ln -s parser/lexer.cpp src/lexer.cpp
+ln -s parser/lexer.lpp src/lexer.lpp
+ln -s parser/parser.cpp src/parser.cpp
+ln -s parser/parser.ypp src/parser.ypp
 
 %build
 %configure


More information about the scm-commits mailing list