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: Playing with attributes and functions...


> I have this need: a function declaration of the type
>
>     rtype fname(t1 arg1, ..., tn argn) __attribute__((amilibcall(libbase, offset)));
>
> should be treated as if it were declared like this:
>
>     rtype fname(void *libbase, t1 arg1, ..., tn argn);

The main problem with your requirements is not that it is hard to do, but
that it's awkward to do.

You'd have to hack INIT_CUMULATIVE_ARGS to stash away a flag that says
this is such a function, and FUNCTION_ARG / FUNCTION_ARG_ADVANCE to
take it into account.
>
> and calling such function should happen like this:
>
>     ((typeof(&fname) *)libbase)[offset](libbase, arg1, ..., argn);
>
> where libbase doesn't need to be a global symbol, but also just a local
> one.
>
> Taking the address of such function should return
>
>     ((typeof(&fname) *)libbase)[offset]
	
You can use TARGET_ENCODE_SECTION_INFO to encode the mailibcall-ness of the
function in the symbol, and then decode this is call / movsi expanders,
splitters and/or instruction output patterns.

> and defining such function (as opposed to "declaring" it), should also
> define a global static symbol (whose name is not rally important), which
> contained the _real_ address of the function (that is, not the one taken
> from the libbase), and should put it into a section named
> "libbase.offset".
	
You could use MACHINE_DEPENDENT_REORG or FINAL_PRESCAN_INSN to add some
extra instructions / output.  Not an elegant solution, but it should do
the job.
Another approach would to hack TARGET_ASM_FUNCTION_PROLOGUE or the prologue
expander.

> Now, how do I go about it? I'm rather new to gcc hacking so I really need
> the help of someone who is more clever than me at this, or at least has
> more knowledge than me. I've looked at the file gcc/call.c, and perhaps
> that's the place where to start hacking? I'm not talking about the
> attribute handling, that I know how to do, but rather about the other
> points.

Just hack your machine description.  You'll find documentation for lots of
useful target macros, expander interfaces, and how to make splitter / output
patterns in the doc/*.texi files.  It is also often useful to look up how
existing ports use these facilities.
	
-- 
--------------------------
SuperH (UK) Ltd.
2410 Aztec West / Almondsbury / BRISTOL / BS32 4QX
T:+44 1454 465658


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