2002-05-05 Bruno Haible <bruno@clisp.org>
+ Force link-time references despite optimizations done by g++ 2.95
+ and newer.
+ * include/cln/modules.h (CL_FORCE_LINK): New macro.
+ * Use CL_FORCE_LINK.
+ * include/cln/GV_integer.h (cl_GV_I_debug_dummy): Likewise.
+ * include/cln/GV_number.h (cl_GV_number_debug_dummy): Likewise.
+ * include/cln/SV_number.h (cl_SV_number_debug_dummy): Likewise.
+ * include/cln/SV_ringelt.h (cl_SV_ringelt_debug_dummy): Likewise.
+ * include/cln/dfloat.h (cl_DF_debug_dummy): Likewise.
+ * include/cln/ffloat.h (cl_FF_classes_dummy, cl_FF_debug_dummy):
+ Likewise.
+ * include/cln/integer.h (cl_I_classes_dummy, cl_I_debug_dummy):
+ Likewise.
+ * include/cln/lfloat.h (cl_LF_debug_dummy): Likewise.
+ * include/cln/modinteger.h (cl_MI_debug_dummy): Likewise.
+ * include/cln/rational.h (cl_RA_debug_dummy): Likewise.
+ * include/cln/real.h (cl_R_debug_dummy): Likewise.
+ * include/cln/ring.h (cl_ring_debug_dummy): Likewise.
+ * include/cln/sfloat.h (cl_SF_classes_dummy, cl_SF_classes_dummy):
+ Likewise.
+ * include/cln/string.h (cl_string_debug_dummy): Likewise.
+ * include/cln/univpoly.h (cl_UP_debug_dummy): Likewise.
+ * src/float/base/cl_ieee.h (cl_ieee_dummy_NNN): Likewise.
+
Avoid g++ 3.1 warnings.
* src/base/cl_offsetof.h (offsetof): Redefine each time.
* src/base/digitseq/cl_DS.h: Include "cl_offsetof.h" after <gmp.h>.
// Debugging support.
#ifdef CL_DEBUG
extern int cl_GV_I_debug_module;
-static void* const cl_GV_I_debug_dummy[] = { &cl_GV_I_debug_dummy,
- &cl_GV_I_debug_module
-};
+CL_FORCE_LINK(cl_GV_I_debug_dummy, cl_GV_I_debug_module)
#endif
} // namespace cln
// Debugging support.
#ifdef CL_DEBUG
extern int cl_GV_number_debug_module;
-static void* const cl_GV_number_debug_dummy[] = { &cl_GV_number_debug_dummy,
- &cl_GV_number_debug_module
-};
+CL_FORCE_LINK(cl_GV_number_debug_dummy, cl_GV_number_debug_module)
#endif
} // namespace cln
// Debugging support.
#ifdef CL_DEBUG
extern int cl_SV_number_debug_module;
-static void* const cl_SV_number_debug_dummy[] = { &cl_SV_number_debug_dummy,
- &cl_SV_number_debug_module
-};
+CL_FORCE_LINK(cl_SV_number_debug_dummy, cl_SV_number_debug_module)
#endif
} // namespace cln
// Debugging support.
#ifdef CL_DEBUG
extern int cl_SV_ringelt_debug_module;
-static void* const cl_SV_ringelt_debug_dummy[] = { &cl_SV_ringelt_debug_dummy,
- &cl_SV_ringelt_debug_module
-};
+CL_FORCE_LINK(cl_SV_ringelt_debug_dummy, cl_SV_ringelt_debug_module)
#endif
} // namespace cln
// Debugging support.
#ifdef CL_DEBUG
extern int cl_DF_debug_module;
-static void* const cl_DF_debug_dummy[] = { &cl_DF_debug_dummy,
- &cl_DF_debug_module
-};
+CL_FORCE_LINK(cl_DF_debug_dummy, cl_DF_debug_module)
#endif
} // namespace cln
// Runtime typing support.
extern cl_class cl_class_ffloat;
#ifdef CL_WIDE_POINTERS
-static const void* const cl_FF_classes_dummy[] = { &cl_FF_classes_dummy,
- &cl_class_ffloat
-};
+CL_FORCE_LINK(cl_FF_classes_dummy, cl_class_ffloat)
#endif
// Debugging support.
#ifdef CL_DEBUG
extern int cl_FF_debug_module;
-static void* const cl_FF_debug_dummy[] = { &cl_FF_debug_dummy,
- &cl_FF_debug_module
-};
+CL_FORCE_LINK(cl_FF_debug_dummy, cl_FF_debug_module)
#endif
} // namespace cln
// Runtime typing support.
extern cl_class cl_class_fixnum;
extern cl_class cl_class_bignum;
-static const void* const cl_I_classes_dummy[] = { &cl_I_classes_dummy,
- &cl_class_fixnum
-};
+CL_FORCE_LINK(cl_I_classes_dummy, cl_class_fixnum)
// Debugging support.
#ifdef CL_DEBUG
extern int cl_I_debug_module;
-static void* const cl_I_debug_dummy[] = { &cl_I_debug_dummy,
- &cl_I_debug_module
-};
+CL_FORCE_LINK(cl_I_debug_dummy, cl_I_debug_module)
#endif
} // namespace cln
// Debugging support.
#ifdef CL_DEBUG
extern int cl_LF_debug_module;
-static void* const cl_LF_debug_dummy[] = { &cl_LF_debug_dummy,
- &cl_LF_debug_module
-};
+CL_FORCE_LINK(cl_LF_debug_dummy, cl_LF_debug_module)
#endif
} // namespace cln
// Debugging support.
#ifdef CL_DEBUG
extern int cl_MI_debug_module;
-static void* const cl_MI_debug_dummy[] = { &cl_MI_debug_dummy,
- &cl_MI_debug_module
-};
+CL_FORCE_LINK(cl_MI_debug_dummy, cl_MI_debug_module)
#endif
} // namespace cln
#define CL_REQUIRE(module)
#endif
+// Sometimes a link time dependency is needed, but without requirements
+// on initialization order.
+//
+// CL_FORCE_LINK(dummy,external_variable)
+// forces a link time reference to the external_variable.
+#include <stdlib.h>
+#if 0
+// This definition does not work. It gets optimized away by g++ 3.1.
+#define CL_FORCE_LINK(dummy,external_variable) \
+ static const void* const dummy[] = { &dummy, &external_variable };
+#else
+#define CL_FORCE_LINK(dummy,external_variable) \
+ static const \
+ struct dummy { \
+ inline dummy () { \
+ if ((void*) &external_variable == (void*) this) \
+ abort(); \
+ } \
+ } \
+ dummy##_instance;
+#endif
+
#endif /* _CL_MODULES_H */
// Debugging support.
#ifdef CL_DEBUG
extern int cl_RA_debug_module;
-static void* const cl_RA_debug_dummy[] = { &cl_RA_debug_dummy,
- &cl_RA_debug_module
-};
+CL_FORCE_LINK(cl_RA_debug_dummy, cl_RA_debug_module)
#endif
} // namespace cln
// Debugging support.
#ifdef CL_DEBUG
extern int cl_R_debug_module;
-static void* const cl_R_debug_dummy[] = { &cl_R_debug_dummy,
- &cl_R_debug_module
-};
+CL_FORCE_LINK(cl_R_debug_dummy, cl_R_debug_module)
#endif
} // namespace cln
// Debugging support.
#ifdef CL_DEBUG
extern int cl_ring_debug_module;
-static void* const cl_ring_debug_dummy[] = { &cl_ring_debug_dummy,
- &cl_ring_debug_module
-};
+CL_FORCE_LINK(cl_ring_debug_dummy, cl_ring_debug_module)
#endif
} // namespace cln
// Runtime typing support.
extern cl_class cl_class_sfloat;
-static const void* const cl_SF_classes_dummy[] = { &cl_SF_classes_dummy,
- &cl_class_sfloat
-};
+CL_FORCE_LINK(cl_SF_classes_dummy, cl_class_sfloat)
// Debugging support.
#ifdef CL_DEBUG
extern int cl_SF_debug_module;
-static void* const cl_SF_debug_dummy[] = { &cl_SF_debug_dummy,
- &cl_SF_debug_module
-};
+CL_FORCE_LINK(cl_SF_debug_dummy, cl_SF_debug_module)
#endif
} // namespace cln
// Debugging support.
#ifdef CL_DEBUG
extern int cl_string_debug_module;
-static void* const cl_string_debug_dummy[] = { &cl_string_debug_dummy,
- &cl_string_debug_module
-};
+CL_FORCE_LINK(cl_string_debug_dummy, cl_string_debug_module)
#endif
} // namespace cln
// Debugging support.
#ifdef CL_DEBUG
extern int cl_UP_debug_module;
-static void* const cl_UP_debug_dummy[] = { &cl_UP_debug_dummy,
- &cl_UP_debug_module
-};
+CL_FORCE_LINK(cl_UP_debug_dummy, cl_UP_debug_module)
#endif
} // namespace cln
#if (defined(linux) || defined(__linux)) // only needed on Linux
#define NEED_IEEE_FLOATS() \
CL_REQUIRE(cl_ieee) \
- static void* const CONCAT(cl_ieee_dummy_,__LINE__) = &cl_ieee_module;
+ CL_FORCE_LINK(CONCAT(cl_ieee_dummy_,__LINE__), cl_ieee_module)
#else
#define NEED_IEEE_FLOATS()
#endif