openenclave: LVI mitigation build under Nix fails to find cstdlib
I’m attempting to package up openenclave for NixOS. I managed to get it building and running fine without LVI mitigations, but enabling them I’m running into some issues with clang.
openenclave-sgx> /build/source/tools/oeedger8r-cpp/src/parser.cpp:4:10/build/source/tools/oeedger8r-cpp/src/main.cpp:: 4:10fatal error:: 'algorithm' file not foundfatal error:
openenclave-sgx> 'cstdlib' file not found
openenclave-sgx> #include <cstdlib>#include <algorithm>
openenclave-sgx> ^~~~~~~~~ ^~~~~~~~~~~
openenclave-sgx> In file included from /build/source/tools/oeedger8r-cpp/src/lexer.cpp:4:
openenclave-sgx> /build/source/tools/oeedger8r-cpp/src/lexer.h:7:10: fatal error: 'cctype' file not found
openenclave-sgx> #include <cctype>
It seems like it cannot find the C++ standard headers, even though they should be included by default. I’m curious if there is something that is being done to modify the search path in the wrappers, because I can’t find anything to that note.
Nix derivation: https://gist.github.com/CitadelCore/17bd121b74c451737d2da24608f1b4ca Build log: https://gist.github.com/CitadelCore/5a17e3c2fac336316f241d452f116353
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 15 (8 by maintainers)
What’s going on is that the
invoke_compilerscript has been generated to hard-code the compiler for the case when LVI mitigation flags are not passed in:This causes clang to be invoked when /lvi_mitigation_bin/clang++ wrapper is called, resulting in missing include errors.
Retaining the the theme of the original snippet would fix the compile error: https://github.com/openenclave/openenclave/blob/a381bfe51de0178b1989fb0d2abbc7b8e7179fbe/scripts/lvi-mitigation/invoke_compiler#L26-L28
We need to invoke the actual compiler, and not the wrapper. The challenge is that under nix, the compilers won’t exist in /usr/bin.
Yes, I would be fine with contributing my changes. Will open a pull request once I’ve got my derivation cleaned up.
I attempted to handle that via
substituteInPlacein my derivation:That should just append $lvi_bin_path, and not do anything funky with /bin or /usr/local.
You should be able to build it like this:
Save my default.nix and that as shell.nix in a folder, and then run
nix-shell. Note that I have includedbreakpointHookin my derivation for testing, so it will pause on an error instead of exiting, use Ctrl+C to exit.