How to force gcc to long-call a function (on MIPS)?

PRC panruochen@gmail.com
Thu Feb 21 12:09:00 GMT 2008


The caller is located in KSEG0 region and the callee is located in KSEG1 region.
And `func_entry' is variable defined in the linker script.
**************************************************************************
SECTIONS
{
  .text 0x80xxxxxx:
  ...
  func_entry = 0xa0xxxxxx;
  ...
}
**************************************************************************
And in the C source code, I declare func_entry as `extern unsigned char func_entry[];'
And there is a linking error:
**********************************************************************************************************
init.o: In function `init':
./../init.c:(.text+0xe4): relocation truncated to fit: R_MIPS_26 against `func_entry'
**********************************************************************************************************
gcc generates the following assembly code for this function call:
  ec:	3c020000 	lui	v0,0x0
  f0:	24440038 	addiu	a0,v0,56
  f4:	0c000000 	jal	0
  f8:	00000000 	nop
where `jal' is not appropriate, since this is a cross-region call.

BTW, if I change the code 
((MY_FUNC_ENTRY)func_entry)(para);
to
void *entry_addr = func_entry;
((MY_FUNC_ENTRY)entry_addr)(para);
gcc can generate `jalr' instruction.

>gcc can see that the cast doesn't do anything and so
>deletes it.  Does `-mlong-calls' solve your problem?
>
>What happens when you declare `func_entry' with __attribute__(( far )) ?
>
>Andrew.



More information about the Gcc-help mailing list