- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Today i found a problem in my code. It return SGX_ERROR_UNEXPECTED when i call sgx_create_enclave in some situations. I think there are something wrong in my CMakeLists.txt( I use cmake to compile the untrusted part in my project), because code run correctly when i use the template Makefile in sdk example to compile. More detail blow:
code available here (i have remove all unnecessary code): https://github.com/chilogen/workspace/tree/master/error/SimpleEnclave
code will run success in below situations:
* compile with Makefile
* compile with cmake and comment out app.cpp:20
code will return error in below situation:
* compile with cmake and do not comment out app.cpp:20
So, what is wrong in my code (or CMakeLists.txt), how should i do?
I will be so thankful if your get me some idea about it.
update : paste code here
app.cpp
#include "enclave_u.h"
#include <sgx_urts.h>
#include <sgx_uae_service.h>
#include <sgx_ukey_exchange.h>
#include <iostream>
using namespace std;
class testClass {
public:
sgx_launch_token_t _token = {0};
sgx_enclave_id_t _eid;
sgx_ra_context_t _ctx;
void init_enclave();
bool request(uint8_t *src, uint32_t srcLen, uint8_t *cmac);
//will set _ctx here
//void do_attestation();
}x;
bool testClass::request(uint8_t *src, uint32_t srcLen, uint8_t *cmac) {
sgx_status_t retval,status;
status = ecall_calcmac(_eid, &retval,&_ctx, SGX_RA_KEY_SK, src, srcLen, cmac);
return true;
}
void testClass::init_enclave(){
sgx_enclave_id_t global_eid;
sgx_launch_token_t token={0};
sgx_status_t ret;
int updated=0;
ret=sgx_create_enclave("enclave.signed.so",SGX_DEBUG_FLAG, \
&token,&updated,&global_eid,NULL);
if(ret!=SGX_SUCCESS){
std::cout<<"error init enclavedsfdsf\n";
printf("%08x\n",ret);
exit(1);
}
}
int main(){
x.init_enclave();
return 0;
}
CMakeLists.txt (code return error code 0000001)
include_directories (/opt/intel/sgxsdk/include)
link_directories (/opt/intel/sgxsdk/lib64)
add_library (enclave_untrusted enclave_u.c)
add_executable (app app.cpp)
target_link_libraries (app enclave_untrusted sgx_ukey_exchange sgx_urts sgx_uae_service pthread)
compile.sh (or Makefile , program run correctly)
gcc -c -I /opt/intel/sgxsdk/include/ -o enclave_u.o enclave_u.c g++ -c app.cpp -o app.o -I /opt/intel/sgxsdk/include/ g++ -o app app.o enclave_u.o -L /opt/intel/sgxsdk/lib64 -lsgx_urts -lsgx_ukey_exchange -lsgx_uae_service -pthread
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
problem have been solved on stackoverflow by guillaume-racicot. Refer to https://stackoverflow.com/questions/54735200/using-cmake-to-complie-cause-sgx-error-unexpected
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi: The poroblem is that you didn't link the right sgx_utrs file.You can change your CmakeLists.txt as this. 1 cmake_minimum_required(VERSION 2.8) 2 SET(App_C_Flags "-m64 -fPIC -Wno-attributescmake") 3 SET(App_Cpp_Flags "${App_C_Flags} -std=c++11") 4 SET(CMAKE_CXX_FLAGS ${App_Cpp_Flags}) 5 SET(SGX_SDK /opt/intel/sgxsdk) 6 SET(Urts_Library_Name sgx_urts) 7 SET(Uservice_Library_Name sgx_uae_service) 8 find_library(Urts sgx_urts "/lib64") 9 SET(App_Link_Flags "-L/lib64 -l${Urts_Library_Name} -L${SGX_SDK}/lib64 -lpthread -l${Uservice_Library_Name}") 10 SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${App_Link_Flags}") 11 include_directories (/opt/intel/sgxsdk/include) 12 LINK_DIRECTORIES("/lib64") 13 14 add_library (enclave_untrusted enclave_u.c) 15 16 add_executable (app app.cpp) 17 18 target_link_libraries (app enclave_untrusted ${Urts} sgx_ukey_exchange sgx_uae_service pthread)

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page