explaination of trampoline

kernel coder lhrkernelcoder@gmail.com
Wed Sep 27 11:10:00 GMT 2006


I was just investigating the trampoline implementation.I have defined
following macros in machine.h file.


#define TRAMPOLINE_SIZE (32 + GET_MODE_SIZE (ptr_mode) * 2)
#define TRAMPOLINE_ALIGNMENT GET_MODE_BITSIZE (ptr_mode)
#define INITIALIZE_TRAMPOLINE(ADDR, FUNC, CHAIN)                            \
{                                                                           \
  rtx func_addr, chain_addr;                                                \
                                                                            \
  func_addr = plus_constant (ADDR, 32);                                     \
  chain_addr = plus_constant (func_addr, GET_MODE_SIZE (ptr_mode));         \
  emit_move_insn (gen_rtx_MEM (ptr_mode, func_addr), FUNC);                 \
  emit_move_insn (gen_rtx_MEM (ptr_mode, chain_addr), CHAIN);               \
                                                                            \
}


The c code for which i'm observing the effect is as follows.

int foo(int (*f)()){
        (*f)();
}
main(){
        int g(){printf("hello");}
        foo(g);
}


But if i comment out the body of macro INITIALIZE_TRAMPOLINE .Nothing
gets changed in the generated assembly file.
According to gcc internals INITIALIZE_TRAMPOLINE is responsible for
initialising the variable parts of a trampoline.

Would you please tell me when does the macros INITIALIZE_TRAMPOLINE
and TRAMPOLINE_TEMPLATE come in effect.Any practical expample will be
helpful.



More information about the Gcc mailing list