OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 5:30 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: GCC is broken
PostPosted: Sat Mar 11, 2017 11:37 am 
Offline

Joined: Wed Feb 15, 2017 8:29 am
Posts: 17
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 ?


Top
 Profile  
 
 Post subject: Re: GCC is broken
PostPosted: Sat Mar 11, 2017 1:18 pm 
Offline
Member
Member
User avatar

Joined: Fri Feb 17, 2017 4:01 pm
Posts: 641
Location: Ukraine, Bachmut
"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).


Top
 Profile  
 
 Post subject: Re: GCC is broken
PostPosted: Sat Mar 11, 2017 3:01 pm 
Offline
Member
Member
User avatar

Joined: Fri Mar 07, 2008 5:36 pm
Posts: 2111
Location: Bucharest, Romania
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 ]


Top
 Profile  
 
 Post subject: Re: GCC is broken
PostPosted: Sat Mar 11, 2017 5:19 pm 
Offline

Joined: Wed Feb 15, 2017 8:29 am
Posts: 17
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


Top
 Profile  
 
 Post subject: Re: GCC is broken
PostPosted: Sat Mar 11, 2017 8:05 pm 
Offline
Member
Member
User avatar

Joined: Fri Mar 07, 2008 5:36 pm
Posts: 2111
Location: Bucharest, Romania
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 ]


Top
 Profile  
 
 Post subject: Re: GCC is broken
PostPosted: Sun Mar 12, 2017 4:39 am 
Offline

Joined: Wed Feb 15, 2017 8:29 am
Posts: 17
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.


Top
 Profile  
 
 Post subject: Re: GCC is broken
PostPosted: Sun Mar 12, 2017 4:55 am 
Offline
Member
Member
User avatar

Joined: Sun Dec 25, 2016 1:54 am
Posts: 204
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...


Top
 Profile  
 
 Post subject: Re: GCC is broken
PostPosted: Sun Mar 12, 2017 5:17 am 
Offline
Member
Member
User avatar

Joined: Thu Mar 27, 2014 3:57 am
Posts: 568
Location: Moscow, Russia
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


Top
 Profile  
 
 Post subject: Re: GCC is broken
PostPosted: Sun Mar 12, 2017 5:45 am 
Offline

Joined: Wed Feb 15, 2017 8:29 am
Posts: 17
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


Top
 Profile  
 
 Post subject: Re: GCC is broken
PostPosted: Sun Mar 12, 2017 5:58 am 
Offline
Member
Member
User avatar

Joined: Fri Feb 17, 2017 4:01 pm
Posts: 641
Location: Ukraine, Bachmut
what
Code:
i686-elf-gcc -print-sysroot

shows?
Code:
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).


Top
 Profile  
 
 Post subject: Re: GCC is broken
PostPosted: Sun Mar 12, 2017 6:34 am 
Offline

Joined: Wed Feb 15, 2017 8:29 am
Posts: 17
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


Top
 Profile  
 
 Post subject: Re: GCC is broken
PostPosted: Sun Mar 12, 2017 8:10 am 
Offline
Member
Member
User avatar

Joined: Fri Feb 17, 2017 4:01 pm
Posts: 641
Location: Ukraine, Bachmut
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).


Top
 Profile  
 
 Post subject: Re: GCC is broken
PostPosted: Sun Mar 12, 2017 10:04 am 
Offline

Joined: Wed Feb 15, 2017 8:29 am
Posts: 17
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


Top
 Profile  
 
 Post subject: Re: GCC is broken
PostPosted: Sun Mar 12, 2017 12:47 pm 
Offline
Member
Member
User avatar

Joined: Sun Dec 25, 2016 1:54 am
Posts: 204
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....

_________________
Plagiarize. Plagiarize. Let not one line escape thine eyes...


Top
 Profile  
 
 Post subject: Re: GCC is broken
PostPosted: Sun Mar 12, 2017 1:13 pm 
Offline

Joined: Wed Feb 15, 2017 8:29 am
Posts: 17
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"


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 31 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group