hi, sorry, I'm so late to reply your E-mail, a little busy these days. On Sun, May 31, 2009 at 2:47 PM, Wang Liming <liming.wang@xxxxxxxxxxxxx> wrote: > hi Wu, > > I have one question about dynamic ftrace support for modules on mips arch. > I have also ported a dynamic ftrace of mips before, but when I using modules > with dynamic ftrace enabled in mips, I have following error: > > # insmod ./usbcore > module usbcore: relocation overflow > insmod: cannot insert './usbcore.ko': invalid module format > # > > I have no time to test your patch, but I think your patch also has this > problem. > > Below I explain possibility of this problem in details: > > We know that on mips, kernel symbol will locate in 0x80000000~0x90000000, > and modules' symbol will locate in >0xc0000000. > > On mips, gcc will insert following assembler code before every functions: > > move at,ra > jal 0 <usb_ifnum_to_if> > 10: R_MIPS_26 _mcount > > > Here "_mcount" is a kernel symbol in 0x80000000~0x90000000, for > example at 0x8027a740. > > When loading a module, kernel should relocate "jal 0" instruction to jump to > the kernel's "_mcount" address, 0x8027a740. But "jal 0" is a 26 bits offset > jump > instruction, it only can be relocated to jump to modules' symbol address > space(>0xc0000000) and it can't be relocated to jump to kernel symbol > address > space(such as 0x8027a740), because offset is 32 bits(is 0xc0000000 - > 0x80000000). We can't modify this instruction to jump to a 32 offset address > except that we modify gcc compiler to insert other assembler codes. > > So, when installing modules, the kernel will try to relocate "jal 0" > instruction > to instruction of jumping to >0xc0000000, but it finds that _mcount's > address > is 0x8027a740 and then print error indicated that it can't be reloacted. > > The following source code is the checking place: > > > ----------arch/mips/kernel/module.c:apply_r_mips_26_rel()------------------- > > static int apply_r_mips_26_rel(struct module *me, u32 *location, Elf_Addr v) > { > ... > if ((v & 0xf0000000) != (((unsigned long)location + 4) & 0xf0000000)) { > printk(KERN_ERR > "module %s: relocation overflow, v:%x, location:%x\n", > me->name, v, (unsigned long)location); > return -ENOEXEC; > } > > *location = (*location & ~0x03ffffff) | > ((*location + (v >> 2)) & 0x03ffffff); > > } > ----------arch/mips/kernel/module.c:apply_r_mips_26_rel()------------------- > > v is kernel _mcount's address, location is the address of the instrution > that should be relocated; > > To resolve this problem, we may need to do more work, either on gcc or on > the kernel. So I want to hear your test result and if you have solution, > please let me know. > yes, current version of mips-specific dynamic ftrace not support modules yet. there is similar solution implemented in PowerPC(something named trampoline), although I did not look into it, but I'm sure we can implement the mips-specific one via imitating it. and currently, I'm planning to fix it in the -v3 of mips-specific ftrace support. best wishes, Wu Zhangjin