Problems using -mrtd and -mshort for m68k
Scott Howard
scott@objsw.com
Mon Feb 1 23:08:00 GMT 1999
Hi,
this may be a bug in the m68k machine description for gcc.
In order to confirm it, can you please re-run your compile and link
commands, but add the option '-v' to the each of the command lines, to
generate a verbose listing of the compiler's activity; and then please
post the output to the list.
Until we get this sorted out, the safest option is to not use -mshort or
-mrtd.
This is very surprising. These two options have existed in gcc for a
long time. Thanks for your great detective work!
Scott
scott@objsw.com
Arjan Koers wrote:
>
> Hi All,
>
> I am using GNU GCC (from objsw.com) to build a library
> that can be loaded into an embedded 68340 system. The software on
> this system is using Pascal calling conventions.
>
> The closest I could get to Pascal calling conventions with GCC is by
> using the -mrtd option when compiling:
> gcc -b 68k -mcpu32 -mshort -mrtd -c -o file.o file.c
> The order of the arguments on the stack is still wrong, but I can
> live with that.
>
> GCC does not use the -mrtd calling convention for all functions that
> get called.
> My own functions get called with the -mrtd calling convention, and
> library functions like strcpy and sin too (called function pops
> arguments from stack).
> Functions like __floatsidf are not called with this calling
> convention (calling function pops arguments from stack).
>
> With and without the -mrtd option, the asm output of the function
> call looks something like this (argument is popped after call):
> x = (double)i;
> 3001e: 306e 0008 moveaw %fp@(8),%a0
> 30022: 2f08 movel %a0,%sp@-
> 30024: 4eb9 0003 0050 jsr 30050 <__floatsidf>
> 3002a: 588f addql #4,%sp
> 3002c: 2d40 fff8 movel %d0,%fp@(-8)
> 30030: 2d41 fffc movel %d1,%fp@(-4)
>
> The linked __floatsidf function is as expected:
>
> gcc -b 68k -mcpu32 -mshort -mrtd -Tlinkfile.ld -o file.cof file.o
> 00030050 <__floatsidf>:
> 30050: 4e56 0000 linkw %fp,#0
> ....
> 300ca: 4e5e unlk %fp
> 300aa: 4e74 0004 rtd #4
>
> gcc -b 68k -mcpu32 -mshort -Tlinkfile.ld -o file.cof file.o
> 00030050 <__floatsidf>:
> 30050: 4e56 0000 linkw %fp,#0
> ....
> 300ca: 4e5e unlk %fp
> 300cc: 4e75 rts
>
> When linking with -mrtd, the stack gets corrupted: The function
> arguments are popped twice for __floatsidf.
> When linking without -mrtd, the stack gets corrupted too: The
> function arguments aren't popped for strcpy.
>
> Is there a solution to this problem that does not involve
> editing asm intermediate files?
>
> A call to strcpy is changed to a call to bcopy if optimisation is
> turned on and the string is long enough. The stack gets corrupted
> again:
>
> strcpy(pch, "Testing my 'Hello World!' string");
> 30044: 3f3c 0021 movew #33,%sp@-
> 30048: 2f02 movel %d2,%sp@-
> 3004a: 487a ffc4 pea %pc@(30010 <.text>)
> 3004e: 4eb9 0003 0064 jsr 30064 <bcopy>
>
> 00030064 <bcopy>:
> 30064: 4e56 0000 linkw %fp,#0
> 30068: 2f2e 0010 movel %fp@(16),%sp@-
> 3006c: 2f2e 0008 movel %fp@(8),%sp@-
> 30070: 2f2e 000c movel %fp@(12),%sp@-
> 30074: 4eb9 0003 0080 jsr 30080 <memmove>
> 3007a: 4e5e unlk %fp
> 3007c: 4e74 000c rtd #12
>
> I can solve this by replacing 'movew #33,%sp@-' by 'movel #33,%sp@-',
> but I would like to fix this without having to edit the intermediate
> asm files. Another solution is not using the -mshort option, but
> the int size preferably is 16-bit.
>
> Thanks,
>
> Arjan Koers.
> _______________________________________________
> New CrossGCC FAQ: http://www.objsw.com/CrossGCC
> _______________________________________________
> To remove yourself from the crossgcc list, send
> mail to crossgcc-request@cygnus.com with the
> text 'unsubscribe' (without the quotes) in the
> body of the message.
_______________________________________________
New CrossGCC FAQ: http://www.objsw.com/CrossGCC
_______________________________________________
To remove yourself from the crossgcc list, send
mail to crossgcc-request@cygnus.com with the
text 'unsubscribe' (without the quotes) in the
body of the message.
More information about the crossgcc
mailing list