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 ?
Cheers
Nick
gcc/ChangeLog
2008-10-14 Nick Clifton <nickc@redhat.com>
* config/mn10300/t-mn10300 (MULTILIB_OPTIONS): Add fPIC.
(MULTILIB_DIRNAMES): Add pic.
(MULTILIB_MATCHES): New. Treat -fpic as -fPIC.