Skip to content

C Program Language Support

SCONE supports native compilation combined with dynamic linking as well as cross-compilation with static as well as dynamic linking.

This page focuses on the SCONE cross compiler. This cross compiler is based on gcc and hence, the command line options are the same as gcc.

Image

Ensure that you have the newest SCONE cross compiler image and determine which SGX device to mount with function determine_sgx_device:

docker pull registry.scontain.com/sconecuratedimages/crosscompilers
determine_sgx_device
docker run $MOUNT_SGXDEVICE -it registry.scontain.com/sconecuratedimages/crosscompilers

In case you do not have an SGX driver installed, no device will be mounted and applications will run in SIM mode.

Help

If you need some help, just execute in the container:

$ scone gcc --help
Usage: x86_64-linux-musl-gcc [options] file...
Options:
...

Example

Let's try to compile a simple program:

cat > fib.c << EOF
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv) {
   int n=0, first = 0, second = 1, next = 0, c;

   if (argc > 1)
        n=atoi(argv[1]);
   printf("fib(%d)= 1",n);
   for ( c = 1 ; c < n ; c++ ) {
        next = first + second;
        first = second;
        second = next;
        printf(", %d",next);
   }
   printf("\n");
}
EOF

We compile the program with scone gcc or scone-gcc or just gcc (all equivalent):

scone gcc fib.c -o fib

To compute fib(23), execute:

SCONE_VERSION=1 ./fib 23

The last line of the output should look as follows:

fib(23)= 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657

Debugging

You can use scone-gdb to debug your applications when running inside of an enclave. For some more details on how to use the debugger, please read how to debug GO programs.

Screencast