MineAssemble icon indicating copy to clipboard operation
MineAssemble copied to clipboard

Couldn't make on Mac OS X 10.8

Open drakmail opened this issue 11 years ago • 18 comments

MineAssemble|master ⇒ make test
nasm -felf -o bin/init.o src/init.asm -isrc/
src/init.asm:47: warning: numeric constant 0x00CF9A000000FFFF does not fit in 32 bits
src/init.asm:48: warning: numeric constant 0x00CF92000000FFFF does not fit in 32 bits
src/init.asm:46: error: integer supplied to a DQ instruction
src/init.asm:47: error: integer supplied to a DQ instruction
src/init.asm:48: error: integer supplied to a DQ instruction
make: *** [bin/init.o] Error 1

drakmail avatar Jun 17 '13 22:06 drakmail

Which version of nasm do you have? The manual states that dq is supposed to be an 8 byte constant.

Overv avatar Jun 17 '13 22:06 Overv

@Overv my nasm version:

MineAssemble|master ⇒ nasm -v
NASM version 0.98.40 (Apple Computer, Inc. build 11) compiled on Aug  4 2012

drakmail avatar Jun 17 '13 22:06 drakmail

@drakmail I'm afraid you'll have to find a way to update NASM on OSX, because it seems incredibly out-of-date:

overv@li517-161:~# nasm -v
NASM version 2.08.01 compiled on Jun  2 2010

Overv avatar Jun 17 '13 22:06 Overv

With nasm from brew:

MineAssemble|master ⇒ /usr/local/Cellar/nasm/2.10.07/bin/nasm -v
NASM version 2.10.07 compiled on Jun 18 2013
MineAssemble|master⚡ ⇒ make
/usr/local/Cellar/nasm/2.10.07/bin/nasm -felf -o bin/init.o src/init.asm -isrc/
/usr/local/Cellar/nasm/2.10.07/bin/nasm -felf -o bin/interrupts.o src/interrupts.asm -isrc/
/usr/local/Cellar/nasm/2.10.07/bin/nasm -felf -o bin/vga.o src/vga.asm -isrc/
/usr/local/Cellar/nasm/2.10.07/bin/nasm -felf -o bin/main.o src/main.asm -isrc/
gcc -m32 -c -g -o bin/reference.o src/reference.c -std=c99 -ffreestanding -Ofast -nostdlib -nostdinc -fno-builtin -nostartfiles -nodefaultlibs -fno-exceptions -fno-stack-protector -static -fno-pic
cc1: error: invalid option argument ‘-Ofast’
make: *** [bin/reference.o] Error 1

Now something is wrong with gcc :)

drakmail avatar Jun 17 '13 22:06 drakmail

You can substitute -Ofast with -O3 -ffast-math. (It's not the same, but it has the same intent.)

Overv avatar Jun 17 '13 22:06 Overv

Almost done:

MineAssemble|master⚡ ⇒ make
gcc -m32 -c -g -o bin/reference.o src/reference.c -std=c99 -ffreestanding -O3 -ffast-math   -nostdlib -nostdinc -fno-builtin -nostartfiles -nodefaultlibs -fno-exceptions -fno-stack-protector -static -fno-pic
/usr/local/Cellar/nasm/2.10.07/bin/nasm -felf -o bin/textures.o src/textures.asm -isrc/
/usr/local/Cellar/nasm/2.10.07/bin/nasm -felf -o bin/cmath.o src/cmath.asm -isrc/
/usr/local/Cellar/nasm/2.10.07/bin/nasm -felf -o bin/splash.o src/splash.asm -isrc/
/usr/local/Cellar/nasm/2.10.07/bin/nasm -felf -o bin/world.o src/world.asm -isrc/
/usr/local/Cellar/nasm/2.10.07/bin/nasm -felf -o bin/player.o src/player.asm -isrc/
/usr/local/Cellar/nasm/2.10.07/bin/nasm -felf -o bin/input.o src/input.asm -isrc/
/usr/local/Cellar/nasm/2.10.07/bin/nasm -felf -o bin/graphics.o src/graphics.asm -isrc/
/usr/local/Cellar/nasm/2.10.07/bin/nasm -felf -o bin/globals.o src/globals.asm -isrc/
ld -m elf_i386 -T src/link.ld -o bin/mineassemble.bin bin/init.o bin/interrupts.o bin/vga.o bin/main.o bin/reference.o bin/textures.o bin/cmath.o bin/splash.o bin/world.o bin/player.o bin/input.o bin/graphics.o bin/globals.o
ld: warning: option -m is obsolete and being ignored
ld: file not found: elf_i386
make: *** [bin/mineassemble.bin] Error 1

drakmail avatar Jun 17 '13 22:06 drakmail

From some searching around the internet, it seems like the OSX version of ld doesn't support elf. I'm not sure what the implications of changing everything to the mach-o format would be.

Try changing -felf to -f macho and -m elf_i386 to -arch i386. (See this post)

Overv avatar Jun 17 '13 22:06 Overv

Another error... and man ld on mac os x doesn't include any reference to scriptfiles.

MineAssemble|master⚡ ⇒ make
mkdir -p bin
/usr/local/Cellar/nasm/2.10.07/bin/nasm -f macho -o bin/init.o src/init.asm -isrc/
/usr/local/Cellar/nasm/2.10.07/bin/nasm -f macho -o bin/interrupts.o src/interrupts.asm -isrc/
/usr/local/Cellar/nasm/2.10.07/bin/nasm -f macho -o bin/vga.o src/vga.asm -isrc/
/usr/local/Cellar/nasm/2.10.07/bin/nasm -f macho -o bin/main.o src/main.asm -isrc/
gcc -m32 -c -g -o bin/reference.o src/reference.c -std=c99 -ffreestanding -O3 -ffast-math   -nostdlib -nostdinc -fno-builtin -nostartfiles -nodefaultlibs -fno-exceptions -fno-stack-protector -static -fno-pic
/usr/local/Cellar/nasm/2.10.07/bin/nasm -f macho -o bin/textures.o src/textures.asm -isrc/
/usr/local/Cellar/nasm/2.10.07/bin/nasm -f macho -o bin/cmath.o src/cmath.asm -isrc/
/usr/local/Cellar/nasm/2.10.07/bin/nasm -f macho -o bin/splash.o src/splash.asm -isrc/
/usr/local/Cellar/nasm/2.10.07/bin/nasm -f macho -o bin/world.o src/world.asm -isrc/
/usr/local/Cellar/nasm/2.10.07/bin/nasm -f macho -o bin/player.o src/player.asm -isrc/
/usr/local/Cellar/nasm/2.10.07/bin/nasm -f macho -o bin/input.o src/input.asm -isrc/
/usr/local/Cellar/nasm/2.10.07/bin/nasm -f macho -o bin/graphics.o src/graphics.asm -isrc/
/usr/local/Cellar/nasm/2.10.07/bin/nasm -f macho -o bin/globals.o src/globals.asm -isrc/
ld -arch i386 -T src/link.ld -o bin/mineassemble.bin bin/init.o bin/interrupts.o bin/vga.o bin/main.o bin/reference.o bin/textures.o bin/cmath.o bin/splash.o bin/world.o bin/player.o bin/input.o bin/graphics.o bin/globals.o
ld: unknown option: -T
make: *** [bin/mineassemble.bin] Error 1

drakmail avatar Jun 17 '13 22:06 drakmail

I'm afraid then that the OSX version of ld is too restricted and will not work.

Overv avatar Jun 17 '13 23:06 Overv

I'll try ld from the brew soon.

drakmail avatar Jun 17 '13 23:06 drakmail

@drakmail Any luck?

Overv avatar Jun 18 '13 19:06 Overv

@Overv couldn't find ld in brew =/

drakmail avatar Jun 18 '13 20:06 drakmail

@drakmail I'm afraid then that this is a case where OSX simply doesn't offer the tools for a niche use case like this. When I worked on my MacBook on this, I used a Linux VPS to compile :V

Overv avatar Jun 18 '13 21:06 Overv

Well, that really sucks. OS X is the only *NIX machine I have consistent access to. I want to try this... I might just fork the problem and see if I can get it working.

SevenBits avatar Jun 19 '13 13:06 SevenBits

@drakmail, @SevenBits . You should be able to build this using any operating system that can run GNU GCC and GNU Binutils, including Mac OS X. You can not use Mac OS X's ld linker, because it produces wrong kind of binaries. You have to build a cross-compiler toolchain.

GNU ld is a part of GNU binutils. You need to build GNU binutils and GNU gcc cross compiler from source (./configure --target=i686-pc-elf or x86_64-pc-elf something like this) to be able to build.

@Overv You must use a cross compiler to build kernel images like this. Using the gcc that is shipped with your OS may cause failures in subtle ways. For example, I had some problems building @rikusalminen/danjeros, a toy kernel image with the compiler shipped in Ubuntu, even though I was building for the same cpu arch as I was running on. Unfortunately, I can't remember the problem but the solution was using a cross compiler (I spent a lot of time debugging this problem).

You should change the Makefile to explicitly use i686-pc-elf-gcc and i686-pc-elf-ld instead of plain ld and gcc.

More info: http://wiki.osdev.org/GCC_Cross-Compiler

rikusalminen avatar Jun 20 '13 10:06 rikusalminen

@rikusalminen That makes sense and may even explain the problems I've had running the program on other computers than my own. I'll get on it.

Overv avatar Jun 20 '13 15:06 Overv

@Overv I built a i686-pc-elf toolchain from source and built and tested MineAssemble with it. Works like a charm.

I changed the Makefile to use i686-pc-elf-ld and i686-pc-elf-gcc explicitly.

Here's how to build the toolchain. Takes about an hour or two on a decent computer.

# Install libmpc, libgmp, libmpfr  (requied for binutils and gcc)
sudo apt-get install libmpc-dev libgmp-dev libmpfr-dev

# http://www.multiprecision.org/
# http://gmplib.org/
# http://www.mpfr.org/

# Install flex and bison (required for GCC)
sudo apt-get install flex bison

# http://flex.sourceforge.net/
# http://www.gnu.org/software/bison/

# Install libsdl (optional front end for qemu)
sudo apt-get install libsdl-dev

# http://www.libsdl.org

# Install nasm (no compile time configuration needed)
sudo apt-get install nasm

# http://www.nasm.us/

# Create directories for source, build files and binaries
mkdir ~/src                 # Source code
mkdir ~/i686-pc-elf-build   # Temporary build files
mkdir ~/i686-pc-elf         # Toolchain install destination

# Get source code for Binutils, GCC and QEMU
git clone git://sourceware.org/git/binutils.git ~/src/binutils
git clone git://gcc.gnu.org/git/gcc.git ~/src/gcc
git clone git://git.qemu-project.org/qemu.git ~/src/qemu

# http://www.gnu.org/software/binutils/
# http://gcc.gnu.org/
# http://www.qemu.org/

# Check out latest release versions
cd ~/src/binutils ; git checkout binutils-2_23_1
cd ~/src/gcc ; git checkout gcc-4_8-branch
cd ~/src/qemu ; git checkout v1.5.0

# Build binutils for target i686-pc-elf
mkdir ~/i686-pc-elf-build/binutils ; cd ~/i686-pc-elf-build/binutils
~/src/binutils/configure --prefix=$HOME/i686-pc-elf --target=i686-pc-elf --disable-shared --disable-nls
make -j 4  # parallel make for 4 cpus
make install

# Build GCC (C compiler only) for target i686-pc-elf
mkdir ~/i686-pc-elf-build/gcc ; cd ~/gcc-pc-elf-build/gcc
~/src/gcc/configure --prefix=$HOME/i686-pc-elf --target=i686-pc-elf --enable-languages=c --disable-shared --disable-nls
make -j 4 all-gcc
make install-gcc

# Build qemu with i386-softmmu target (with SDL front end)
mkdir ~/i686-pc-elf-build/qemu ; cd ~/gcc-pc-elf-build/qemu
~/src/qemu/configure --prefix=$HOME/i686-pc-elf --target-list=i386-softmmu --enable-sdl
make -j 4
make install

# Add toolchain to $PATH
export PATH=$HOME/i686-pc-elf/bin:$PATH

@drakmail, @SevenBits . These instructions above should work for OSX too, but you'll have to install the prerequisites from brew instead of apt-get or compile them from source. Alternatively, you can investigate if brew provides a way to install GCC and binutils cross toolchains (for i686-pc-elf target).

rikusalminen avatar Jun 21 '13 09:06 rikusalminen

@SevenBits sure go ahead and use crosstool-ng, it probably works.

rikusalminen avatar Jun 21 '13 11:06 rikusalminen