From 8838e2cf22bb10ced016be3d4ef38a43070b45cf Mon Sep 17 00:00:00 2001 From: apio Date: Fri, 6 Jan 2023 17:35:07 +0100 Subject: [PATCH] Bring back the OS-Specific Toolchain on restart :^) --- .drone.yml | 4 +- CMakeLists.txt | 2 +- README.md | 13 ++- libc/CMakeLists.txt | 2 + libc/include/bits/attrs.h | 3 +- libc/include/bits/errno-return.h | 16 ++++ libc/include/errno.h | 8 ++ libc/include/stdio.h | 32 +++++++- libc/include/string.h | 31 +++++++ libc/include/time.h | 4 + libc/include/unistd.h | 10 +++ libc/src/errno.cpp | 3 + libc/src/stdio.cpp | 8 +- libc/src/string.cpp | 14 ++++ tools/binutils.patch | 117 +++++++++++++++++++++++++++ tools/env.sh | 4 +- tools/gcc.patch | 134 +++++++++++++++++++++++++++++++ tools/setup-binutils.sh | 8 +- tools/setup-env.sh | 4 +- tools/setup-gcc.sh | 21 ++--- 20 files changed, 400 insertions(+), 38 deletions(-) create mode 100644 libc/include/bits/errno-return.h create mode 100644 libc/include/errno.h create mode 100644 libc/include/string.h create mode 100644 libc/include/time.h create mode 100644 libc/src/errno.cpp create mode 100644 libc/src/string.cpp create mode 100644 tools/binutils.patch create mode 100644 tools/gcc.patch diff --git a/.drone.yml b/.drone.yml index ac733b83..2636d74a 100644 --- a/.drone.yml +++ b/.drone.yml @@ -11,7 +11,7 @@ steps: image: ubuntu commands: - apt update - - apt install build-essential cmake ninja-build wget nasm -y + - apt install cmake ninja-build wget nasm -y - wget https://pub.cloudapio.eu/luna/toolchains/ci-toolchain-arm64.tar.gz --quiet - tar xf ci-toolchain-arm64.tar.gz - rm ci-toolchain-arm64.tar.gz @@ -23,4 +23,4 @@ trigger: - restart event: - push - - pull_request \ No newline at end of file + - pull_request diff --git a/CMakeLists.txt b/CMakeLists.txt index 691b5745..0d4e5b69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ set(CMAKE_ASM_NASM_OBJECT_FORMAT elf64) set(CMAKE_ASM_NASM_LINK_EXECUTABLE "${ARCH}-luna-ld -o ") -set(CMAKE_FIND_ROOT_PATH ${LUNA_ROOT}/toolchain/x86-64-luna) +set(CMAKE_FIND_ROOT_PATH ${LUNA_ROOT}/toolchain/x86_64-luna) message(STATUS "Configuring Luna for ${ARCH}") diff --git a/README.md b/README.md index e0e08b1a..6bf71a57 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ A simple kernel and userspace for the x86_64 platform, written mostly in C++ and - Keeps track of [memory](kernel/src/memory/). (Rewritten) - Can read, write and execute files from a [virtual file system](kernel/src/fs/) supporting an initial ramdisk, device pseudo-filesystems... but no hard disks yet. (Not there yet) - Preemptive multitasking, with a round-robin [scheduler](kernel/src/thread/) that can switch between tasks. (Rewritten) -- Can [load ELF programs](kernel/src/sys/elf/) from the file system as userspace tasks. (Not there yet) -- [System call](kernel/src/sys/) interface and [C Library](libs/libc/), aiming to be mostly POSIX-compatible. (Not there yet) +- Can [load ELF programs](kernel/src/ELF.cpp) from the file system as userspace tasks. (Rewritten) +- [System call](kernel/src/sys/) interface and [C Library](libc/), aiming to be mostly POSIX-compatible. (Rewriting) - UNIX-like [multitasking primitives](kernel/src/sys/exec.cpp), which allow user tasks to spawn other tasks. (Not there yet) - Some simple [userspace programs](apps/src/), written in C. (Not there yet) - Simple [command-line shell](apps/src/sh.c), allowing for interactive use of the system. (Not there yet) @@ -25,12 +25,9 @@ A simple kernel and userspace for the x86_64 platform, written mostly in C++ and ## Notes - The default user is named 'selene' and you can log into it with the password 'moon'. -## Setup (broken) -**WARNING**: Setup will fail on this branch, since we do not have the required libc headers yet, and I removed the patches for now. Your best bet to build the toolchain is to switch to the `main` branch, where it will build successfully, and run `tools/setup.sh`. Then switch back to this branch, run `git clean -fd`, and continue development :) +## Setup (not broken anymore) -Alternatively, you can also download prebuilt toolchains for x86_64/arm64 Linux hosts from [here](https://pub.cloudapio.eu/luna/toolchains). Then run `tar xf toolchain-linux-ARCH.tar.gz -C /path/to/luna`. - -**ORIGINAL INSTRUCTIONS** +Although some prebuilt toolchains do exist, they have a hardcoded directory structure which is unlikely to match your setup and will thus cause problems. The best option is always to compile your own cross-toolchain, and now that the `restart` branch is mature enough to do that, go for it! To build and run Luna, you will need to build a [GCC Cross-Compiler](https://wiki.osdev.org/Why_do_I_need_a_Cross_Compiler) and cross-binutils for `x86_64-luna`. (Yes, Luna is advanced enough that it can use its own [OS-Specific Toolchain](https://wiki.osdev.org/OS_Specific_Toolchain), instead of a bare metal target like `x86_64-elf`. It is the first of my OS projects to be able to do so. The patches for Binutils and GCC are [binutils.patch](tools/binutils.patch) and [gcc.patch](tools/gcc.patch)). @@ -113,4 +110,4 @@ Port usage: `ports/make-package.sh ` will compile the port and make a package archive from it, which may be used in the future with a package manager :) ## License -Luna is open-source and free software under the [BSD-2 License](LICENSE). \ No newline at end of file +Luna is open-source and free software under the [BSD-2 License](LICENSE). diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt index 00e9e281..da64b048 100644 --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -5,6 +5,8 @@ set(SOURCES src/stdio.cpp src/stdlib.cpp src/unistd.cpp + src/errno.cpp + src/string.cpp ) if(${ARCH} STREQUAL "x86_64") diff --git a/libc/include/bits/attrs.h b/libc/include/bits/attrs.h index f71081cc..e8d28f34 100644 --- a/libc/include/bits/attrs.h +++ b/libc/include/bits/attrs.h @@ -1,10 +1,11 @@ #ifndef _BITS_ATTRS_H #define _BITS_ATTRS_H -#if !defined(_STDLIB_H) +#if !defined(_STDLIB_H) && !defined(_STRING_H) #error "Never include bits/attrs.h directly; use one of the standard library headers." #endif #define __noreturn __attribute__((noreturn)) +#define __deprecated __attribute__((deprecated)) #endif diff --git a/libc/include/bits/errno-return.h b/libc/include/bits/errno-return.h new file mode 100644 index 00000000..2a147622 --- /dev/null +++ b/libc/include/bits/errno-return.h @@ -0,0 +1,16 @@ +#ifndef _BITS_ERRNO_RETURN_H +#define _BITS_ERRNO_RETURN_H + +#include + +#define __errno_return(value, type) \ + do { \ + if (value < 0) \ + { \ + errno = (int)(-value); \ + return (type)-1; \ + } \ + return (type)value; \ + } while (0) + +#endif diff --git a/libc/include/errno.h b/libc/include/errno.h new file mode 100644 index 00000000..5ffee032 --- /dev/null +++ b/libc/include/errno.h @@ -0,0 +1,8 @@ +#ifndef _ERRNO_H +#define _ERRNO_H + +extern int errno; + +#include + +#endif diff --git a/libc/include/stdio.h b/libc/include/stdio.h index 746fe3a9..422efb68 100644 --- a/libc/include/stdio.h +++ b/libc/include/stdio.h @@ -1,12 +1,42 @@ #ifndef _STDIO_H #define _STDIO_H +#include +#include + +typedef struct +{ + int __unused; +} FILE; + +#define SEEK_SET 0 + +extern FILE* stderr; +#define stderr stderr + #ifdef __cplusplus extern "C" { #endif - void console_print(const char*); + int fflush(FILE*); + + FILE* fopen(const char*, const char*); + int fclose(FILE*); + + size_t fread(void*, size_t, size_t, FILE*); + size_t fwrite(const void*, size_t, size_t, FILE*); + + int fseek(FILE*, long, int); + long ftell(FILE*); + + void setbuf(FILE*, char*); + + int fprintf(FILE*, const char*, ...); + int vfprintf(FILE*, const char*, va_list); + int sprintf(char*, const char*, ...); + + int console_print(const char*); #ifdef __cplusplus } diff --git a/libc/include/string.h b/libc/include/string.h new file mode 100644 index 00000000..7fd223ae --- /dev/null +++ b/libc/include/string.h @@ -0,0 +1,31 @@ +#ifndef _STRING_H +#define _STRING_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + void* memcpy(void* dest, const void* src, size_t n); + void* memset(void* buf, int c, size_t n); + int memcmp(const void* a, const void* b, size_t n); + void* memmove(void* dest, const void* src, size_t n); + size_t strlen(const char* str); + + int strcmp(const char* a, const char* b); + __deprecated char* strcpy(char* dest, const char* src); + __deprecated char* strcat(char* dest, const char* src); + char* strchr(const char* str, int c); + + char* strdup(const char* str); + + char* strerror(int errnum); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libc/include/time.h b/libc/include/time.h new file mode 100644 index 00000000..4c01e32c --- /dev/null +++ b/libc/include/time.h @@ -0,0 +1,4 @@ +#ifndef _TIME_H +#define _TIME_H + +#endif diff --git a/libc/include/unistd.h b/libc/include/unistd.h index 6ad244fa..46e904c2 100644 --- a/libc/include/unistd.h +++ b/libc/include/unistd.h @@ -1,11 +1,21 @@ #ifndef _UNISTD_H #define _UNISTD_H +#include +#include + #ifdef __cplusplus extern "C" { #endif + pid_t fork(); + pid_t getpid(); + + int execv(const char*, char* const*); + int execve(const char*, char* const*, char* const*); + int execvp(const char*, char* const*); + long syscall(long, ...); #ifdef __cplusplus diff --git a/libc/src/errno.cpp b/libc/src/errno.cpp new file mode 100644 index 00000000..14a81221 --- /dev/null +++ b/libc/src/errno.cpp @@ -0,0 +1,3 @@ +#include + +int errno = 0; diff --git a/libc/src/stdio.cpp b/libc/src/stdio.cpp index aec92562..cecba48f 100644 --- a/libc/src/stdio.cpp +++ b/libc/src/stdio.cpp @@ -1,11 +1,15 @@ +#include #include #include #include +FILE* stderr = nullptr; + extern "C" { - void console_print(const char* str) + int console_print(const char* str) { - syscall(SYS_console_print, str); + long rc = syscall(SYS_console_print, str); + __errno_return(rc, int); } } diff --git a/libc/src/string.cpp b/libc/src/string.cpp new file mode 100644 index 00000000..0c22b9af --- /dev/null +++ b/libc/src/string.cpp @@ -0,0 +1,14 @@ +#define _LUNA_SYSTEM_ERROR_EXTENSIONS +#include +#include + +extern "C" +{ + // memcpy, memset, memcmp, memmove, strlen, strcmp, strcpy, strchr, strcat and strdup are defined in + // luna/CString.cpp, so the same definitions can be used by both kernel and userspace. + + char* strerror(int errnum) + { + return const_cast(error_string(errnum)); + } +} diff --git a/tools/binutils.patch b/tools/binutils.patch new file mode 100644 index 00000000..d375e06f --- /dev/null +++ b/tools/binutils.patch @@ -0,0 +1,117 @@ +diff --color -rN -u binutils-2.38/bfd/config.bfd build/binutils-2.38/bfd/config.bfd +--- a/binutils-2.38/bfd/config.bfd 2022-01-22 13:14:07.000000000 +0100 ++++ b/binutils-2.38/bfd/config.bfd 2022-10-01 22:12:16.914033792 +0200 +@@ -651,6 +651,11 @@ + targ_selvecs="iamcu_elf32_vec i386_pei_vec" + targ64_selvecs="x86_64_elf64_vec x86_64_elf32_vec x86_64_pe_vec x86_64_pei_vec l1om_elf64_vec k1om_elf64_vec" + ;; ++ i[3-7]86-*-luna*) ++ targ_defvec=i386_elf32_vec ++ targ_selvecs= ++ targ64_selvecs=x86_64_elf64_vec ++ ;; + i[3-7]86-*-redox*) + targ_defvec=i386_elf32_vec + targ_selvecs= +@@ -706,6 +711,11 @@ + targ_selvecs="i386_elf32_vec iamcu_elf32_vec x86_64_elf32_vec i386_pei_vec x86_64_pe_vec x86_64_pei_vec l1om_elf64_vec k1om_elf64_vec" + want64=true + ;; ++ x86_64-*-luna*) ++ targ_defvec=x86_64_elf64_vec ++ targ_selvecs=i386_elf32_vec ++ want64=true ++ ;; + x86_64-*-mingw* | x86_64-*-pe | x86_64-*-pep | x86_64-*-cygwin) + targ_defvec=x86_64_pe_vec + targ_selvecs="x86_64_pe_vec x86_64_pei_vec x86_64_pe_big_vec x86_64_elf64_vec l1om_elf64_vec k1om_elf64_vec i386_pe_vec i386_pei_vec i386_elf32_vec iamcu_elf32_vec" +diff --color -rN -u binutils-2.38/gas/configure.tgt build/binutils-2.38/gas/configure.tgt +--- a/binutils-2.38/gas/configure.tgt 2022-01-22 13:14:08.000000000 +0100 ++++ b/binutils-2.38/gas/configure.tgt 2022-10-01 22:12:38.115093972 +0200 +@@ -238,6 +238,7 @@ + x86_64*-linux-gnux32) arch=x86_64:32 ;; + esac ;; + i386-*-lynxos*) fmt=elf em=lynx ;; ++ i386-*-luna*) fmt=elf em=gnu ;; + i386-*-redox*) fmt=elf ;; + i386-*-solaris*) fmt=elf em=solaris ;; + i386-*-freebsd* \ +diff --color -rN -u binutils-2.38/ld/configure.tgt build/binutils-2.38/ld/configure.tgt +--- a/binutils-2.38/ld/configure.tgt 2022-01-22 15:19:36.000000000 +0100 ++++ b/binutils-2.38/ld/configure.tgt 2022-10-01 22:15:04.853571062 +0200 +@@ -329,6 +329,11 @@ + targ64_extra_emuls="elf_x86_64 elf32_x86_64 elf_l1om elf_k1om" + targ64_extra_libpath="elf_x86_64 elf32_x86_64" + ;; ++i[3-7]86-*-luna*) ++ targ_emul=elf_i386_luna ++ targ_extra_emuls=elf_i386 ++ targ64_extra_emuls="elf_x86_64_luna elf_x86_64" ++ ;; + i[3-7]86-*-redox*) targ_emul=elf_i386 + targ_extra_emuls=elf_x86_64 + ;; +@@ -967,6 +972,10 @@ + targ_extra_libpath="elf_i386 elf32_x86_64 elf_l1om elf_k1om" + tdir_elf_i386=`echo ${targ_alias} | sed -e 's/x86_64/i386/'` + ;; ++x86_64-*-luna*) ++ targ_emul=elf_x86_64_luna ++ targ_extra_emuls="elf_i386_luna elf_x86_64 elf_i386" ++ ;; + x86_64-*-redox*) targ_emul=elf_x86_64 + targ_extra_emuls=elf_i386 + ;; +diff --color -rN -u binutils-2.38/ld/emulparams/elf_i386_luna.sh build/binutils-2.38/ld/emulparams/elf_i386_luna.sh +--- a/dev/null 1970-01-01 01:00:00.000000000 +0100 ++++ b/binutils-2.38/ld/emulparams/elf_i386_luna.sh 2022-10-01 21:52:12.394068335 +0200 +@@ -0,0 +1,3 @@ ++source_sh ${srcdir}/emulparams/elf_i386.sh ++TEXT_START_ADDR=0x08000000 ++MAXPAGESIZE=0x1000 +\ No newline at end of file +diff --color -rN -u binutils-2.38/ld/emulparams/elf_x86_64_luna.sh build/binutils-2.38/ld/emulparams/elf_x86_64_luna.sh +--- a/dev/null 1970-01-01 01:00:00.000000000 +0100 ++++ b/binutils-2.38/ld/emulparams/elf_x86_64_luna.sh 2022-10-01 21:53:00.411200592 +0200 +@@ -0,0 +1,2 @@ ++source_sh ${srcdir}/emulparams/elf_x86_64.sh ++MAXPAGESIZE=0x1000 +\ No newline at end of file +diff --color -rN -u binutils-2.38/ld/Makefile.am build/binutils-2.38/ld/Makefile.am +--- a/binutils-2.38/ld/Makefile.am 2022-01-22 13:14:09.000000000 +0100 ++++ b/binutils-2.38/ld/Makefile.am 2022-10-01 22:18:02.660263017 +0200 +@@ -278,6 +278,7 @@ + eelf32xtensa.c \ + eelf32z80.c \ + eelf_i386.c \ ++ eelf_i386_luna.c \ + eelf_i386_be.c \ + eelf_i386_fbsd.c \ + eelf_i386_haiku.c \ +@@ -464,6 +465,7 @@ + eelf_x86_64_fbsd.c \ + eelf_x86_64_haiku.c \ + eelf_x86_64_sol2.c \ ++ eelf_x86_64_luna.c \ + ehppa64linux.c \ + ei386pep.c \ + emmo.c +diff --color -rN -u binutils-2.38/ld/Makefile.in build/binutils-2.38/ld/Makefile.in +--- a/binutils-2.38/ld/Makefile.in 2022-02-09 12:49:03.000000000 +0100 ++++ b/binutils-2.38/ld/Makefile.in 2022-10-01 22:17:46.740196925 +0200 +@@ -769,6 +769,7 @@ + eelf32xtensa.c \ + eelf32z80.c \ + eelf_i386.c \ ++ eelf_i386_luna.c \ + eelf_i386_be.c \ + eelf_i386_fbsd.c \ + eelf_i386_haiku.c \ +@@ -954,6 +955,7 @@ + eelf_x86_64_fbsd.c \ + eelf_x86_64_haiku.c \ + eelf_x86_64_sol2.c \ ++ eelf_x86_64_luna.c \ + ehppa64linux.c \ + ei386pep.c \ + emmo.c diff --git a/tools/env.sh b/tools/env.sh index daf02519..72d65835 100755 --- a/tools/env.sh +++ b/tools/env.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash export LUNA_ROOT=${LUNA_ROOT:-$(realpath $(dirname $0)/..)} export LUNA_BASE=${LUNA_BASE:-$LUNA_ROOT/base} -export PATH=$LUNA_ROOT/toolchain/x86-64-luna/bin:$LUNA_ROOT/toolchain/dist:$PATH +export PATH=$LUNA_ROOT/toolchain/x86_64-luna/bin:$LUNA_ROOT/toolchain/dist:$PATH [ -f "$LUNA_ROOT/env-local.sh" ] && source $LUNA_ROOT/env-local.sh @@ -16,4 +16,4 @@ export BUILD=ninja export CMAKE_GEN="Ninja" fi -export BUILD_DIR=$LUNA_ROOT/build/$BUILD-$ARCH \ No newline at end of file +export BUILD_DIR=$LUNA_ROOT/build/$BUILD-$ARCH diff --git a/tools/gcc.patch b/tools/gcc.patch new file mode 100644 index 00000000..3a984f97 --- /dev/null +++ b/tools/gcc.patch @@ -0,0 +1,134 @@ +diff --color -rN -u gcc-12.2.0/config.sub build/gcc-12.2.0/config.sub +--- a/gcc-12.2.0/config.sub 2022-08-19 10:09:52.128656687 +0200 ++++ b/gcc-12.2.0/config.sub 2022-10-02 11:27:45.660055384 +0200 +@@ -1723,7 +1723,7 @@ + | hpux* | unos* | osf* | luna* | dgux* | auroraux* | solaris* \ + | sym* | plan9* | psp* | sim* | xray* | os68k* | v88r* \ + | hiux* | abug | nacl* | netware* | windows* \ +- | os9* | macos* | osx* | ios* \ ++ | os9* | macos* | osx* | ios* | luna* \ + | mpw* | magic* | mmixware* | mon960* | lnews* \ + | amigaos* | amigados* | msdos* | newsos* | unicos* | aof* \ + | aos* | aros* | cloudabi* | sortix* | twizzler* \ +diff --color -rN -u gcc-12.2.0/fixincludes/mkfixinc.sh build/gcc-12.2.0/fixincludes/mkfixinc.sh +--- a/gcc-12.2.0/fixincludes/mkfixinc.sh 2022-08-19 10:09:52.160657095 +0200 ++++ b/gcc-12.2.0/fixincludes/mkfixinc.sh 2022-10-02 11:27:45.662055397 +0200 +@@ -12,6 +12,8 @@ + # Check for special fix rules for particular targets + case $machine in + i?86-*-cygwin* | \ ++ *-luna* | \ ++ *-*-luna* | \ + i?86-*-mingw32* | \ + x86_64-*-mingw32* | \ + powerpc-*-eabisim* | \ +diff --color -rN -u gcc-12.2.0/gcc/config/i386/x86_64-luna-kernel build/gcc-12.2.0/gcc/config/i386/x86_64-luna-kernel +--- a/dev/null 1970-01-01 01:00:00.000000000 +0100 ++++ b/gcc-12.2.0/gcc/config/i386/x86_64-luna-kernel 2022-10-02 11:45:30.955856133 +0200 +@@ -0,0 +1,4 @@ ++#Add libgcc multilib variant without red-zone requirement, for use in the kernel ++ ++MULTILIB_OPTIONS += mno-red-zone ++MULTILIB_DIRNAMES += no-red-zone +\ No newline at end of file +diff --color -rN -u gcc-12.2.0/gcc/config/luna.h build/gcc-12.2.0/gcc/config/luna.h +--- a/dev/null 1970-01-01 01:00:00.000000000 +0100 ++++ b/gcc-12.2.0/gcc/config/luna.h 2022-10-02 11:27:45.663055404 +0200 +@@ -0,0 +1,36 @@ ++#undef TARGET_LUNA ++#define TARGET_LUNA 1 ++ ++/* Default arguments you want when running your ++ i686-luna-gcc/x86_64-luna-gcc toolchain */ ++#undef LIB_SPEC ++#define LIB_SPEC "-lc" /* link against C standard library */ ++ ++/* Files that are linked before user code. ++ The %s tells GCC to look for these files in the library directory. */ ++#undef STARTFILE_SPEC ++#define STARTFILE_SPEC "crt0.o%s crti.o%s crtbegin.o%s" ++ ++/* Files that are linked after user code. */ ++#undef ENDFILE_SPEC ++#define ENDFILE_SPEC "crtend.o%s crtn.o%s" ++ ++#undef SIZE_TYPE ++#define SIZE_TYPE (TARGET_64BIT ? "long unsigned int" : "unsigned int") ++ ++/* Ensure that ptrdiff_t matches the actual pointer size */ ++#undef PTRDIFF_TYPE ++#define PTRDIFF_TYPE (TARGET_64BIT ? "long int" : "int") ++ ++/* Additional predefined macros. */ ++#undef TARGET_OS_CPP_BUILTINS ++#define TARGET_OS_CPP_BUILTINS() \ ++ do { \ ++ builtin_define("__luna__"); \ ++ builtin_define("__unix__"); \ ++ builtin_assert("system=luna"); \ ++ builtin_assert("system=unix"); \ ++ builtin_assert("system=posix"); \ ++ } while (0); ++ ++#undef LINK_SPEC ++#define LINK_SPEC "-z max-page-size=4096" +\ No newline at end of file +diff --color -rN -u gcc-12.2.0/gcc/config.gcc build/gcc-12.2.0/gcc/config.gcc +--- a/gcc-12.2.0/gcc/config.gcc 2022-08-19 10:09:52.552662114 +0200 ++++ b/gcc-12.2.0/gcc/config.gcc 2022-10-02 11:45:18.311797546 +0200 +@@ -895,6 +895,12 @@ + ;; + esac + ;; ++*-*-luna*) ++ gas=yes ++ gnu_ld=yes ++ default_use_cxa_atexit=yes ++ use_gcc_stdint=provide ++ ;; + *-*-netbsd*) + tm_p_file="${tm_p_file} netbsd-protos.h" + tmake_file="t-netbsd t-slibgcc" +@@ -1901,6 +1907,13 @@ + 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" + ;; ++i[34567]86-*-luna*) ++ tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h newlib-stdint.h i386/i386elf.h luna.h" ++ ;; ++x86_64-*-luna*) ++ tmake_file="${tmake_file} i386/x86_64-luna-kernel" ++ tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h newlib-stdint.h i386/i386elf.h i386/x86-64.h luna.h" ++ ;; + x86_64-*-rtems*) + tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h newlib-stdint.h i386/i386elf.h i386/x86-64.h i386/rtemself.h rtems.h" + ;; +diff --color -rN -u gcc-12.2.0/libgcc/config.host build/gcc-12.2.0/libgcc/config.host +--- a/gcc-12.2.0/libgcc/config.host 2022-08-19 10:09:54.664689148 +0200 ++++ b/gcc-12.2.0/libgcc/config.host 2022-10-02 11:27:45.671055461 +0200 +@@ -783,6 +783,14 @@ + ;; + i[34567]86-*-lynxos*) + ;; ++i[34567]86-*-luna*) ++ extra_parts="$extra_parts crti.o crtbegin.o crtend.o crtn.o" ++ tmake_file="$tmake_file i386/t-crtstuff t-crtstuff-pic t-libgcc-pic" ++ ;; ++x86_64-*-luna*) ++ extra_parts="$extra_parts crti.o crtbegin.o crtend.o crtn.o" ++ tmake_file="$tmake_file i386/t-crtstuff t-crtstuff-pic t-libgcc-pic" ++ ;; + i[34567]86-*-nto-qnx*) + tmake_file="$tmake_file i386/t-nto t-libgcc-pic" + extra_parts=crtbegin.o +diff --color -rN -u gcc-12.2.0/libgcc/libgcov.h build/gcc-12.2.0/libgcc/libgcov.h +--- a/gcc-12.2.0/libgcc/libgcov.h 2022-08-19 10:09:54.728689966 +0200 ++++ b/gcc-12.2.0/libgcc/libgcov.h 2022-10-02 11:41:48.571807335 +0200 +@@ -194,6 +194,7 @@ + #endif + + #include "gcov-io.h" ++#include + + /* Structures embedded in coveraged program. The structures generated + by write_profile must match these. */ diff --git a/tools/setup-binutils.sh b/tools/setup-binutils.sh index e7f59b03..e1b98559 100755 --- a/tools/setup-binutils.sh +++ b/tools/setup-binutils.sh @@ -24,7 +24,7 @@ echo Patching Binutils... cd toolchain -patch -u -i $LUNA_ROOT/tools/binutils.patch -p 1 -d build | filter-lines "binutils" "patch" +patch -u -i $LUNA_ROOT/tools/binutils.patch -p 1 -d build cd - @@ -39,12 +39,12 @@ unset CXX unset LD unset AR -../binutils-$LUNA_BINUTILS_VERSION_REQUIRED/configure --prefix="$BUILD_PREFIX" --target=$BUILD_TARGET --disable-nls --with-sysroot=$BUILD_SYSROOT --disable-werror | filter-lines "binutils" "configure" +../binutils-$LUNA_BINUTILS_VERSION_REQUIRED/configure --prefix="$BUILD_PREFIX" --target=$BUILD_TARGET --disable-nls --with-sysroot=$BUILD_SYSROOT --disable-werror echo Building Binutils... -make -j$(nproc) | filter-lines "binutils" "build" +make -j$(nproc) echo Installing Binutils... -make install | filter-lines "binutils" "install" \ No newline at end of file +make install diff --git a/tools/setup-env.sh b/tools/setup-env.sh index 1d3aa3d0..6e92d193 100755 --- a/tools/setup-env.sh +++ b/tools/setup-env.sh @@ -4,6 +4,6 @@ source $(dirname $0)/env.sh export LUNA_GCC_VERSION_REQUIRED=12.2.0 export LUNA_BINUTILS_VERSION_REQUIRED=2.38 -export BUILD_PREFIX=$LUNA_ROOT/toolchain/x86-64-luna +export BUILD_PREFIX=$LUNA_ROOT/toolchain/x86_64-luna export BUILD_TARGET=x86_64-luna -export BUILD_SYSROOT=$LUNA_ROOT/base \ No newline at end of file +export BUILD_SYSROOT=$LUNA_ROOT/base diff --git a/tools/setup-gcc.sh b/tools/setup-gcc.sh index 844509bf..94500386 100755 --- a/tools/setup-gcc.sh +++ b/tools/setup-gcc.sh @@ -32,7 +32,7 @@ echo Patching GCC... cd toolchain -patch -u -i $LUNA_ROOT/tools/gcc.patch -p 1 -d build | filter-lines "gcc" "patch" +patch -u -i $LUNA_ROOT/tools/gcc.patch -p 1 -d build cd - @@ -47,23 +47,14 @@ unset CXX unset LD unset AR -../gcc-$LUNA_GCC_VERSION_REQUIRED/configure --prefix="$BUILD_PREFIX" --target=$BUILD_TARGET --disable-nls --with-sysroot=$BUILD_SYSROOT --enable-languages=c,c++ --without-headers | filter-lines "gcc" "configure" +../gcc-$LUNA_GCC_VERSION_REQUIRED/configure --prefix="$BUILD_PREFIX" --target=$BUILD_TARGET --disable-nls --with-sysroot=$BUILD_SYSROOT --enable-languages=c,c++ --without-headers echo Building GCC... -make all-gcc -j$(nproc) | filter-lines "gcc" "build" -make all-target-libgcc -j$(nproc) CFLAGS_FOR_TARGET='-g -O2 -mcmodel=large -mno-red-zone' | filter-lines "libgcc" "build" +make all-gcc -j$(nproc) +make all-target-libgcc -j$(nproc) CFLAGS_FOR_TARGET='-g -O2 -mcmodel=large -mno-red-zone' echo Installing GCC... -make install-gcc | filter-lines "gcc" "install" -make install-target-libgcc | filter-lines "libgcc" "install" - -echo Building libstdc++... - -$LUNA_ROOT/tools/sync-libc.sh # libstdc++ needs libc to be built -make all-target-libstdc++-v3 CXXFLAGS_FOR_TARGET="-fno-exceptions" -j$(nproc) | filter-lines "libstdc++" "build" - -echo Installing libstdc++... - -make install-target-libstdc++-v3 | filter-lines "libstdc++" "install" \ No newline at end of file +make install-gcc +make install-target-libgcc