Add additional code to function (c/c++) while compiling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



i'm very new to gcc-hacking. i've only used and built gcc (as a crosscompiler for powerpc-eabi) so far...

i would like to add a very simple stack-protection (for our own-brewed os) to the code compiled with gcc 3.x. therefore i should be able to add about 5 lines of PPC assembler to each function body... first i hoped this should be quite easy - but it seams to be harder than expected. at least for me.

first i tried to add the code in the rs6000.c in the function
rs6000_output_function_prologue
ok this worked, but the stack-pointer (r1 in case of the PPC) is adjusted later - and of course i need the adjusted value of the stackpointer.


.LFB5:
   .loc 1 21 0
   .extern    my stackcheck_code   // my code
   stwu 1,-544(1)                           // stack adjustment...
.LCFI3:
   mflr 0
   stw 31,540(1)
.LCFI4:
   stw 0,548(1)
.LCFI5:
   mr 31,1
.LCFI6:


then i found that the file gcc/final.c (function final() ) calls the function final_scan_insn( ) which really writes out the assembler-code to the assembler-file. the problem seams to be that in this state of assembling, i don't have a chance to check if the actual insn is a stackpointer adjustment or some other commands, right? (ok, i could scan for the string "stwu" and the destination register "1"...)


at the moment i think the best place to add my "checking-code" is right after parsing the c/c++ code. but i really don't know in which file and which function...

in fact, everythings very unclear for me, thats why i'm writing to you.
it would be very nice, if someone could point me in the right direction by telling me what possibilities i do have and telling me what files & functions i have to extend. if it's not c-code (rtl, ...) i really would like to have a code-snippet which does:
- compare the complete size of the stack, added to the value of a ppc-hardware-register (spr 274)
- by a value which i may read from the memory


btw: this stack-check should be enabled/disabled by an -f switch or simillar, it's only needed for the powerpc-eabi-family and may be a hack instead of a clean solution.


thanks in advance! raphael zulliger



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux