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

Could not link Rust static lib to enclave code #45

Open
tiziano88 opened this issue Nov 7, 2019 · 9 comments
Open

Could not link Rust static lib to enclave code #45

tiziano88 opened this issue Nov 7, 2019 · 9 comments

Comments

@tiziano88
Copy link
Member

I have been experimenting compiling Rust to a static library and linking it against our existing enclave code (will provide detailed steps if anyone is interested), but while I can link the resulting artifacts against standard C++ code, asylo seems picky about it, and I get the following errors in bazel:

bazel-out/k8-fastbuild/bin/rust/oak_runtime/liboak_runtime--866734307.a(divxc3.o): In function `__divxc3':
/rustc/1423bec54cf2db283b614e527cfd602b481485d1/src/llvm-project/compiler-rt/lib/builtins/divxc3.c:23: undefined reference to `fmaxl'
/rustc/1423bec54cf2db283b614e527cfd602b481485d1/src/llvm-project/compiler-rt/lib/builtins/divxc3.c:23: undefined reference to `logbl'
/rustc/1423bec54cf2db283b614e527cfd602b481485d1/src/llvm-project/compiler-rt/lib/builtins/divxc3.c:26: undefined reference to `scalbnl'
/rustc/1423bec54cf2db283b614e527cfd602b481485d1/src/llvm-project/compiler-rt/lib/builtins/divxc3.c:27: undefined reference to `scalbnl'
/rustc/1423bec54cf2db283b614e527cfd602b481485d1/src/llvm-project/compiler-rt/lib/builtins/divxc3.c:31: undefined reference to `scalbnl'
/rustc/1423bec54cf2db283b614e527cfd602b481485d1/src/llvm-project/compiler-rt/lib/builtins/divxc3.c:33: undefined reference to `scalbnl'

For reference, I also came across this https://dev.to/luzero/building-crates-so-they-look-like-c-abi-libraries-1ibn#static-libraries , but it did not help.

@tiziano88
Copy link
Member Author

tiziano88 commented Nov 7, 2019

@deeglaze
Copy link
Contributor

deeglaze commented Nov 7, 2019

Are you perhaps using libc++ instead of libstdc++? Our libc (newlib) doesn't implement long double functions for architectures where double != long double. libstdc++ seems to fill in the blanks, but libc++ doesn't.

We're experimenting with splicing long double functions from musl into newlib in order to fill in the blanks for libc++, which leads to some weird header #define contortions, but that's not ready to release.

@tiziano88
Copy link
Member Author

Thanks @deeglaze for the quick and relevant reply! That may well be the case, unfortunately there is no easy way (that I know of) to force the Rust compiler to use one or the other lib. Do you have a prototype version of Asylo implementing the spliced functions you mentioned? I'd be happy to patch things locally and give it a try to see if it solves the issue.

@tiziano88
Copy link
Member Author

tiziano88 commented Nov 7, 2019

If it helps, the functions seem to be defined in https://github.com/llvm-mirror/compiler-rt/blob/master/lib/builtins/int_math.h .

@tiziano88
Copy link
Member Author

Blocks project-oak/oak#313

@deeglaze
Copy link
Contributor

deeglaze commented Nov 8, 2019

int_math.h is referencing libc there, not defining the missing symbols. I don't have anything in a shareable state, sad to say. I spent a few hours trying to make newlib + musl build in the github environment but have hit some snags. I can share that with you to figure out a bit more, but I just don't have the capacity to put more time into it right now.
https://github.com/deeglaze/repro/raw/master/newlib_musl.tgz

@TheMarshalMole
Copy link

This problem also appears when trying to build a driver for Linux Kernel -- 2021. 😢
Is there any fix for it?

@TheMarshalMole
Copy link

UPDATE: it works for Ubuntu 20+, but for Debian 10, no 😭

@joelimgu
Copy link

Same issue here

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

No branches or pull requests

4 participants