summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2017-04-27 21:37:54 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2017-04-27 21:37:54 +0200
commit6872bc9ae68e02ab43b9ba4870c4a23992948b95 (patch)
tree41c29752f893bc6b4f2fc806a1fac12d762542e3 /doc
parent55fe269eaa3bd3f63b8672119aa1e96ae30f26db (diff)
downloadabaos-6872bc9ae68e02ab43b9ba4870c4a23992948b95.tar.gz
abaos-6872bc9ae68e02ab43b9ba4870c4a23992948b95.tar.bz2
bootstrapped from an OSX with separate ELF toolchain
Diffstat (limited to 'doc')
-rw-r--r--doc/HOWTO.OSX36
-rw-r--r--doc/README.OSDever1
-rw-r--r--doc/README.OsDevOrg1
-rw-r--r--doc/README.Wyoos2
-rw-r--r--doc/wiki_os_dev_org_How_to_Develop_on_Mac_OS_X.txt829
5 files changed, 869 insertions, 0 deletions
diff --git a/doc/HOWTO.OSX b/doc/HOWTO.OSX
new file mode 100644
index 0000000..326cb70
--- /dev/null
+++ b/doc/HOWTO.OSX
@@ -0,0 +1,36 @@
+Followed: http://wiki.osdev.org/How_to_develop_on_Mac_OS_X
+
+brew uninstall binutils
+lynx ftp://ftp.gnu.org/gnu/binutils/
+lynx ftp://ftp.gnu.org/gnu/gcc/
+tar zxvf binutils-2.28.tar.gz
+tar zxvf gcc-6.3.0.tar.gz
+cd gcc-6.3.0
+contrib/download_prerequisites
+brew install gcc
+export CC=/usr/local/bin/gcc-6
+export CXX=/usr/local/bin/g++-6
+export CPP=/usr/local/bin/cpp-6
+export LD=/usr/local/bin/gcc-6
+export PREFIX="$HOME/opt/cross"
+export TARGET=i486-elf
+export PATH="$PREFIX/bin:$PATH"
+mkdir src
+mv binutils-2.28* src
+mv gcc-6.3.0* src
+cd src/
+mkdir build-binutils
+cd build-binutils
+../binutils-2.28/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror
+make
+make install
+which -- $TARGET-as || echo $TARGET-as is not in the PATH
+mkdir build-gcc
+cd build-gcc
+../gcc-6.3.0/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers
+make all-gcc
+make all-target-libgcc
+make install-gcc
+make install-target-libgcc
+
+make CC=~/opt/cross/bin/i486-elf-gcc LD=~/opt/cross/bin/i486-elf-ld
diff --git a/doc/README.OSDever b/doc/README.OSDever
new file mode 100644
index 0000000..9942c8d
--- /dev/null
+++ b/doc/README.OSDever
@@ -0,0 +1 @@
+http://www.osdever.net/bkerndev/Docs/title.htm
diff --git a/doc/README.OsDevOrg b/doc/README.OsDevOrg
new file mode 100644
index 0000000..f61033d
--- /dev/null
+++ b/doc/README.OsDevOrg
@@ -0,0 +1 @@
+http://wiki.osdev.org/How_to_develop_on_Mac_OS_X
diff --git a/doc/README.Wyoos b/doc/README.Wyoos
index fa96fc8..a766065 100644
--- a/doc/README.Wyoos
+++ b/doc/README.Wyoos
@@ -1,3 +1,5 @@
+http://wyoos.org
+
IDT interupt descriptor table
GDT global descriptor table
diff --git a/doc/wiki_os_dev_org_How_to_Develop_on_Mac_OS_X.txt b/doc/wiki_os_dev_org_How_to_Develop_on_Mac_OS_X.txt
new file mode 100644
index 0000000..1d4fe8d
--- /dev/null
+++ b/doc/wiki_os_dev_org_How_to_Develop_on_Mac_OS_X.txt
@@ -0,0 +1,829 @@
+ #[1]OSDev Wiki (en) [2]OSDev Wiki Atom feed
+
+GCC Cross-Compiler
+
+ From OSDev Wiki
+ (Redirected from [3]How to develop on Mac OS X)
+ Jump to: [4]navigation, [5]search
+ Difficulty level
+ [6]Difficulty 1.png
+ Beginner
+
+ In this tutorial we will create a GCC cross-compiler for your own
+ operating system. This compiler is specially made to target exactly
+ your operating system and is what allows you to leave the current
+ operating system behind. You need a cross-compiler for operating
+ systems development, unless you are developing on your own operating
+ system.
+
+Contents
+
+ * [7]1 Introduction
+ + [8]1.1 Why do I need a Cross Compiler?
+ + [9]1.2 Which compiler version do I want?
+ + [10]1.3 Which Binutils version do I want?
+ + [11]1.4 Deciding on the target platform
+ * [12]2 Preparing for the build
+ + [13]2.1 Downloading the Source Code
+ + [14]2.2 Linux Users
+ + [15]2.3 OS X Users
+ + [16]2.4 Windows Users
+ * [17]3 The Build
+ + [18]3.1 Preparation
+ + [19]3.2 Binutils
+ + [20]3.3 GCC
+ * [21]4 Using the new Compiler
+ * [22]5 Troubleshooting
+ + [23]5.1 ld: cannot find -lgcc
+ + [24]5.2 Binutils 2.9
+ * [25]6 See Also
+ + [26]6.1 Articles
+ + [27]6.2 External Links
+ + [28]6.3 Prebuilt Toolchains
+
+Introduction
+
+ Generally speaking, a cross-compiler is a compiler that runs on
+ platform A (the host), but generates executables for platform B (the
+ target). These two platforms may (but do not need to) differ in CPU,
+ operating system, and/or [29]executable format. In our case, the host
+ platform is your current operating system, and the target platform is
+ the operating system you are about to make. It is important to realize
+ that these two platforms are not the same; your operating system is
+ always going to be different from your current operating system. This
+ is why we need to build a cross-compiler first, you will most certainly
+ run into trouble otherwise.
+
+Why do I need a Cross Compiler?
+
+ Main article: [30]Why do I need a Cross Compiler?
+
+ You need to use a cross-compiler unless you are developing on your own
+ operating system. The compiler must know the correct target platform
+ (CPU, operating system), otherwise you will run into trouble. If you
+ use the compiler that comes with your system, then the compiler won't
+ know it is compiling something else entirely. Some tutorials suggest
+ using your system compiler and passing a lot of problematic options to
+ the compiler. This will certainly give you a lot of problems in the
+ future and the solution is build a cross-compiler. If you have already
+ attempted to make an operating system without using a cross-compiler,
+ please read the article [31]Why do I need a Cross Compiler?.
+
+Which compiler version do I want?
+
+ Main article: [32]Building GCC
+
+ The newest [33]GCC is recommended as it is the latest and greatest
+ release. For instance, you may run into trouble if you use GCC 4.6.3 to
+ build a GCC 4.8.0 cross-compiler. If you are not using the latest major
+ GCC release for your system compiler, we recommend that you [34]build
+ the newest GCC as your system compiler.
+
+ You can also use older releases as they are usually reasonably good. If
+ your local system compiler isn't too terribly old (at least GCC 4.6.0),
+ you may wish to save yourself the trouble and just pick the latest
+ minor release (such as 4.6.3 if your system compiler is 4.6.1) for your
+ cross-compiler.
+
+ You can view your current compiler version by invoking:
+gcc --version
+
+ You may be able to use an older major GCC release to build a
+ cross-compiler of a newer major GCC release. For instance, GCC 4.7.3
+ may be able to build a GCC 4.8.0 cross-compiler. However, if you want
+ to use the latest and greatest GCC version for your cross-compiler, we
+ recommend that you [35]bootstrap the newest GCC as your system compiler
+ first. Individuals using OS X 10.7 or earlier might want to invest in
+ either building a system GCC (that outputs native Mach-O), or upgrading
+ the local LLVM/Clang installation. Users with 10.8 and above should
+ install the Command Line Tools from Apple's developer website and use
+ Clang to cross-compile GCC.
+
+Which Binutils version do I want?
+
+ Main article: [36]Cross-Compiler Successful Builds
+
+ We recommend that you use the latest and greatest [37]Binutils release.
+ Note, however, that not all combinations of GCC and Binutils work. If
+ you run into trouble, use a Binutils that was released at roughly the
+ same time as your desired compiler version. You probably need at least
+ Binutils 2.22, or preferably the latest 2.23.2 release. It doesn't
+ matter what Binutils version you have installed on your current
+ operating system.
+
+Deciding on the target platform
+
+ Main article: [38]Target Triplet
+
+ You should already know this. If you are following the [39]Bare Bones
+ tutorial, you wish to build a cross-compiler for i686-elf.
+
+Preparing for the build
+
+ The GNU Compiler Collection is an advanced piece of software with
+ dependencies. You need to install certain dependencies in order to
+ build gcc. You need to install GNU make, GNU bison, flex, and of course
+ an existing system compiler you wish to replace. In addition, you also
+ need the packages GNU GMP, GNU MPFR, and MPC that are used by GCC for
+ floating point support.
+
+ You need a host system with a working GCC installation, and enough
+ memory as well as hard drive space. How much qualifies as "enough" is
+ depending on the versions of the software involved, but GCC is a big
+ piece of software, so don't be surprised when 128 or 256 MByte are not
+ sufficient.
+
+ In short you need the following that you can install manually or
+ through package management:
+ * An Unix-like environment (Windows users)
+ * GCC (existing release you wish to replace)
+ * G++ (if building a version of GCC >= 4.8.0)
+ * GNU Make
+ * GNU Bison
+ * Flex
+ * GNU GMP
+ * GNU MPFR
+ * GNU MPC
+ * Texinfo
+ * ISL (optional)
+ * CLooG (optional)
+
+Downloading the Source Code
+
+ You can download the desired Binutils release by visiting the
+ [40]Binutils website or directly accessing the [41]GNU main FTP mirror.
+
+ You can download the desired GCC release by visiting the [42]GCC
+ website or directly accessing the [43]GNU main FTP mirror.
+
+ In addition, to build GCC you need to have installed GNU GMP, GNU MPFR,
+ GNU Mpc and the ISL library. You may already have these libraries and
+ the development files installed, but this tutorial builds them as part
+ of GCC. If you don't need this, simply don't build them as part of GCC.
+ Note that not all GMP, MPFR and Mpc combinations are compatible with a
+ given GCC release. You also need Texinfo to build Binutils.
+
+ You can download [44]GNU GMP from its website. (libgmp3-dev on
+ apt-based systems, dev-libs/gmp on Gentoo, gmp-devel on Fedora,
+ libgmp-devel on Cygwin)
+
+ You can download [45]GNU MPFR from its website. (libmpfr-dev on
+ apt-based systems, dev-libs/mpfr on Gentoo, mpfr-devel on Fedora,
+ libmpfr-devel on Cygwin)
+
+ You can download [46]ISL from its website (optional). (libisl-dev on
+ apt-based systems, libisl-devel on Cygwin)
+
+ You can download [47]ClooG from its website (optional).
+ (libcloog-isl-dev on apt-based systems, libcloog-isl-devel on Cygwin)
+
+ You can download [48]GNU Mpc from its website. (libmpc-dev on apt-based
+ systems, dev-libs/mpc on Gentoo, libmpc-devel on Fedora, libmpc-devel
+ on Cygwin)
+
+ You can download [49]GNU Texinfo from its website. (texinfo on
+ apt-based systems, texinfo on Arch Linux, sys-apps/texinfo on Gentoo,
+ texinfo on Cygwin)
+
+ Download the needed source code into a suitable directory such as
+ $HOME/src.
+ An alternative way to download GMP, MPFR and Mpc is to go to the top
+ level directory of the GCC source code (i.e. gcc-x.y.z/) and type the
+ following:
+contrib/download_prerequisites
+
+ The download_prerequisites script will run and will download GMP, MPFR
+ and Mpc.
+
+ Note: The versioning scheme used is that each fullstop separates a full
+ number, i.e. Binutils 2.20.0 is newer than 2.9.0. This may be
+ confusing, if you have not encountered this (quite common) versioning
+ scheme yet, when looking at an alphanumerically sorted list of
+ tarballs: The file at the bottom of the list is not the latest version!
+ An easy way of getting the latest version is to sort by the last
+ modified date and scrolling to the bottom.
+
+ Note: Version 5.x (or later) of Texinfo is known to be incompatible
+ with the current Binutils 2.23.2 release (and older). You can check
+ your current version using makeinfo --version. If your version is too
+ new and you encounter problems during the build, you will need to
+ either use Binutils 2.24 release (or newer) or install an older version
+ of Texinfo - perhaps through building from source - and add it to your
+ PATH prior and during the Binutils build.
+
+ Note: Version 0.13 (or later) of ISL is incompatible with the current
+ CLooG 0.18.1 release (and older). Use version 0.12.2 of ISL or the
+ build will fail.
+
+Linux Users
+
+ Your distribution may ship its own patched GCC and Binutils that is
+ customized to work on your particular Linux distribution. You may not
+ be able to build a functional system compiler using the upstream
+ sources you downloaded above. In that case, try a newer GCC release or
+ get the patched source code. For instance, some GCC releases are known
+ to not understand the new Debian multiarch directory structure.
+ However, if the compiler we are about to build is a cross-compiler
+ targetting another operating system (such as your new one), then this
+ is much less a worry.
+
+ Note for all Gentoo users: Gentoo, being a source-based distribution,
+ makes it almost ridiculously easy to set up a cross-development
+ toolchain:
+ emerge -av crossdev
+ crossdev --help
+ PORTDIR_OVERLAY="/usr/local/crossdev" crossdev --stage1 --binutils <binutils-
+version> --gcc <gcc-version> --target <target>
+
+ This will install a GCC cross-compiler into a "slot", i.e. alongside
+ already-existing compiler versions. You can install several
+ cross-compilers that way, simply by changing target designations. An
+ unfortunate downside is that it will also pull in gentoo patches and
+ pass additional configure options that differ from the official GCC
+ Cross-Compiler setup, and they might behave differently.
+
+ After the compilation ran, you can now use your cross-compiler by
+ calling <target>-gcc. You can also use gcc-config to toggle between
+ compiler versions should you need to do so. Don't replace your system
+ compiler with a cross-compiler however. The package manager will also
+ suggest updates as soon as they become available.
+
+ You can uninstall the cross-compiler by calling crossdev --clean
+ <target>. Read the [50]cross-development document for additional
+ information.
+
+ Note that the version numbers to binutils and gcc are Gentoo package
+ versions, i.e. there might be a suffix to the "official" (GNU) version
+ that addresses additional patchsets supplied by the Gentoo maintainers.
+ (For example, --binutils 2.24-r3 --gcc 4.8.3 is the latest stable
+ package pair at the time of this writing.) You can omit the version
+ numbers to use the latest package available.
+
+ Portage uses overlays to store packages that are not part of the
+ original package management. Crossdev needs one overlay where it can
+ store its binutils and gcc packages before building them. You can
+ configure one properly, or you can use PORTDIR_OVERLAY to point at
+ where it should keep its package manager files. Using PORTDIR_OVERLAY
+ is not a good idea with existing overlays, but by then you should know
+ how you have personally set them up earlier anyway and how to do it
+ properly.
+
+OS X Users
+
+ Additionally, OS X users need a replacement libiconv because the system
+ libiconv is seriously out of date. OS X users can download the latest
+ libiconv release by visiting the [51]libiconv website or directly
+ accessing the [52]GNU main FTP mirror.
+
+ When compiling GCC 4.3 or higher on OS X 10.4 and 10.5, you may get
+ unresolved symbol errors related to libiconv. This is because the
+ version shipped with OS X is seriously out of date. Install a new
+ version (compile it yourself or use MacPorts) and add
+ --with-libiconv-prefix=/opt/local (or /usr/local if you compiled it
+ yourself) to GCC's ./configure line. Alternatively you may place the
+ libiconv source as gcc-x.y.z/libiconv and it will be compiled as part
+ of the GCC compilation process. (This trick also works for MPFR, GMP,
+ and Mpc).
+
+ The makefiles of Binutils and GCC use the $(CC) variable to invoke the
+ compiler. On OS X, this resolves to GCC by default, which is actually
+ not the "real thing", but Clang. Note that since at least OS X 10.8,
+ Xcode's Command Line Tools package comes with Clang, and this version
+ of Clang does indeed work to compile a working version of GCC, unlike
+ what these instructions previously reflected.
+
+ Note that users running OS X 10.7 may need to find and install GCC,
+ either from [53]Homebrew, or from somewhere on Apple's website. Thus,
+ the instructions below are really only relevant for these users, but
+ your mileage may vary.
+# This is only necessary for OS X users running 10.7 or below.
+export CC=/usr/bin/gcc-4.2
+export CXX=/usr/bin/g++-4.2
+export CPP=/usr/bin/cpp-4.2
+export LD=/usr/bin/gcc-4.2
+
+ You might want to unset these exports once you compiled and installed
+ the cross compiler, as it might confuse other builds. Do not make these
+ permanent!
+
+ Note for Lion users: If you're on Lion (or above) chances are that you
+ don't have the "real" GCC since Apple removed it from the Xcode
+ package, but you can still install it. You can do it via Homebrew or by
+ compiling from source, both are perfectly described on [54]a
+ StackExchange answer.
+
+ Note for Maverick users: You can build binutils-2.24 and gcc-4.8.3
+ (possible other version) with Xcode 5.1.1. Note that building GCC with
+ LLVM is not officially supported and may cause interesting bugs, if you
+ are willing to take this risk and save time building host-gcc just to
+ compile a cross-gcc, follow this. Install GMP, MPFR, Mpc with
+ [55]MacPorts.
+sudo port install gmp mpfr libmpc
+
+../binutils-2.24/configure --prefix=$PREFIX \
+--target=$TARGET \
+--enable-interwork --enable-multilib \
+--disable-nls --disable-werror
+
+../gcc-4.8.3/configure --prefix=$PREFIX \
+--target=$TARGET \
+--disable-nls \
+--enable-languages=c,c++ --without-headers \
+--enable-interwork --enable-multilib \
+--with-gmp=/usr --with-mpc=/opt/local --with-mpfr=/opt/local
+
+ * Note that there is issue with port's GMP, we use the version from
+ OS X from /usr instead.
+
+Windows Users
+
+ Windows users need to set up a Unix-like enviroment such as [56]MinGW
+ or [57]Cygwin. It may well be worth looking into systems such as Linux
+ and see if they fit your needs, as you commonly use a lot of Unix-like
+ tools in operating systems development and this is much easier from a
+ Unix-like operating system. If you have just installed the basic
+ [58]Cygwin package, you have to run the setup.exe again and install the
+ following packages: GCC, G++, Make, Flex, Bison, Diffutils,
+ libintl-devel, libgmp-devel, libmpfr-devel, libmpc-devel, Texinfo
+
+ MinGW + MSYS is an option, and as it addresses the native Windows API
+ instead of a POSIX emulation layer, results in a slightly faster
+ toolchain. Some software packages will not build properly under MSYS as
+ they were not designed for use with Windows. As far as this tutorial is
+ concerned, everything that applies to Cygwin also applies to MSYS
+ unless otherwise specified. Make sure you install the C and C++
+ compilers, and the MSYS Basic System.
+
+ The "Windows Subsystem for Linux (Beta)", released with the Windows 10
+ Anniversary update is also an option for using a cross compiler.
+ (Tested 08/08/2016 with GCC 6.1.0 and Binutils 2.27) This
+ cross-compiler works reasonably fast, although being in beta state, it
+ may not be ideal permanent development platform.
+
+ Cygwin note: Cygwin includes your Windows %PATH% in its bash $PATH. If
+ you were using DJGPP before, this could result in confusion as e.g.
+ calling GCC on the Cygwin bash command line would still call the DJGPP
+ compiler. After uninstalling DJGPP, you should delete the DJGPP
+ environment variable and clear the C:\djgpp entry (or wherever you
+ installed it) from your %PATH%. Likewise, it might be a bad idea to mix
+ build environments in your system PATH variable.
+
+ MinGW note: Some MinGW-specific information on building a
+ cross-toolchain can be found on the [59]hosted cross-compiler how-to
+ page on the MinGW homepage.
+
+ Windows Subsystem for Linux (Beta) Note: You cannot have your cross
+ compiler in the /mnt/c/ (or /mnt/"x") areas, as trying to compile your
+ cross-compiler there will generate errors, whereas building to
+ $HOME/opt/cross works perfectly. This is fixed with Windows Update
+ KB3176929
+
+The Build
+
+ We build a toolset running on your host that can turn source code into
+ object files for your target system.
+
+ You need to decide where to install your new compiler. It is dangerous
+ and a very bad idea to install it into system directories. You also
+ need to decide whether the new compiler should be installed globally or
+ just for you. If you want to install it just for you (recommended),
+ installing into $HOME/opt/cross is normally a good idea. If you want to
+ install it globally, installing it into /usr/local/cross is normally a
+ good idea.
+
+ Please note that we build everything out of the source directory tree,
+ as is considered good practice. Some packages only support building
+ outside, some only inside and some both (but may not offer extensive
+ checking with make). Building GCC inside the source directory tree
+ fails miserably, at least for older versions.
+
+Preparation
+
+export PREFIX="$HOME/opt/cross"
+export TARGET=i686-elf
+export PATH="$PREFIX/bin:$PATH"
+
+ We add the installation prefix to the PATH of the current shell
+ session. This ensures that the compiler build is able to detect our new
+ binutils once we have built them.
+
+ The prefix will configure the build process so that all the files of
+ your cross-compiler environment end up in $HOME/opt/cross. You can
+ change that prefix to whatever you like (e.g., /opt/cross or
+ $HOME/cross would be options). If you have administrator access and
+ wish to make the cross-compiler toolchain available to all users, you
+ can install it into the /usr/local prefix - or perhaps a
+ /usr/local/cross prefix if you are willing to change the system
+ configuration such that this directory is in the search paths for all
+ users. Technically, you could even install directly to /usr, so that
+ your cross-compiler would reside alongside your system compiler, but
+ that is not recommended for several reasons (like risking to overwrite
+ your system compiler if you get TARGET wrong, or getting into conflict
+ with your system's package management).
+
+Binutils
+
+cd $HOME/src
+
+mkdir build-binutils
+cd build-binutils
+../binutils-x.y.z/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot -
+-disable-nls --disable-werror
+make
+make install
+
+ This compiles the binutils (assembler, disassembler, and various other
+ useful stuff), runnable on your system but handling code in the format
+ specified by $TARGET.
+
+ --disable-nls tells binutils not to include native language support.
+ This is basically optional, but reduces dependencies and compile time.
+ It will also result in English-language diagnostics, which the people
+ on the [60]Forum understand when you ask your questions. ;-)
+
+ --with-sysroot tells binutils to enable sysroot support in the
+ cross-compiler by pointing it to a default empty directory. By default
+ the linker refuses to use sysroots for no good technical reason, while
+ gcc is able to handle both cases at runtime. This will be useful later
+ on.
+
+GCC
+
+ See also the [61]offical instructions for configuring gcc.
+
+ Now, you can build [62]GCC.
+cd $HOME/src
+
+# The $PREFIX/bin dir _must_ be in the PATH. We did that above.
+which -- $TARGET-as || echo $TARGET-as is not in the PATH
+
+mkdir build-gcc
+cd build-gcc
+../gcc-x.y.z/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enabl
+e-languages=c,c++ --without-headers
+make all-gcc
+make all-target-libgcc
+make install-gcc
+make install-target-libgcc
+
+ We build [63]libgcc, a low-level support library that the compiler
+ expects available at compile time. Linking against [64]libgcc provides
+ integer, floating point, decimal, stack unwinding (useful for exception
+ handling) and other support functions. Note how we are not simply
+ running make && make install as that would build way too much, not all
+ components of gcc are ready to target your unfinished operating system.
+
+ --disable-nls is the same as for binutils above.
+
+ --without-headers tells [65]GCC not to rely on any C library (standard
+ or runtime) being present for the target.
+
+ --enable-languages tells [66]GCC not to compile all the other language
+ frontends it supports, but only C (and optionally C++).
+
+ It will take a while to build your cross-compiler.
+
+Using the new Compiler
+
+ Now you have a "naked" cross-compiler. It does not have access to a C
+ library or C runtime yet, so you cannot use any of the standard
+ includes or create runnable binaries. But it is quite sufficient to
+ compile the kernel you will be making shortly. Your toolset resides in
+ $HOME/opt/cross (or what you set $PREFIX to). For example, you have a
+ GCC executable installed as $HOME/opt/cross/bin/$TARGET-gcc, which
+ creates programs for your TARGET.
+
+ You can now run your new compiler by invoking something like:
+$HOME/opt/cross/bin/$TARGET-gcc --version
+
+ Note how this compiler is not able to compile normal C programs. The
+ cross-compiler will spit errors whenever you want to #include any of
+ the standard headers (except for a select few that actually are
+ platform-independent, and generated by the compiler itself). This is
+ quite correct - you don't have a standard library for the target system
+ yet!
+
+ The C standard defines two different kinds of executing environments -
+ "freestanding" and "hosted". While the definition might be rather fuzzy
+ for the average application programmer, it is pretty clear-cut when
+ you're doing OS development: A kernel is "freestanding", everything you
+ do in user space is "hosted". A "freestanding" environment needs to
+ provide only a subset of the C library: float.h, iso646.h, limits.h,
+ stdalign.h, stdarg.h, stdbool.h, stddef.h, stdint.h and stdnoreturn.h
+ (as of C11). All of these consist of typedef s and #define s "only", so
+ you can implement them without a single .c file in sight.
+
+ To use your new compiler simply by invoking $TARGET-gcc, add
+ $HOME/opt/cross/bin to your $PATH by typing:
+export PATH="$HOME/opt/cross/bin:$PATH"
+
+ This command will add your new compiler to your PATH for this shell
+ session. If you wish to use it permanently, add the PATH command to
+ your ~/.profile configuration shell script or similar. Consult your
+ shell documentation for more information.
+
+ You can now move on to complete the [67]Bare Bones tutorial variant
+ that lead you here and complete it using your new cross-compiler. If
+ you built a new GCC version as your system compiler and used it to
+ build the cross-compiler, you can now safely uninstall it unless you
+ wish to continue using it.
+
+Troubleshooting
+
+ In general, verify that you read the instructions carefully and typed
+ the commands precisely. Don't skip instructions. You will have to set
+ your PATH variable again if you use a new shell instance, if you don't
+ make it permanent by adding it to your shell profile. If a compilation
+ seems to have gotten really messed up, type make distclean, and then
+ start the make process over again. Ensure your un-archiever doesn't
+ change newline characters.
+
+ld: cannot find -lgcc
+
+ You specified that you want to link the GCC low-level runtime library
+ into your executable through the -lgcc' switch, but forgot to build and
+ properly install the library.
+
+Binutils 2.9
+
+ What's alphabetically on the top or bottom is not necessarily the
+ latest version. After 2.9 comes 2.10, 2.11, 2.12 and then there are
+ fifteen more releases that are all newer and progressively more likely
+ to build or support your choice of GCC version.
+
+See Also
+
+Articles
+
+ * [68]Cross-Compiler Successful Builds - combinations of GCC and
+ Binutils which have been shown to work with this tutorial by
+ OSDev.org members.
+ * [69]Target Triplet - on target triplets and their use
+ * [70]OS Specific Toolchain - going a step further and adding your
+ own target.
+ * [71]LLVM Cross-Compiler - some compilers make things much easier.
+ * [72]Canadian Cross - making things yet more complicated.
+
+External Links
+
+ * [73]http://kegel.com/crosstool has a popular example of a script
+ that automatically downloads, patches, and builds binutils, gcc,
+ and glibc for known platforms.
+ * [74]http://gcc.gnu.org/onlinedocs/gccint/Libgcc.html - Summary of
+ the support functions you get when you link with libgcc.
+ * [75]http://forums.gentoo.org/viewtopic.php?t=66125 - Compiling
+ Windows applications under Linux
+ * [76]http://www.libsdl.org/extras/win32/cross/README.txt - dito
+ * [77]https://github.com/travisg/toolchains - Another script for
+ building simple cross compilers
+ * [78]https://www.youtube.com/watch?v=aESwsmnA7Ec - A walkthrough of
+ how to build a cross-compiler using Cygwin on Windows.
+ * [79]https://github.com/Cheapskate01/Cross-Compiler-Build-Script - A
+ dead-simple script that Binutils and Gcc for you.
+
+Prebuilt Toolchains
+
+ These were built by people in the OSdev community for their own
+ building needs and shared at will, without guaranteeing any support or
+ that it will even work on your setup. YMMV.
+
+ Latests versions for Linux (many arch)
+ * [80]kernel.org various hosts/targets
+
+ For Linux x86_64 host
+ * [81]i386-elf 4.9.1 target
+ * [82]i686-elf 4.9.1 target
+ * [83]x86_64-elf 4.9.1 target
+ * [84]aarch64-elf 4.9.1 target
+ * [85]arm-eabi 4.9.1 target
+ * [86]m68k-elf 4.9.1 target
+ * [87]powerpc-elf 4.9.1 target
+ * [88]sparc-elf 4.9.1 target
+ * [89]sh-elf 4.9.1 target
+
+ The packages from phillid.tk below have been shrunk to about 10 MiB for
+ each pair of packages (GCC & Binutils). Please note that this has been
+ achieved by enabling only the C front-end for GCC. If you're going to
+ write your OS in any language but C or Assembly, these packages aren't
+ for you. These are actually Pacman packages, but untarring them to /
+ and rm-ing /.MTREE and other clutter dotfiles contained in the package
+ will work the same.
+
+ For Windows host
+ * [90]i686-elf 4.8.2 target
+ * [91]x86_64-elf 5.1.0 target
+
+ For Windows Subsystem for Linux (Beta) host
+ * [92]i686-elf 6.1.0 target (extracts to a directory called "cross",
+ don't forget to install 'make' - I would recommend "apt-get install
+ build-essential" to also add additional useful tools)
+
+ For OSX host
+ * [93]x86_64-pc-elf Cross Compiler setup with GCC and Binutils for
+ x86_64 OSX
+
+ ARM prebuilt toolchains for multiple host platforms
+
+ ARM provides it's own prebuilt toolchain based upon GNU utilities for
+ development targeting ARM systems.
+ * [94]GNU ARM Embedded Toolchain
+
+ Retrieved from
+ "[95]http://wiki.osdev.org/index.php?title=GCC_Cross-Compiler&oldid=207
+ 46"
+ [96]Categories:
+ * [97]Level 1 Tutorials
+ * [98]Compilers
+ * [99]Tutorials
+
+Personal tools
+
+ * [100]Log in
+
+Namespaces
+
+ * [101]Page
+ * [102]Discussion
+
+Variants
+
+Views
+
+ * [103]Read
+ * [104]View source
+ * [105]View history
+
+Actions
+
+Search
+
+ ____________________ Go Search
+
+Navigation
+
+ * [106]Main Page
+ * [107]Forums
+ * [108]FAQ
+ * [109]OS Projects
+ * [110]Random page
+
+About
+
+ * [111]This site
+ * [112]Joining
+ * [113]Editing help
+ * [114]Recent changes
+
+Toolbox
+
+ * [115]What links here
+ * [116]Related changes
+ * [117]Special pages
+ * [118]Printable version
+ * [119]Permanent link
+
+In other languages
+
+ * [120]Deutsch
+
+ * This page was last modified on 24 April 2017, at 00:09.
+ * This page has been accessed 589,447 times.
+
+ * [121]Privacy policy
+ * [122]About OSDev Wiki
+ * [123]Disclaimers
+
+ * [124]Powered by MediaWiki
+
+References
+
+ Visible links
+ 1. http://wiki.osdev.org/opensearch_desc.php
+ 2. http://wiki.osdev.org/index.php?title=Special:RecentChanges&feed=atom
+ 3. http://wiki.osdev.org/index.php?title=How_to_develop_on_Mac_OS_X&redirect=no
+ 4. http://wiki.osdev.org/How_to_develop_on_Mac_OS_X#mw-head
+ 5. http://wiki.osdev.org/How_to_develop_on_Mac_OS_X#p-search
+ 6. http://wiki.osdev.org/File:Difficulty_1.png
+ 7. http://wiki.osdev.org/How_to_develop_on_Mac_OS_X#Introduction
+ 8. http://wiki.osdev.org/How_to_develop_on_Mac_OS_X#Why_do_I_need_a_Cross_Compiler.3F
+ 9. http://wiki.osdev.org/How_to_develop_on_Mac_OS_X#Which_compiler_version_do_I_want.3F
+ 10. http://wiki.osdev.org/How_to_develop_on_Mac_OS_X#Which_Binutils_version_do_I_want.3F
+ 11. http://wiki.osdev.org/How_to_develop_on_Mac_OS_X#Deciding_on_the_target_platform
+ 12. http://wiki.osdev.org/How_to_develop_on_Mac_OS_X#Preparing_for_the_build
+ 13. http://wiki.osdev.org/How_to_develop_on_Mac_OS_X#Downloading_the_Source_Code
+ 14. http://wiki.osdev.org/How_to_develop_on_Mac_OS_X#Linux_Users
+ 15. http://wiki.osdev.org/How_to_develop_on_Mac_OS_X#OS_X_Users
+ 16. http://wiki.osdev.org/How_to_develop_on_Mac_OS_X#Windows_Users
+ 17. http://wiki.osdev.org/How_to_develop_on_Mac_OS_X#The_Build
+ 18. http://wiki.osdev.org/How_to_develop_on_Mac_OS_X#Preparation
+ 19. http://wiki.osdev.org/How_to_develop_on_Mac_OS_X#Binutils
+ 20. http://wiki.osdev.org/How_to_develop_on_Mac_OS_X#GCC
+ 21. http://wiki.osdev.org/How_to_develop_on_Mac_OS_X#Using_the_new_Compiler
+ 22. http://wiki.osdev.org/How_to_develop_on_Mac_OS_X#Troubleshooting
+ 23. http://wiki.osdev.org/How_to_develop_on_Mac_OS_X#ld:_cannot_find_-lgcc
+ 24. http://wiki.osdev.org/How_to_develop_on_Mac_OS_X#Binutils_2.9
+ 25. http://wiki.osdev.org/How_to_develop_on_Mac_OS_X#See_Also
+ 26. http://wiki.osdev.org/How_to_develop_on_Mac_OS_X#Articles
+ 27. http://wiki.osdev.org/How_to_develop_on_Mac_OS_X#External_Links
+ 28. http://wiki.osdev.org/How_to_develop_on_Mac_OS_X#Prebuilt_Toolchains
+ 29. http://wiki.osdev.org/Category:Executable_Formats
+ 30. http://wiki.osdev.org/Why_do_I_need_a_Cross_Compiler%3F
+ 31. http://wiki.osdev.org/Why_do_I_need_a_Cross_Compiler%3F
+ 32. http://wiki.osdev.org/Building_GCC
+ 33. http://wiki.osdev.org/GCC
+ 34. http://wiki.osdev.org/Building_GCC
+ 35. http://wiki.osdev.org/Building_GCC
+ 36. http://wiki.osdev.org/Cross-Compiler_Successful_Builds
+ 37. http://wiki.osdev.org/Binutils
+ 38. http://wiki.osdev.org/Target_Triplet
+ 39. http://wiki.osdev.org/Bare_Bones
+ 40. https://gnu.org/software/binutils/
+ 41. ftp://ftp.gnu.org/gnu/binutils/
+ 42. https://gnu.org/software/gcc/
+ 43. ftp://ftp.gnu.org/gnu/gcc/
+ 44. http://gmplib.org/
+ 45. http://mpfr.org/
+ 46. http://isl.gforge.inria.fr/
+ 47. http://www.cloog.org/
+ 48. http://multiprecision.org/
+ 49. https://www.gnu.org/software/texinfo/
+ 50. http://www.gentoo.org/proj/en/base/embedded/cross-development.xml
+ 51. https://gnu.org/software/libiconv/
+ 52. ftp://ftp.gnu.org/gnu/libiconv/
+ 53. http://brew.sh/
+ 54. http://apple.stackexchange.com/a/38247
+ 55. http://http://www.macports.org/
+ 56. http://wiki.osdev.org/MinGW
+ 57. http://wiki.osdev.org/Cygwin
+ 58. http://wiki.osdev.org/Cygwin
+ 59. http://www.mingw.org/wiki/HostedCrossCompilerHOWTO
+ 60. http://forum.osdev.org/
+ 61. http://gcc.gnu.org/install/configure.html
+ 62. http://wiki.osdev.org/GCC
+ 63. http://wiki.osdev.org/Libgcc
+ 64. http://wiki.osdev.org/Libgcc
+ 65. http://wiki.osdev.org/GCC
+ 66. http://wiki.osdev.org/GCC
+ 67. http://wiki.osdev.org/Bare_Bones
+ 68. http://wiki.osdev.org/Cross-Compiler_Successful_Builds
+ 69. http://wiki.osdev.org/Target_Triplet
+ 70. http://wiki.osdev.org/OS_Specific_Toolchain
+ 71. http://wiki.osdev.org/LLVM_Cross-Compiler
+ 72. http://wiki.osdev.org/Canadian_Cross
+ 73. http://kegel.com/crosstool
+ 74. http://gcc.gnu.org/onlinedocs/gccint/Libgcc.html
+ 75. http://forums.gentoo.org/viewtopic.php?t=66125
+ 76. http://www.libsdl.org/extras/win32/cross/README.txt
+ 77. https://github.com/travisg/toolchains
+ 78. https://www.youtube.com/watch?v=aESwsmnA7Ec
+ 79. https://github.com/Cheapskate01/Cross-Compiler-Build-Script
+ 80. https://www.kernel.org/pub/tools/crosstool/
+ 81. http://newos.org/toolchains/i386-elf-4.9.1-Linux-x86_64.tar.xz
+ 82. http://newos.org/toolchains/i686-elf-4.9.1-Linux-x86_64.tar.xz
+ 83. http://newos.org/toolchains/x86_64-elf-4.9.1-Linux-x86_64.tar.xz
+ 84. http://newos.org/toolchains/aarch64-elf-4.9.1-Linux-x86_64.tar.xz
+ 85. http://newos.org/toolchains/arm-eabi-4.9.1-Linux-x86_64.tar.xz
+ 86. http://newos.org/toolchains/m68k-elf-4.9.1-Linux-x86_64.tar.xz
+ 87. http://newos.org/toolchains/powerpc-elf-4.9.1-Linux-x86_64.tar.xz
+ 88. http://newos.org/toolchains/sparc-elf-4.9.1-Linux-x86_64.tar.xz
+ 89. http://newos.org/toolchains/sh-elf-4.9.1-Linux-x86_64.tar.xz
+ 90. https://drive.google.com/file/d/0B85K_c7mx3QjUnZuaFRPWlBIcXM/edit?usp=sharing
+ 91. https://mega.co.nz/#F!bBxA3SKJ!TDL4i1NjaZKd4YMo9p2U7g
+ 92. http://www.bin-os.com/i686-elf-6.1.0.tar.gz
+ 93. https://docs.google.com/file/d/0BxDNp6DGU6SZcmlHVWpNblRnWWs/edit?usp=sharing
+ 94. https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads
+ 95. http://wiki.osdev.org/index.php?title=GCC_Cross-Compiler&oldid=20746
+ 96. http://wiki.osdev.org/Special:Categories
+ 97. http://wiki.osdev.org/Category:Level_1_Tutorials
+ 98. http://wiki.osdev.org/Category:Compilers
+ 99. http://wiki.osdev.org/Category:Tutorials
+ 100. http://wiki.osdev.org/index.php?title=Special:UserLogin&returnto=GCC_Cross-Compiler
+ 101. http://wiki.osdev.org/GCC_Cross-Compiler
+ 102. http://wiki.osdev.org/Talk:GCC_Cross-Compiler
+ 103. http://wiki.osdev.org/GCC_Cross-Compiler
+ 104. http://wiki.osdev.org/index.php?title=GCC_Cross-Compiler&action=edit
+ 105. http://wiki.osdev.org/index.php?title=GCC_Cross-Compiler&action=history
+ 106. http://wiki.osdev.org/Main_Page
+ 107. http://forum.osdev.org/
+ 108. http://wiki.osdev.org/Category:FAQ
+ 109. http://wiki.osdev.org/Projects
+ 110. http://wiki.osdev.org/Special:Random
+ 111. http://wiki.osdev.org/OSDevWiki:About
+ 112. http://wiki.osdev.org/OSDevWiki:Joining
+ 113. http://wiki.osdev.org/OSDevWiki:Editing
+ 114. http://wiki.osdev.org/Special:RecentChanges
+ 115. http://wiki.osdev.org/Special:WhatLinksHere/GCC_Cross-Compiler
+ 116. http://wiki.osdev.org/Special:RecentChangesLinked/GCC_Cross-Compiler
+ 117. http://wiki.osdev.org/Special:SpecialPages
+ 118. http://wiki.osdev.org/index.php?title=GCC_Cross-Compiler&printable=yes
+ 119. http://wiki.osdev.org/index.php?title=GCC_Cross-Compiler&oldid=20746
+ 120. http://www.lowlevel.eu/wiki/Cross-Compiler
+ 121. http://wiki.osdev.org/OSDev_Wiki:Privacy_policy
+ 122. http://wiki.osdev.org/OSDev_Wiki:About
+ 123. http://wiki.osdev.org/OSDev_Wiki:General_disclaimer
+ 124. http://www.mediawiki.org/
+
+ Hidden links:
+ 126. http://wiki.osdev.org/How_to_develop_on_Mac_OS_X
+ 127. http://wiki.osdev.org/How_to_develop_on_Mac_OS_X
+ 128. http://wiki.osdev.org/Main_Page