Openenclave: CMake config doesn't expose oeenclave or mbedtls libraries

Created on 25 Jul 2018  路  8Comments  路  Source: openenclave/openenclave

The CMake config (previously the include file) doesn't expose oeenclave as a target, nor does it expose mbedcrypto/tls. As of the latest master, linking against oeenclave (and thus mbedtls) is required or linking fails missing the oe_handle_verify_report symbol.

Since users must link against these libraries, they should be exposed just like oehostapp, oecore, etc.

bug build engineering

Most helpful comment

Regarding the external dependencies shipped with OE, I probably wouldn't export them directly as this could lead to conflicts with the existing non-OE variants. Switching to namespaced export may be a solution.

All 8 comments

If I manually link against liboeenclave then I get:

/usr/bin/ld: /usr/local/lib/openenclave/enclave/liboecore.a(enter.S.o): relocation R_X86_64_PC32 against symboloe_snap_current_context' can not be used when making a shared object; recompile with -fPIC`

Not really sure what's going on here...I can't build the OpenEnclave samples to test because none of them have updated to match the standard find_package CMake style, and if I do that, we're missing the add_enclave_executable function...if I drag that in we get the same build errors.

Hi @Lusitanian,

Are you using the latest master?
As you noted, oe_handle_verify_report is implemented in liboeenclave.

Can you add oeenclave to your cmake link libraries as shown below:
target_link_libraries(create_rapid_enc oeenclave)

Adding @mikbras

Yes. Using latest master.

If I do as you described, I get:

/usr/bin/ld: cannot find -loeenclave
collect2: error: ld returned 1 exit status

because "oeenclave" isn't defined as a target in the exported CMake config. If I manually specify the full path to the library, I get the aforementioned relocation error.

Ultimately, I can get a build to work by manually specifying the path to liboeenclave.a and its other dependencies (not quite sure why yet but the relocation error disappeared)

It seems that oeenclave alongside the mbedcrypto libraries it is dependent on should be included in the cmake config.

    if (USES_OE_ENCLAVE)
        # We need OpenEnclave libraries
        message(STATUS "${PROJECT_NAME} finding OpenEnclave Enclave libraries...${CMAKE_PREFIX_PATH}")
        find_package(OpenEnclave CONFIG REQUIRED)
        target_link_libraries( ${PROJECT_NAME} PRIVATE oelibcxx) # OpenEnclave C++ STL support
        target_link_libraries( ${PROJECT_NAME} PRIVATE oelibc)   # OpenEnclave C stdlib support
        #target_link_libraries( ${PROJECT_NAME} PRIVATE oeenclave ) # doesn't work; not exported as target
        target_link_libraries( ${PROJECT_NAME} PRIVATE /usr/local/lib/openenclave/enclave/liboeenclave.a) # Link oeenclave manually for oe_handle_verify_report for successful enclave build
        target_link_libraries( ${PROJECT_NAME} PRIVATE /usr/local/lib/openenclave/enclave/libmbedcrypto.a) # Link mbedtls from OpenEnclave's build of it manually (not exported)
    endif()

This produces a successful build; I'm going to rename this issue to reflect that the CMake config needs to be updated to export all libraries dropped as targets and I'll open a separate issue for the samples.

+1, oeenclave and the oe mbedtls library references aren't pulled in correctly using cmake config files.

@CodeMonkeyLeet @anakrish @andschwa Just stumbled upon the same issue. The fix is to change enclave/CMakeLists.txt from

install(TARGETS oeenclave ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/openenclave/enclave)

to

install(TARGETS oeenclave EXPORT openenclave-targets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/openenclave/enclave)

This should be fixed before public preview as it makes using OE from CMake really hard.

EDIT: I realized that the fix above is not enough as oeenclave has a dependency on mbedcrypto which would have to be exported as well. See my other comment below for suggestions.

Current work-around:

find_package(openenclave REQUIRED)

add_library(mbedcrypto INTERFACE)
target_include_directories(mbedcrypto INTERFACE ${OE_INCLUDEDIR}/openenclave/)
target_link_libraries(mbedcrypto INTERFACE 
    ${OE_LIBDIR}/openenclave/enclave/libmbedtls.a
    ${OE_LIBDIR}/openenclave/enclave/libmbedx509.a
    ${OE_LIBDIR}/openenclave/enclave/libmbedcrypto.a
    ${OE_LIBDIR}/openenclave/enclave/liboelibc.a
    ${OE_LIBDIR}/openenclave/enclave/liboecore.a
)

add_library(oeenclave INTERFACE)
target_link_libraries(oeenclave INTERFACE
    mbedcrypto
    oelibc)

Regarding the external dependencies shipped with OE, I probably wouldn't export them directly as this could lead to conflicts with the existing non-OE variants. Switching to namespaced export may be a solution.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andschwa picture andschwa  路  3Comments

eozturk1 picture eozturk1  路  6Comments

haitaohuang picture haitaohuang  路  3Comments

dthaler picture dthaler  路  5Comments

jxyang picture jxyang  路  3Comments