OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Apr 17, 2024 8:52 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Assembly file errors when using i686-elf-gcc cross-compiler
PostPosted: Fri Apr 20, 2018 9:28 am 
Offline
Member
Member

Joined: Fri Apr 20, 2018 9:15 am
Posts: 35
Location: Cambridge, UK
I compiled a cross-compiler for my Mac (macOS 10.13.3 High Sierra) targeting i686-elf using the tutorial on the wiki. When trying to compile my kernel's main c file (I neglected to make a cross-compiler before starting on my OS) with make VERBOSE=1 I get the following:

Quote:
-> Compiling src/kernel/kmain.c
mkdir -p build/obj/kernel
i686-elf-gcc -std=gnu99 -Isrc/inc -nostdlib -ffreestanding -lgcc -Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-variable -c src/kernel/kmain.c -o build/obj/kernel/kmain.o
/var/folders/2t/xt0gv1y9783gf_wwtyp3_y_00000gn/T//ccS8Jmd5.s:6:9: error: invalid alignment value
.align 32
^
/var/folders/2t/xt0gv1y9783gf_wwtyp3_y_00000gn/T//ccS8Jmd5.s:7:2: error: unknown directive
.type driver_ifc, @object
^
/var/folders/2t/xt0gv1y9783gf_wwtyp3_y_00000gn/T//ccS8Jmd5.s:8:2: error: unknown directive
.size driver_ifc, 64
^
/var/folders/2t/xt0gv1y9783gf_wwtyp3_y_00000gn/T//ccS8Jmd5.s:26:18: error: unexpected token in '.section' directive
.section .rodata
^
/var/folders/2t/xt0gv1y9783gf_wwtyp3_y_00000gn/T//ccS8Jmd5.s:33:2: error: unknown directive
.type kmain, @function
^
/var/folders/2t/xt0gv1y9783gf_wwtyp3_y_00000gn/T//ccS8Jmd5.s:37:2: error: instruction requires: Not 64-bit mode
pushl %ebp
^
/var/folders/2t/xt0gv1y9783gf_wwtyp3_y_00000gn/T//ccS8Jmd5.s:61:2: error: instruction requires: Not 64-bit mode
pushl -20(%ebp)
^
/var/folders/2t/xt0gv1y9783gf_wwtyp3_y_00000gn/T//ccS8Jmd5.s:62:2: error: instruction requires: Not 64-bit mode
pushl -12(%ebp)
^
/var/folders/2t/xt0gv1y9783gf_wwtyp3_y_00000gn/T//ccS8Jmd5.s:67:2: error: instruction requires: Not 64-bit mode
pushl $50
^
/var/folders/2t/xt0gv1y9783gf_wwtyp3_y_00000gn/T//ccS8Jmd5.s:72:2: error: instruction requires: Not 64-bit mode
pushl $.LC0
^
/var/folders/2t/xt0gv1y9783gf_wwtyp3_y_00000gn/T//ccS8Jmd5.s:78:2: error: instruction requires: Not 64-bit mode
pushl %eax
^
/var/folders/2t/xt0gv1y9783gf_wwtyp3_y_00000gn/T//ccS8Jmd5.s:82:2: error: instruction requires: Not 64-bit mode
pushl $.LC1
^
/var/folders/2t/xt0gv1y9783gf_wwtyp3_y_00000gn/T//ccS8Jmd5.s:90:2: error: instruction requires: Not 64-bit mode
pushl -16(%ebp)
^
/var/folders/2t/xt0gv1y9783gf_wwtyp3_y_00000gn/T//ccS8Jmd5.s:102:2: error: unknown directive
.size kmain, .-kmain
^
make: *** [build/obj/kernel/kmain.o] Error 1


Below is the output from i686-elf-gcc -v

Quote:
Using built-in specs.
COLLECT_GCC=i686-elf-gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/i686-elf/7.3.0/lto-wrapper
Target: i686-elf
Configured with: ../gcc-7.3.0/configure --target=i686-elf --prefix=/usr/local --disable-nls --enable-languages=c,c++ --without-headers
Thread model: single
gcc version 7.3.0 (GCC)


And here is the repohttps://github.com/SamTebbs33/jaq

All google searches have yielded nothing and I'm really confused.


Top
 Profile  
 
 Post subject: Re: Assembly file errors when using i686-elf-gcc cross-compi
PostPosted: Fri Apr 20, 2018 1:13 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
Some of the error messages would seem to indicate that you are assembling 32-bit source with a 64-bit assembler.

Can we assume that you built the appropriate binutils?


Top
 Profile  
 
 Post subject: Re: Assembly file errors when using i686-elf-gcc cross-compi
PostPosted: Fri Apr 20, 2018 2:14 pm 
Offline
Member
Member

Joined: Fri Aug 19, 2016 10:28 pm
Posts: 360
I am not a mac user, but I am left with the impression that your gcc is trying to use the xcode's assembler, which is also called "as". This assembler is not intended to produce x86 code, so the interaction fails. Google tells me that xcode installs gas as well, but I doubt that it is x86 targeted either. You could check this with "gcc -print-prog-name=as" (which could be different from the one in the path) and then interrogate the executable you are given or use the package manager to tell you its origin.

So. One option is to build (or acquire from somewhere) a cross-targeting binutils and point the gcc configuration with the --with-as and --with-ld options, as described here. Or you could simply set the PATH and I believe the configure script should pick them up. If you want to make a test without rebuilding gcc, you could install the target specific gas and then use the -B option to tell the compiler what (extra) paths to search for binaries and executables. Also check this SO post.


Top
 Profile  
 
 Post subject: Re: Assembly file errors when using i686-elf-gcc cross-compi
PostPosted: Fri Apr 20, 2018 3:38 pm 
Offline
Member
Member

Joined: Fri Apr 20, 2018 9:15 am
Posts: 35
Location: Cambridge, UK
simeonz wrote:
I am not a mac user, but I am left with the impression that your gcc is trying to use the xcode's assembler, which is also called "as". This assembler is not intended to produce x86 code, so the interaction fails. Google tells me that xcode installs gas as well, but I doubt that it is x86 targeted either. You could check this with "gcc -print-prog-name=as" (which could be different from the one in the path) and then interrogate the executable you are given or use the package manager to tell you its origin.

So. One option is to build (or acquire from somewhere) a cross-targeting binutils and point the gcc configuration with the --with-as and --with-ld options, as described here. Or you could simply set the PATH and I believe the configure script should pick them up. If you want to make a test without rebuilding gcc, you could install the target specific gas and then use the -B option to tell the compiler what (extra) paths to search for binaries and executables. Also check this SO post.


I ran "gcc -print-prog-name=as" and it did indeed look like gcc was using the xcode installation, so I reconfigured my GCC download with the "--with-as" and "--with-ld" arguments pointing to the path of the i686 as and ld. Making this then produced a working version of i686-elf-gcc, thanks to you both for the help!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 211 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