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]
Other format: [Raw text]

Any hints on this problem? Thanks!


Hi,
I am working on gcc-4.1.1 and Itanium architecure. Today I try to add
a function call before each ld instruction. The method I use to
achieve this goal is to modify final_scan_insn() in final.c: before
calling get_insn_template, I add codes to check whether the insn
matches a template that will emit ld instruction, then I use
emit_library_call to emit new insns and output them by calling
final_scan_insn() again. Now,the modified gcc is successfully builded
and when I use it to compile a program, I observe that it successfully
intercept each ld instruction and add the desired function call before
them.
	But the problem comes, when I run the modified program compiled by
the hacked gcc, it crashes due to segment fault. I use gdb to debug
the program, and observe that the fault is due to this:  originally,
what I want to do is ld r14=[r14], and r14 contains the correct
address, but in my inserted function call, say FOO, it modifies r14 to
0, and when the program returns from FOO and load from r14 again, it
crashes, undoubtedly. Here is a concrete example, just a very simple
one to illstrate the situation:

~~~~~~~~~~~~~~~~~~~~~~~
old code:
<main>:
	...
	ld r14=[r14]
	...
~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~~~~~~~~~~
new code:
<FOO>:
	...
	mov r14=0
	...

<main>:
	...
	br.call FOO
	ld r14=[r14] 	/* CRASH! */
	...
~~~~~~~~~~~~~~~~~~~~~~~
	Now, my question becomes clear. How to make my inserted function call
not affect the orginal state of program? Further more, if I add more
instructions (not only a function call), how can I keep the that
state? Is there a general way to do this?
	Any hints on this problem will be *truely* appreciated. Thanks!

Best Regards

Andy.Wu


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