jkmcnk / sx-gcc

The GNU Compiler Collection port to NEC SX CPU architecture.
GNU General Public License v2.0
0 stars 2 forks source link

bug in parameter passing on the stack #12

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
consider these two source files:

-- func.c --
#include <stdio.h>

int extern_func(int a)
{
    printf("Hello, I have been compiled with GCC and I say: %d\n", a);

    return a + 42;
}
--

-- func-main.c --
#include <stdlib.h>
#include <stdio.h>

extern int extern_func(int);

int local_func(int r)
{
    printf("Local func says: %d\n", r);

    return 42;
}

int main(int argc, char **argv)
{
    int r = extern_func(42);
    int v = local_func(r);
    printf("Main says: %d\n", v);
}
--

when compiled with gcc, linked with native SX ld and run on v00, they
produce the following, obviously wrong output:

Hello, I have been compiled with GCC and I say: 2048
Local func says: 2560
Main says: 3072

if sources are compiled with native SX cc, I get the correct output:

Hello, I have been compiled with GCC and I say: 42
Local func says: 84
Main says: 42

Original issue reported on code.google.com by jmoc...@gmail.com on 23 Sep 2008 at 12:36

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Bad. This was working before. Will check it.

Original comment by efo...@gmail.com on 23 Sep 2008 at 2:23

GoogleCodeExporter commented 8 years ago
I am still using the glibc includes, but that shouldn't matter...

When I build with the GNU as I get:
{{{
bash-2.05b$ ./func
Hello, I have been compiled with GCC and I say: 2098202624
Local func says: 2098203136
Main says: 2098203648
}}}

whereas when I assemble with sxld I get:
{{{
bash-2.05b$ ./func
Hello, I have been compiled with GCC and I say: 42
Local func says: 84
Main says: 42
}}}

Original comment by efo...@gmail.com on 23 Sep 2008 at 3:10

GoogleCodeExporter commented 8 years ago
Fancy... when I build with GNU as and -O0, I see the messy result. But with -O2 
and 
GNU as thinks look good!!! ???

Original comment by efo...@gmail.com on 23 Sep 2008 at 3:16

Attachments:

GoogleCodeExporter commented 8 years ago
After the fixes to #13 and #14 GAS problems, this works.

{{{
bash-2.05b$ ./func
Hello, I have been compiled with GCC and I say: 42
Local func says: 84
Main says: 42
}}}

Original comment by efo...@gmail.com on 24 Sep 2008 at 1:18