Hi Ian/All That information was really very helpful. I have been able to localize the bug. The issue is in the assembler. When I create a object file using the assembler(as test.s -o test.o), the contents of .rdata which contains the jump table is all wrong.
The assembly file:- .section .rdata,"r" .balign 4 L8: .long [EMAIL PROTECTED] .long [EMAIL PROTECTED] .long [EMAIL PROTECTED] .long [EMAIL PROTECTED] .long [EMAIL PROTECTED] .long [EMAIL PROTECTED] The object file generated by assembly(the contents of .rdata) Contents of section .rdata: 0000 99000000 32000000 47000000 5c000000 ....2...G...\... 0010 71000000 86000000 q....... Values of symbol L2-L7 00000099 t L2 00000032 t L3 00000047 t L4 0000005c t L5 00000071 t L6 00000086 t L7 Basically the assembly file shows, that the contents of .rdata are value of Labels relative to GOT but in the assembly phase since GOT is not defined, the contents of .rdata should have been all zeroes(as was the case for elf binaries on a bsd box) but for interix coff binaries, the contents are actually values of labels. When this objects gets further linked to become a shared library, the GOT gets defined and hence the value Label-GOT(I mean L2-GOT or L3-GOT or L4-GOT) gets added to the contents of .rdata hence giving wrong jump targets for switch case. I have fixed this temporarily in bfd_install_relocation but I know that this is not the place where the fix should be. Now I could not figure out how this case is handled in elf binaries and where in the code ? If somebody can point me to the code where and how elf takes care of the above scenario , I could make a similar fix for coff binaries. Thanks Mayank -----Original Message----- From: Ian Lance Taylor [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 03, 2007 9:14 PM To: Mayank Kumar Cc: gcc@gcc.gnu.org Subject: Re: Information regarding -fPIC support for Interix gcc Mayank Kumar <[EMAIL PROTECTED]> writes: > For Movl [EMAIL PROTECTED](%ebx,%eax),%eax --------> mov > 0xffffbd14(%eax,%ebx,1),%eax > > I verified that data contained in .rdata section is all wrong in my case with > both my gcc3.3 compiler as well gcc4.3 compiler. > This is why the jump happens to the wrong code which lies outside the > function. > > Can you point me to the relevant section of gcc code which populates the > .rdata section or calculates these values to be populated in there ? gcc emits the code you see in the .s file. In this case it is just code like ".long [EMAIL PROTECTED]", which certainly looks right to me. It is the assembler which determines the value to place in the .o file; for the GNU binutils, this happens in gas/config/tc-i386.h; look for the handling of got_reloc. It is the linker which computes the final value in the executable; for the GNU binutils search for GOTOFF in bfd/elf32-i386.c. Ian