Page 1 of 1

Strange behavior on Gcc cross compiler

Posted: Sun May 12, 2013 5:03 pm
by bigorenski
Im writing a kernel, and using gcc(cross) to compile it. Everything works just fine, except that:

Code: Select all

void foo(){
 uint64_t i=1;
 i = i << 33;
}
after executing that:
i=0

(I tried unsigned long and unsigned long long too)

Gcc target is x86, but as far as I know it should be able to use unsigned long vars.



PS. Sorry for my poorly written English. Thats not my natural language.

Re: Strange behavior on Gcc cross compiler

Posted: Sun May 12, 2013 5:13 pm
by Kazinsal
Did you build libgcc as well? IIRC a cross-compiled libgcc is needed for 64-bit computation on 32-bit machines.

Re: Strange behavior on Gcc cross compiler

Posted: Sun May 12, 2013 5:43 pm
by bigorenski
Yeah, i have libgcc... And, since Im using a cross compiler, Im not using the "-nodefaultlibs" switch.
Any ideas?


Thanks.

Re: Strange behavior on Gcc cross compiler

Posted: Sun May 12, 2013 6:47 pm
by bigorenski

Code: Select all

i = (1LL << 33);

Code: Select all

i = ((uint64_t)1 << 33);

This doesnt work too. Im going crazy with it.

Re: Strange behavior on Gcc cross compiler

Posted: Sun May 12, 2013 7:00 pm
by bigorenski
Oh, the error was on my putn(put number) function, it prints only 32bit numbers.

Code: Select all

void foo(){
  uint64_t bar = 1;
  bar = bar << 40;
  
  if(bar == 0x10000000000){
    video.puts("\nEQUALS\n");
  }
output:
EQUALS

Re: Strange behavior on Gcc cross compiler

Posted: Mon May 13, 2013 1:07 am
by sortie
Note how unsigned long is 32-bit on your platform and unsigned long long is 64-bit on your platform.

Please note that the option -nostdlib is equal to passing both -nostartfiles -nodefaultlibs. You will want to pass both flags in a kernel because you want neither the start files (crt0.o, crti.o, crtn.o) nor the C library, and then manually add -lgcc to the end of the link command.

Re: Strange behavior on Gcc cross compiler

Posted: Mon May 13, 2013 7:15 am
by bigorenski
sortie wrote:Note how unsigned long is 32-bit on your platform and unsigned long long is 64-bit on your platform.

Please note that the option -nostdlib is equal to passing both -nostartfiles -nodefaultlibs. You will want to pass both flags in a kernel because you want neither the start files (crt0.o, crti.o, crtn.o) nor the C library, and then manually add -lgcc to the end of the link command.
As far as i know on a cross compiler those flags are not needed. My kernel is working fine without it.