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

Example: snap_tool fails with "Check failed: std::filesystem::exists(p)" error when processing valid input #17

Open
23-cpu opened this issue Dec 4, 2024 · 6 comments

Comments

@23-cpu
Copy link

23-cpu commented Dec 4, 2024

I encountered an issue while using the snap_tool in the Silifuzz project. When attempting to process valid raw x86 machine code, the tool fails with an error indicating that a required file or dependency is missing (Check failed: std::filesystem::exists(p)). Despite ensuring the environment is set up as per the documentation, the tool does not generate the expected output or snapshot.

Steps to Reproduce

$echo -en '\xFF\xC0' > /tmp/inc_eax

$SILIFUZZ_BIN_DIR/tools/snap_tool --raw print /tmp/inc_eax

I am expecting this below.

Metadata:
Id: inc_eax
Architecture: x86_64 Linux
Completeness: complete
Registers:
gregs (non-0 only)
rax = 0x20000000
....

The tool fails with the following error:

WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
F0000 00:00:1733272965.389669 625799 data_dependency.cc:37] Check failed: std::filesystem::exists(p)
*** Check failure stack trace: ***
@ 0xad7684 absl::log_internal::LogMessage::SendToLog()
@ 0xad74b9 absl::log_internal::LogMessage::Flush()
@ 0xad7ab9 absl::log_internal::LogMessageFatal::~LogMessageFatal()
@ 0x9d857f silifuzz::GetDataDependencyFilepathBazelabi:cxx11
@ 0x9d802e silifuzz::GetDataDependencyFilepathabi:cxx11
@ 0x9d7ed8 silifuzz::RunnerLocationabi:cxx11
@ 0x84695e silifuzz::MakingConfig::Default()
@ 0x83e677 silifuzz::CreateSnapshotFromRawInstructions()
@ 0x84062e silifuzz::SnapToolMain()
@ 0x8436e1 main
@ 0xd9fbc4 __libc_start_call_main
Aborted

Could you please confirm if there are additional data dependencies that need to be explicitly set up or included for the snap_tool to work? Additionally, is there a way to debug what file/path std::filesystem::exists(p) is checking for?

Environment
Running on a google cloud instance
Debian GNU/Linux 12 (bookworm)
gcc 12.2.0

Thanks

@ksteuck
Copy link
Contributor

ksteuck commented Dec 4, 2024

I suspect it's not finding the runner binary. Runtime data dependencies in bazel are a little bit fragile unfortunately. Please try explicitly setting --runner=${SILIFUZZ_BIN_DIR}/runner/reading_runner_main_nolibc, this should fix the problem.

@23-cpu
Copy link
Author

23-cpu commented Dec 4, 2024

Unfortunately, it did not resolve the issue. I explicitly set the --runner argument as instructed, but I am still encountering the same error. Here is the command I used and the output I received:

$SILIFUZZ_BIN_DIR/tools/snap_tool --raw print /tmp/inc_eax --runner=${SILIFUZZ_BIN_DIR}/runner/reading_runner_main_nolibc

@ksteuck
Copy link
Contributor

ksteuck commented Dec 4, 2024

Try $SILIFUZZ_BIN_DIR/tools/snap_tool --runner=${SILIFUZZ_BIN_DIR}/runner/reading_runner_main_nolibc --raw print /tmp/inc_eax instead but first make sure that the path ${SILIFUZZ_BIN_DIR}/runner/reading_runner_main_nolibc is correct and the file exists

@23-cpu
Copy link
Author

23-cpu commented Dec 4, 2024

Unfortunately it still did not work. I tried creating a simple snapshot too, and it was giving the same output.

@ncbray
Copy link
Contributor

ncbray commented Dec 7, 2024

I am able to reproduce the issue. It looks like the dependency finding code for the Bazel build assumes that you're invoking the tools through Bazel. This works, for example:

bazel run //tools:snap_tool -- --raw print /tmp/inc_eax

It will also work if you first cd bazel-bin.

Basically when you run the tool directly it is looking for $CWD/runner/reading_runner_main_nolibc rather than inside the bazel-bin dir. Further more, even when you override the binary it still does the search and the check fails.

Step 1, I will make sure it doesn't search for the binary when it doesn't need to.
Step 2, I will make the searching logic more robust somehow.

@ncbray
Copy link
Contributor

ncbray commented Dec 12, 2024

Tip-of-tree snap_tool should now work when you pass an explicit --runner path.
I am still thinking through if there's an easy way to make the automatic searching work better.

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

3 participants