This is the mail archive of the gcc@gcc.gnu.org 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]

Linux and Windows generate different binaries


I have seen reproducible builds being discussed here, but what is the
position on inter c-lib and OS reproducible builds?

As it happens, I just hit by an interesting case were different OS'es
generate (significant) different code. The difference originate from a
relatively small memory ordering difference in the 'lim2' / tree-ssa-
loop-im  pass". Memory references show something like:

    Memory reference 1: AGC_S_error
    Memory reference 2: AGC_ACC_error
    Memory reference 3: AGC_Coeff
    Memory reference 4: *_35
    Memory reference 5: *_9

Investigation show that a call to qsort() without any tie breaker is
the root-cause:

    static int
    sort_bbs_in_loop_postorder_cmp (const void *bb1_, const void *bb2_)
    {
      basic_block bb1 = *(basic_block *)const_cast<void *>(bb1_);
      basic_block bb2 = *(basic_block *)const_cast<void *>(bb2_);
      struct loop *loop1 = bb1->loop_father;
      struct loop *loop2 = bb2->loop_father;
 ->  fprintf(stderr, "Debug: loop1->num == loop2->num (%d,%d)\n",
                     loop1->num, loop2->num);
      if (loop1->num == loop2->num)
        return 0;
      return bb_loop_postorder[loop1->num] < bb_loop_postorder[loop2-
>num] ? -1 : 1;
    }

The debug statement show (for this test-case) that:

    loop1->num == loop2->num (1,1)
    loop1->num == loop2->num (1,1)
    loop1->num == loop2->num (1,1)
    [...]
    loop1->num == loop2->num (1,1)

... all (loop_father->num)'s are the same and thus the sort_bbs..()
function return 0. This guarantee that qsort shuffle the elements in a
implementation specific way.

Obviously not the best case if you are interested in reproducible
builds (and the qsort() implementation isn't part of your build).


Maybe it is time to add a stable sort?


BR, Klaus




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