OSDev.org
https://forum.osdev.org/

GCC is broken
https://forum.osdev.org/viewtopic.php?f=13&t=31413
Page 1 of 2

Author:  DridriLaBastos [ Sat Mar 11, 2017 11:37 am ]
Post subject:  GCC is broken

I just finished to compile GCC following the tutorial on this site, but when I try to compile this simple program with my new cross-platform gcc:
Code:
int main (void)
{
    return 0;
}


GCC sais this :
Code:
/var/folders/vp/ytlzwk9j0tg1krkknx4ytqbw0000gn/T//ccLmojzB.s:2:11: error: mach-o section specifier uses an unknown section type
        .section        .text.unlikely,"ax",@progbits
                        ^
/var/folders/vp/ytlzwk9j0tg1krkknx4ytqbw0000gn/T//ccLmojzB.s:4:11: error: mach-o section specifier uses an unknown section type
        .section        .text.startup,"ax",@progbits
                        ^
/var/folders/vp/ytlzwk9j0tg1krkknx4ytqbw0000gn/T//ccLmojzB.s:8:2: error: unknown directive
        .type   main, @function
        ^
/var/folders/vp/ytlzwk9j0tg1krkknx4ytqbw0000gn/T//ccLmojzB.s:16:2: error: unknown directive
        .size   main, .-main
        ^
/var/folders/vp/ytlzwk9j0tg1krkknx4ytqbw0000gn/T//ccLmojzB.s:17:25: error: unexpected token in '.section' directive
        .section        .text.unlikely
                                      ^
/var/folders/vp/ytlzwk9j0tg1krkknx4ytqbw0000gn/T//ccLmojzB.s:19:24: error: unexpected token in '.section' directive
        .section        .text.startup


and I have no idea why he is doing that :( The funny thing is that I had a previous version of gcc that runs perfectly, and, for some reasons, I decided to compile an other one (that which doesn't works, thus), following perfectly the tutorial ... I am totally lost, what is the problem ?

Author:  zaval [ Sat Mar 11, 2017 1:18 pm ]
Post subject:  Re: GCC is broken

"he"? Maybe GCC is "she" and thus is mad at you for confusing that. :lol:
Anyway, those section names are perfectly suitable names. for ELF targets. And you kind of want mach-o one. I have no idea what sections that apple mach-o uses, but probably that's the reason, your compiler generates intermediate assembly files for ELF, not for mach-o. obviously mach-o doesn't get what .text is.

Author:  Love4Boobies [ Sat Mar 11, 2017 3:01 pm ]
Post subject:  Re: GCC is broken

Your compiler, assembler, and linker should all agree on the ABI (which you should decide upon depending on your needs).

Author:  DridriLaBastos [ Sat Mar 11, 2017 5:19 pm ]
Post subject:  Re: GCC is broken

zaval wrote:
"he"? Maybe GCC is "she" and thus is mad at you for confusing that. :lol:


Maybe that is the solution, GCC is a "she", :D (sorry for that mistake, I am ashamed)

zaval wrote:
Anyway, those section names are perfectly suitable names. for ELF targets. And you kind of want mach-o one. I have no idea what sections that apple mach-o uses, but probably that's the reason, your compiler generates intermediate assembly files for ELF, not for mach-o. obviously mach-o doesn't get what .text is.


That is what I don't understand, why do I want mach-o section names ? I compiled hundreds of time with my previous version of i686-elf-gcc, and when I recompiled the same one (I wanted to have a nicer organization so I recompiled all : gmp, mpfr, mpc, binutils, gcc to get one folder for each one), the files that compiled without problems with my previous gcc, doesn't want to be compiled with that newer version :/ I compile main.c with :
Code:
i686-elf-gcc -c -ffreestanding -fno-builtin -O2 -o main.o main.c

Author:  Love4Boobies [ Sat Mar 11, 2017 8:05 pm ]
Post subject:  Re: GCC is broken

I've hinted at the problem in my previous answer. You are not getting a compilation error. In fact, GCC is working just fine for you. However, you are using the assembler (and, most likely, also the linker) that target your system rather than the one you are cross-compiling to. The version you used before agreed with these tools but wasn't the cross-compiler you need.

Did you even read the diagnostic messages you got? Because you should really understand something as trivial as the steps involved in building and running software (which is something all programmers and even some even regular UNIX users sometimes have to do) before you embark on such a project.

Author:  DridriLaBastos [ Sun Mar 12, 2017 4:39 am ]
Post subject:  Re: GCC is broken

Love4Boobies wrote:
I've hinted at the problem in my previous answer. You are not getting a compilation error. In fact, GCC is working just fine for you. However, you are using the assembler (and, most likely, also the linker) that target your system rather than the one you are cross-compiling to. The version you used before agreed with these tools but wasn't the cross-compiler you need.

Did you even read the diagnostic messages you got? Because you should really understand something as trivial as the steps involved in building and running software (which is something all programmers and even some even regular UNIX users sometimes have to do) before you embark on such a project.


I compiled binutils and gcc with --target=i686-elf, they should be agree with the targeted system, I know the problem is that the target system is mach-o but I don't know why.

Author:  dchapiesky [ Sun Mar 12, 2017 4:55 am ]
Post subject:  Re: GCC is broken

while stack overflow has an answer I will reiterate love's post and say that it is pretty clear you aren't using the right assembler... check your path variable
:shock:

Author:  Roman [ Sun Mar 12, 2017 5:17 am ]
Post subject:  Re: GCC is broken

How do you compile the code?

Author:  DridriLaBastos [ Sun Mar 12, 2017 5:45 am ]
Post subject:  Re: GCC is broken

dchapiesky wrote:
while stack overflow has an answer I will reiterate love's post and say that it is pretty clear you aren't using the right assembler... check your path variable
:shock:


My path variable looks like OK, when I type i686-elf- and then double press TAB, in the list displayed I can find i686-elf-as, and in .bash_profile, I wrote the path to binutils and gcc before write ":$PATH" when I set PATH

I compile with
Code:
-c -ffreestanding -O2

Author:  zaval [ Sun Mar 12, 2017 5:58 am ]
Post subject:  Re: GCC is broken

what
Code:
i686-elf-gcc -print-sysroot

shows?
Code:
i686-elf-objdump -i

and finally what's in your PATH?

Author:  DridriLaBastos [ Sun Mar 12, 2017 6:34 am ]
Post subject:  Re: GCC is broken

zaval wrote:
what
Code:
i686-elf-gcc -print-sysroot

shows?
Code:
i686-elf-objdump -i

and finally what's in your PATH?


I didn't compile gcc with sysroot so -print-sysroot shows nothing (but I compiled binutils with the option --with-sysroot) and
Code:
i686-elf-objdump -i
shows :
Code:
elf32-i386
(header little endian, data little endian)
  i386
elf32-iamcu
(header little endian, data little endian)
  iamcu
coff-i386
(header little endian, data little endian)
  i386
elf32-little
(header little endian, data little endian)
  i386
  iamcu
  plugin
elf32-big
(header big endian, data big endian)
  i386
  iamcu
  plugin
plugin
(header little endian, data little endian)
srec
(header endianness unknown, data endianness unknown)
  i386
  iamcu
  plugin
symbolsrec
(header endianness unknown, data endianness unknown)
  i386
  iamcu
  plugin
verilog
(header endianness unknown, data endianness unknown)
  i386
  iamcu
  plugin
tekhex
(header endianness unknown, data endianness unknown)
  i386
  iamcu
  plugin
binary
(header endianness unknown, data endianness unknown)
  i386
  iamcu
  plugin
ihex
(header endianness unknown, data endianness unknown)
  i386
  iamcu
  plugin

         elf32-i386 elf32-iamcu coff-i386 elf32-little elf32-big plugin srec
    i386 elf32-i386 ----------- coff-i386 elf32-little elf32-big ------ srec
   iamcu ---------- elf32-iamcu --------- elf32-little elf32-big ------ srec
  plugin ---------- ----------- --------- elf32-little elf32-big ------ srec

         symbolsrec verilog tekhex binary ihex
    i386 symbolsrec verilog tekhex binary ihex
   iamcu symbolsrec verilog tekhex binary ihex
  plugin symbolsrec verilog tekhex binary ihex


and in my PATH :
Code:
/Users/adrien/util/nasm/bin:/Users/adrien/util/gcc/6.3.0/bin:/Users/adrien/util/binutils/bin:/Users/adrien/bochs/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Frameworks/Mono.framework/Versions/Current/Commands

Author:  zaval [ Sun Mar 12, 2017 8:10 am ]
Post subject:  Re: GCC is broken

well, your PATH doesn't have path to your i686-elf tools. Instead it points to the host's gcc. which is for mach-o obviously. define PATH in your cross-compile tool shell properly.

Author:  DridriLaBastos [ Sun Mar 12, 2017 10:04 am ]
Post subject:  Re: GCC is broken

zaval wrote:
well, your PATH doesn't have path to your i686-elf tools. Instead it points to the host's gcc. which is for mach-o obviously. define PATH in your cross-compile tool shell properly.


I installed the cross compiler in /User/adrien/util/gcc/6.3.0 so /Users/adrien/util/gcc/6.3.0/bin is the path where the shell can find the executable i686-elf-gcc, like I said, when I double tap the TAB button when I type i686-elf- in the shell, in the list it displays there is i686-elf-gcc, so the shell knows where to find it, and also all the others tools :
Code:
MBP-de-Adrien:~ adrien$ i686-elf-
i686-elf-addr2line   i686-elf-gcc-6.3.0   i686-elf-nm
i686-elf-ar          i686-elf-gcc-ar      i686-elf-objcopy
i686-elf-as          i686-elf-gcc-nm      i686-elf-objdump
i686-elf-c++         i686-elf-gcc-ranlib  i686-elf-ranlib
i686-elf-c++filt     i686-elf-gcov        i686-elf-readelf
i686-elf-cpp         i686-elf-gcov-tool   i686-elf-size
i686-elf-elfedit     i686-elf-gprof       i686-elf-strings
i686-elf-g++         i686-elf-ld          i686-elf-strip
i686-elf-gcc         i686-elf-ld.bfd

Author:  dchapiesky [ Sun Mar 12, 2017 12:47 pm ]
Post subject:  Re: GCC is broken

Quote:
I wrote the path to binutils and gcc before write ":$PATH" when I set PATH


kindly post the output of

Code:
export | grep PATH


You may be setting PATH but I don't think you are exporting it for children of gcc to see....

Author:  DridriLaBastos [ Sun Mar 12, 2017 1:13 pm ]
Post subject:  Re: GCC is broken

Code:
declare -x PATH="/Users/adrien/util/nasm/bin:/Users/adrien/util/gcc/6.3.0/bin:/Users/adrien/util/binutils/bin:/Users/adrien/bochs/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Frameworks/Mono.framework/Versions/Current/Commands"

Page 1 of 2 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/