public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Add additional code to function (c/c++) while compiling
@ 2004-04-15 14:29 Raphael Zulliger
  2004-04-15 15:15 ` Ian Lance Taylor
  0 siblings, 1 reply; 2+ messages in thread
From: Raphael Zulliger @ 2004-04-15 14:29 UTC (permalink / raw)
  To: gcc-help

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Add additional code to function (c/c++) while compiling
  2004-04-15 14:29 Add additional code to function (c/c++) while compiling Raphael Zulliger
@ 2004-04-15 15:15 ` Ian Lance Taylor
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 2004-04-15 15:15 UTC (permalink / raw)
  To: Raphael Zulliger; +Cc: gcc-help

Raphael Zulliger <zulliger@indel.ch> writes:

> 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.

You might try taking a look at how -fstack-check is implemented.

Ian

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-04-15 15:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-15 14:29 Add additional code to function (c/c++) while compiling Raphael Zulliger
2004-04-15 15:15 ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).