Compiling FHE programs

Say we had the following FHE program:

typedef unsigned char uint8_t;

[[clang::fhe_program]] uint8_t add([[clang::encrypted]] uint8_t a,
                                   [[clang::encrypted]] uint8_t b) {
  return a + b;
}

If we wanted to compile this program, we can use the Sunscreen version of clang that supports the Parasol processor using the following command:

# Create the object file
clang             \
  -target parasol \ # Target the parasol CPU
  -O2             \ # Turn on compiler optimizatons
  -c              \ # Only run compile, do not link
  add.c           \ # Specify the file to compile
  -o add.o          # And where to write the output

# Combine object files into a single binary
ld.lld            \
  add.o           \ # Specify the file to link
  -o add            # And where to write the output binary file

This will produce a small binary file at add. This file is an Executable and Linkable Format (ELF) file that contains some metadata about the Parasol programs, the specific FHE programs specified with [[clang::fhe_program]], and the assembly code to run the FHE programs on the Parasol processor.

The file generated here can be used with SPF to execute the program. For more information, see my first program