* varasm.c (output_object_block_htab): Push each object_block into a vector instead of calling output_object_block. (output_object_block_compare): New. (output_object_blocks): Sort object_blocks and then output them. diff --git a/gcc/varasm.c b/gcc/varasm.c index 18f3eac..008360e 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -7420,22 +7420,57 @@ output_object_block (struct object_block *block) } } -/* A htab_traverse callback used to call output_object_block for - each member of object_block_htab. */ +/* An htab_traverse callback used to copy object_blocks into a vector. */ int -output_object_block_htab (object_block **slot, void *) +output_object_block_htab (object_block **slot, void *data) { - output_object_block (*slot); + vec *v = (vec *) data; + v->safe_push (*slot); return 1; } +/* A callback for qsort to compare object_blocks. We only care about + named sections. */ + +static int +output_object_block_compare (const void *x, const void *y) +{ + object_block *p1 = *(object_block * const*)x; + object_block *p2 = *(object_block * const*)y; + + if (p1->sect->common.flags & SECTION_NAMED + && !(p2->sect->common.flags & SECTION_NAMED)) + return 1; + + if (!(p1->sect->common.flags & SECTION_NAMED) + && p2->sect->common.flags & SECTION_NAMED) + return -1; + + if (p1->sect->common.flags & SECTION_NAMED + && p2->sect->common.flags & SECTION_NAMED) + return strcmp (p1->sect->named.name, + p2->sect->named.name); + + return 0; +} + /* Output the definitions of all object_blocks. */ void output_object_blocks (void) { - object_block_htab->traverse (NULL); + vec v = vNULL; + object_block_htab->traverse (&v); + + /* Sort them in order to output them in a deterministic manner, + otherwise we may get .rodata sections in different orders with + and without -g. */ + v.qsort (output_object_block_compare); + unsigned i; + object_block *obj; + FOR_EACH_VEC_ELT (v, i, obj) + output_object_block (obj); } /* This function provides a possible implementation of the