Description
Attempting to reproduce the architectural enclaves on a non-NixOS platform fails, despite having the same toolchain versions. Debugging revealed that this is a result of the built enclaves containing a reference to the NixOS ld-linux path.
This can be easily seen by querying the INTERP section of the binaries
$ readelf -l libsgx_*.signed.so | grep --after 2 INTERP
INTERP 0x00000000000002a8 0x00000000000002a8 0x00000000000002a8
0x0000000000000054 0x0000000000000054 R 0x1
[Requesting program interpreter: /nix/store/scd5n7xsn0hh0lvhhnycr9gx0h8xfzsl-glibc-2.34-210/lib/ld-linux-x86-64.so.2]
--
INTERP 0x00000000000002a8 0x00000000000002a8 0x00000000000002a8
0x0000000000000054 0x0000000000000054 R 0x1
[Requesting program interpreter: /nix/store/scd5n7xsn0hh0lvhhnycr9gx0h8xfzsl-glibc-2.34-210/lib/ld-linux-x86-64.so.2]
--
INTERP 0x00000000000002a8 0x00000000000002a8 0x00000000000002a8
0x0000000000000054 0x0000000000000054 R 0x1
[Requesting program interpreter: /nix/store/scd5n7xsn0hh0lvhhnycr9gx0h8xfzsl-glibc-2.34-210/lib/ld-linux-x86-64.so.2]
--
INTERP 0x00000000000002a8 0x00000000000002a8 0x00000000000002a8
0x0000000000000054 0x0000000000000054 R 0x1
[Requesting program interpreter: /nix/store/scd5n7xsn0hh0lvhhnycr9gx0h8xfzsl-glibc-2.34-210/lib/ld-linux-x86-64.so.2]
IIUC, the ld-linux interpretor is irrelevant for SGX, since the SGX SDK contains native logic for loading code into the enclaves. If this is indeed the case, then I'd request that the reference to the NixOX ld-linux is removed from future pre-built enclave binaries.
Looking at the build system this could potentially be achieved by extending the 'strip' command usage to also purge the '.interp' section of the ELF binary.
$(STRIP) --strip-unneeded --remove-section=.comment --remove-section=.note --remove-section=.interp $(SONAME)
Alternatively the -Wl,-dynamic-linker
arg could be used to set the .interp section contents to some dummy value to indicate it is redundant / unused e.g.
LDTFLAGS = -L$(SGX_LIB_DIR) -Wl,--whole-archive $(TRTSLIB) -Wl,--no-whole-archive \
-Wl,--start-group $(EXTERNAL_LIB) -Wl,--end-group -Wl,--build-id \
-Wl,--version-script=$(ROOT_DIR)/build-scripts/enclave.lds $(ENCLAVE_LDFLAGS) \
-Wl,dynamic-linker,/bin/false
There are probably other options too - I don't mind as long as this (apparently) redundant NixOS path can be removed from future pre-built enclave binaries.