From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24654 invoked by alias); 15 Apr 2004 14:29:31 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 24633 invoked from network); 15 Apr 2004 14:29:29 -0000 Received: from unknown (HELO smtp.hispeed.ch) (62.2.95.247) by sources.redhat.com with SMTP; 15 Apr 2004 14:29:29 -0000 Received: from indel.ch (217-162-226-91.dclient.hispeed.ch [217.162.226.91]) by smtp.hispeed.ch (8.12.6/8.12.6/tornado-1.0) with SMTP id i3FETSA8021620 for ; Thu, 15 Apr 2004 16:29:28 +0200 Received: from indel.ch [192.168.1.11] by indel.ch [127.0.0.1] with SMTP (MDaemon.v2.7.SP5.R) for ; Thu, 15 Apr 2004 16:29:04 +0200 Message-ID: <412216C6.2020408@indel.ch> Date: Thu, 15 Apr 2004 14:29:00 -0000 From: Raphael Zulliger User-Agent: Mozilla Thunderbird 0.5 (Windows/20040207) MIME-Version: 1.0 To: gcc-help@gcc.gnu.org Subject: Add additional code to function (c/c++) while compiling Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-MDaemon-Deliver-To: gcc-help@gcc.gnu.org X-Return-Path: zulliger@indel.ch X-SW-Source: 2004-04/txt/msg00190.txt.bz2 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