Skip to content

Running compiled code on OSv

Nadav Har'El edited this page Sep 22, 2013 · 7 revisions

This document explains how to run compiled code (C code, C++ code, etc.) on OSv

Compiling Linux applications for OSv

OSv in ABI-compatible with Linux, meaning that it should be able to run (minus any bugs still in OSv...) executable code compiled for Linux, if it doesn't use a few unsupported features such as fork(). This means that you can compile your existing Linux application with its normal build process, and run the resulting Linux executable on OSv.

There's one snag, though: OSv cannot currently run "normal" (fixed-position) executables, and can only run a relocatable shared-object (a file normally given a ".so" extension). It looks for the main() function in that shared object, and runs it.

Converting a compilation process to produce a shared-object instead of an executable is fairly trivial: All you need to do is to add "-fPIC" option to the compilation of each source file (to produce an object file with position-independent code) and to add "-shared" to the linking stage, to produce a shared-object instead of an executable. That's it, and you can result the result on OSv (the next section explains how to do that).

By the way, some projects already create ".so"s that can be run in OSv. For example, the Java runtime (the JVM) is mostly a collection of shared objects, with a simple main() that calls the right functions. So to run Java in OSv, all we needed to do is to take unmodified ".so"s (we can take precompiled versions, e.g., from some Linux distribution), and add to it our own simple main which we compiled as explained above (see java/java.cc in OSv's source repository).

Putting the application into OSv's image and running it

Compiling applications which uses OSv APIs

Clone this wiki locally