forked from rafaelauler/openisa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
167 lines (118 loc) · 6.04 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
OpenISA Tools
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Part I. Building the tools
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
0. Introduction
-------------------------------------------------------------------------------
This document describes how to compile and install the OpenISA toolchain.
-------------------------------------------------------------------------------
1. Linker
-------------------------------------------------------------------------------
The OpenISA linker is based on GNU binutils. To have access to its source code,
you need to clone (you haven't done it already) the OpenISA master repository:
$ git clone https://github.com/OpenISA/openisa.git --depth 1
1.1 Building the linker
In this step, we will build the first element of our OpenISA toolchain, a folder
where we will keep all toolchain utils. We will call this folder "oi-toolchain".
$ cd openisa/linker-oi
$ wget http://ftp.gnu.org/gnu/binutils/binutils-2.23.2.tar.bz2
$ tar xjvf binutils-2.23.2.tar.bz2
$ git reset --hard #recover modifications caused by extracting binutils package
$ mkdir build
$ cd build
$ ../binutils-2.23.2/configure --prefix=$(pwd)/../../oi-toolchain \
--disable-nls --enable-shared --disable-multilib \
--target=mipsel-unknown-linux-gnu --disable-werror
$ make MAKEINFO=true -j20 # Adjust -j accordingly
$ make install MAKEINFO=true
$ cd ../..
-------------------------------------------------------------------------------
2. Compiler
-------------------------------------------------------------------------------
The OpenISA compiler is based on Clang and LLVM. The llvm-openisa.git repo
contains the source code in its entirety. Keep in mind that the LLVM project
is composed of multiple repositories. We fork llvm, clang and compiler-rt
repos. The latter two are added inside our llvm fork as git submodules, so
you may want to use the "--recursive" flag when cloning.
2.1 Setting up repos
$ git clone --recursive https://github.com/OpenISA/llvm-openisa.git \
-b openisa --depth 1
This may take a while because of the long history of commits of the LLVM
project. If you clone with "--depth 1", you can get a shallow copy much faster.
2.2 Setting up your build
Next step is to create a folder to build the compiler.
$ mkdir obj
$ cd obj
And configure it, keeping in mind we intend to install it in the *same* folder
you installed the linker, so adjust the command line to reflect so.
$ cmake ../llvm-openisa -DLLVM_TARGETS_TO_BUILD="Mips;X86;ARM" \
-DCMAKE_INSTALL_PREFIX=$(pwd)/../oi-toolchain \
-DLLVM_DEFAULT_TARGET_TRIPLE="mipsel-unknown-linux-gnu" \
-DCLANG_VENDOR="OpenISA Tools" -GNinja
If you don't use ninja, please remember to remove "-GNinja". You may also want
to add the -DCMAKE_BUILD_TYPE="Release" flag to build an optimized binary.
Now build and install it:
$ ninja && ninja install
$ cd ..
-------------------------------------------------------------------------------
3. C standard library
-------------------------------------------------------------------------------
The OpenISA toolchain relies on newlib to provide its C library. Its source
code is available in the same repository of the linker (the master repository).
3.1 Setting up build
First you need to put whatever tools you have so far of the OpenISA toolchain in
your path:
$ cd oi-toolchain/bin
$ export PATH=$(pwd):$PATH
$ cd ../..
Now go to newlib's folder and prepare your build. Configure it to install in the
same oi-toolchain folder used before (adjust the command line below
accordingly).
$ cd newlib
$ mkdir build
$ cd build
$ CC_FOR_TARGET="clang"\
CXX_FOR_TARGET="clang++"\
AR_FOR_TARGET="mipsel-unknown-linux-gnu-ar"\
AS_FOR_TARGET="mipsel-unknown-linux-gnu-as"\
LD_FOR_TARGET="mipsel-unknown-linux-gnu-ld"\
NM_FOR_TARGET="mipsel-unknown-linux-gnu-nm"\
OBJDUMP_FOR_TARGET="mipsel-unknown-linux-gnu-objdump"\
RANLIB_FOR_TARGET="mipsel-unknown-linux-gnu-ranlib"\
READELF_FOR_TARGET="mipsel-unknown-linux-gnu-readelf"\
STRIP_FOR_TARGET="mipsel-unknown-linux-gnu-strip"\
../newlib-2.1.0/configure --prefix=$(pwd)/../../oi-toolchain -target=oi-elf
$ make && make install
Now, manually copy the linker script used by the OpenISA linker:
$ cp ../newlib-2.1.0/libgloss/libnosys/ac_link.ld ../../oi-toolchain/oi-elf/lib
Finally, compile ac_start.o:
$ cd ../../oi-toolchain/oi-elf/lib
$ clang -c ../../../newlib/newlib-2.1.0/libgloss/libnosys/ac_start.S \
-o ac_start.o
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Part II. Using the tools
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
4. Using the compiler, assembler and disassembler
-------------------------------------------------------------------------------
Use the clang compiler driver (command line "clang" if you put oi-toolchain/bin
in your path) to access the OpenISA compiler, assembler or linker. The linker
itself is an external tool, but the clang driver knows where to find it, if you
installed everything following the instructions in this manual.
Example 1: compile to assembly
$ echo 'int main() { printf("Hello, world!\n"); return 0; }' | clang -x c \
-S -o test.s - && cat test.s
Example 2: compile to object
$ echo 'int main() { printf("Hello, world!\n"); return 0; }' | clang -x c \
-c -o test.o -
Example 3: using a disassembler to disassemble the obj created in the previous
example
$ llvm-objdump -disassemble test.o
Example 4: compile to final executable
$ clang input.c -o input
*.---.* end of document *.---.*