This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] fix PR sanitizer/55617

On Mon, Feb 04, 2013 at 09:22:27AM -0500, Jack Howarth wrote:
>    I switched to the simple insertion of the asan priorities for two reasons...
> 1) Mike seemed unconvinced that the single qsort with the proposed sort_ctor_records
> of...
> +static int
> +sort_ctor_records (const void * a, const void * b)
> +{
> +  const ctor_record *ca = (const ctor_record *)a;
> +  const ctor_record *cb = (const ctor_record *)b;
> +  if (ca->priority > cb->priority)
> +    return 1;
> +  if (ca->priority < cb->priority)
> +    return -1;
> +  if (ca->position > cb->position)
> +    return -1;

Obviously this should have been return 1;

> +  if (ca->position < cb->position)
> +    return 1;

and this return -1;

> +  return 0;
> +}
> would really be stable in absence of a second call to qsort.

Ugh, how can that not be stable?  position is different in every vector
entry, so even the return 0; case above would happen only if qsort
(incorrectly) called it with two same pointers.  So, the second and any
further calls to qsort with the same comparison function in this case
necessarily don't change anything in the array (ok, unless you have more
than 4billion ctors and overflow position, or unless your OS has a buggy
qsort (which wouldn't surprise me for Darwin)).

> 2) Once I realized that darwin sets the default priority of constructors to
> DEFAULT_INIT_PRIORITY 65535, the desired sorting method seemed rather unclear.
> I assume we need to really sort these so that the priorities from 
> MAX_INIT_PRIORITY-1 through 0 appear first in the queue and then those with
> MAX_INIT_PRIORITY, right? It isn't obvious how we can achieve that in
> sort_ctor_record with a single pass through qsort.

??  You simply sort by priority ascending, and for same priorities, by
position ascending.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]