Strange behavior on Gcc cross compiler

Programming, for all ages and all languages.
Post Reply
bigorenski
Posts: 14
Joined: Thu May 09, 2013 5:51 pm

Strange behavior on Gcc cross compiler

Post 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.
User avatar
Kazinsal
Member
Member
Posts: 559
Joined: Wed Jul 13, 2011 7:38 pm
Libera.chat IRC: Kazinsal
Location: Vancouver
Contact:

Re: Strange behavior on Gcc cross compiler

Post by Kazinsal »

Did you build libgcc as well? IIRC a cross-compiled libgcc is needed for 64-bit computation on 32-bit machines.
bigorenski
Posts: 14
Joined: Thu May 09, 2013 5:51 pm

Re: Strange behavior on Gcc cross compiler

Post by bigorenski »

Yeah, i have libgcc... And, since Im using a cross compiler, Im not using the "-nodefaultlibs" switch.
Any ideas?


Thanks.
bigorenski
Posts: 14
Joined: Thu May 09, 2013 5:51 pm

Re: Strange behavior on Gcc cross compiler

Post 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.
bigorenski
Posts: 14
Joined: Thu May 09, 2013 5:51 pm

Re: Strange behavior on Gcc cross compiler

Post 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
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: Strange behavior on Gcc cross compiler

Post 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.
bigorenski
Posts: 14
Joined: Thu May 09, 2013 5:51 pm

Re: Strange behavior on Gcc cross compiler

Post 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.
Post Reply