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]

RE: mips va_arg question


> -----Original Message-----
> From: gcc-owner On Behalf Of Mile Davidovic
> Sent: 12 August 2004 13:56

> Thanks a lot.
> 
> This code is little snapshots from pretty large SW
> with underlaying RTOS and we have problem with calling
> function with variable number of arguments from
> threads. 
> 
> I am very thankfull for Your effort. 


  It is sometimes a problem with some combinations of CPU, OS and C
library/runtime, that the stack pointer doesn't acquire the correct aligment
when a new thread is started.

  The compiler always makes functions adjust the stack pointer by a multiple
of the aligment, so it guarantees that if the code starts off executing with
an aligned stack, it will stay aligned, but the compiler has no control over
how the OS initialises the state of a new thread and whether or not it
aligns the initial value of the SP correctly.

  For example, in once case I came across, the first thread in a process is
setup with a correctly aligned stack but subsequent threads spawned by the
application itself have unaligned stacks.

  So the answer to your problem may well be that when you spawn a thread, it
should be started at an asm wrapper function that adjusts the stack aligment
as needed and then calls out to the actual C language function you wanted;
from that point on the stack will stay aligned.


    cheers, 
      DaveK
-- 
Can't think of a witty .sigline today....


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