ecomaikgolf / alma

toy kernel written in C++ for x86-64 machines with the mere purpose of learning OS development
8 stars 1 forks source link

libgcc without red_zone #1

Closed ecomaikgolf closed 3 years ago

ecomaikgolf commented 3 years ago

Maybe I have to rebuild gcc to make libgcc not use red_zone.

More info: https://wiki.osdev.org/Libgcc_without_red_zone

ecomaikgolf commented 3 years ago

Create the following file toolchain/gcc/gcc/config/i386/t-x86_64-elf

MULTILIB_OPTIONS += mno-red-zone
MULTILIB_DIRNAMES += no-red-zone

Modify toolchain/gcc/gcc/config.gcc

From:
 x86_64-*-elf*)
    tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h newlib-stdint.h i386/i386elf.h i386/x86-64.h"
    ;;
To:
 x86_64-*-elf*)
    tmake_file="${tmake_file} i386/t-x86_64-elf" # include the new multilib configuration
    tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h newlib-stdint.h i386/i386elf.h i386/x86-64.h"
    ;;

Then build as usual, GCC will build libgcc in two versions - one with red-zone enabled and one without.

./gcc/x86_64-pc-elf/4.9.1/libgcc.a
./gcc/x86_64-pc-elf/4.9.1/no-red-zone/libgcc.a

Using gcc, if you're unsure which libgcc version is going to be used you can check by passing -mno-red-zone and -print-libgcc-file-name to GCC:

x86_64-elf-gcc -mno-red-zone -print-libgcc-file-name
lib/gcc/x86_64-pc-elf/4.9.1/no-red-zone/libgcc.a

https://wiki.osdev.org/Libgcc_without_red_zone

ecomaikgolf commented 3 years ago

Works fine

[ecomaikgolf@desktop ../os-dev/bootloader]$ x86_64-elf-gcc -mno-red-zone -print-libgcc-file-name   

/run/media/HDD/Proyectos/os-dev/toolchain/build/bin/../lib/gcc/x86_64-elf/11.1.0/no-red-zone/libgcc.a