GCC+binutils: Added basic support for KolibriOS

Signed-off-by: Maxim Logaev <maxlogaev@proton.me>
This commit is contained in:
2024-11-18 13:04:06 +03:00
parent c093165814
commit 7dfee0d47d
19 changed files with 364 additions and 6 deletions

4
.gitignore vendored
View File

@@ -30,3 +30,7 @@
*.exe *.exe
*.out *.out
*.app *.app
# Build dirs
toolchain/binutils/build
toolchain/gcc/build

38
build-toolchain.sh Executable file
View File

@@ -0,0 +1,38 @@
#!/bin/bash
# Copyright (C) KolibriOS-NG team 2024. All rights reserved
# Distributed under terms of the GNU General Public License
source scripts/start-recipe
ROOT_DIR="$PWD"
PATH=$PATH:"$SDK_TOOLCHAIN_DIR/bin"
declare -a DIRS=(
"toolchain/binutils"
"toolchain/gcc"
)
BUILD()
{
for dir in "${DIRS[@]}" ; do
cd "$ROOT_DIR/$dir"
./kos-recipe.sh
done
}
INSTALL()
{
:;
# "For root recipes, installation is performed in BUILD"
}
CLEAN()
{
for dir in "${DIRS[@]}" ; do
cd "$ROOT_DIR/$dir"
./kos-recipe.sh --clean
done
}
source scripts/end-recipe

32
scripts/end-recipe Normal file
View File

@@ -0,0 +1,32 @@
# Copyright (C) KolibriOS-NG team 2024. All rights reserved
# Distributed under terms of the GNU General Public License
show_help()
{
cat << EOF
usage: $0 [OPTION]
Options:
--build run recipe build
--install run recipe install (stub for root scripts)
--clean remove build artifacts
--help show this help
Running without parameters is equivalent to running:
'--build' and '--install'
Warning: Run the script only from the directory where it is located!
EOF
}
if [[ $# -eq 0 ]]; then
BUILD
INSTALL
else
case $1 in
"--build" ) BUILD ;;
"--install" ) INSTALL ;;
"--clean" ) CLEAN ;;
"--help" ) show_help ;;
*) fatal "Unknown argument!"
esac
fi

17
scripts/start-recipe Normal file
View File

@@ -0,0 +1,17 @@
set -eu
TARGET=i586-kolibrios
SDK_TOOLCHAIN_DIR=/opt/kolibrios-sdk/toolchain
SDK_SYSROOT_DIR=/opt/kolibrios-sdk/sysroot
NUM_JOBS=8
msg()
{
echo -e "\e[32m$1\e[0m"
}
fatal()
{
echo -e "\e[31m$1\e[0m"
exit 1
}

View File

@@ -778,6 +778,11 @@ case "${targ}" in
targ_selvecs="i386_pe_vec i386_pe_big_vec i386_pei_vec i386_elf32_vec iamcu_elf32_vec pdb_vec" targ_selvecs="i386_pe_vec i386_pe_big_vec i386_pei_vec i386_elf32_vec iamcu_elf32_vec pdb_vec"
targ_underscore=yes targ_underscore=yes
;; ;;
i[3-7]86-*-kolibrios*)
targ_defvec=i386_pe_vec
targ_selvecs="i386_pe_vec i386_pei_vec"
targ_underscore=yes
;;
i[3-7]86-*-vxworks*) i[3-7]86-*-vxworks*)
targ_defvec=i386_elf32_vxworks_vec targ_defvec=i386_elf32_vxworks_vec
targ_underscore=yes targ_underscore=yes

View File

@@ -14626,7 +14626,7 @@ do
BUILD_WINDMC='$(WINDMC_PROG)$(EXEEXT)' BUILD_WINDMC='$(WINDMC_PROG)$(EXEEXT)'
BUILD_DLLWRAP='$(DLLWRAP_PROG)$(EXEEXT)' BUILD_DLLWRAP='$(DLLWRAP_PROG)$(EXEEXT)'
;; ;;
i[3-7]86-*-interix) i[3-7]86-*-interix | i[3-7]86-*-kolibrios*)
BUILD_DLLTOOL='$(DLLTOOL_PROG)' BUILD_DLLTOOL='$(DLLTOOL_PROG)'
if test -z "$DLLTOOL_DEFAULT"; then if test -z "$DLLTOOL_DEFAULT"; then
DLLTOOL_DEFAULT="-DDLLTOOL_DEFAULT_I386" DLLTOOL_DEFAULT="-DDLLTOOL_DEFAULT_I386"
@@ -14685,7 +14685,7 @@ do
powerpc*-*-aix* | rs6000-*-aix*) powerpc*-*-aix* | rs6000-*-aix*)
od_vectors="$od_vectors objdump_private_desc_xcoff" od_vectors="$od_vectors objdump_private_desc_xcoff"
;; ;;
*-*-pe* | *-*-cygwin* | *-*-mingw*) *-*-pe* | *-*-cygwin* | *-*-mingw* | *-*-kolibrios*)
od_vectors="$od_vectors objdump_private_desc_pe" od_vectors="$od_vectors objdump_private_desc_pe"
;; ;;
*-*-darwin*) *-*-darwin*)

View File

@@ -399,6 +399,10 @@ case $1 in
basic_machine=arm-unknown basic_machine=arm-unknown
basic_os=mingw32ce basic_os=mingw32ce
;; ;;
kolibrios)
basic_machine=i586-pc
basic_os=kolibrios
;;
monitor) monitor)
basic_machine=m68k-rom68k basic_machine=m68k-rom68k
basic_os=coff basic_os=coff
@@ -1758,7 +1762,7 @@ case $os in
| onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \ | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \
| midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \ | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \
| nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \ | nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \
| fiwix* | mlibc* ) | fiwix* | mlibc* | kolibrios*)
;; ;;
# This one is extra strict with allowed versions # This one is extra strict with allowed versions
sco3.2v2 | sco3.2v[4-9]* | sco5v6*) sco3.2v2 | sco3.2v[4-9]* | sco5v6*)

View File

@@ -250,6 +250,7 @@ case ${generic_target} in
i386-*-msdos*) fmt=aout ;; i386-*-msdos*) fmt=aout ;;
i386-*-moss*) fmt=elf ;; i386-*-moss*) fmt=elf ;;
i386-*-pe) fmt=coff em=pe ;; i386-*-pe) fmt=coff em=pe ;;
i386-*-kolibrios*) fmt=coff em=pe ;;
i386-*-cygwin*) i386-*-cygwin*)
case ${cpu} in case ${cpu} in
x86_64*) fmt=coff em=pep ;; x86_64*) fmt=coff em=pep ;;

View File

@@ -0,0 +1,38 @@
#!/bin/bash
source ../../scripts/start-recipe
BUILD()
{
mkdir -p build
cd build
../configure --target=$TARGET \
--prefix="$SDK_TOOLCHAIN_DIR" \
--with-sysroot="$SDK_SYSROOT_DIR" \
--disable-werror \
--disable-nls \
--disable-intl \
--disable-sim \
--disable-gdb \
--enable-shared
make -j$NUM_JOBS
msg "Binutils build successful!"
cd ..
}
INSTALL()
{
cd build
make install-strip
msg "Binutils install successful!"
cd ..
}
CLEAN()
{
rm -rf build
msg "Binutils build artifacts removed!"
}
source ../../scripts/end-recipe

View File

@@ -430,6 +430,9 @@ i[3-7]86-*-cygwin*) targ_emul=i386pe ;
i[3-7]86-*-mingw32*) targ_emul=i386pe ; i[3-7]86-*-mingw32*) targ_emul=i386pe ;
targ_extra_ofiles="deffilep.o pdb.o pe-dll.o" targ_extra_ofiles="deffilep.o pdb.o pe-dll.o"
;; ;;
i[3-7]86-*-kolibrios*) targ_emul=i386pe ;
targ_extra_ofiles="deffilep.o pe-dll.o"
;;
i[3-7]86-*-interix*) targ_emul=i386pe_posix; i[3-7]86-*-interix*) targ_emul=i386pe_posix;
targ_extra_ofiles="deffilep.o pe-dll.o" targ_extra_ofiles="deffilep.o pe-dll.o"
;; ;;

View File

@@ -395,6 +395,10 @@ case $1 in
basic_machine=i686-pc basic_machine=i686-pc
basic_os=mingw32 basic_os=mingw32
;; ;;
kolibrios)
basic_machine=i586-pc
basic_os=kolibrios
;;
mingw32ce) mingw32ce)
basic_machine=arm-unknown basic_machine=arm-unknown
basic_os=mingw32ce basic_os=mingw32ce
@@ -1749,7 +1753,7 @@ case $os in
| onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \ | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \
| midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \ | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \
| nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \ | nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \
| fiwix* ) | fiwix* | kolibrios*)
;; ;;
# This one is extra strict with allowed versions # This one is extra strict with allowed versions
sco3.2v2 | sco3.2v[4-9]* | sco5v6*) sco3.2v2 | sco3.2v[4-9]* | sco5v6*)

View File

@@ -13,6 +13,7 @@ target=fixinc.sh
case $machine in case $machine in
i?86-*-cygwin* | \ i?86-*-cygwin* | \
i?86-*-mingw32* | \ i?86-*-mingw32* | \
i?86-*-kolibrios* | \
x86_64-*-mingw32* | \ x86_64-*-mingw32* | \
powerpc-*-eabisim* | \ powerpc-*-eabisim* | \
powerpc-*-eabi* | \ powerpc-*-eabi* | \

View File

@@ -2102,6 +2102,29 @@ i[34567]86-*-cygwin*)
default_use_cxa_atexit=yes default_use_cxa_atexit=yes
use_gcc_stdint=wrap use_gcc_stdint=wrap
;; ;;
i[34567]86-*-kolibrios*)
tm_file="${tm_file} i386/unix.h i386/bsd.h i386/gas.h i386/cygming.h i386/kolibrios.h i386/mingw-stdint.h"
tm_defines="${tm_defines} TARGET_KOLIBRIOS=1"
c_target_objs="${c_target_objs} winnt-c.o"
cxx_target_objs="${cxx_target_objs} winnt-c.o"
d_target_objs="${d_target_objs} winnt-d.o"
tmake_file="${tmake_file} t-winnt i386/t-cygming t-slibgcc"
native_system_header_dir=/include
target_gtfiles="$target_gtfiles \$(srcdir)/config/i386/winnt.cc"
extra_options="${extra_options} i386/kolibrios.opt"
extra_objs="${extra_objs} winnt.o winnt-stubs.o"
cxx_target_objs="${cxx_target_objs} winnt-cxx.o"
target_has_targetcm="yes"
target_has_targetdm="yes"
gas=yes
gnu_ld=yes
default_use_cxa_atexit=yes
use_gcc_stdint=wrap
if test x$enable_threads = xyes; then
# Not supported yet!
thread_file='posix'
fi
;;
x86_64-*-cygwin*) x86_64-*-cygwin*)
need_64bit_isa=yes need_64bit_isa=yes
tm_file="${tm_file} i386/unix.h i386/bsd.h i386/gas.h i386/cygming.h i386/cygwin.h i386/cygwin-w64.h i386/cygwin-stdint.h" tm_file="${tm_file} i386/unix.h i386/bsd.h i386/gas.h i386/cygming.h i386/cygwin.h i386/cygwin-w64.h i386/cygwin-stdint.h"

View File

@@ -124,6 +124,12 @@ along with GCC; see the file COPYING3. If not see
#define TARGET_EXECUTABLE_SUFFIX ".exe" #define TARGET_EXECUTABLE_SUFFIX ".exe"
#ifdef TARGET_KOLIBRIOS
#define CYGMING_BUILTIN_ASSERT builtin_assert ("system=kolibrios");
#else
#define CYGMING_BUILTIN_ASSERT builtin_assert ("system=winnt");
#endif
#define TARGET_OS_CPP_BUILTINS() \ #define TARGET_OS_CPP_BUILTINS() \
do \ do \
{ \ { \
@@ -131,7 +137,7 @@ along with GCC; see the file COPYING3. If not see
builtin_define ("_X86_=1"); \ builtin_define ("_X86_=1"); \
if (TARGET_SEH) \ if (TARGET_SEH) \
builtin_define ("__SEH__"); \ builtin_define ("__SEH__"); \
builtin_assert ("system=winnt"); \ CYGMING_BUILTIN_ASSERT \
builtin_define ("__stdcall=__attribute__((__stdcall__))"); \ builtin_define ("__stdcall=__attribute__((__stdcall__))"); \
builtin_define ("__fastcall=__attribute__((__fastcall__))"); \ builtin_define ("__fastcall=__attribute__((__fastcall__))"); \
builtin_define ("__thiscall=__attribute__((__thiscall__))"); \ builtin_define ("__thiscall=__attribute__((__thiscall__))"); \

View File

@@ -0,0 +1,77 @@
/* Operating system specific defines to be used when targeting
GCC for KolibriOS
Copyright (C) 1997-2023 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>.
Copyright (C) KolibriOS team 2024. All rights reserved.
Distributed under terms of the GNU General Public License */
/* Additional predefined macros. */
#define EXTRA_OS_CPP_BUILTINS() \
do \
{ \
builtin_define ("__KOS__"); \
builtin_define ("__KOLIBRIOS__"); \
builtin_define ("_KOLIBRI"); \
builtin_define ("KOLIBRI"); \
} \
while (0)
/* Always link libgcc */
#undef LIBGCC_SPEC
#define LIBGCC_SPEC "-lgcc"
#undef REAL_LIBGCC_SPEC
#define REAL_LIBGCC_SPEC LIBGCC_SPEC
/* For KolibriOS applications always link libc.a */
#undef LIB_SPEC
#define LIB_SPEC "%{!shared: %{!mdll: -Tkos-app.lds}} -lc"
#define LINK_SPEC "%{mwindows:--subsystem windows} \
%{mconsole:--subsystem console} \
%{shared: %{mdll: %eshared and mdll are not compatible}} \
%{shared: --shared} %{mdll: --dll} \
%{shared|mdll: --image-base=0} \
%{!shared: %{!mdll: -Bstatic --image-base=0}} --file-alignment=16 --section-alignment=16"
/* Stub! Start file not used. */
#undef STARTFILE_SPEC
#define STARTFILE_SPEC ""
/* Stub! End file not used. */
#undef ENDFILE_SPEC
#define ENDFILE_SPEC ""
/* Running objcopy for KolibriOS applications */
#undef POST_LINK_SPEC
#define POST_LINK_SPEC "%{!shared: %{!mdll: i586-kolibrios-objcopy -Obinary %{o*:%*} %{!o*:a.exe} }}"
/* Native header directory */
#undef NATIVE_SYSTEM_HEADER_DIR
#define NATIVE_SYSTEM_HEADER_DIR "/include"
/* Don't use ".exe" suffix by default for KolibriOS */
#undef TARGET_EXECUTABLE_SUFFIX
#define TARGET_EXECUTABLE_SUFFIX ""
/* Stub! "-pthread" is not supported for KolibriOS. */
#undef GOMP_SELF_SPECS
#define GOMP_SELF_SPECS ""
#undef GTM_SELF_SPECS
#define GTM_SELF_SPECS ""

View File

@@ -0,0 +1,51 @@
; KolibriOS-specific options (For MinGW compatibility).
; Copyright (C) 2005-2023 Free Software Foundation, Inc.
;
; This file is part of GCC.
;
; GCC is free software; you can redistribute it and/or modify it under
; the terms of the GNU General Public License as published by the Free
; Software Foundation; either version 3, or (at your option) any later
; version.
;
; GCC is distributed in the hope that it will be useful, but WITHOUT ANY
; WARRANTY; without even the implied warranty of MERCHANTABILITY or
; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
; for more details.
;
; You should have received a copy of the GNU General Public License
; along with GCC; see the file COPYING3. If not see
; <http://www.gnu.org/licenses/>.
;
; Copyright (C) KolibriOS team 2024. All rights reserved.
; Distributed under terms of the GNU General Public License
mconsole
Target RejectNegative
Create console application.
mdll
Target RejectNegative
Generate code for a DLL.
mnop-fun-dllimport
Target Var(TARGET_NOP_FUN_DLLIMPORT)
Ignore dllimport for functions.
mwindows
Target
Create GUI application.
mpe-aligned-commons
Target Var(use_pe_aligned_common) Init(HAVE_GAS_ALIGNED_COMM)
Use the GNU extension to the PE format for aligned common data.
posix
Driver
fwritable-relocated-rdata
Common Var(flag_writable_rel_rdata) Init(0)
Put relocated read-only data into .data section.
; Retain blank line above

View File

@@ -13012,7 +13012,7 @@ case ${enable_threads} in
target_thread_file='single' target_thread_file='single'
;; ;;
aix | dce | lynx | mipssde | posix | rtems | \ aix | dce | lynx | mipssde | posix | rtems | \
single | tpf | vxworks | win32 | mcf) single | tpf | vxworks | win32 | mcf | kolibrios)
target_thread_file=${enable_threads} target_thread_file=${enable_threads}
;; ;;
*) *)

51
toolchain/gcc/kos-recipe.sh Executable file
View File

@@ -0,0 +1,51 @@
#!/bin/bash
# Copyright (C) KolibriOS-NG team 2024. All rights reserved
# Distributed under terms of the GNU General Public License
source ../../scripts/start-recipe
BUILD()
{
mkdir -p "$SDK_SYSROOT_DIR"
cp -af ../../libraries/newlib/newlib/libc/include/. "$SDK_SYSROOT_DIR/include"
msg "Newlib headers install successful!"
mkdir -p build
cd build
../configure --target=$TARGET \
--prefix="$SDK_TOOLCHAIN_DIR" \
--with-sysroot="$SDK_SYSROOT_DIR" \
--disable-nls \
--enable-shared \
--enable-languages=c
make -j$NUM_JOBS all-gcc
msg "GCC build successful!"
make -j$NUM_JOBS all-target-libgcc
msg "Libgcc build successful!"
cd ..
}
INSTALL()
{
cd build
make install-strip-gcc
msg "GCC install successful!"
make install-target-libgcc
msg "Libgcc install successful!"
cd ..
}
CLEAN()
{
rm -rf build
msg "GCC build artifacts removed!"
}
source ../../scripts/end-recipe

View File

@@ -837,6 +837,9 @@ x86_64-*-cygwin*)
# FIXME - dj - t-chkstk used to be in here, need a 64-bit version of that # FIXME - dj - t-chkstk used to be in here, need a 64-bit version of that
tmake_file="${tmake_file} ${tmake_eh_file} ${tmake_dlldir_file} i386/t-slibgcc-cygming i386/t-cygming i386/t-cygwin t-crtfm t-dfprules i386/t-chkstk" tmake_file="${tmake_file} ${tmake_eh_file} ${tmake_dlldir_file} i386/t-slibgcc-cygming i386/t-cygming i386/t-cygwin t-crtfm t-dfprules i386/t-chkstk"
;; ;;
i[34567]86-*-kolibrios*)
tmake_file="${tmake_file} i386/t-chkstk
esac
i[34567]86-*-mingw*) i[34567]86-*-mingw*)
extra_parts="crtbegin.o crtend.o crtfastmath.o" extra_parts="crtbegin.o crtend.o crtfastmath.o"
if test x$enable_vtable_verify = xyes; then if test x$enable_vtable_verify = xyes; then