debug-early branch merged into mainline
diff mbox

Message ID 5576B4E9.4020800@redhat.com
State New
Headers show

Commit Message

Aldy Hernandez June 9, 2015, 9:42 a.m. UTC
On 06/09/2015 04:00 AM, Richard Biener wrote:
> On Mon, Jun 8, 2015 at 10:25 PM, Aldy Hernandez <aldyh@redhat.com> wrote:
>> On 06/08/2015 02:59 PM, Richard Biener wrote:
>>>
>>> On June 8, 2015 7:14:19 PM GMT+02:00, Aldy Hernandez <aldyh@redhat.com>
>>> wrote:
>>>>
>>>> On 06/08/2015 09:30 AM, Richard Biener wrote:
>>>>>
>>>>> On Mon, Jun 8, 2015 at 2:05 PM, Aldy Hernandez <aldyh@redhat.com>
>>>>
>>>> wrote:
>>>>>>
>>>>>> On 06/08/2015 04:26 AM, Richard Biener wrote:
>>>>>>>
>>>>>>>
>>>>>>> On Mon, Jun 8, 2015 at 3:23 AM, Aldy Hernandez <aldyh@redhat.com>
>>
>>
>>>> What about if the comparison routine gets a named section and an
>>>> unnamed
>>>> section?  How to compare?  That's why I was giving priority to one over
>>>>
>>>> the other originally, but I didn't know about problematic qsort
>>>> implementations.
>>>
>>>
>>> Obviously unnamed and a named section can be sorted like you did in the
>>> original patch.
>>
>>
>> Obviously I'm not understanding :).
>>
>> How about this?
>
> Ok with adding

I've committed the attached patch.

>
> v.create (object_block_htab->elements ());
>
> and using v.quick_push () (avoids re-allocations)
>
> and with adding a
>
> v.release ();

For some reason I thought the new C++ vector world released stuff on its 
own if allocated on the heap.  Oh well...

Thanks.
Aldy
commit d2f1a9cd6e91c400ab4fa569565eece1ae08b64d
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Tue Jun 9 05:39:34 2015 -0400

    	* varasm.c (output_object_block_htab): Remove.
    	(output_object_block_compare): New.
    	(output_object_blocks): Sort named object_blocks before outputting
    	them.

Patch
diff mbox

diff --git a/gcc/varasm.c b/gcc/varasm.c
index 18f3eac..86a70db 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -7420,14 +7420,31 @@  output_object_block (struct object_block *block)
     }
 }
 
-/* A htab_traverse callback used to call output_object_block for
-   each member of object_block_htab.  */
+/* A callback for qsort to compare object_blocks.  */
 
-int
-output_object_block_htab (object_block **slot, void *)
+static int
+output_object_block_compare (const void *x, const void *y)
 {
-  output_object_block (*slot);
-  return 1;
+  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);
+
+  unsigned f1 = p1->sect->common.flags;
+  unsigned f2 = p2->sect->common.flags;
+  if (f1 == f2)
+    return 0;
+  return f1 < f2 ? -1 : 1;
 }
 
 /* Output the definitions of all object_blocks.  */
@@ -7435,7 +7452,23 @@  output_object_block_htab (object_block **slot, void *)
 void
 output_object_blocks (void)
 {
-  object_block_htab->traverse<void *, output_object_block_htab> (NULL);
+  vec<object_block *, va_heap> v;
+  v.create (object_block_htab->elements ());
+  object_block *obj;
+  hash_table<object_block_hasher>::iterator hi;
+
+  FOR_EACH_HASH_TABLE_ELEMENT (*object_block_htab, obj, object_block *, hi)
+    v.quick_push (obj);
+
+  /* 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;
+  FOR_EACH_VEC_ELT (v, i, obj)
+    output_object_block (obj);
+
+  v.release ();
 }
 
 /* This function provides a possible implementation of the