|
| 1 | +How To Build On Linux |
| 2 | +--------------------- |
| 3 | + |
| 4 | + |
| 5 | +Contents: |
| 6 | + - Overview |
| 7 | + - Checking out sources to build out-of-the-box |
| 8 | + - Building out of the box |
| 9 | + - Building the VM Simulator Support Libraries |
| 10 | + - How to configure and build a VM on Unix |
| 11 | + - Debugging configuration failures |
| 12 | + - Testing an external plugin has completely linked |
| 13 | + - Optimization level and gcc version (please read!) |
| 14 | + - Installing support libraries |
| 15 | + |
| 16 | + |
| 17 | +Overview |
| 18 | +-------- |
| 19 | +The "Cog" VM comes in a bewildering variety of forms. The first distinction |
| 20 | +is between Squeak/Croquet VMs that run Squeak, Pharo, Cuis, Croquet images |
| 21 | +and their ilk, and between Newspeak VMs that run Newspeak. |
| 22 | + |
| 23 | +Another distinction is between Stack, Cog and Sista VMs. Stack VMs are those |
| 24 | +with context-to-stack mapping that optimise message sending by keeping method |
| 25 | +activations on a stack instead of in contexts. These are pure interpreters but |
| 26 | +significantly faster than the standard context-based Interpreter VM. Cog VMs |
| 27 | +add a JIT to the mix, compiling methods used more than once to maxchine code on |
| 28 | +the fly. Sista VMs, as yet unrealised and in development, add support for |
| 29 | +adaptive optimization that does speculative inlining at the bytecode-to-bytecode |
| 30 | +level. These are targeted for release in 2015. |
| 31 | + |
| 32 | +Another distinction is between "v3" VMs and Spur VMs. "v3" is the original |
| 33 | +object representation for Squeak as described in the back-to-the-future paper. |
| 34 | +Spur, as described on the www.mirandabanda.org blog, is a faster object |
| 35 | +representation which uses generation scavenging, lazy forwarding for fast |
| 36 | +become, and a single object header format common to 32 and 64 bit versions. |
| 37 | + |
| 38 | +Another distinction is between normal single-threaded VMs that schedule "green" |
| 39 | +Smalltalk processes above a single-threaded VM, and "multi-threaded" VMs that |
| 40 | +share the VM between any number of native threads such that only one native |
| 41 | +thread owns the VM at any one time, switching between threads on FFI calls and |
| 42 | +callbacks or on Smalltalk process switches when Smalltalk processes are owned |
| 43 | +by threads. This multi-threaded support is as yet experimental. |
| 44 | + |
| 45 | +A distinction on linux is between VMs with an itimer hearbeat or a threaded |
| 46 | +heartbeat. VMs with an itimer hearbeat use setitimer to deliver a SIGALRM |
| 47 | +signal at regular intervals to interrupt the VM to check for events. These |
| 48 | +signals can be troublesome, interrupting foreign code that cannot cope with |
| 49 | +such signals. VMs with a threaded heartbeat use a high-priority thread that |
| 50 | +loops, blocking on nanosleep and then interrupting the VM, performing the same |
| 51 | +function as the itimer heartbeat but without using signals. These VMs are to |
| 52 | +be preferred but suport for multiple thread priorities in user-level processes |
| 53 | +has only been available on linux in kernels later than 2.6.12. |
| 54 | + |
| 55 | +The final distinction is between production, assert and debug VMs. Production |
| 56 | +VMs are fully optimized, although they may include debugging symbols, and as |
| 57 | +their name implies are for use in production. Assert and debug VMs include |
| 58 | +many assert checks that are disabled in the production VMs. These asserts are |
| 59 | +very helpful in debugging VM problems but significantly impact performance. |
| 60 | +The difference between assert and debug VMs is that assert VMs are compiled |
| 61 | +with moderate optimization, which improves the performance of the asserts, |
| 62 | +whereas debug VMs are compiled with no optimization at all, providing maximum |
| 63 | +debuggability with minimum performance. |
| 64 | + |
| 65 | +This directory tree provides build directories for some of this matrix. For |
| 66 | +example, squeak.cog.v3 contains build directories for Smalltalk Cog VMs using |
| 67 | +the old object representation, newspeak.stack.spur contains build directories |
| 68 | +for Newspeak Stack VMs using the Spur object representation. Build as desired. |
| 69 | + |
| 70 | + |
| 71 | +Checking out sources to build out-of-the-box |
| 72 | +-------------------------------------------- |
| 73 | +Check-out the repository from github: |
| 74 | + git clone http://www.github.com/OpenSmalltalk/opensmalltalk-vm oscogvm |
| 75 | + cd ./oscogvm |
| 76 | + more README.md |
| 77 | + |
| 78 | + |
| 79 | +Building out of the box |
| 80 | +----------------------- |
| 81 | +Install the tools (gcc, X11-devel, etc, e.g. libpng, libuuid libX11 & libxt |
| 82 | +source). See "Installing support libraries" below. If the configure step fails |
| 83 | +when "checking for C compiler default output file name", you have yet to install |
| 84 | +all the necessary support packages (e.g. libuuid). |
| 85 | +Then cd to the build directory of your choice, e.g. |
| 86 | + build.linux32x86/squeak.cog.spur/build |
| 87 | +Then execute |
| 88 | + ./mvm |
| 89 | +answering "y" to perform a clean build or "n" to rebuild without recionfiguring. |
| 90 | +Again, if the configure step fails when "checking for C compiler default output |
| 91 | +file name", you have yet to install all the necessary support (e.g. lubuuid). |
| 92 | + |
| 93 | +The subdirectories confrm to the production/assert/debug x itimer vs threaded |
| 94 | +heartbeat x single vs multi-threaded parts of the matrix described above. For |
| 95 | +example, build.linux32x86/squeak.cog.v3 includes |
| 96 | + |
| 97 | + build |
| 98 | + build.itimerheartbeat |
| 99 | + build.multithreaded |
| 100 | + |
| 101 | + build.assert |
| 102 | + build.assert.itimerheartbeat |
| 103 | + build.multithreaded.assert |
| 104 | + |
| 105 | + build.debug |
| 106 | + build.multithreaded.debug |
| 107 | + build.debug.itimerheartbeat |
| 108 | + |
| 109 | +subdirectories. It includes two convenience scripts that will make all |
| 110 | +configurations: |
| 111 | + makeallclean |
| 112 | + makealldirty |
| 113 | + |
| 114 | +Each build directory contains three files |
| 115 | + mvm |
| 116 | + plugins.int |
| 117 | + plugins.ext |
| 118 | +The mvm script runs ../platforms/unix/config/configure with the relevant |
| 119 | +options, runs make, and then make install to create a VM directory tree in |
| 120 | +../products, ../products/assert or ../products/debug as appropriate. |
| 121 | +plugins.int and plugins.ext determine the set of plugins to be taken from |
| 122 | +the supplied plugins directory (which defaults to ../src/plugins), and which |
| 123 | +are to be linked into the VM (plugins.int) or compiled as external shared |
| 124 | +objects to be dynamically linked at run-time (plugins.ext). |
| 125 | + |
| 126 | +Finally, at the build.linux32x86 level the makeall script will run all the |
| 127 | +makeallclean scripts it can find. |
| 128 | + |
| 129 | + |
| 130 | +Building the VM Simulator Support Libraries |
| 131 | +------------------------------------------- |
| 132 | +If you want to get the Cog VM simulator working you'll need to build one or more |
| 133 | +of the processor simulator plugins, each of which has support libraries that |
| 134 | +must be built: |
| 135 | + Processor Plugin Support Library |
| 136 | + x86 BochsIA32Plugin build.linux32x86/bochsx86 |
| 137 | + x86_64/x64 BochsX64Plugin build.linux32x86/bochsx64 |
| 138 | + ARMv5 GdbARMPlugin build.linux32x86/gdbarm32 |
| 139 | +cd to the relevant directories; run conf.COG and then the build script, e.g. |
| 140 | + $ cd build.linux32x86/bochsx86 |
| 141 | + $ ./conf.COG |
| 142 | + $ ./makeem |
| 143 | + |
| 144 | +Then when Squeak VMs are built they will include the plugin(s) for which support |
| 145 | +libraries have been provided. |
| 146 | + |
| 147 | + |
| 148 | +How to configure and build a VM on Unix |
| 149 | +--------------------------------------- |
| 150 | +The mvm scripts are themselves wrappers around an adaptation of Ian Piumarta's |
| 151 | +Squeak build system above autoconf to the Cog sources. One can choose the vm |
| 152 | +source files, plugin source files, and optimization level to compile a VM of |
| 153 | +your choice. To find the full set of options via |
| 154 | + |
| 155 | + ../platforms/unix/config/configure --help |
| 156 | + |
| 157 | +You can see the use of configure in the various mvm scripts in each build |
| 158 | +directory. |
| 159 | + |
| 160 | +e.g. |
| 161 | + ../../platforms/unix/config/configure --without-npsqueak CFLAGS="-g -O2 -msse2 -D_GNU_SOURCE -DNDEBUG -DITIMER_HEARTBEAT=1 -DCOGMTVM=0 -DDEBUGVM=0" LIBS=-lpthread |
| 162 | + make install prefix=WhereYouWantTheVmToGo |
| 163 | + |
| 164 | + N.B. If you're on a 64-bit linux read 3e below!! |
| 165 | + N.B. On Ubuntu *do not* supply "LIBS=-lpthread -luuid", i.e. use |
| 166 | + ../../platforms/unix/config/configure --without-npsqueak CFLAGS="-g -O2 -msse2 -D_GNU_SOURCE -DNDEBUG -DITIMER_HEARTBEAT=1 -DCOGMTVM=0 -DDEBUGVM=0" |
| 167 | + |
| 168 | + |
| 169 | +N.B. The plugin set is defined by plugins.ext and plugins.int in the build dir. |
| 170 | + |
| 171 | +Be prepared to install libuuid support. e.g. on CentOS 6.5 use |
| 172 | +sudo yum -y install libuuid-devel |
| 173 | + |
| 174 | + |
| 175 | +Debugging configuration failures |
| 176 | +-------------------------------- |
| 177 | +If your development system does not have the required libraries installed then |
| 178 | +the configure step run by the mvm script will fail cryptically. You will see |
| 179 | +something like |
| 180 | + checking sanity of generated src directory... okay |
| 181 | + checking build system type... i686-pc-linux-gnu |
| 182 | + checking host system type... i686-pc-linux-gnu |
| 183 | + checking target system type... i686-pc-linux-gnu |
| 184 | + |
| 185 | + Configuring Squeak (.-) for i686-pc-linux-gnu |
| 186 | + |
| 187 | + checking whether make sets $(MAKE)... yes |
| 188 | + checking for gcc... gcc -m32 |
| 189 | + checking for C compiler default output file name... configure: error: C compiler cannot create executables |
| 190 | + See `config.log' for more details. |
| 191 | +But config.log is missing the relevant details. It only contains the failing gcc |
| 192 | +invocation, not the output from that failing command. To diagnose, grep to find |
| 193 | +the gcc invocation: |
| 194 | + $ grep gcc config.log |
| 195 | + ... |
| 196 | + configure:2269: gcc -m32 -g3 -O0 -fwrapv -DDEBUGVM=1 -DEnforceAccessControl=0 -msse2 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -Wl,-z,now conftest.c -lpthread -luuid >& |
| 197 | +and then repeat the compilation supplying your own test file, e.g. |
| 198 | + $ gcc -m32 -g3 -O0 -fwrapv -DDEBUGVM=1 -DEnforceAccessControl=0 -msse2 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -Wl,-z,now helloworld.c -lpthread -luuid |
| 199 | + helloworld.c: In function 'main': |
| 200 | + /usr/bin/ld: cannot find -luuid |
| 201 | + collect2: ld returned 1 exit status |
| 202 | +From which one can infer that one needs to install either the 64-bit or the 32-bit |
| 203 | +version of libuuid, e.g. sudo yum install libuuid-devel |
| 204 | + |
| 205 | + |
| 206 | +Testing an external plugin has completely linked |
| 207 | +------------------------------------------------ |
| 208 | +You may find that an external plugin compiles and links but does not load. |
| 209 | +This is usually because it contans undefined symbols. To find undefined |
| 210 | +symbols, remake the plugin, capturing the link step and then supply |
| 211 | + -Wl,--warn-unresolved-symbols -Wl,--no-allow-shlib-undefined |
| 212 | +when manually repeating the link command |
| 213 | + |
| 214 | + |
| 215 | +Optimization level and gcc version |
| 216 | +---------------------------------- |
| 217 | +There are issues with gcc version > 4.2.1. Any of the following flags may break the build at -O2: |
| 218 | +-ftree-pre |
| 219 | +-fpartial-inlining |
| 220 | +-fcaller-saves |
| 221 | + |
| 222 | +So turn them off. e.g. |
| 223 | + ../../platforms/unix/config/configure --without-npsqueak CFLAGS="-g -O2 -msse2 -fno-caller-saves -fno-partial-inlining -fno-tree-pre -D_GNU_SOURCE -DNDEBUG -DCOGMTVM=0 -DDEBUGVM=0" LIBS="-lpthread -luuid" |
| 224 | +See http://smallissimo.blogspot.fr/2013/02/compiling-squeak-cog-virtual-machine-on.html |
| 225 | + |
| 226 | +There appear to be issues with 3.4.x gcc version on RedHat. In particular |
| 227 | +compiling the Newspeak VM with either of |
| 228 | + gcc version 3.4.6 20060404 (Red Hat 3.4.6-3) |
| 229 | + gcc version 3.4.6 20060404 (Red Hat 3.4.6-10) |
| 230 | +using -O2 results in a VM that segfaults early in startup. For these compilers |
| 231 | +it is probably wise to use -O1, even though -O3 seems to work. |
| 232 | + |
| 233 | +People have reported that the OSProcessPlugin is broken on gcc versions > 4.8 |
| 234 | +on Debian. |
| 235 | + |
| 236 | + |
| 237 | +Installing support libraries |
| 238 | +---------------------------- |
| 239 | +Different linux distributions have different mechanisms for loading packages. |
| 240 | +Here are some examples: |
| 241 | + |
| 242 | +CentOS |
| 243 | + sudo yum install cairo-devel |
| 244 | + sudo yum install pango-devel |
| 245 | + sudo yum install libuuid-devel |
| 246 | + sudo yum install libX11-devel |
| 247 | + sudo yum install mesa-libGL mesa-libGL-devel |
| 248 | +N.B. if you get failures due to version conflicts try |
| 249 | + sudo yum update |
| 250 | +and then retry. |
| 251 | + |
| 252 | + |
| 253 | +Ubuntu |
| 254 | + sudo apt-get install uuid-dev libcairo2-dev libpango1.0-dev libgl1-mesa-dev libgl1-mesa-glx |
| 255 | + |
| 256 | +More advice and examples for other distros gratefully received. |
0 commit comments