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]

Re: function structure


First of all, I'd like to appreciate your help, thanks!

Have you heard about StackGuard?
I'm trying to do some work similar to that, but I'm a GCC newbie and have so many questions.

My patch semmed to be ok except one thing (may be there are still many other bugs):
In RTL, I emitted a function call (using emit_lib_call()) before each CALL_INSN in the current RTL unit.
But I found that my function call is emitted between the parameter evaluate instructions and the real call instruction, this ruined the parameters to be passed to the original routine. 

For example:
the original assemble code of the function call to 
    fopen("/tmp/file1", "a+b")
may be the following 3 assembel instructions:
0x08048613 <main+31>:   movl   $0x804885c,0x4(%esp,1)
0x0804861b <main+39>:   movl   $0x8048860,(%esp,1)
0x0804862e <main+58>:   call   0x8048528

and the next 2 lines is the assemble code of my function call to 
    f(0)
0x08048622 <main+46>:   movl   $0x0,(%esp,1)
0x08048629 <main+53>:   call   0x80484b8

then, if I just insert the instructions before the original call instruction, it will be
0x08048613 <main+31>:   movl   $0x804885c,0x4(%esp,1)
0x0804861b <main+39>:   movl   $0x8048860,(%esp,1)
0x08048622 <main+46>:   movl   $0x0,(%esp,1)
0x08048629 <main+53>:   call   0x80484b8
0x0804862e <main+58>:   call   0x8048528

you can see that the parameters passed to the fopen function is not what I expected.
This is my problem, I'm seeking for help to solve it.
Thanks for your concerning.

WangYi


----- Original Message ----- 
From: "Jim Wilson" <wilson@specifixinc.com>
To: "ç é" <cnnjuwy@hotmail.com>
Cc: <gcc@gcc.gnu.org>
Sent: Sunday, July 04, 2004 4:33 AM
Subject: Re: function structure


On Mon, 2004-07-05 at 17:05, ç é wrote:
> But I'm afraid that I can only get the RTL.
> After the RTL of a function is generated, I looked through this RTL unit. When a call_insn is met, I need to determine the number of arguments of the called routine.
> What can I do?

I don't know what you are doing, or why you are doing it, so this is
hard to answer.  But one thing you should consider is why you are doing
this at the RTL level instead of doing this at the tree or gimple level,
where it might be easier to do.

There are 3 things of interest here.  The number of parameters a
function is defined with.  The number of parameters a function is
declared with.  The number of arguments passed to a function at a call
site.  All 3 of these numbers can be different.  There is also the issue
of stdarg functions which is another complication.  Function definitions
might be in another file, in which case this info might be unavailable
with current gcc sources.

If you have a CALL_EXPR tree, then you can see how many arguments as
being passed to a function call.  If you have a FUNCTION_DECL tree, then
you can see how many parameters the declaration/definition contains,
assuming it contains any.  A declaration contains parameters only if it
is a prototype, and it is common in older code to declare functions
without listing the parameters.  So if you really need to know the
number of arguments, then looking at FUNCTION_DECL trees may be
misleading.

I don't think you can get the info you want simply from looking at a
CALL rtl.  You need to go higher up, e.g. to the CALL_EXPR, see for
example where expand_expr calls expand_call.
-- 
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com


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