diff --git a/docs/GettingStartedDocs/AdvancedTestInfo.md b/docs/GettingStartedDocs/AdvancedTestInfo.md index 8bf38a8de1a..e4d5df719ca 100644 --- a/docs/GettingStartedDocs/AdvancedTestInfo.md +++ b/docs/GettingStartedDocs/AdvancedTestInfo.md @@ -13,9 +13,7 @@ build$ make ``` To run valgrind-tests, add "**-D ExperimentalMemCheck**" to the ctest call. -Enclave tests all seem to fail today, though this succeeds: +Enclave tests all seem to fail today. -``` -build$ ctest -D ExperimentalMemCheck -R oeelf ``` Execute the tests via ctest (see "man ctest" for details). diff --git a/docs/GettingStartedDocs/prerequisites.md b/docs/GettingStartedDocs/prerequisites.md index 03850e9fa02..d670ec69395 100644 --- a/docs/GettingStartedDocs/prerequisites.md +++ b/docs/GettingStartedDocs/prerequisites.md @@ -26,7 +26,7 @@ The files and directories in the top-level directory are described as follows. - [samples](samples) - Contains enclave-development sample sources - [scripts](scripts) - Contains Shell scripts - [tests](tests) - Contains all test programs, which may also serve as samples -- [tools](tools) - Contains command-line tools (oesgx, oesign, oegen, oeelf) +- [tools](tools) - Contains command-line tools (oesgx, oesign, oegen) Install Prerequisites ====================== diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 866dea1eb9b..f86b1ede322 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,8 +1,6 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -add_subdirectory(oedump) -add_subdirectory(oeelf) add_subdirectory(oegen) add_subdirectory(oesgx) add_subdirectory(oesign) diff --git a/tools/oedump/CMakeLists.txt b/tools/oedump/CMakeLists.txt deleted file mode 100644 index 337e840dbb2..00000000000 --- a/tools/oedump/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -add_executable(oedump main.c) - -target_link_libraries(oedump oehost) - -# assemble into proper collector dir -set_property(TARGET oedump PROPERTY RUNTIME_OUTPUT_DIRECTORY ${OE_BINDIR}) - -# test-case -add_test(NAME tools/oedump - COMMAND oedump $.signed.so) - -# install rule -install (TARGETS oedump DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/tools/oedump/main.c b/tools/oedump/main.c deleted file mode 100644 index e42f67565cc..00000000000 --- a/tools/oedump/main.c +++ /dev/null @@ -1,256 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#include -#include -#include -#include -#include -#include -#include -#include - -static const char* arg0; - -size_t errors = 0; - -static bool verbose_opt = false; - -OE_PRINTF_FORMAT(1, 2) -void err(const char* fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - fprintf(stderr, "*** Error: "); - vfprintf(stderr, fmt, ap); - fprintf(stderr, "\n"); - va_end(ap); - errors++; -} - -void DumpEntryPoint(Elf64* elf) -{ - Elf64_Sym sym; - const char* name; - - if (Elf64_FindDynamicSymbolByAddress( - elf, Elf64_GetHeader(elf)->e_entry, STT_FUNC, &sym) != 0) - { - err("cannot find entry point symbol"); - return; - } - - if (!(name = Elf64_GetStringFromDynstr(elf, sym.st_name))) - { - err("cannot resolve entry point name"); - return; - } - - if (strcmp(name, "_start") != 0) - { - err("invalid entry point name: %s", name); - return; - } - - printf("=== Entry point: \n"); - printf("name=%s\n", name); - printf("address=%016llx\n", OE_LLX(sym.st_value)); - printf("\n"); -} - -void DumpEnclaveProperties(const oe_sgx_enclave_properties_t* props) -{ - const sgx_sigstruct_t* sigstruct; - - printf("=== SGX Enclave Properties:\n"); - - printf("product_id=%u\n", props->config.product_id); - - printf("security_version=%u\n", props->config.security_version); - - bool debug = props->config.attributes & OE_SGX_FLAGS_DEBUG; - printf("debug=%u\n", debug); - - printf( - "num_heap_pages=%llu\n", - OE_LLU(props->header.size_settings.num_heap_pages)); - - printf( - "num_stack_pages=%llu\n", - OE_LLU(props->header.size_settings.num_stack_pages)); - - printf("num_tcs=%llu\n", OE_LLU(props->header.size_settings.num_tcs)); - - sigstruct = (const sgx_sigstruct_t*)props->sigstruct; - - printf("mrenclave="); - oe_hex_dump(sigstruct->enclavehash, sizeof(sigstruct->enclavehash)); - - printf("signature="); - oe_hex_dump(sigstruct->signature, sizeof(sigstruct->signature)); - - printf("\n"); - - if (verbose_opt) - __sgx_dump_sigstruct(sigstruct); -} - -typedef struct _VisitSymData -{ - const Elf64* elf; - const Elf64_Shdr* shdr; - oe_result_t result; -} VisitSymData; - -static int _VisitSym(const Elf64_Sym* sym, void* data_) -{ - int rc = -1; - VisitSymData* data = (VisitSymData*)data_; - const Elf64_Shdr* shdr = data->shdr; - const char* name; - - data->result = OE_UNEXPECTED; - - /* Skip symbol if not a function */ - if ((sym->st_info & 0x0F) != STT_FUNC) - { - rc = 0; - goto done; - } - - /* Skip symbol if not in the ".ecall" section */ - if (sym->st_value < shdr->sh_addr || - sym->st_value + sym->st_size > shdr->sh_addr + shdr->sh_size) - { - rc = 0; - goto done; - } - - /* Skip null names */ - if (!(name = Elf64_GetStringFromDynstr(data->elf, sym->st_name))) - { - rc = 0; - goto done; - } - - /* Dump the ECALL name */ - printf("%s (%016llx)\n", name, OE_LLX(sym->st_value)); - - rc = 0; - -done: - return rc; -} - -void DumpECallSection(Elf64* elf) -{ - Elf64_Shdr shdr; - - printf("=== ECALLs:\n"); - - /* Find the .ecall section */ - if (Elf64_FindSectionHeader(elf, ".ecall", &shdr) != 0) - { - err("missing .ecall section"); - return; - } - - /* Dump all the ECALLs */ - { - VisitSymData data; - data.elf = elf; - data.shdr = &shdr; - - if (Elf64_VisitSymbols(elf, _VisitSym, &data) != 0) - { - err("failed to find ECALLs in .ecall section"); - return; - } - } - - printf("\n"); -} - -void CheckGlobal(Elf64* elf, const char* name) -{ - Elf64_Sym sym; - - if (Elf64_FindDynamicSymbolByName(elf, name, &sym) != 0) - { - err("failed to find required symbol: %s\n", name); - return; - } - - printf("%s (%016llx)\n", name, OE_LLX(sym.st_value)); -} - -void CheckGlobals(Elf64* elf) -{ - printf("=== Globals:\n"); - - CheckGlobal(elf, "__oe_numPages"); - CheckGlobal(elf, "__oe_virtualBaseAddr"); - CheckGlobal(elf, "__oe_baseRelocPage"); - CheckGlobal(elf, "__oe_numRelocPages"); - CheckGlobal(elf, "__oe_baseECallPage"); - CheckGlobal(elf, "__oe_numECallPages"); - CheckGlobal(elf, "__oe_baseHeapPage"); - CheckGlobal(elf, "__oe_numHeapPages"); - - printf("\n"); -} - -int main(int argc, const char* argv[]) -{ - arg0 = argv[0]; - int ret = 1; - Elf64 elf; - oe_sgx_enclave_properties_t props; - - /* Check arguments */ - if (argc != 2) - { - fprintf(stderr, "Usage: %s ENCLAVE\n", arg0); - goto done; - } - - /* Load the ELF-64 object */ - if (Elf64_Load(argv[1], &elf) != 0) - { - fprintf(stderr, "%s: failed to load %s\n", argv[0], argv[1]); - goto done; - } - - /* Load the SGX enclave properties */ - if (oe_sgx_load_properties(&elf, OE_INFO_SECTION_NAME, &props) != OE_OK) - { - err("failed to load SGX enclave properties from %s section", - OE_INFO_SECTION_NAME); - } - - printf("\n"); - - /* Dump the entry point */ - DumpEntryPoint(&elf); - - /* Dump the signature section */ - DumpEnclaveProperties(&props); - - /* Dump the ECALL section */ - DumpECallSection(&elf); - - /* Check globals */ - CheckGlobals(&elf); - - if (errors) - { - fprintf(stderr, "*** Found %zu errors\n", errors); - goto done; - } - - ret = 0; - -done: - Elf64_Unload(&elf); - return ret; -} diff --git a/tools/oeelf/CMakeLists.txt b/tools/oeelf/CMakeLists.txt deleted file mode 100644 index d516b2a4286..00000000000 --- a/tools/oeelf/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -add_executable(oeelf main.c) - -target_link_libraries(oeelf oehost) - -# assemble into proper collector dir -set_property(TARGET oeelf PROPERTY RUNTIME_OUTPUT_DIRECTORY ${OE_BINDIR}) - -# no install rule - not distributed -install (TARGETS oeelf DESTINATION ${CMAKE_INSTALL_BINDIR}) - -add_test(oeelf ${OE_BINDIR}/oeelf ${PROJECT_BINARY_DIR}/tests/echo/enc/echo_enc.signed.so) - diff --git a/tools/oeelf/README.md b/tools/oeelf/README.md deleted file mode 100644 index 2589438c53a..00000000000 --- a/tools/oeelf/README.md +++ /dev/null @@ -1,3 +0,0 @@ -Enclave binary inspection tool similar to readelf. - -Less useful for an enclave developer, yet valuable for elf lib debugging. diff --git a/tools/oeelf/main.c b/tools/oeelf/main.c deleted file mode 100644 index 460687645be..00000000000 --- a/tools/oeelf/main.c +++ /dev/null @@ -1,144 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#include -#include -#include -#include - -/* -**============================================================================== -** -** To use this for loading an enclave, check these: -** header.e_type=ET_DYN -** iheader.e_machine=EM_X86_64 -** -**============================================================================== -*/ - -int main(int argc, const char* argv[]) -{ - int status = 1; - FILE* is = NULL; - Elf64 elf; - - /* Check argument count */ - if (argc != 2) - { - fprintf(stderr, "Usage: %s FILENAME\n", argv[0]); - return 1; - } - - assert(sizeof(Elf64_Addr) == 8); - assert(sizeof(Elf64_Off) == 8); - assert(sizeof(Elf64_Half) == 2); - assert(sizeof(Elf64_Word) == 4); - assert(sizeof(Elf64_Sword) == 4); - assert(sizeof(Elf64_Xword) == 8); - assert(sizeof(Elf64_Sxword) == 8); - -#if 0 -printf("%zu\n", offsetof(Elf64_Ehdr, e_shoff)); -printf("%zu\n", offsetof(Elf64_Ehdr, e_shnum)); -exit(0); -#endif - - /* Load the ELF-64 object */ - if (Elf64_Load(argv[1], &elf) != 0) - { - fprintf(stderr, "%s: failed to load %s\n", argv[0], argv[1]); - goto done; - } - - Elf64_Dump(&elf); - Elf64_DumpSymbols(&elf); - Elf64_DumpSections(&elf); - Elf64_DumpSectionNames(&elf); - Elf64_DumpStrings(&elf); - - /* Find the entry point symbol */ - const char* entry; - { - Elf64_Sym sym; - - if (Elf64_FindSymbolByAddress( - &elf, Elf64_GetHeader(&elf)->e_entry, STT_FUNC, &sym) != 0) - { - fprintf(stderr, "%s: cannot find entry point symbol\n", argv[0]); - goto done; - } - - if (!(entry = Elf64_GetStringFromStrtab(&elf, sym.st_name))) - { - fprintf(stderr, "%s: cannot resolve entry point name\n", argv[0]); - goto done; - } - - printf("=== entry point: {%s}\n\n", entry); - } - - /* Find a symbol by name */ - { - Elf64_Sym sym; - - if (Elf64_FindSymbolByName(&elf, entry, &sym) != 0) - { - fprintf( - stderr, "%s: failed to find entry point: %s\n", argv[0], entry); - goto done; - } - - Elf64_DumpSymbol(&elf, &sym); - } - -#if 0 - { - /* Add a new section */ - { - const char secdata[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; - size_t secsize = sizeof(secdata); - - if (Elf64_AddSection( - &elf, ".mysec", SHT_PROGBITS, secdata, secsize) != 0) - { - fprintf(stderr, "%s: failed to add section\n", argv[0]); - goto done; - } - } - - /* Add a new section */ - { - const char secdata[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; - size_t secsize = sizeof(secdata); - - if (Elf64_AddSection( - &elf, ".mysec2", SHT_PROGBITS, secdata, secsize) != 0) - { - fprintf(stderr, "%s: failed to add section\n", argv[0]); - goto done; - } - } - - Elf64_Dump(&elf); - Elf64_DumpSymbols(&elf); - Elf64_DumpSections(&elf); - Elf64_DumpSectionNames(&elf); - } -#endif - - /* Unload the ELF-64 object */ - if (Elf64_Unload(&elf) != 0) - { - fprintf(stderr, "%s: failed to unload\n", argv[0]); - goto done; - } - - status = 0; - -done: - - if (is) - fclose(is); - - return status; -}