modutils bug? 'if' clause executes incorrectly
I'm finding that in a Linux/MIPS module the test case attached executes the 'if' clause in
if A
B
else
C
in the order A, C, B when A is false and correctly (A, B) when A is true.
This is with GCC version egcs-2.90.29 980515 (egcs-1.0.3 release) and binutils 2.8.1 (with BFD 2.8.1).
The asm in this routine looks good and I can keep the code from failing by removing the request_irq() and replacing it with something else that doesn't call into the kernel. I can't reproduce this in user-code or in kernel code.
Does anyone have any suggestions? Perhaps a suggestion for modutils version?
Quoted 2 lines · Cort Dougan
I'm finding that in a Linux/MIPS module the test case attached executes the 'if' clause in
Almost certainly nothing to do with modutils, insmod just relocates and loads the program. The only possible modutil problems are an unexpected relocation being emitted by binutils or insmod not handling a valid relocation correctly. Compile with -g then do "objdump -rS object.o". What does the offending section of code look like, including the relocations?
Quoted 10 lines · Cort Dougan
if A
B
else
Cin the order A, C, B when A is false and correctly (A, B) when A is true.
This is with GCC version egcs-2.90.29 980515 (egcs-1.0.3 release) and binutils 2.8.1 (with BFD 2.8.1).
Quoted 7 lines
The asm in this routine looks good and I can keep the code from failing by removing the
request_irq()and replacing it with something else that doesn't call into the kernel. I can't reproduce this in user-code or in kernel code.Does anyone have any suggestions? Perhaps a suggestion for modutils version?
Please send the resulting asm code - I hear someone whispering "Branch delay slot".
Flo
Signature · 2 lines
Florian Lohoff [email protected] +49-5201-669912 "Write only memory - Oops. Time for my medication again ..."
} On Tue, Oct 10, 2000 at 10:43:17PM -0600, Cort Dougan wrote:
}
} > This is with GCC version egcs-2.90.29 980515 (egcs-1.0.3 release) and } > binutils 2.8.1 (with BFD 2.8.1).
} >
} > The asm in this routine looks good and I can keep the code from failing by } > removing the request_irq() and replacing it with something else that } > doesn't call into the kernel. I can't reproduce this in user-code or in } > kernel code.
} >
} > Does anyone have any suggestions? Perhaps a suggestion for modutils } > version?
}
} I have an idea what's going wrong, maybe it's related to something that } Brady Brown recently discovered. Are the object files you are trying to } load generated by the assembler? If so, try to do a relocatable link } on them with ld -r module-out.o module-in.o.
The small test case I have (bug.c) is being built through gcc and that does shove the output through as.
I did a mips-linux-ld -r -o bug.re.o bug.o and I get the same incorrect execution.
} On Tue, Oct 10, 2000 at 10:43:17PM -0600, Cort Dougan wrote:
} > if A
} > B
} > else
} > C
} >
} > in the order A, C, B when A is false and correctly (A, B) when A is true. } >
} > This is with GCC version egcs-2.90.29 980515 (egcs-1.0.3 release) and } > binutils 2.8.1 (with BFD 2.8.1).
} >
} > The asm in this routine looks good and I can keep the code from failing by } > removing the request_irq() and replacing it with something else that } > doesn't call into the kernel. I can't reproduce this in user-code or in } > kernel code.
} >
} > Does anyone have any suggestions? Perhaps a suggestion for modutils } > version?
}
} Please send the resulting asm code - I hear someone whispering } "Branch delay slot".
.c and gzip'd .s attached.
Compiled with: mips-linux-gcc -v -G 0 -mno-abicalls -fno-pic -ffixed-8__
-D__KERNEL__ -DMODULE -D_LOOSE_KERNEL_NAMES -O2 -c
-fomit-frame-pointer -pipe -mcpu=r8000 -mips2 -mlong-calls -I/sys/linux/include -I/sys/rtlinux/include -I/sys/rtlinux/include/compat -I/sys/rtlinux/include/posix -Wall -Wstrict-prototypes -g -D__RTL__
-D__KERNEL__ -DMODULE -D_LOOSE_KERNEL_NAMES -O2 -c -o bug.o main/bug.c
#include <linux/kernel.h>
#include <linux/version.h>
#include <linux/errno.h>
#include <linux/malloc.h>
#include <linux/timex.h>
#include <linux/spinlock.h>
#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/console.h>
#include <linux/irq.h>
#include <linux/config.h>
#include <asm/uaccess.h>
#include <asm/system.h>
#include <asm/irq.h>
#include <asm/segment.h>
#include <asm/ptrace.h>
int var;MODULE_PARM(var, "i");
void foo(void)
{
}
int init_module(void)
{
int debug, i;
#define RTL_NR_IRQS 32
for (i = RTL_NR_IRQS - 1; i > 15; i--)
{
printk("A\n");
debug = request_irq (i, foo, 0, "blah", 0);
printk("debug %d \n", debug);
if ( debug )
{
printk("B\n");
continue;
}
else
{
printk("C\n");
return debug;
}
}
return 0;
}void cleanup_module(void)
{
}
Quoted 10 lines · Cort Dougan
This is with GCC version egcs-2.90.29 980515 (egcs-1.0.3 release) and binutils 2.8.1 (with BFD 2.8.1).
The asm in this routine looks good and I can keep the code from failing by removing the
request_irq()and replacing it with something else that doesn't call into the kernel. I can't reproduce this in user-code or in kernel code.Does anyone have any suggestions? Perhaps a suggestion for modutils version?
I have an idea what's going wrong, maybe it's related to something that Brady Brown recently discovered. Are the object files you are trying to load generated by the assembler? If so, try to do a relocatable link on them with ld -r module-out.o module-in.o.
Ralf
Keith,
Quoted 9 lines
Quoted 2 lines
I'm finding that in a Linux/MIPS module the test case attached executes the 'if' clause in
Almost certainly nothing to do with modutils, insmod just relocates and loads the program. The only possible modutil problems are an unexpected relocation being emitted by binutils or insmod not handling a valid relocation correctly. Compile with -g then do "objdump -rS object.o". What does the offending section of code look like, including the relocations?
For such occassions I would like to see some debugging functionality in modutils which allows dumping the relocated disk image as it would be loaded into the kernel into a disk image which then could be examined with objdump etc. for potencial problems.
Ralf
Quoted 4 lines · Ralf Baechle
For such occassions I would like to see some debugging functionality in modutils which allows dumping the relocated disk image as it would be loaded into the kernel into a disk image which then could be examined with objdump etc. for potencial problems.
By the time insmod has finished with the module, the rest is a binary blob. No ELF headers, no symbols, all the sections run together with a struct module at the start. I can dump that easily enough but I question how much use it would be. Outputing anything more complicated such as ELF headers and symbols would be a significant addition to insmod.
Quoted 6 lines · Keith Owens
Quoted 4 lines · Ralf Baechle
For such occassions I would like to see some debugging functionality in modutils which allows dumping the relocated disk image as it would be loaded into the kernel into a disk image which then could be examined with objdump etc. for potencial problems.
Quoted 6 lines
By the time insmod has finished with the module, the rest is a binary blob. No ELF headers, no symbols, all the sections run together with a struct module at the start. I can dump that easily enough but I question how much use it would be. Outputing anything more complicated such as ELF headers and symbols would be a significant addition to insmod.
The blob is actually already ok and just what I wanted. You can easily talk objdump into disassembling that easily. All that is required in addition is the base address of the blob as the argument of the --adjust-vma option.
[ralf@lappi ralf]$ mips-linux-objdump -b binary -m mips --adjust-vma 0xc0000000 -D /etc/group | head
/etc/group: file format binary
No symbols in "/etc/group".
Disassembly of section .data:
00000000c0000000 <.data>:
c0000000: 726f6f74 jalx c1bdbdc8
c0000004: 3a3a303a xori $s0,$s1,0x3a3a
c0000008: 726f6f74 jalx c1bdbdc8Ralf
Quoted 11 lines · Ralf Baechle
Quoted 6 lines · Keith Owens
By the time insmod has finished with the module, the rest is a binary blob. No ELF headers, no symbols, all the sections run together with a struct module at the start. I can dump that easily enough but I question how much use it would be. Outputing anything more complicated such as ELF headers and symbols would be a significant addition to insmod.
The blob is actually already ok and just what I wanted. You can easily talk objdump into disassembling that easily. All that is required in addition is the base address of the blob as the argument of the --adjust-vma option.
I will add insmod option -O to save the binary object to a file.
insmod -m -O binary module
will save the binary blob, -m already gives you the section and symbol map for the final binary object.
Cort,
I think in your module the following jump gets misstreated:
90: 0800002d j b4 <init_module+ac>
90: R_MIPS_26 .text
This one is is supposed to skip over the ``printk("A");'' code after ``printk("B");'', so it's the prime suspect.
And this is how current modutils correctly compute such a R_MIPS_26 relocation in obj/obj_mips.c:
*loc = (*loc & ~0x03ffffff) | ((*loc + (v >> 2)) & 0x03ffffff);
But older modutils - including the modutils-2.1.121-12lm.src.rpm package from oss - do this:
*loc = (*loc & ~0x03ffffff) | ((*loc & 0x03ffffff) + (v >> 2));
which is different - and wrong. This latter expression will for an assumed load address of 0xc0000000 place 0x3800042d into *loc which is ``xori $zero, $zero, 0x42d'', in other words a glorified nop resulting in the printk("A") statement also getting executed.
So the fix should be either upgrading modutils or replacing above expression in obj/obj_mips.c in your old version of modutils with the correct one.
Ralf
Quoted 11 lines · Ralf Baechle
I think in your module the following jump gets misstreated:
90:
0800002dj b4 <init_module+ac>90: R_MIPS_26 .textBut older modutils - including the modutils-2.1.121-12lm.src.rpm package from oss - do this:
*loc = (*loc & ~0x03ffffff) | ((*loc & 0x03ffffff) + (v >> 2));which is different - and wrong.
Would that be this entry in the change log from 1998?
Tue Nov 3 22:26:18 MET 1998 Ralf Baechle <[email protected]>
* obj/obj_mips.c (arch_apply_relocation): Fix application of R_MIPS_26 relocations.
Thanks for tracking the problem down. I really, *really* want to kill people using modutils 2.1.121 on current kernels.
Quoted 9 lines · Keith Owens
Would that be this entry in the change log from 1998?
Tue Nov 3 22:26:18 MET 1998 Ralf Baechle <[email protected]>
*
obj/obj_mips.c(arch_apply_relocation): Fix application ofR_MIPS_26relocations.Thanks for tracking the problem down. I really, *really* want to kill people using modutils 2.1.121 on current kernels.
Now that explains the deja vue I had when I found this one ...
I'm not using modules at all which why I still have such vintage modutils around ...
Ralf
} Now that explains the deja vue I had when I found this one ... }
} I'm not using modules at all which why I still have such vintage modutils } around ...
Can someone send me a fixed version of the BE modutils binary? I can give it a try and see if the trouble goes away.