intel / linux-sgx

Intel SGX for Linux*
https://www.intel.com/content/www/us/en/developer/tools/software-guard-extensions/linux-overview.html
Other
1.34k stars 548 forks source link

How to use Pthread in sgx? #905

Open Karssadin opened 2 years ago

Karssadin commented 2 years ago

I use the demo "helloworld" and add a thread in it,but there is an error.

#include <pthread.h>
#include "Enclave_t.h"

void* test(void *arg){
ocall_print_string("123\n");
}
void ecall_hello(void){
pthread_t tid;
pthread(&tid,NULL,test,NULL);
ocall_print_string("123\n");
}

I add the -sgx_pthread in the Makefile but when i run the make,there is an error:

CXX  <=  Enclave/Enclave.cpp
/usr/local/bin/ld: /opt/intel/sgxsdk/lib64/libsgx_pthread.a(pthread.o): in function `_pthread_wakeup(unsigned long) [clone .part.0]':
pthread.cpp:(.text._Z15_pthread_wakeupm.part.0+0x2d): undefined reference to `pthread_wakeup_ocall'
/usr/local/bin/ld: /opt/intel/sgxsdk/lib64/libsgx_pthread.a(pthread.o): in function `_pthread_wait_timeout(unsigned long, unsigned long)':
pthread.cpp:(.text._Z21_pthread_wait_timeoutmm+0x30): undefined reference to `pthread_wait_timeout_ocall'
/usr/local/bin/ld: /opt/intel/sgxsdk/lib64/libsgx_pthread.a(pthread.o): in function `pthread_create':
pthread.cpp:(.text.pthread_create+0x113): undefined reference to `pthread_create_ocall'
/usr/local/bin/ld: pthread.cpp:(.text.pthread_create+0x16c): undefined reference to `pthread_wait_timeout_ocall'
/usr/local/bin/ld: /opt/intel/sgxsdk/lib64/libsgx_pthread.a(pthread.o): in function `pthread_join':
pthread.cpp:(.text.pthread_join+0xe0): undefined reference to `pthread_wait_timeout_ocall'
collect2: error: ld returned 1 exit status
Makefile:216: recipe for target 'enclave.so' failed

how to fix it?

jbdelcuv commented 2 years ago

Please add "from "sgx_pthread.edl" import *;" to you enclave EDL file.

ksy980418 commented 1 year ago

Is it correctly work? In my case, it doesn't work and I found that pthread during ecall does not work in the sgx developement document.