Page 1 of 2
GCC is broken
Posted: Sat Mar 11, 2017 11:37 am
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:
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 ?
Re: GCC is broken
Posted: Sat Mar 11, 2017 1:18 pm
by zaval
"he"? Maybe GCC is "she" and thus is mad at you for confusing that.
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.
Re: GCC is broken
Posted: Sat Mar 11, 2017 3:01 pm
by Love4Boobies
Your compiler, assembler, and linker should all agree on the ABI (which you should decide upon depending on your needs).
Re: GCC is broken
Posted: Sat Mar 11, 2017 5:19 pm
by DridriLaBastos
zaval wrote:"he"? Maybe GCC is "she" and thus is mad at you for confusing that.
Maybe that is the solution, GCC is a "she",
(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
Re: GCC is broken
Posted: Sat Mar 11, 2017 8:05 pm
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.
Re: GCC is broken
Posted: Sun Mar 12, 2017 4:39 am
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.
Re: GCC is broken
Posted: Sun Mar 12, 2017 4:55 am
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
Re: GCC is broken
Posted: Sun Mar 12, 2017 5:17 am
by Roman
How do you compile the code?
Re: GCC is broken
Posted: Sun Mar 12, 2017 5:45 am
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
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
Re: GCC is broken
Posted: Sun Mar 12, 2017 5:58 am
by zaval
what
shows?
and finally what's in your PATH?
Re: GCC is broken
Posted: Sun Mar 12, 2017 6:34 am
by DridriLaBastos
zaval wrote:what
shows?
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
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
Re: GCC is broken
Posted: Sun Mar 12, 2017 8:10 am
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.
Re: GCC is broken
Posted: Sun Mar 12, 2017 10:04 am
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
Re: GCC is broken
Posted: Sun Mar 12, 2017 12:47 pm
by dchapiesky
I wrote the path to binutils and gcc before write ":$PATH" when I set PATH
kindly post the output of
You may be setting PATH but I don't think you are exporting it for children of gcc to see....
Re: GCC is broken
Posted: Sun Mar 12, 2017 1:13 pm
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"