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: RFA: Add an FPIC set of multilibs to the MN10300 port

Nick Clifton wrote:
Hi Jeff, Hi Alex,

I believe that there is a need for a new set of multilibs for the
MN10300 port. The -fpic and -fPIC command line options change the
ABI by making register r6 fixed instead of call_saved. This
resulted in the problem with __main() in crt1.c that I reported
earlier and I now have a test case which demonstrates the problem in
normal C code:
#include <stdlib.h>
#include <stdio.h>

#define array_size 128

    int array[array_size];
    int ascend = 1;

static int comp (const void * _a, const void * _b)
int * a = (int *) _a;
int * b = (int *) _b;

      return ascend ? *a - *b : *b - *a;

int main (void)
int i;

      for (i = array_size; i--;)
        array[i] = i;

qsort (array, array_size, sizeof * array, comp);

      for (i = array_size; i--;)
        if (array[i] != (ascend ? i : (array_size - i) - 1))
          abort ();

      exit (0);

  Compile this program without -fPIC and run it and it will exit
  successfully, compile it with -fPIC and it will seg fault because
  the comp() function will corrupt the value held in register a2 which
  the qsort() library function expects will be preserved.

  I have attached a patch to add a set of pic multilibs.  Please may I
  apply it ?


2008-10-14  Nick Clifton  <>

* config/mn10300/t-mn10300 (MULTILIB_OPTIONS): Add fPIC.
(MULTILIB_MATCHES): New. Treat -fpic as -fPIC.
Something doesn't make sense here. a2 is call-saved and thus a function can reasonably expect its value to be preserved across calls -- which ought to apply to PIC code as well.

So ISTM that if comp is modifying a2 in a way which is visible to qsort, then the problem would be that a2 isn't being saved/restored within comp.

At least that's the way it seems to me and how things work on other ports. Alex -- is there something special in the mn103 ABI for PIC code that I'm not aware of?


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