Switch back to GCC
This commit is contained in:
parent
859a10b142
commit
5663169aa6
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,6 +1,5 @@
|
|||||||
/**/*.o
|
/**/*.o
|
||||||
/**/*.a
|
/**/*.a
|
||||||
/**/*.bc
|
|
||||||
/**/*.bin
|
/**/*.bin
|
||||||
/**/*.bin.gz
|
/**/*.bin.gz
|
||||||
/**/*.elf
|
/**/*.elf
|
||||||
|
12
Makefile
12
Makefile
@ -2,8 +2,8 @@ DESTDIR =
|
|||||||
PREFIX = /usr/local
|
PREFIX = /usr/local
|
||||||
|
|
||||||
OS := $(shell uname)
|
OS := $(shell uname)
|
||||||
CC = clang
|
CC = cc
|
||||||
OBJCOPY = llvm-objcopy
|
OBJCOPY = objcopy
|
||||||
CFLAGS = -O2 -pipe -Wall -Wextra
|
CFLAGS = -O2 -pipe -Wall -Wextra
|
||||||
|
|
||||||
.PHONY: all install clean echfs-test ext2-test test.img
|
.PHONY: all install clean echfs-test ext2-test test.img
|
||||||
@ -21,12 +21,8 @@ src/limine.bin:
|
|||||||
$(MAKE) -C src all
|
$(MAKE) -C src all
|
||||||
|
|
||||||
limine-install: src/limine.bin limine-install.c
|
limine-install: src/limine.bin limine-install.c
|
||||||
$(CC) $(CFLAGS) -c limine-install.c -o limine-install.o
|
$(OBJCOPY) -I binary -O default src/limine.bin limine.o
|
||||||
# FIXME: GNU objcopy supports `-O default` but for some stupid reason
|
$(CC) $(CFLAGS) limine.o limine-install.c -o limine-install
|
||||||
# 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
|
|
||||||
|
|
||||||
test.img:
|
test.img:
|
||||||
rm -f test.img
|
rm -f test.img
|
||||||
|
40
src/Makefile
40
src/Makefile
@ -1,11 +1,13 @@
|
|||||||
OPT_LEVEL = z
|
CC = ../toolchain/bin/i386-elf-gcc
|
||||||
CFLAGS = -pipe -Wall -Wextra
|
LD = ../toolchain/bin/i386-elf-gcc
|
||||||
|
|
||||||
INTERNAL_CFLAGS = \
|
CFLAGS = -flto -Os -pipe -Wall -Wextra
|
||||||
-O$(OPT_LEVEL) \
|
|
||||||
|
INTERNAL_CFLAGS = \
|
||||||
-std=gnu99 \
|
-std=gnu99 \
|
||||||
-ffreestanding \
|
-ffreestanding \
|
||||||
-flto \
|
-fno-stack-protector \
|
||||||
|
-fno-pic \
|
||||||
-mno-80387 \
|
-mno-80387 \
|
||||||
-mno-mmx \
|
-mno-mmx \
|
||||||
-mno-sse \
|
-mno-sse \
|
||||||
@ -13,37 +15,37 @@ INTERNAL_CFLAGS = \
|
|||||||
-I. \
|
-I. \
|
||||||
-Wno-address-of-packed-member
|
-Wno-address-of-packed-member
|
||||||
|
|
||||||
|
LDFLAGS = -flto -Os
|
||||||
|
|
||||||
INTERNAL_LDFLAGS = \
|
INTERNAL_LDFLAGS = \
|
||||||
-static \
|
-lgcc \
|
||||||
|
-static-libgcc \
|
||||||
-nostdlib \
|
-nostdlib \
|
||||||
-Tlinker.ld \
|
-no-pie \
|
||||||
-no-pie
|
-static \
|
||||||
|
-Tlinker.ld
|
||||||
|
|
||||||
.PHONY: all clean
|
.PHONY: all clean
|
||||||
|
|
||||||
C_FILES := $(shell find ./ -type f -name '*.c' | grep -v bootsect | grep -v decompressor | sort)
|
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_FILES := $(shell find ./ -type f -name '*.asm' | grep -v bootsect | grep -v decompressor | sort)
|
||||||
ASM_OBJ := $(ASM_FILES:.asm=.o)
|
OBJ := $(ASM_FILES:.asm=.o) $(C_FILES:.c=.o)
|
||||||
BC := $(C_FILES:.c=.bc)
|
|
||||||
|
|
||||||
all: limine.bin
|
all: limine.bin
|
||||||
|
|
||||||
limine.bin: $(BC) $(ASM_OBJ)
|
limine.bin: $(OBJ)
|
||||||
llvm-link $(BC) -o bundle.bc
|
$(LD) $(OBJ) $(LDFLAGS) $(INTERNAL_LDFLAGS) -o stage2.elf
|
||||||
opt --O$(OPT_LEVEL) bundle.bc -o optimised_bundle.bc
|
objcopy -O binary stage2.elf stage2.bin
|
||||||
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
|
|
||||||
gzip -9 < stage2.bin > stage2.bin.gz
|
gzip -9 < stage2.bin > stage2.bin.gz
|
||||||
$(MAKE) -C decompressor
|
$(MAKE) -C decompressor
|
||||||
cd bootsect && nasm bootsect.asm -fbin -o ../limine.bin
|
cd bootsect && nasm bootsect.asm -fbin -o ../limine.bin
|
||||||
|
|
||||||
%.bc: %.c
|
%.o: %.c
|
||||||
clang --target=i386-elf $(CFLAGS) $(INTERNAL_CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) $(INTERNAL_CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
%.o: %.asm
|
%.o: %.asm
|
||||||
nasm $< -f elf32 -o $@
|
nasm $< -f elf32 -o $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(MAKE) -C decompressor 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)
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
OPT_LEVEL = z
|
CC = ../../toolchain/bin/i386-elf-gcc
|
||||||
CFLAGS = -pipe -Wall -Wextra
|
LD = ../../toolchain/bin/i386-elf-gcc
|
||||||
|
|
||||||
INTERNAL_CFLAGS = \
|
CFLAGS = -flto -Os -pipe -Wall -Wextra
|
||||||
-O$(OPT_LEVEL) \
|
|
||||||
|
INTERNAL_CFLAGS = \
|
||||||
-std=gnu99 \
|
-std=gnu99 \
|
||||||
-ffreestanding \
|
-ffreestanding \
|
||||||
-flto \
|
-fno-stack-protector \
|
||||||
|
-fno-pic \
|
||||||
-mno-80387 \
|
-mno-80387 \
|
||||||
-mno-mmx \
|
-mno-mmx \
|
||||||
-mno-sse \
|
-mno-sse \
|
||||||
@ -13,28 +15,29 @@ INTERNAL_CFLAGS = \
|
|||||||
-I. \
|
-I. \
|
||||||
-Wno-address-of-packed-member
|
-Wno-address-of-packed-member
|
||||||
|
|
||||||
|
LDFLAGS = -flto -Os
|
||||||
|
|
||||||
INTERNAL_LDFLAGS = \
|
INTERNAL_LDFLAGS = \
|
||||||
-static \
|
-lgcc \
|
||||||
|
-static-libgcc \
|
||||||
-nostdlib \
|
-nostdlib \
|
||||||
-Tlinker.ld \
|
-no-pie \
|
||||||
-no-pie
|
-static \
|
||||||
|
-Tlinker.ld
|
||||||
|
|
||||||
.PHONY: all clean
|
.PHONY: all clean
|
||||||
|
|
||||||
C_FILES := $(shell find ./ -type f -name '*.c' | sort)
|
C_FILES := $(shell find ./ -type f -name '*.c' | sort)
|
||||||
BC := $(C_FILES:.c=.bc)
|
OBJ := $(C_FILES:.c=.o)
|
||||||
|
|
||||||
all: decompressor.bin
|
all: decompressor.bin
|
||||||
|
|
||||||
decompressor.bin: $(BC)
|
decompressor.bin: $(OBJ)
|
||||||
llvm-link $(BC) -o bundle.bc
|
$(LD) $(OBJ) $(LDFLAGS) $(INTERNAL_LDFLAGS) -o decompressor.elf
|
||||||
opt --O$(OPT_LEVEL) bundle.bc -o optimised_bundle.bc
|
objcopy -O binary decompressor.elf decompressor.bin
|
||||||
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
|
|
||||||
|
|
||||||
%.bc: %.c
|
%.o: %.c
|
||||||
clang --target=i386-elf $(CFLAGS) $(INTERNAL_CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) $(INTERNAL_CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f decompressor.bin $(BC)
|
rm -f decompressor.bin decompressor.elf $(OBJ)
|
||||||
|
@ -12,8 +12,7 @@ ASM_BASIC(
|
|||||||
"sub ecx, OFFSET bss_begin\n\t"
|
"sub ecx, OFFSET bss_begin\n\t"
|
||||||
"rep stosb\n\t"
|
"rep stosb\n\t"
|
||||||
|
|
||||||
"mov ebx, OFFSET main\n\t"
|
"jmp main\n\t"
|
||||||
"jmp ebx\n\t"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
#include <limine.h>
|
#include <limine.h>
|
||||||
|
3
toolchain/.gitignore
vendored
Normal file
3
toolchain/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
||||||
|
!make_toolchain.sh
|
58
toolchain/make_toolchain.sh
Executable file
58
toolchain/make_toolchain.sh
Executable 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
|
Loading…
Reference in New Issue
Block a user