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]

Function Prologue and epilogue


Dear friends:

 I have some questions about GCC. I appreciate any suggestions about
these questions. Thanks.

 (1)
  As we know, under X86 processor each function compiled by gcc 
will have the following function prologue and epilogue.(the 
version I used is gcc 2.95.2 )
         
   pushl %ebp
   movl %esp,%ebp    <---- function prologue
   pushl %ebx
       :
       :
   movl %ebp,%esp
   popl %ebp         <---- function epilogue
   ret 
 
 Now I want to add some instrutions into each prologue and epilogue
, so the new ones will be as follows:

   ( new added instructions )  --|      
   pushl %ebp                    |
   movl %esp,%ebp                | <---- function prologue
   pushl %ebx                  --|
       :
       :
   movl %ebp,%esp
   popl %ebp         <---- function epilogue
   ( new added instructions)
   ret 

 According to GNU's document 
  (http://www.gnu.org/software/gcc/onlinedocs/gcc_17.html), I could
accomplish this by modifying the following two functions,
function_prologue() and function_epilogue. In file "i386.c" I found
these two functions. But when I added the instructions,  compiled
the modified gcc, used the new gcc to compiled a c program and used
gdb to see the result, I can not find the new added instructions in
prologue and epilogue. In fact in function_epilogue(), there is only
one c statement, "return". 

 Does any one know where is the correct place to add the 
instructions?

(2)
    I created 3 files, fi1, fi2, fi3. Each file has only one global
initialized variable. glb1 is the global initialized
variable of file fi1. glb2 and glb3 are the global initialized
varibales of fi2 and fi3 respectively. If I compile the 3 files
in the following way, "gcc fi1 fi2 fi3", using gdb I found
these 3 variables are arranged in the following order in memory,
glb1 glb2 glb3. glb1 has the lowest address. Similarly if I compile
in the following way, gcc fi3 fi1 fi2, they are arranged in the 
following order, glb3 glb1 glb2. 

 Does gcc always allocate addresses for global initialized variables
according to the file order, in which the variables are difined,  in
the command line? (ie. Does global initialized variable in the files
appearing earlier in the command line will be assigned lower addresses
in the virtual memory address space?)


                                 Vito Hsu

    
            
 


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