Intel® Software Guard Extensions (Intel® SGX)
Discussion board focused on hardware-based isolation and memory encryption to provide extended code protection in solutions.

Need help! Undefined reference in trusted cpp enclave

zhou__boxiao
Beginner
713 Views

I am new to SGX linux development, and I am trying to build a TestEnclave.cpp)onto sgx.

I have encountered this undefined reference error when I linked the "trusted" part of the program.

make all 
make -f sgx_u.mk LINUX_SGX_BUILD=0 all
make[1]: 进入目录“/home/zhou/下载/intel-sgx-ssl-master/Linux/sgx/test_pdp”
GEN  =>  app/TestEnclave_u.c
CC   <=  app/TestEnclave_u.c
LINK =>  TestApp
make[1]: 离开目录“/home/zhou/下载/intel-sgx-ssl-master/Linux/sgx/test_pdp”

----------- >> the untrusted part builds successfully

make -f sgx_t.mk LINUX_SGX_BUILD=0 all
make[1]: 进入目录“/home/zhou/下载/intel-sgx-ssl-master/Linux/sgx/test_pdp”
GEN  =>  enclave/TestEnclave_t.c
CC   <=  enclave/TestEnclave_t.c
enclave/TestEnclave_t.o:在函数‘sgx_pdp_generate_proof_update’中:
TestEnclave_t.c:(.text+0x436):对‘pdp_generate_proof_update’未定义的引用 ----------------------- >> here
enclave/TestEnclave_t.o:在函数‘sgx_pdp_challenge’中:
sgx_t.mk:139: recipe for target 'TestEnclave.so' failed
TestEnclave_t.c:(.text+0x5f0):对‘pdp_challenge’未定义的引用 ----------------------- >> here
make[1]: 离开目录“/home/zhou/下载/intel-sgx-ssl-master/Linux/sgx/test_pdp”
Makefile:34: recipe for target 'all' failed
TestEnclave_t.c:(.text+0x62a):对‘pdp_challenge’未定义的引用
enclave/TestEnclave_t.o:在函数‘sgx_pdp_tag_block’中:
TestEnclave_t.c:(.text+0x6d8):对‘pdp_tag_block’未定义的引用 ---------------------- >> here
TestEnclave_t.c:(.text+0x754):对‘pdp_tag_block’未定义的引用
TestEnclave_t.c:(.text+0x79e):对‘pdp_tag_block’未定义的引用
TestEnclave_t.c:(.text+0x7f9):对‘pdp_tag_block’未定义的引用
collect2: error: ld returned 1 exit status
make[1]: *** [TestEnclave.so] Error 1
make: *** [all] Error 2

17:53:59 Build Finished (took 815ms)

I have defined these functions(pdp_challenge,pdp_tag_block,etc) in the EDL file, and the untrusted part of TestEnclave.cpp linked successfully. But I don't know what's wrong with the trusted part.

Any help is greatly appreciated!!

my makefile is as follows:

								
TestEnclave_Cpp_Files := $(wildcard $(ENCLAVE_DIR)/*.cpp) $(wildcard $(ENCLAVE_DIR)/tests/*.cpp)
TestEnclave_C_Files := $(wildcard $(ENCLAVE_DIR)/*.c) $(wildcard $(ENCLAVE_DIR)/tests/*.c)

TestEnclave_Cpp_Objects := $(TestEnclave_Cpp_Files:.cpp=.o)
TestEnclave_C_Objects := $(TestEnclave_C_Files:.c=.o)

TestEnclave_Include_Paths := -I. -I$(ENCLAVE_DIR) -I$(SGX_SDK_INC) -I$(SGX_SDK_INC)/tlibc -I$(STL_PORT_INC)/stlport -I$(PACKAGE_INC) -IInclude

Common_C_Cpp_Flags := -DOS_ID=$(OS_ID) $(SGX_COMMON_CFLAGS)  -nostdinc -fvisibility=hidden -fpic -fpie -fstack-protector -fno-builtin-printf -Wformat -Wformat-security $(TestEnclave_Include_Paths) -include "tsgxsslio.h"
TestEnclave_C_Flags := $(Common_C_Cpp_Flags) -Wno-implicit-function-declaration -std=c11
TestEnclave_Cpp_Flags :=  $(Common_C_Cpp_Flags) -std=c++11 -nostdinc++

SgxSSL_Link_Libraries := -L$(OPENSSL_LIBRARY_PATH) -Wl,--whole-archive -l$(SGXSSL_Library_Name) -Wl,--no-whole-archive \
						 -l$(OpenSSL_Crypto_Library_Name)
Security_Link_Flags := -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -pie

TestEnclave_Link_Flags := $(SGX_COMMON_CFLAGS) -Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles \
	$(Security_Link_Flags) \
	$(SgxSSL_Link_Libraries) -L$(SGX_LIBRARY_PATH) \
	-Wl,--whole-archive -l$(Trts_Library_Name) -Wl,--no-whole-archive \
	-Wl,--start-group -lsgx_tstdc -lsgx_tstdcxx -lsgx_tcrypto $(TSETJMP_LIB) -l$(Service_Library_Name) -Wl,--end-group \
	-Wl,-Bstatic -Wl,-Bsymbolic -Wl,--no-undefined \
	-Wl,-pie,-eenclave_entry -Wl,--export-dynamic  \
	-Wl,--defsym,__ImageBase=0 \
	-Wl,--version-script=$(ENCLAVE_DIR)/TestEnclave.lds


.PHONY: all test

all: TestEnclave.signed.so
# usually release mode don't sign the enclave, but here we want to run the test also in release mode
# this is not realy a release mode as the XML file don't disable debug - we can't load real release enclaves (white list)

test: all


######## TestEnclave Objects ########

。。。。(omitted)

TestEnclave.so: $(ENCLAVE_DIR)/TestEnclave_t.o $(TestEnclave_Cpp_Objects) $(TestEnclave_C_Objects)
	$(VCXX) $^ -o $@ $(TestEnclave_Link_Flags)
	@echo "LINK =>  $@"

TestEnclave.signed.so: TestEnclave.so
	@$(SGX_ENCLAVE_SIGNER) sign -key $(ENCLAVE_DIR)/TestEnclave_private.pem -enclave TestEnclave.so -out $@ -config $(ENCLAVE_DIR)/TestEnclave.config.xml
	@echo "SIGN =>  $@"

clean:
	@rm -f TestEnclave.* $(ENCLAVE_DIR)/TestEnclave_t.* $(TestEnclave_Cpp_Objects) $(TestEnclave_C_Objects)

my EDL file is as follows:

/* TestEnclave.edl - Top EDL file. */

enclave {
    include "user_types.h"
    from "sgx_tsgxssl.edl" import *;

    /* 
     * uprint - invokes OCALL to display string buffer inside the enclave.
     *  [in]: copy the string buffer to App outside.
     *  [string]: specifies 'str' is a NULL terminated buffer.
     */
    untrusted {
        void uprint([in, string] const char *str);
        void usgx_exit(int reason);

    };
  
    trusted{    
        public int pdp_verify_proof([in]PDP_key *key, [in]PDP_challenge *challenge, [in]PDP_proof *proof);
        public PDP_key *generate_pdp_key();
        
        public PDP_tag *pdp_tag_block([in]PDP_key *key,[in] unsigned char *block, size_t blocksize, size_t index);
       
        public PDP_challenge *pdp_challenge([in]PDP_key *key, size_t numfileblocks);
       
        public PDP_proof *pdp_generate_proof_update([in]PDP_key *key,[in] PDP_challenge *challenge,[in] PDP_tag *tag,[in,out]PDP_proof *proof, [in, size=blocksize]unsigned char *block, size_t blocksize, size_t j);
       
        public PDP_proof *pdp_generate_proof_final([in]PDP_key *key, [in]PDP_challenge *challenge, [in,out]PDP_proof *proof);
       
        
    };
};

 

 

 

Thanks in advance!

 

0 Kudos
2 Replies
zhou__boxiao
Beginner
713 Views

I have solved this problem!

0 Kudos
Nappa__Antonio
Beginner
713 Views

Hello, I have had the same issue.

My Makefile had the following line 

TestEnclave_Cpp_Objects := $(TestEnclave_Cpp_Files:.cpp=.o)

which is your line 5

the Makefile is trying to build the .so without having Enclave.o - I don't know why, it could be a problem with make version or the OS

before line 42 try to add

Enclave/Enclave.o: Enclave/Enclave.cpp
    $(CXX) $(Enclave_Cpp_Flags) -c $< -o $@
    @echo "CXX  <=  $<"

after 4 hours I solved the issue.

0 Kudos
Reply