Switch back to GCC

This commit is contained in:
mintsuki 2020-09-13 14:36:18 +02:00
parent 859a10b142
commit 5663169aa6
7 changed files with 108 additions and 48 deletions

1
.gitignore vendored
View File

@ -1,6 +1,5 @@
/**/*.o
/**/*.a
/**/*.bc
/**/*.bin
/**/*.bin.gz
/**/*.elf

View File

@ -2,8 +2,8 @@ DESTDIR =
PREFIX = /usr/local
OS := $(shell uname)
CC = clang
OBJCOPY = llvm-objcopy
CC = cc
OBJCOPY = objcopy
CFLAGS = -O2 -pipe -Wall -Wextra
.PHONY: all install clean echfs-test ext2-test test.img
@ -21,12 +21,8 @@ src/limine.bin:
$(MAKE) -C src all
limine-install: src/limine.bin limine-install.c
$(CC) $(CFLAGS) -c limine-install.c -o limine-install.o
# FIXME: GNU objcopy supports `-O default` but for some stupid reason
# llvm-objcopy does not. This needs to be worked around.
# For now hardcode elf64-x86-64.
$(OBJCOPY) -I binary -O elf64-x86-64 src/limine.bin limine.o
$(CC) $(CFLAGS) limine.o limine-install.o -o limine-install
$(OBJCOPY) -I binary -O default src/limine.bin limine.o
$(CC) $(CFLAGS) limine.o limine-install.c -o limine-install
test.img:
rm -f test.img

View File

@ -1,11 +1,13 @@
OPT_LEVEL = z
CFLAGS = -pipe -Wall -Wextra
CC = ../toolchain/bin/i386-elf-gcc
LD = ../toolchain/bin/i386-elf-gcc
CFLAGS = -flto -Os -pipe -Wall -Wextra
INTERNAL_CFLAGS = \
-O$(OPT_LEVEL) \
-std=gnu99 \
-ffreestanding \
-flto \
-fno-stack-protector \
-fno-pic \
-mno-80387 \
-mno-mmx \
-mno-sse \
@ -13,37 +15,37 @@ INTERNAL_CFLAGS = \
-I. \
-Wno-address-of-packed-member
LDFLAGS = -flto -Os
INTERNAL_LDFLAGS = \
-static \
-lgcc \
-static-libgcc \
-nostdlib \
-Tlinker.ld \
-no-pie
-no-pie \
-static \
-Tlinker.ld
.PHONY: all clean
C_FILES := $(shell find ./ -type f -name '*.c' | grep -v bootsect | grep -v decompressor | sort)
ASM_FILES := $(shell find ./ -type f -name '*.asm' | grep -v bootsect | grep -v decompressor | sort)
ASM_OBJ := $(ASM_FILES:.asm=.o)
BC := $(C_FILES:.c=.bc)
OBJ := $(ASM_FILES:.asm=.o) $(C_FILES:.c=.o)
all: limine.bin
limine.bin: $(BC) $(ASM_OBJ)
llvm-link $(BC) -o bundle.bc
opt --O$(OPT_LEVEL) bundle.bc -o optimised_bundle.bc
clang --target=i386-elf -O$(OPT_LEVEL) -c optimised_bundle.bc -o optimised_bundle.o
ld.lld optimised_bundle.o $(ASM_OBJ) $(INTERNAL_LDFLAGS) -o stage2.elf
llvm-objcopy -O binary stage2.elf stage2.bin
limine.bin: $(OBJ)
$(LD) $(OBJ) $(LDFLAGS) $(INTERNAL_LDFLAGS) -o stage2.elf
objcopy -O binary stage2.elf stage2.bin
gzip -9 < stage2.bin > stage2.bin.gz
$(MAKE) -C decompressor
cd bootsect && nasm bootsect.asm -fbin -o ../limine.bin
%.bc: %.c
clang --target=i386-elf $(CFLAGS) $(INTERNAL_CFLAGS) -c $< -o $@
%.o: %.c
$(CC) $(CFLAGS) $(INTERNAL_CFLAGS) -c $< -o $@
%.o: %.asm
nasm $< -f elf32 -o $@
clean:
$(MAKE) -C decompressor clean
rm -f stage2.bin.gz limine.bin $(ASM_OBJ) $(BC)
rm -f stage2.bin.gz stage2.bin stage2.elf limine.bin $(OBJ)

View File

@ -1,11 +1,13 @@
OPT_LEVEL = z
CFLAGS = -pipe -Wall -Wextra
CC = ../../toolchain/bin/i386-elf-gcc
LD = ../../toolchain/bin/i386-elf-gcc
CFLAGS = -flto -Os -pipe -Wall -Wextra
INTERNAL_CFLAGS = \
-O$(OPT_LEVEL) \
-std=gnu99 \
-ffreestanding \
-flto \
-fno-stack-protector \
-fno-pic \
-mno-80387 \
-mno-mmx \
-mno-sse \
@ -13,28 +15,29 @@ INTERNAL_CFLAGS = \
-I. \
-Wno-address-of-packed-member
LDFLAGS = -flto -Os
INTERNAL_LDFLAGS = \
-static \
-lgcc \
-static-libgcc \
-nostdlib \
-Tlinker.ld \
-no-pie
-no-pie \
-static \
-Tlinker.ld
.PHONY: all clean
C_FILES := $(shell find ./ -type f -name '*.c' | sort)
BC := $(C_FILES:.c=.bc)
OBJ := $(C_FILES:.c=.o)
all: decompressor.bin
decompressor.bin: $(BC)
llvm-link $(BC) -o bundle.bc
opt --O$(OPT_LEVEL) bundle.bc -o optimised_bundle.bc
clang --target=i386-elf -O$(OPT_LEVEL) -c optimised_bundle.bc -o optimised_bundle.o
ld.lld optimised_bundle.o $(INTERNAL_LDFLAGS) -o decompressor.elf
llvm-objcopy -O binary decompressor.elf decompressor.bin
decompressor.bin: $(OBJ)
$(LD) $(OBJ) $(LDFLAGS) $(INTERNAL_LDFLAGS) -o decompressor.elf
objcopy -O binary decompressor.elf decompressor.bin
%.bc: %.c
clang --target=i386-elf $(CFLAGS) $(INTERNAL_CFLAGS) -c $< -o $@
%.o: %.c
$(CC) $(CFLAGS) $(INTERNAL_CFLAGS) -c $< -o $@
clean:
rm -f decompressor.bin $(BC)
rm -f decompressor.bin decompressor.elf $(OBJ)

View File

@ -12,8 +12,7 @@ ASM_BASIC(
"sub ecx, OFFSET bss_begin\n\t"
"rep stosb\n\t"
"mov ebx, OFFSET main\n\t"
"jmp ebx\n\t"
"jmp main\n\t"
);
#include <limine.h>

3
toolchain/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*
!.gitignore
!make_toolchain.sh

58
toolchain/make_toolchain.sh Executable file
View File

@ -0,0 +1,58 @@
#!/usr/bin/env bash
set -e
set -x
PREFIX="$(pwd)"
TARGET=i386-elf
BINUTILSVERSION=2.35
GCCVERSION=10.2.0
if [ -z "$MAKEFLAGS" ]; then
MAKEFLAGS="$1"
fi
export MAKEFLAGS
export PATH="$PREFIX/bin:$PATH"
if [ -x "$(command -v gmake)" ]; then
mkdir -p "$PREFIX/bin"
cat <<EOF >"$PREFIX/bin/make"
#!/usr/bin/env sh
gmake "\$@"
EOF
chmod +x "$PREFIX/bin/make"
fi
mkdir -p build
cd build
if [ ! -f binutils-$BINUTILSVERSION.tar.gz ]; then
wget -4 https://ftp.gnu.org/gnu/binutils/binutils-$BINUTILSVERSION.tar.gz # Force IPv4 otherwise wget hangs
fi
if [ ! -f gcc-$GCCVERSION.tar.gz ]; then
wget -4 https://ftp.gnu.org/gnu/gcc/gcc-$GCCVERSION/gcc-$GCCVERSION.tar.gz # Same as above
fi
tar -xf binutils-$BINUTILSVERSION.tar.gz
tar -xf gcc-$GCCVERSION.tar.gz
rm -rf build-gcc build-binutils
mkdir build-binutils
cd build-binutils
../binutils-$BINUTILSVERSION/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror
make
make install
cd ..
cd gcc-$GCCVERSION
contrib/download_prerequisites
cd ..
mkdir build-gcc
cd build-gcc
../gcc-$GCCVERSION/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c --without-headers
make all-gcc
make all-target-libgcc
make install-gcc
make install-target-libgcc