GCC is broken

Programming, for all ages and all languages.
DridriLaBastos
Posts: 17
Joined: Wed Feb 15, 2017 8:29 am
Libera.chat IRC: DridriLaBastos

GCC is broken

Post by DridriLaBastos »

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: Select all

int main (void)
{
    return 0;
}
GCC sais this :

Code: Select all

/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 ?
User avatar
zaval
Member
Member
Posts: 656
Joined: Fri Feb 17, 2017 4:01 pm
Location: Ukraine, Bachmut
Contact:

Re: GCC is broken

Post by zaval »

"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.
ANT - NT-like OS for x64 and arm64.
efify - UEFI for a couple of boards (mips and arm). suspended due to lost of all the target park boards (russians destroyed our town).
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: GCC is broken

Post by Love4Boobies »

Your compiler, assembler, and linker should all agree on the ABI (which you should decide upon depending on your needs).
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
DridriLaBastos
Posts: 17
Joined: Wed Feb 15, 2017 8:29 am
Libera.chat IRC: DridriLaBastos

Re: GCC is broken

Post by DridriLaBastos »

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: Select all

i686-elf-gcc -c -ffreestanding -fno-builtin -O2 -o main.o main.c
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: GCC is broken

Post by Love4Boobies »

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.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
DridriLaBastos
Posts: 17
Joined: Wed Feb 15, 2017 8:29 am
Libera.chat IRC: DridriLaBastos

Re: GCC is broken

Post by DridriLaBastos »

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.
User avatar
dchapiesky
Member
Member
Posts: 204
Joined: Sun Dec 25, 2016 1:54 am
Libera.chat IRC: dchapiesky

Re: GCC is broken

Post by dchapiesky »

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:
Plagiarize. Plagiarize. Let not one line escape thine eyes...
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Re: GCC is broken

Post by Roman »

How do you compile the code?
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
DridriLaBastos
Posts: 17
Joined: Wed Feb 15, 2017 8:29 am
Libera.chat IRC: DridriLaBastos

Re: GCC is broken

Post by DridriLaBastos »

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: Select all

-c -ffreestanding -O2
User avatar
zaval
Member
Member
Posts: 656
Joined: Fri Feb 17, 2017 4:01 pm
Location: Ukraine, Bachmut
Contact:

Re: GCC is broken

Post by zaval »

what

Code: Select all

i686-elf-gcc -print-sysroot
shows?

Code: Select all

i686-elf-objdump -i
and finally what's in your PATH?
ANT - NT-like OS for x64 and arm64.
efify - UEFI for a couple of boards (mips and arm). suspended due to lost of all the target park boards (russians destroyed our town).
DridriLaBastos
Posts: 17
Joined: Wed Feb 15, 2017 8:29 am
Libera.chat IRC: DridriLaBastos

Re: GCC is broken

Post by DridriLaBastos »

zaval wrote:what

Code: Select all

i686-elf-gcc -print-sysroot
shows?

Code: Select all

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: Select all

i686-elf-objdump -i
shows :

Code: Select all

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: Select all

/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
User avatar
zaval
Member
Member
Posts: 656
Joined: Fri Feb 17, 2017 4:01 pm
Location: Ukraine, Bachmut
Contact:

Re: GCC is broken

Post by zaval »

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.
ANT - NT-like OS for x64 and arm64.
efify - UEFI for a couple of boards (mips and arm). suspended due to lost of all the target park boards (russians destroyed our town).
DridriLaBastos
Posts: 17
Joined: Wed Feb 15, 2017 8:29 am
Libera.chat IRC: DridriLaBastos

Re: GCC is broken

Post by DridriLaBastos »

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: Select all

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
User avatar
dchapiesky
Member
Member
Posts: 204
Joined: Sun Dec 25, 2016 1:54 am
Libera.chat IRC: dchapiesky

Re: GCC is broken

Post by dchapiesky »

I wrote the path to binutils and gcc before write ":$PATH" when I set PATH
kindly post the output of

Code: Select all

export | grep PATH
You may be setting PATH but I don't think you are exporting it for children of gcc to see....
Plagiarize. Plagiarize. Let not one line escape thine eyes...
DridriLaBastos
Posts: 17
Joined: Wed Feb 15, 2017 8:29 am
Libera.chat IRC: DridriLaBastos

Re: GCC is broken

Post by DridriLaBastos »

Code: Select all

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