===================================================================
@@ -89,7 +89,14 @@ typedef struct GTY(()) ctor_record {
int position; /* original position */
} ctor_record;
+typedef struct GTY(()) dtor_record {
+ rtx symbol;
+ int priority; /* destructor priority */
+ int position; /* original position */
+} dtor_record;
+
static GTY(()) vec<ctor_record, va_gc> *ctors = NULL;
+static GTY(()) vec<dtor_record, va_gc> *dtors = NULL;
/* A flag to determine whether we are running c++ or obj-c++. This has to be
settable from non-c-family contexts too (i.e. we can't use the c_dialect_
@@ -1724,6 +1731,17 @@ machopic_asm_out_constructor (rtx symbol
fprintf (asm_out_file, ".reference .constructors_used\n");
}
+void
+machopic_asm_out_destructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
+{
+ dtor_record new_elt = {symbol, priority, vec_safe_length (dtors)};
+
+ vec_safe_push (dtors, new_elt);
+
+ if (! MACHOPIC_INDIRECT)
+ fprintf (asm_out_file, ".reference .destructors_used\n");
+}
+
static int
sort_ctor_records (const void * a, const void * b)
{
@@ -1740,6 +1758,22 @@ sort_ctor_records (const void * a, const
return 0;
}
+static int
+sort_dtor_records (const void * a, const void * b)
+{
+ const dtor_record *da = (const dtor_record *)a;
+ const dtor_record *db = (const dtor_record *)b;
+ if (da->priority > db->priority)
+ return 1;
+ if (da->priority < db->priority)
+ return -1;
+ if (da->position > db->position)
+ return 1;
+ if (da->position < db->position)
+ return -1;
+ return 0;
+}
+
static void
finalize_ctors()
{
@@ -1760,18 +1794,24 @@ finalize_ctors()
}
}
-void
-machopic_asm_out_destructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
+static void
+finalize_dtors()
{
+ unsigned int i;
+ dtor_record *elt;
+
if (MACHOPIC_INDIRECT)
switch_to_section (darwin_sections[mod_term_section]);
else
switch_to_section (darwin_sections[destructor_section]);
- assemble_align (POINTER_SIZE);
- assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
- if (! MACHOPIC_INDIRECT)
- fprintf (asm_out_file, ".reference .destructors_used\n");
+ if (vec_safe_length (dtors) > 1)
+ dtors->qsort (sort_dtor_records);
+ FOR_EACH_VEC_SAFE_ELT (dtors, i, elt)
+ {
+ assemble_align (POINTER_SIZE);
+ assemble_integer (elt->symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
+ }
}
void
@@ -2805,6 +2845,8 @@ darwin_file_end (void)
{
if (!vec_safe_is_empty (ctors))
finalize_ctors();
+ if (!vec_safe_is_empty (dtors))
+ finalize_dtors();
machopic_finish (asm_out_file);
if (strcmp (lang_hooks.name, "GNU C++") == 0)
{