Compare commits

...

26 Commits

Author SHA1 Message Date
f607ac54ce Fallback to curl(1) if wget(1) is not available 2019-06-24 15:18:32 +02:00
edeb084a80 Update the copyright notice 2019-06-10 22:39:27 +02:00
6c1bca1d8b Code cleanup 2019-06-10 22:39:27 +02:00
a344f50d48 Fix building GCC for i386 2019-06-10 22:39:27 +02:00
65077c310b Fix the destination prefix and environment 2019-06-10 22:39:27 +02:00
c951afb206 Refer to the ports as architectures instead 2019-06-10 22:37:10 +02:00
349c5e8e70 Stop building binutils or GCC upon errors 2019-06-10 22:37:10 +02:00
db4d22ad4f Code cleanup 2019-06-10 22:37:10 +02:00
dba8998597 Allow flags to be set for make(1) 2019-06-10 22:37:10 +02:00
6e054d538e Add a few comments 2019-06-10 22:37:10 +02:00
4bfb0f484d Let the port be specified on the command-line 2019-06-10 22:37:10 +02:00
55639d6ed8 Import patches to binutils and GCC
While there, also update the documentation.
2019-06-10 22:37:10 +02:00
418ac53c63 Actually port binutils and GCC to DeforaOS
This currently enables the i386 and amd64 ports.
2019-06-10 22:37:10 +02:00
abccc8ae02 Correct the definitions for multilib 2019-06-10 22:37:10 +02:00
25bd73685a Include architecture-dependent files on x86
Both are still empty though (32- and 64-bit)
2019-06-10 22:37:10 +02:00
e41057f853 No longer force --enable-shared
According to GCC's documentation it is enabled by default since GCC >
2.95, see:
https://gcc.gnu.org/install/configure.html
2019-06-10 22:37:10 +02:00
8a9e99a0fa Also set LD_LIBRARY_PATH on NetBSD 2019-06-10 22:37:10 +02:00
7f67fe895f Avoid warnings about old recipes
It seems that ${GENSCRIPTS} is now ran automatically by binutils.
2019-06-10 22:37:10 +02:00
9643b84432 Default to gmake(1) for $MAKE on NetBSD 2019-06-10 22:37:10 +02:00
cf2b0803ec Only patch or configure binutils and GCC once 2019-06-10 22:37:10 +02:00
4568376d4a Allow flags to be set per platform for tar 2019-06-10 22:37:10 +02:00
bf920e1fcc Add a helper for portability 2019-06-10 22:37:10 +02:00
abcfb8382c Add a multilib without red zone on amd64 2019-06-10 22:37:10 +02:00
1ca45414b4 Progress towards a dedicated toolchain 2019-06-10 22:37:10 +02:00
8457bae2cd Code cleanup 2019-06-10 22:37:10 +02:00
3fff50c2a8 Default to "i686-deforaos-elf" as the target 2019-06-10 22:37:10 +02:00
11 changed files with 671 additions and 106 deletions

View File

@ -6,8 +6,10 @@ compile code suitable there. This document gathers the different steps required
for this purpose. Three major steps are required:
* install the dependencies
* compile binutils
* compile GCC
* patch and compile binutils
* patch and compile GCC
For convenience, a helper script is available in `cross-gcc.sh`.
Dependencies
------------
@ -15,15 +17,15 @@ Dependencies
Binutils and GCC require the following software components to be available in
the system prior to their installation:
| Component | Notes |
| --------- | ----------------------- |
| Make | eg GNU Make or BSD Make |
| Bison | |
| Flex | |
| GMP | |
| MPC | |
| MPFR | |
| Texinfo | |
| Component | Notes |
| --------- | -------------------- |
| Make | GNU Make is required |
| Bison | |
| Flex | |
| GMP | |
| MPC | |
| MPFR | |
| Texinfo | Optional |
Please refer to the manual of your local system for information on how to find
and install these components as required.
@ -39,20 +41,23 @@ is version 2.32:
To configure binutils it is necessary to choose a target. It can be chosen
according to the following table:
| Port | Target |
| ----- | --------- |
| amd64 | amd64-elf |
| i386 | i686-elf |
| Architecture | Target |
| ------------ | ------------------- |
| amd64 | amd64-none-deforaos |
| i386 | i686-none-deforaos |
Modify the environment to reflect this choice; in this case for the i386 port:
Modify the environment to reflect this choice; in this case for the i386
architecture:
$ TARGET="i686-elf"
$ TARGET="i686-none-deforaos"
$ PREFIX="$HOME/opt/cross-gcc-$TARGET"
$ PATH="$PREFIX/bin:$PATH"
Extract, configure, and build binutils in a dedicated tree:
Extract, patch, configure, and build binutils in a dedicated tree:
$ tar xzf binutils-2.32.tar.gz
$ (cd binutils-2.32 && patch -p1 < ../doc/patch-binutils_2.32.diff)
$ (cd binutils-2.32/ld && aclocal && automake)
$ mkdir binutils-build
$ (cd binutils-build && ../binutils-2.32/configure --target="$TARGET" \
--prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror)
@ -69,11 +74,10 @@ version 8.3.0:
Just the same, GCC has to be configured for the target chosen.
*Note:* GNU Make is required to build GCC.
Extract, configure, and build GCC in a dedicated tree:
Extract, patch, configure, and build GCC in a dedicated tree:
$ tar xzf gcc-8.3.0.tar.gz
$ (cd gcc-8.3.0 && patch -p1 < ../doc/patch-gcc_8.3.0.diff)
$ mkdir gcc-build
$ (cd gcc-build && ../gcc-8.3.0/configure --target="$TARGET" \
--prefix="$PREFIX" --disable-nls --enable-languages=c,c++ \
@ -88,7 +92,7 @@ Using the cross-compiler
Make sure the compiler binaries are available in your PATH:
$ export TARGET="i686-elf"
$ export TARGET="i686-none-deforaos"
$ export PATH="$HOME/opt/cross-gcc-$TARGET/bin:$PATH"
The compiler can then be used directly. For instance, its version can be

View File

@ -26,6 +26,7 @@
#variables
ARCH="i386"
BINUTILS_FLAGS=
BINUTILS_TARGETS="all install"
BINUTILS_VERSION="2.32"
@ -34,60 +35,434 @@ GCC_TARGETS="all-gcc all-target-libgcc install-gcc install-target-libgcc"
GCC_VERSION="8.3.0"
GZEXT="gz"
MIRROR="https://ftpmirror.gnu.org"
TARGET="i686-elf"
PROGNAME="cross-gcc.sh"
TARGET=
#executables
ACLOCAL="aclocal"
AUTOMAKE="automake"
CAT="cat"
CURL="curl"
MAKE="make"
MAKE_FLAGS=
MKDIR="mkdir -p"
PATCH="patch"
TAR="tar"
TAR_FLAGS="-xzf"
UNAME="uname"
WGET="wget"
#functions
#main
#binutils
_binutils()
{
version="$1"
#Modify the environment to reflect the port chosen
#Download binutils
[ -f "binutils-$version.tar.$GZEXT" ] ||
_download "$MIRROR/binutils/binutils-$version.tar.$GZEXT"
#Extract binutils
if [ ! -d "binutils-$version" ]; then
$TAR $TAR_FLAGS "binutils-$version.tar.$GZEXT"
#Patch binutils for DeforaOS
(cd "binutils-$version" && $PATCH -p1) << EOF
--- binutils-2.32/ld/emulparams/elf_i386_deforaos.sh.orig 1970-01-01 01:00:00.000000000 +0100
+++ binutils-2.32/ld/emulparams/elf_i386_deforaos.sh 2019-05-09 17:30:46.000000000 +0200
@@ -0,0 +1,3 @@
+. \${srcdir}/emulparams/elf_i386.sh
+GENERATE_SHLIB_SCRIPT=yes
+GENERATE_PIE_SCRIPT=yes
--- binutils-2.32/ld/emulparams/elf_x86_64_deforaos.sh.orig 1970-01-01 01:00:00.000000000 +0100
+++ binutils-2.32/ld/emulparams/elf_x86_64_deforaos.sh 2019-05-09 17:30:46.000000000 +0200
@@ -0,0 +1 @@
+. \${srcdir}/emulparams/elf_x86_64_deforaos.sh
--- binutils-2.32/ld/Makefile.am.orig 2019-01-19 17:01:33.000000000 +0100
+++ binutils-2.32/ld/Makefile.am 2019-05-09 17:30:46.000000000 +0200
@@ -285,6 +285,7 @@
eelf_i386.c \\
eelf_i386_be.c \\
eelf_i386_chaos.c \\
+ eelf_i386_deforaos.c \\
eelf_i386_fbsd.c \\
eelf_i386_ldso.c \\
eelf_i386_nacl.c \\
@@ -455,6 +456,7 @@
eelf_k1om_fbsd.c \\
eelf_x86_64.c \\
eelf_x86_64_cloudabi.c \\
+ eelf_x86_64_deforaos.c \\
eelf_x86_64_fbsd.c \\
eelf_x86_64_nacl.c \\
eelf_x86_64_sol2.c \\
@@ -1295,6 +1297,10 @@
eelf_i386_chaos.c: \$(srcdir)/emulparams/elf_i386_chaos.sh \\
\$(ELF_X86_DEPS) \$(srcdir)/scripttempl/elf_chaos.sc \${GEN_DEPENDS}
+eelf_i386_deforaos.c: \$(srcdir)/emulparams/elf_i386_deforaos.sh \\
+ \$(srcdir)/emulparams/elf_i386.sh \\
+ \$(ELF_X86_DEPS) \$(srcdir)/scripttempl/elf.sc \${GEN_DEPENDS}
+
eelf_i386_fbsd.c: \$(srcdir)/emulparams/elf_i386_fbsd.sh \\
\$(srcdir)/emulparams/elf_i386.sh \\
\$(ELF_X86_DEPS) \$(srcdir)/scripttempl/elf.sc \${GEN_DEPENDS}
@@ -1853,6 +1859,10 @@
\$(srcdir)/emulparams/elf_x86_64.sh \\
\$(ELF_X86_DEPS) \$(srcdir)/scripttempl/elf.sc \${GEN_DEPENDS}
+eelf_x86_64_deforaos.c: \$(srcdir)/emulparams/elf_x86_64_deforaos.sh \\
+ \$(srcdir)/emulparams/elf_x86_64.sh \\
+ \$(ELF_X86_DEPS) \$(srcdir)/scripttempl/elf.sc \${GEN_DEPENDS}
+
eelf_x86_64_fbsd.c: \$(srcdir)/emulparams/elf_x86_64_fbsd.sh \\
\$(srcdir)/emulparams/elf_x86_64.sh \\
\$(ELF_X86_DEPS) \$(srcdir)/scripttempl/elf.sc \${GEN_DEPENDS}
--- binutils-2.32/ld/configure.tgt.orig 2019-05-11 04:48:32.000000000 +0200
+++ binutils-2.32/ld/configure.tgt 2019-05-11 05:58:31.000000000 +0200
@@ -240,10 +240,13 @@
i[3-7]86-*-lynxos*) targ_emul=i386lynx ;;
i[3-7]86-*-aros*) targ_emul=elf_i386
targ_extra_emuls=elf_iamcu ;;
+i[3-7]86-*-deforaos*) targ_emul=elf_i386
+ targ_extra_emuls=elf_iamcu ;;
i[3-7]86-*-rdos*) targ_emul=elf_i386
targ_extra_emuls=elf_iamcu ;;
x86_64-*-rdos*) targ_emul=elf64rdos ;;
x86_64-*-cloudabi*) targ_emul=elf_x86_64_cloudabi ;;
+x86_64-*-deforaos*) targ_emul=elf_x86_64 ;;
i[3-7]86-*-bsd) targ_emul=i386bsd ;;
i[3-7]86-*-bsd386) targ_emul=i386bsd ;;
i[3-7]86-*-bsdi*) targ_emul=i386bsd ;;
--- binutils-2.32/gas/configure.tgt.orig 2019-01-19 17:01:33.000000000 +0100
+++ binutils-2.32/gas/configure.tgt 2019-05-09 17:30:46.000000000 +0200
@@ -260,6 +260,7 @@
i386-*-chaos) fmt=elf ;;
i386-*-rdos*) fmt=elf ;;
i386-*-darwin*) fmt=macho ;;
+ i386-*-deforaos*) fmt=elf ;;
ia16-*-elf*) fmt=elf ;;
--- binutils-2.32/bfd/config.bfd.orig 2019-01-19 17:01:32.000000000 +0100
+++ binutils-2.32/bfd/config.bfd 2019-05-11 05:49:12.000000000 +0200
@@ -66,6 +66,7 @@
case \$targ in
*-*-netbsdelf* | i[3-7]86-*-netbsd*-gnu* | i[3-7]86-*-knetbsd*-gnu | \\
+ *-*-deforaos* | \\
mips*-*-irix5* | mips*-*-irix6*)
# Not obsolete
;;
@@ -589,6 +590,11 @@
targ_defvec=i386_elf32_vec
targ_selvecs=iamcu_elf32_vec
;;
+ i[3-7]86-*-deforaos*)
+ targ_defvec=i386_elf32_vec
+ targ_selvecs="iamcu_elf32_vec"
+ targ64_selvecs="x86_64_elf64_vec l1om_elf64_vec k1om_elf64_vec"
+ ;;
i[3-7]86-*-dicos*)
targ_defvec=i386_elf32_vec
targ_selvecs=iamcu_elf32_vec
@@ -663,6 +669,11 @@
targ_archs="\$targ_archs bfd_powerpc_arch bfd_rs6000_arch"
want64=true
;;
+ x86_64-*-deforaos*)
+ targ_defvec=x86_64_elf64_vec
+ targ_selvecs="i386_elf32_vec iamcu_elf32_vec x86_64_elf32_vec l1om_elf64_vec k1om_elf64_vec"
+ want64=true
+ ;;
x86_64-*-dicos*)
targ_defvec=x86_64_elf64_vec
targ_selvecs="i386_elf32_vec iamcu_elf32_vec l1om_elf64_vec k1om_elf64_vec"
--- binutils-2.32/config.sub.orig 2019-05-11 04:38:21.000000000 +0200
+++ binutils-2.32/config.sub 2019-05-11 04:38:24.000000000 +0200
@@ -135,6 +135,7 @@
| linux-newlib* | linux-musl* | linux-uclibc* | uclinux-uclibc* \\
| uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* \\
| netbsd*-eabi* | kopensolaris*-gnu* | cloudabi*-eabi* \\
+ | deforaos*-elf* \\
| storm-chaos* | os2-emx* | rtmk-nova*)
basic_machine=\$field1
os=\$maybe_os
@@ -1341,7 +1342,7 @@
| hpux* | unos* | osf* | luna* | dgux* | auroraux* | solaris* \\
| sym* | kopensolaris* | plan9* \\
| amigaos* | amigados* | msdos* | newsos* | unicos* | aof* \\
- | aos* | aros* | cloudabi* | sortix* \\
+ | aos* | aros* | cloudabi* | deforaos* | sortix* \\
| nindy* | vxsim* | vxworks* | ebmon* | hms* | mvs* \\
| clix* | riscos* | uniplus* | iris* | isc* | rtu* | xenix* \\
| knetbsd* | mirbsd* | netbsd* \\
EOF
(cd "binutils-$version/ld" && $ACLOCAL && $AUTOMAKE)
fi
#Configure and build binutils in a dedicated tree
case "$TARGET" in
aarch64-elf|aarch64-*-elf|amd64-elf|amd64-*-elf|sparc64-elf|sparc64-*-elf)
BINUTILS_FLAGS="$BINUTILS_FLAGS --enable-multilib"
;;
esac
$MKDIR "binutils-$TARGET"
if [ ! -f "binutils-$TARGET/Makefile" ]; then
(cd "binutils-$TARGET" &&
"../binutils-$version/configure" \
--target="$TARGET" --prefix="$PREFIX" --with-sysroot \
--disable-nls --disable-werror $BINUTILS_FLAGS)
fi
for target in $BINUTILS_TARGETS; do
(cd "binutils-$TARGET" && $MAKE $MAKE_FLAGS "$target") \
|| break
done
}
#download
_download()
{
url="$1"
$WGET -O "${url##*/}" "$url"
ret=$?
if [ $ret -eq 127 ]; then
$CURL -o "${url##*/}" "$url"
ret=$?
fi
return $ret
}
#error
_error()
{
echo "$PROGNAME: $@" 1>&2
return 2
}
#gcc
_gcc()
{
version="$1"
#Download GCC
[ -f "gcc-$version.tar.$GZEXT" ] ||
_download "$MIRROR/gcc/gcc-$version/gcc-$version.tar.$GZEXT"
#Extract GCC
if [ ! -d "gcc-$version" ]; then
$TAR $TAR_FLAGS "gcc-$version.tar.$GZEXT"
#Extend GCC for DeforaOS
$CAT > "gcc-$version/gcc/config/deforaos.h" << EOF
/* Useful if you wish to make target-specific GCC changes. */
#undef TARGET_DEFORAOS
#define TARGET_DEFORAOS 1
#undef LIB_SPEC
#define LIB_SPEC "-lc" /* link against C standard library */
#undef LINK_SPEC
#define LINK_SPEC "%{shared:-shared} %{static:-static} %{!shared: %{!static: %{rdynamic:-export-dynamic}}}"
/* 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"
/* Don't automatically add extern "C" { } around header files. */
#undef NO_IMPLICIT_EXTERN_C
#define NO_IMPLICIT_EXTERN_C 1
/* Additional predefined macros. */
#undef TARGET_OS_CPP_BUILTINS
#define TARGET_OS_CPP_BUILTINS() \\
do { \\
builtin_define ("__DeforaOS__"); \\
builtin_define ("__unix__"); \\
builtin_assert ("system=deforaos");\\
builtin_assert ("system=unix"); \\
builtin_assert ("system=posix"); \\
} while(0);
EOF
$CAT > "gcc-$version/gcc/config/i386/t-x86_64-elf" << EOF
MULTILIB_OPTIONS = m64 m32 mno-red-zone
MULTILIB_DIRNAMES = m64 m32 no-red-zone
MULTILIB_OSDIRNAMES = ../lib ../lib/i386 ../lib/no-red-zone
EOF
$CAT > "gcc-$version/gcc/config/i386/deforaos.h" << EOF
EOF
$CAT > "gcc-$version/gcc/config/i386/deforaos64.h" << EOF
#if TARGET_64BIT_DEFAULT
# define MULTILIB_DEFAULTS { "m64" }
#else
# define MULTILIB_DEFAULTS { "m32" }
#endif
EOF
#Patch GCC for DeforaOS
(cd "gcc-$version" && $PATCH -p1) << EOF
--- gcc-8.3.0/libgcc/config.host.orig 2018-04-06 22:04:17.000000000 +0200
+++ gcc-8.3.0/libgcc/config.host 2019-05-11 04:54:00.000000000 +0200
@@ -603,6 +603,15 @@
tm_file="\$tm_file i386/darwin-lib.h"
extra_parts="\$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
;;
+i[34567]86-*-deforaos*)
+ tmake_file="\$tmake_file i386/t-crtstuff t-crtstuff-pic t-libgcc-pic"
+ extra_parts="crtbegin.o crtbeginS.o crtend.o crtendS.o crti.o crtn.o"
+ ;;
+x86_64-*-deforaos*)
+ extra_parts="crti.o crtbegin.o crtend.o crtn.o"
+ tmake_file="\$tmake_file i386/t-crtstuff t-crtstuff-pic t-libgcc-pic"
+ tmake_file="\$tmake_file i386/t-x86_64-elf"
+ ;;
i[34567]86-*-elfiamcu)
tmake_file="\$tmake_file i386/t-crtstuff t-softfp-sfdftf i386/32/t-softfp i386/32/t-iamcu i386/t-softfp t-softfp t-dfprules"
;;
--- gcc-8.3.0/gcc/config.gcc.orig 2019-01-29 16:31:10.000000000 +0100
+++ gcc-8.3.0/gcc/config.gcc 2019-05-11 04:54:00.000000000 +0200
@@ -676,6 +676,12 @@
"" | yes | posix) thread_file='posix' ;;
esac
;;
+*-*-deforaos*)
+ gas=yes
+ gnu_ld=yes
+ default_use_cxa_atexit=yes
+ use_gcc_stdint=wrap
+ ;;
*-*-dragonfly*)
gas=yes
gnu_ld=yes
@@ -1490,6 +1496,15 @@
tmake_file="\${tmake_file} \${cpu_type}/t-darwin64 t-slibgcc"
tm_file="\${tm_file} \${cpu_type}/darwin64.h"
;;
+i[34567]86-*-deforaos*)
+ tm_file="\${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h"
+ tm_file="\${tm_file} i386/i386elf.h deforaos.h i386/deforaos.h"
+ ;;
+x86_64-*-deforaos*)
+ tmake_file="\${tmake_file} i386/t-x86_64-elf"
+ tm_file="\${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h"
+ tm_file="\${tm_file} i386/i386elf.h i386/x86-64.h deforaos.h i386/deforaos64.h"
+ ;;
i[34567]86-*-elfiamcu)
tm_file="\${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h newlib-stdint.h i386/iamcu.h"
;;
--- gcc-8.3.0/config.sub.orig 2018-01-03 05:25:18.000000000 +0100
+++ gcc-8.3.0/config.sub 2019-05-11 04:54:00.000000000 +0200
@@ -1395,7 +1395,7 @@
| -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \\
| -sym* | -kopensolaris* | -plan9* \\
| -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \\
- | -aos* | -aros* | -cloudabi* | -sortix* \\
+ | -aos* | -aros* | -cloudabi* | -deforaos* | -sortix* \\
| -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \\
| -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \\
| -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \\
EOF
fi
#Configure and build GCC in a dedicated tree
case "$TARGET" in
aarch64-elf|aarch64-*-elf)
GCC_FLAGS="$GCC_FLAGS --with-multilib-list=lp64,ilp32"
;;
amd64-elf|amd64-*-elf)
GCC_FLAGS="$GCC_FLAGS --with-multilib-list=m64,m32,no-red-zone"
;;
sparc64-elf|sparc64-*-elf)
GCC_FLAGS="$GCC_FLAGS --with-multilib-list=m64,m32"
;;
esac
$MKDIR "gcc-$TARGET"
if [ ! -f "gcc-$TARGET/Makefile" ]; then
(cd "gcc-$TARGET" && "../gcc-$version/configure" \
--target="$TARGET" --prefix="$PREFIX" \
--disable-nls --enable-languages=c,c++ \
--without-headers $GCC_FLAGS)
fi
for target in $GCC_TARGETS; do
(cd "gcc-$TARGET" && $MAKE $MAKE_FLAGS "$target") \
|| break
done
}
#platform
_platform()
{
case $($UNAME -s) in
NetBSD)
GCC_FLAGS="$GCCFLAGS --with-gmp=/usr/pkg --with-mpfr=/usr/pkg"
if [ -n "$LD_LIBRARY_PATH" ]; then
LD_LIBRARY_PATH="/usr/pkg/lib:$LD_LIBRARY_PATH"
else
LD_LIBRARY_PATH="/usr/pkg/lib"
fi
export LD_LIBRARY_PATH
MAKE="gmake"
;;
esac
}
#usage
_usage()
{
echo "Usage: $PROGNAME [-a architecture]" 1>&2
echo " -a Select the architecture to build" 1>&2
return 1
}
#main
while getopts "a:O:" name; do
case "$name" in
a)
ARCH="$OPTARG"
;;
O)
export "${OPTARG%%=*}"="${OPTARG#*=}"
;;
?)
_usage
exit $?
;;
esac
done
shift $((OPTIND - 1))
if [ $# -ne 0 ]; then
_usage
exit $?
fi
case "$ARCH" in
i386)
TARGET="i686-none-deforaos"
;;
amd64)
TARGET="amd64-none-deforaos"
;;
*)
_error "$ARCH: Architecture not supported"
exit $?
;;
esac
#Modify the environment to reflect the architecture chosen
PREFIX="$HOME/opt/cross-gcc-$TARGET"
PATH="$PREFIX/bin:$PATH"
#Download binutils
[ -f "binutils-$BINUTILS_VERSION.tar.$GZEXT" ] ||
$WGET "$MIRROR/binutils/binutils-$BINUTILS_VERSION.tar.$GZEXT"
#Extract, configure, and build binutils in a dedicated tree
[ -d "binutils-$BINUTILS_VERSION" ] ||
$TAR xzvf "binutils-$BINUTILS_VERSION.tar.$GZEXT"
case "$TARGET" in
aarch64-elf|amd64-elf|sparc64-elf)
BINUTILS_FLAGS="$BINUTILS_FLAGS --enable-multilib"
;;
esac
$MKDIR "binutils-$TARGET"
(cd "binutils-$TARGET" && "../binutils-$BINUTILS_VERSION/configure" \
--target="$TARGET" --prefix="$PREFIX" --with-sysroot --disable-nls \
--disable-werror $BINUTILS_FLAGS)
for target in $BINUTILS_TARGETS; do
(cd "binutils-$TARGET" && $MAKE "$target")
done
#Download GCC
[ -f "gcc-$GCC_VERSION.tar.$GZEXT" ] ||
$WGET "$MIRROR/gcc/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.$GZEXT"
#Extract, configure, and build GCC in a dedicated tree
[ -d "gcc-$GCC_VERSION" ] ||
$TAR xzvf "gcc-$GCC_VERSION.tar.$GZEXT"
case "$TARGET" in
aarch64-elf)
GCC_FLAGS="$GCC_FLAGS --with-multilib-list=lp64,ilp32"
;;
amd64-elf|sparc64-elf)
GCC_FLAGS="$GCC_FLAGS --with-multilib-list=m64,m32"
;;
esac
$MKDIR "gcc-$TARGET"
(cd "gcc-$TARGET" && "../gcc-$GCC_VERSION/configure" --target="$TARGET" \
--prefix="$PREFIX" --disable-nls --enable-languages=c,c++ \
--without-headers $GCC_FLAGS)
for target in $GCC_TARGETS; do
(cd "gcc-$TARGET" && $MAKE "$target")
done
_platform &&
_binutils "$BINUTILS_VERSION" &&
_gcc "$GCC_VERSION"

View File

@ -0,0 +1,129 @@
--- binutils-2.32/ld/emulparams/elf_i386_deforaos.sh.orig 1970-01-01 01:00:00.000000000 +0100
+++ binutils-2.32/ld/emulparams/elf_i386_deforaos.sh 2019-05-09 17:30:46.000000000 +0200
@@ -0,0 +1,3 @@
+. ${srcdir}/emulparams/elf_i386.sh
+GENERATE_SHLIB_SCRIPT=yes
+GENERATE_PIE_SCRIPT=yes
--- binutils-2.32/ld/emulparams/elf_x86_64_deforaos.sh.orig 1970-01-01 01:00:00.000000000 +0100
+++ binutils-2.32/ld/emulparams/elf_x86_64_deforaos.sh 2019-05-09 17:30:46.000000000 +0200
@@ -0,0 +1 @@
+. ${srcdir}/emulparams/elf_x86_64_deforaos.sh
--- binutils-2.32/ld/Makefile.am.orig 2019-01-19 17:01:33.000000000 +0100
+++ binutils-2.32/ld/Makefile.am 2019-05-09 17:30:46.000000000 +0200
@@ -285,6 +285,7 @@
eelf_i386.c \
eelf_i386_be.c \
eelf_i386_chaos.c \
+ eelf_i386_deforaos.c \
eelf_i386_fbsd.c \
eelf_i386_ldso.c \
eelf_i386_nacl.c \
@@ -455,6 +456,7 @@
eelf_k1om_fbsd.c \
eelf_x86_64.c \
eelf_x86_64_cloudabi.c \
+ eelf_x86_64_deforaos.c \
eelf_x86_64_fbsd.c \
eelf_x86_64_nacl.c \
eelf_x86_64_sol2.c \
@@ -1295,6 +1297,10 @@
eelf_i386_chaos.c: $(srcdir)/emulparams/elf_i386_chaos.sh \
$(ELF_X86_DEPS) $(srcdir)/scripttempl/elf_chaos.sc ${GEN_DEPENDS}
+eelf_i386_deforaos.c: $(srcdir)/emulparams/elf_i386_deforaos.sh \
+ $(srcdir)/emulparams/elf_i386.sh \
+ $(ELF_X86_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+
eelf_i386_fbsd.c: $(srcdir)/emulparams/elf_i386_fbsd.sh \
$(srcdir)/emulparams/elf_i386.sh \
$(ELF_X86_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
@@ -1853,6 +1859,10 @@
$(srcdir)/emulparams/elf_x86_64.sh \
$(ELF_X86_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+eelf_x86_64_deforaos.c: $(srcdir)/emulparams/elf_x86_64_deforaos.sh \
+ $(srcdir)/emulparams/elf_x86_64.sh \
+ $(ELF_X86_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+
eelf_x86_64_fbsd.c: $(srcdir)/emulparams/elf_x86_64_fbsd.sh \
$(srcdir)/emulparams/elf_x86_64.sh \
$(ELF_X86_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
--- binutils-2.32/ld/configure.tgt.orig 2019-05-11 04:48:32.000000000 +0200
+++ binutils-2.32/ld/configure.tgt 2019-05-11 05:58:31.000000000 +0200
@@ -240,10 +240,13 @@
i[3-7]86-*-lynxos*) targ_emul=i386lynx ;;
i[3-7]86-*-aros*) targ_emul=elf_i386
targ_extra_emuls=elf_iamcu ;;
+i[3-7]86-*-deforaos*) targ_emul=elf_i386
+ targ_extra_emuls=elf_iamcu ;;
i[3-7]86-*-rdos*) targ_emul=elf_i386
targ_extra_emuls=elf_iamcu ;;
x86_64-*-rdos*) targ_emul=elf64rdos ;;
x86_64-*-cloudabi*) targ_emul=elf_x86_64_cloudabi ;;
+x86_64-*-deforaos*) targ_emul=elf_x86_64 ;;
i[3-7]86-*-bsd) targ_emul=i386bsd ;;
i[3-7]86-*-bsd386) targ_emul=i386bsd ;;
i[3-7]86-*-bsdi*) targ_emul=i386bsd ;;
--- binutils-2.32/gas/configure.tgt.orig 2019-01-19 17:01:33.000000000 +0100
+++ binutils-2.32/gas/configure.tgt 2019-05-09 17:30:46.000000000 +0200
@@ -260,6 +260,7 @@
i386-*-chaos) fmt=elf ;;
i386-*-rdos*) fmt=elf ;;
i386-*-darwin*) fmt=macho ;;
+ i386-*-deforaos*) fmt=elf ;;
ia16-*-elf*) fmt=elf ;;
--- binutils-2.32/bfd/config.bfd.orig 2019-01-19 17:01:32.000000000 +0100
+++ binutils-2.32/bfd/config.bfd 2019-05-11 05:49:12.000000000 +0200
@@ -66,6 +66,7 @@
case $targ in
*-*-netbsdelf* | i[3-7]86-*-netbsd*-gnu* | i[3-7]86-*-knetbsd*-gnu | \
+ *-*-deforaos* | \
mips*-*-irix5* | mips*-*-irix6*)
# Not obsolete
;;
@@ -589,6 +590,11 @@
targ_defvec=i386_elf32_vec
targ_selvecs=iamcu_elf32_vec
;;
+ i[3-7]86-*-deforaos*)
+ targ_defvec=i386_elf32_vec
+ targ_selvecs="iamcu_elf32_vec"
+ targ64_selvecs="x86_64_elf64_vec l1om_elf64_vec k1om_elf64_vec"
+ ;;
i[3-7]86-*-dicos*)
targ_defvec=i386_elf32_vec
targ_selvecs=iamcu_elf32_vec
@@ -663,6 +669,11 @@
targ_archs="$targ_archs bfd_powerpc_arch bfd_rs6000_arch"
want64=true
;;
+ x86_64-*-deforaos*)
+ targ_defvec=x86_64_elf64_vec
+ targ_selvecs="i386_elf32_vec iamcu_elf32_vec x86_64_elf32_vec l1om_elf64_vec k1om_elf64_vec"
+ want64=true
+ ;;
x86_64-*-dicos*)
targ_defvec=x86_64_elf64_vec
targ_selvecs="i386_elf32_vec iamcu_elf32_vec l1om_elf64_vec k1om_elf64_vec"
--- binutils-2.32/config.sub.orig 2019-05-11 04:38:21.000000000 +0200
+++ binutils-2.32/config.sub 2019-05-11 04:38:24.000000000 +0200
@@ -135,6 +135,7 @@
| linux-newlib* | linux-musl* | linux-uclibc* | uclinux-uclibc* \
| uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* \
| netbsd*-eabi* | kopensolaris*-gnu* | cloudabi*-eabi* \
+ | deforaos*-elf* \
| storm-chaos* | os2-emx* | rtmk-nova*)
basic_machine=$field1
os=$maybe_os
@@ -1341,7 +1342,7 @@
| hpux* | unos* | osf* | luna* | dgux* | auroraux* | solaris* \
| sym* | kopensolaris* | plan9* \
| amigaos* | amigados* | msdos* | newsos* | unicos* | aof* \
- | aos* | aros* | cloudabi* | sortix* \
+ | aos* | aros* | cloudabi* | deforaos* | sortix* \
| nindy* | vxsim* | vxworks* | ebmon* | hms* | mvs* \
| clix* | riscos* | uniplus* | iris* | isc* | rtu* | xenix* \
| knetbsd* | mirbsd* | netbsd* \

60
doc/patch-gcc_8.3.0.diff Normal file
View File

@ -0,0 +1,60 @@
--- gcc-8.3.0/libgcc/config.host.orig 2018-04-06 22:04:17.000000000 +0200
+++ gcc-8.3.0/libgcc/config.host 2019-05-11 04:54:00.000000000 +0200
@@ -603,6 +603,15 @@
tm_file="$tm_file i386/darwin-lib.h"
extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
;;
+i[34567]86-*-deforaos*)
+ tmake_file="$tmake_file i386/t-crtstuff t-crtstuff-pic t-libgcc-pic"
+ extra_parts="crtbegin.o crtbeginS.o crtend.o crtendS.o crti.o crtn.o"
+ ;;
+x86_64-*-deforaos*)
+ extra_parts="crti.o crtbegin.o crtend.o crtn.o"
+ tmake_file="$tmake_file i386/t-crtstuff t-crtstuff-pic t-libgcc-pic"
+ tmake_file="$tmake_file i386/t-x86_64-elf"
+ ;;
i[34567]86-*-elfiamcu)
tmake_file="$tmake_file i386/t-crtstuff t-softfp-sfdftf i386/32/t-softfp i386/32/t-iamcu i386/t-softfp t-softfp t-dfprules"
;;
--- gcc-8.3.0/gcc/config.gcc.orig 2019-01-29 16:31:10.000000000 +0100
+++ gcc-8.3.0/gcc/config.gcc 2019-05-11 04:54:00.000000000 +0200
@@ -676,6 +676,12 @@
"" | yes | posix) thread_file='posix' ;;
esac
;;
+*-*-deforaos*)
+ gas=yes
+ gnu_ld=yes
+ default_use_cxa_atexit=yes
+ use_gcc_stdint=wrap
+ ;;
*-*-dragonfly*)
gas=yes
gnu_ld=yes
@@ -1490,6 +1496,15 @@
tmake_file="${tmake_file} ${cpu_type}/t-darwin64 t-slibgcc"
tm_file="${tm_file} ${cpu_type}/darwin64.h"
;;
+i[34567]86-*-deforaos*)
+ tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h"
+ tm_file="${tm_file} i386/i386elf.h deforaos.h i386/deforaos.h"
+ ;;
+x86_64-*-deforaos*)
+ tmake_file="${tmake_file} i386/t-x86_64-elf"
+ tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h"
+ tm_file="${tm_file} i386/i386elf.h i386/x86-64.h deforaos.h i386/deforaos64.h"
+ ;;
i[34567]86-*-elfiamcu)
tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h newlib-stdint.h i386/iamcu.h"
;;
--- gcc-8.3.0/config.sub.orig 2018-01-03 05:25:18.000000000 +0100
+++ gcc-8.3.0/config.sub 2019-05-11 04:54:00.000000000 +0200
@@ -1395,7 +1395,7 @@
| -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \
| -sym* | -kopensolaris* | -plan9* \
| -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
- | -aos* | -aros* | -cloudabi* | -sortix* \
+ | -aos* | -aros* | -cloudabi* | -deforaos* | -sortix* \
| -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
| -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
| -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \

View File

@ -1 +1 @@
dist=Makefile,cross-gcc.md,cross-gcc.sh
dist=Makefile,cross-gcc.md,cross-gcc.sh,patch-binutils_2.32.diff,patch-gcc_8.3.0.diff

View File

@ -1,11 +1,19 @@
/* $Id$ */
/* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2018-2019 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
/* Originally from https://wiki.osdev.org/Bare_Bones */
/* text */
/* variables */
.section .bss
.align 16
gdt_descriptor:
.skip 2 /* size */
.skip 4 /* offset */
/* functions */
.section .text
/* arch_setgdt */
.global __arch_setgdt
@ -26,11 +34,3 @@ __arch_setgdt:
/* load the GDT */
lgdt (%ecx)
ret
/* bss */
.section .bss
.align 16
gdt_descriptor:
.skip 2 /* size */
.skip 4 /* offset */

View File

@ -1,11 +1,19 @@
/* $Id$ */
/* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2018-2019 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
/* Originally from https://wiki.osdev.org/Bare_Bones */
/* text */
/* variables */
.section .bss
.align 16
idt:
.skip 2 /* size */
.skip 4 /* offset */
/* functions */
.section .text
/* arch_setidt */
.global __arch_setidt
@ -22,11 +30,3 @@ __arch_setidt:
/* load the IDT */
lidt (%ecx)
ret
/* bss */
.section .bss
.align 16
idt:
.skip 2 /* size */
.skip 4 /* offset */

View File

@ -1,12 +1,12 @@
/* $Id$ */
/* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2018-2019 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
/* sections */
/* text */
/* functions */
.section .text
/* intr_disable */
.global intr_disable
.type intr_disable, @function
intr_disable:

View File

@ -20,8 +20,7 @@
#endif
/* sections */
/* bss */
/* variables */
.section .bss
.align 16
stack_bottom:
@ -29,7 +28,7 @@ stack_bottom:
stack_top:
/* text */
/* functions */
.section .text
/* start */
.global _start

View File

@ -20,8 +20,7 @@
#endif
/* sections */
/* bss */
/* variables */
.section .bss
.align 16
stack_bottom:
@ -29,7 +28,7 @@ stack_bottom:
stack_top:
/* text */
/* functions */
.section .text
/* start */
.global _start

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2018-2019 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
@ -20,8 +20,13 @@
#endif
/* sections */
/* text */
/* variables */
.section .bss
k_ptr:
.skip 4
/* functions */
.section .text
/* multiboot_boot_kernel32 */
.global multiboot_boot_kernel32
@ -83,9 +88,3 @@ multiboot_boot_kernel64:
1:
mov $-1, %eax
ret
/* data */
.section .data
k_ptr:
.long 0x0