Skip to content

Fortran

SCONE supports Fortran with the help of cross-compilation. This page focuses on the SCONE gfortran cross compiler scone gfortran (a.k.a. scone-gfortran, a.k.a. gfortran). This cross compiler is based on gfortran and hence, the command line options are the same as those of gfortran.

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 gfortran --help
Usage: x86_64-linux-musl-gfortran [options] file...
Options:
...

Let's try a simple Fortran program.

cat > gcd.f << EOF
*     euclid.f (FORTRAN 77)
*     Find greatest common divisor using the Euclidean algorithm

      PROGRAM EUCLID
        PRINT *, 'A?'
        READ *, NA
        IF (NA.LE.0) THEN
          PRINT *, 'A must be a positive integer.'
          STOP
        END IF
        PRINT *, 'B?'
        READ *, NB
        IF (NB.LE.0) THEN
          PRINT *, 'B must be a positive integer.'
          STOP
        END IF
        PRINT *, 'The GCD of', NA, ' and', NB, ' is', NGCD(NA, NB), '.'
        STOP
      END

      FUNCTION NGCD(NA, NB)
        IA = NA
        IB = NB
    1   IF (IB.NE.0) THEN
          ITEMP = IA
          IA = IB
          IB = MOD(ITEMP, IB)
          GOTO 1
        END IF
        NGCD = IA
        RETURN
      END
EOF

We compile the program with scone gfortran (a.k.a. scone-gfortran):

scone gfortran gcd.f -o gcd

We can now run this program as follows:

SCONE_VERSION=1 ./gcd << EOF
10
15
EOF

The output will look like this:

export SCONE_QUEUES=4
export SCONE_SLOTS=256
export SCONE_SIGPIPE=0
export SCONE_MMAP32BIT=0
export SCONE_SSPINS=100
export SCONE_SSLEEP=4000
export SCONE_KERNEL=0
export SCONE_HEAP=67108864
export SCONE_STACK=81920
export SCONE_CONFIG=/etc/sgx-musl.conf
export SCONE_MODE=sim
export SCONE_SGXBOUNDS=no
export SCONE_VARYS=no
export SCONE_ALLOW_DLOPEN=no
export SCONE_MPROTECT=no
Revision: b1e014e64b4d332a51802580ec3252370ffe44bb (Wed May 30 15:17:05 2018 +0200)
Branch: master
Configure options: --enable-shared --enable-debug --prefix=/mnt/ssd/franz/subtree-scone2/built/cross-compiler/x86_64-linux-musl

Enclave hash: e9c60984724c6d5ffc8cc8a6ba4377910e63c8534ef24b87d0727e712809ba50
 A?
 B?
 The GCD of          10  and          15  is           5 .

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