Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix switchless sample code #260

Merged
merged 1 commit into from
Aug 3, 2020
Merged

Fix switchless sample code #260

merged 1 commit into from
Aug 3, 2020

Conversation

xu-cheng
Copy link
Contributor

@xu-cheng xu-cheng commented Aug 1, 2020

In order to use the switchless feature of the SGX, the app binary needs
to be linked with the following flags.

-Wl,--whole-archive -lsgx_uswitchless -Wl,--no-whole-archive

Noted that there is currently no proper way to pass custom link flags to
all the binaries in a cargo project. As such, the link_args macro need
to be set for each of Rust files with main methods.

References:

In order to use the switchless feature of the SGX, the app binary needs
to be linked with the following flags.

```
-Wl,--whole-archive -lsgx_uswitchless -Wl,--no-whole-archive
````

Noted that there is currently no proper way to pass custom link flags to
all the binaries in a cargo project. As such, the `link_args` macro need
to be set for each of Rust files with `main` methods.

References:

* Build flags used in Intel SGX sample code: https://github.com/intel/linux-sgx/blob/ce4a18d9a0963b14f717cc7462241cfadd233f55/SampleCode/Switchless/Makefile#L104
* Rust tracking issue on `link_args`: rust-lang/rust#29596
* PR for `cargo:rustc-link-arg-bins` in cargo build script: rust-lang/cargo#8441
@dingelish
Copy link
Contributor

thanks!

@dingelish dingelish merged commit 3eeaf9a into apache:master Aug 3, 2020
@xu-cheng xu-cheng deleted the switchless branch August 3, 2020 19:00
@rashmik8
Copy link

rashmik8 commented Mar 3, 2023

I understand this issue has been closed but I needed more clarity on this one. I tried including -Wl,--whole-archive -lsgx_uswitchless -Wl,--no-whole-archive in my file with main() however I run into following error:
= note: /opt/intel/sgxsdk/lib64/libsgx_uswitchless.a(sl_urts_loader_untrusted.o): In function urts_loader_t::urts_loader_t()':
sl_urts_loader_untrusted.cpp:(.text._ZN13urts_loader_tC2Ev+0x8): undefined reference to sgx_set_switchless_itf' /opt/intel/sgxsdk/lib64/libsgx_uswitchless.a(sl_workers_untrusted.o): In function tworker_process_calls':
sl_workers_untrusted.c:(.text.tworker_process_calls+0x21): undefined reference to sl_run_switchless_tworker' /opt/intel/sgxsdk/lib64/libsgx_uswitchless.a(sgx_ecall_switchless_untrusted.o): In function init_tswitchless':
sgx_ecall_switchless_untrusted.c:(.text.init_tswitchless+0x10): undefined reference to sl_init_switchless' collect2: error: ld returned 1 exit status
Looks like it cannot find sgx_urts or other files. Not sure what I am missing here.
Apologies in advance if this is not the right place to post this.

@volcano0dr
Copy link
Contributor

I understand this issue has been closed but I needed more clarity on this one. I tried including -Wl,--whole-archive -lsgx_uswitchless -Wl,--no-whole-archive in my file with main() however I run into following error: = note: /opt/intel/sgxsdk/lib64/libsgx_uswitchless.a(sl_urts_loader_untrusted.o): In function urts_loader_t::urts_loader_t()': sl_urts_loader_untrusted.cpp:(.text._ZN13urts_loader_tC2Ev+0x8): undefined reference to sgx_set_switchless_itf' /opt/intel/sgxsdk/lib64/libsgx_uswitchless.a(sl_workers_untrusted.o): In function tworker_process_calls': sl_workers_untrusted.c:(.text.tworker_process_calls+0x21): undefined reference to sl_run_switchless_tworker' /opt/intel/sgxsdk/lib64/libsgx_uswitchless.a(sgx_ecall_switchless_untrusted.o): In function init_tswitchless': sgx_ecall_switchless_untrusted.c:(.text.init_tswitchless+0x10): undefined reference to sl_init_switchless' collect2: error: ld returned 1 exit status Looks like it cannot find sgx_urts or other files. Not sure what I am missing here. Apologies in advance if this is not the right place to post this.

You can refer to switchless example

@rashmik8
Copy link

rashmik8 commented Mar 13, 2023

Hi @volcano0dr , thank you for your response. I did refer to this switchless example. However, it still doesn't work.
Original post states that the switchless flag is required in link_args wherever main is. Does this mean entry point? My cargo project builds internally calls to build shared library with trusted and untrusted code. The error I run into is linking of this sgx_uswitchless, where the error probably wants path using -L. But that causes a cascaded effect as it cannot find other dependent libraries. Also does it necessary have to be main.rs? Currently I have it included in my lib.rs file of project, but I still receive SGX_ERROR_UNEXPECTED. Mimicked the build steps of switchless code example but to no avail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants