Following the 'Recoding' thread, I decided to go ahead and write a more conventional kernel as practice for my more ambitious plans. To this end, I was trying out the UEFI bare bones tutorial to see how to boot on a modern system.
I followed the tutorial example for compiling with GCC - mostly blindly, in part to see what faults I might find - and after making symoblic links to the data.c and efi.h files, I compiled the code successfully as follows:
Code: Select all
x86_64-w64-mingw32-gcc -ffreestanding -I ~/Deployments/cross-dev-utils/gnu-efi-code/inc/ -I ~/Deployments/cross-dev-utils/gnu-efi-code/inc/x86_64/ -I ~/Deployments/cross-dev-utils/gnu-efi-code/inc/protocol/ -c -o hello.o boot.c
x86_64-w64-mingw32-gcc -ffreestanding -I ~/Deployments/cross-dev-utils/gnu-efi-code/inc/ -I ~/Deployments/cross-dev-utils/gnu-efi-code/inc/x86_64/ -I ~/Deployments/cross-dev-utils/gnu-efi-code/inc/protocol/ -c -o data.o data.c
Code: Select all
x86_64-w64-mingw32-gcc -nostdlib -Wl,-dll -shared -Wl,--subsystem,10 -e efi_main -o BOOTX64.EFI hello.o data.o -lgcc
/home/schol-r-lea/opt/cross/lib/gcc/x86_64-w64-mingw32/11.0.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lgcc
collect2: error: ld returned 1 exit status
I tried adding the library path as recommended here,
Code: Select all
x86_64-w64-mingw32-gcc -nostdlib -Wl,-dll -shared -Wl,--subsystem,10 -e efi_main -L /home/schol-r-lea/opt/cross/lib/gcc/x86_64-w64-mingw32/11.0.0/../../../../x86_64-w64-mingw32/lib/ -lgcc -o BOOTX64.EFI hello.o data.o
I suspect the problem is either with my cross-compiler setup, or with the library path I am adding. To get the path and other relevant details, I used the following command:
Code: Select all
$ x86_64-w64-mingw32-gcc -xc -E -v -lgcc
Code: Select all
Using built-in specs.
COLLECT_GCC=x86_64-w64-mingw32-gcc
Target: x86_64-w64-mingw32
Configured with: /home/schol-r-lea/Deployments/cross-dev-utils/gcc/configure --target=x86_64-w64-mingw32 --prefix=/home/schol-r-lea/opt/cross --disable-nls --enable-languages=ada --without-headers
Thread model: win32
Supported LTO compression algorithms: zlib zstd
gcc version 11.0.0 20201231 (experimental) (GCC)
COMPILER_PATH=/home/schol-r-lea/opt/cross/libexec/gcc/x86_64-w64-mingw32/11.0.0/:/home/schol-r-lea/opt/cross/libexec/gcc/x86_64-w64-mingw32/11.0.0/:/home/schol-r-lea/opt/cross/libexec/gcc/x86_64-w64-mingw32/:/home/schol-r-lea/opt/cross/lib/gcc/x86_64-w64-mingw32/11.0.0/:/home/schol-r-lea/opt/cross/lib/gcc/x86_64-w64-mingw32/:/home/schol-r-lea/opt/cross/lib/gcc/x86_64-w64-mingw32/11.0.0/../../../../x86_64-w64-mingw32/bin/
LIBRARY_PATH=/home/schol-r-lea/opt/cross/lib/gcc/x86_64-w64-mingw32/11.0.0/:/home/schol-r-lea/opt/cross/lib/gcc/x86_64-w64-mingw32/11.0.0/../../../../x86_64-w64-mingw32/lib/../lib/:/home/schol-r-lea/opt/cross/lib/gcc/x86_64-w64-mingw32/11.0.0/../../../../x86_64-w64-mingw32/lib/
COLLECT_GCC_OPTIONS='-E' '-v' '-mtune=generic' '-march=x86-64'
Code: Select all
#!/bin/bash
HOME_DIR="/home/schol-r-lea"
BINUTILS_SRC="$HOME_DIR/Deployments/cross-dev-utils/binutils-gdb"
BINUTILS_BUILD="$BINUTILS_SRC/build"
DEST="$HOME_DIR/opt/cross"
cd $BINUTILS_SRC
git pull origin master
cd $BINUTILS_BUILD
for TARGET in "i686-elf" "x86_64-elf" \
"x86_64-w64-mingw32" \
"arm-none-eabi" "aarch64-none-elf" \
"arm-linux-gnueabihf" "aarch64-linux-gnu" \
"riscv32-unknown-elf" "riscv64-unknown-elf" \
"mipsel-unknown-elf" "mips64el-unknown-elf"
do
TARGET_DIR="$BINUTILS_BUILD/$TARGET"
if [ ! -d $TARGET_DIR ]; then
mkdir -p $TARGET_DIR
fi
make distclean
cd $TARGET_DIR
$BINUTILS_SRC/configure --target=$TARGET --prefix=$DEST --with-sysroot --disable-nls --disable-werror
make
make install
done
Code: Select all
#!/bin/bash
GCC_SRC="/home/schol-r-lea/Deployments/cross-dev-utils/gcc"
GCC_BUILD="$GCC_SRC/build"
DEST="/home/schol-r-lea/opt/cross"
cd $GCC_SRC
git pull origin master
cd $GCC_BUILD
for TARGET in "i686-elf" "x86_64-elf" \
"x86_64-w64-mingw32" \
"arm-none-eabi" "aarch64-none-elf" \
"arm-linux-gnueabihf" "aarch64-linux-gnu" \
"riscv32-unknown-elf" "riscv64-unknown-elf" \
"mipsel-unknown-elf" "mips64el-unknown-elf"
do
TARGET_DIR="$GCC_BUILD/$TARGET"
if [ ! -d $TARGET_DIR ]; then
mkdir -p $TARGET_DIR
fi
cd $TARGET_DIR
$GCC_SRC/configure --target=$TARGET --prefix=$DEST --disable-nls \
--enable-languages=objc,c,d,c++,go,ada \
--without-headers
make all-gcc
make all-target-libgcc
make install-gcc
make install-target-libgcc
done
One thing I did note was the absence of a linker script in the tutorial. LD scripts are something I sadly have ignored for the most part up until now, and I will definitely need help with writing one here.