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

Move Shadow's main function from C to Rust #2095

Open
stevenengler opened this issue Apr 26, 2022 · 0 comments
Open

Move Shadow's main function from C to Rust #2095

stevenengler opened this issue Apr 26, 2022 · 0 comments
Labels
Type: Maintenance Refactoring, cleanup, documenation, or process improvements

Comments

@stevenengler
Copy link
Contributor

stevenengler commented Apr 26, 2022

Shadow's main function is a small C wrapper around a Rust function:

int main(int argc, char* argv[]) { return main_runShadow(argc, (const char**)argv); }

#[no_mangle]
pub extern "C" fn main_runShadow(
argc: libc::c_int,
argv: *const *const libc::c_char,
) -> libc::c_int {

It would be nice to remove the C main function and build the Rust version directly.

Shadow currently uses CMake to build a C library shadow-c, a Rust library shadow-rs, and then builds the final C binary:

add_library(shadow-c-and-rs INTERFACE)
target_link_libraries(shadow-c-and-rs INTERFACE "-Wl,--start-group" shadow-rs shadow-c "-Wl,--end-group")

add_executable(shadow main.c)
target_link_libraries(shadow shadow-c-and-rs)
set_target_properties(shadow PROPERTIES LINK_FLAGS "-Wl,--no-as-needed")

If we built the main Shadow binary as a Cargo project, we could reduce this to two steps: the C library and a Rust binary. This would also allow us to skip the final link step, which would save us a few seconds of build time.

One issue is that we set the runpath to the shim library directories and shadow reads this runpath to use the correct shim libraries. For example, after building Shadow, the runpath will be set to /abs-path/shadow/build/src/lib/shim:/abs-path/shadow/build/src/lib/injector_preload:/abs-path/shadow/build/src/lib/libc_preload:/abs-path/shadow/build/src/lib/openssl_preload:. After installing Shadow, the runpath will be changed to /home/user/.local/lib. We will either need to use a different mechanism for specifying the correct path of shim libraries, or use something like patchelf to manually modify the runpath as part of the build and installation steps (CMake does this for us, but we'd have to do it manually if building the binary with Cargo). And instead of the runpath, we could maybe use a different custom elf section instead.

@stevenengler stevenengler added the Type: Bug Error or flaw producing unexpected results label Apr 26, 2022
@stevenengler stevenengler added this to To do in Release v2.2 via automation Apr 26, 2022
@stevenengler stevenengler added Type: Maintenance Refactoring, cleanup, documenation, or process improvements and removed Type: Bug Error or flaw producing unexpected results labels Apr 26, 2022
@robgjansen robgjansen removed this from To do in Release v2.2 Jul 19, 2022
@robgjansen robgjansen added this to To do in Release v2.3 via automation Jul 19, 2022
@robgjansen robgjansen removed this from To do in Release v2.3 Dec 5, 2022
@robgjansen robgjansen added this to To do in Release v2.4 via automation Dec 5, 2022
@robgjansen robgjansen removed this from To do in Release v2.4 Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Maintenance Refactoring, cleanup, documenation, or process improvements
Projects
None yet
Development

No branches or pull requests

1 participant