diff --git a/rune/libenclave/intelsgx/device_linux.go b/rune/libenclave/intelsgx/device_linux.go index e40a593d2be587d10debf7e20d810e5d4a698c38..2ce26359b1b2acb4a827c066e927a3ade69e7982 100644 --- a/rune/libenclave/intelsgx/device_linux.go +++ b/rune/libenclave/intelsgx/device_linux.go @@ -3,6 +3,7 @@ package intelsgx // import "github.com/opencontainers/runc/libenclave/intelsgx" /* #cgo linux LDFLAGS: -ldl #include +#include #include */ import "C" @@ -11,6 +12,15 @@ import ( "unsafe" ) +func loadLibrary(p string) { + path := C.CString(p) + dl := C.dlopen(path, C.RTLD_NOW) + if dl == nil { + C.perror(C.CString("failed to load library " + p)) + } + C.free(unsafe.Pointer(path)) +} + // Due to the design of runelet, the Enclave Runtime PAL is loaded // in host but launched in container. The fact that certain libraries // from Intel SGX PSW would use dlopen() to further load @@ -19,9 +29,7 @@ import ( // are completely loaded in host, preload them prior to switch // into container. func preloadSgxPswLib() { - path := C.CString("libsgx_launch.so") - C.dlopen(path, C.RTLD_NOW) - C.free(unsafe.Pointer(path)) + loadLibrary("libsgx_launch.so.1") } func init() {