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

Include the fuzzer entrypoint on Windows #279

Merged
merged 1 commit into from
Sep 30, 2021

Conversation

danielframpton
Copy link
Contributor

The current entrypoint for fuzzing ends up in a bundled static library in an rlib.

This change tells the linker to include main, which will then cause the entrypoint to be found and included from the rlib.

Note that this also requires a change on the rust side rust-lang/rust#89369 to enable sanitizer support.

@nagisa
Copy link
Member

nagisa commented Sep 29, 2021

This seems like a fairly unfortunate workaround to have. Is there an explanation for why link.exe discards main here? I mildly remember Windows expecting a different entrypoint name, maybe we could introduce an alias or somesuch?

@danielframpton
Copy link
Contributor Author

It is not so much that link discards main, but that it never loaded the object with main in the first place (it doesn't automatically get included on the list of required symbols). It is only after doing a pass of linking that link then searches for main or wmain (or others like WinMain for different subsystems) to infer the correct crt entrypoint to use based on the symbols that it has seen. So I don't think we can alias anything, we need to do something to get the object that has main linked in.

Since in this case we know the method we need to include from the fuzzing library /include:main seemed like a straightforward way to require the linker to include it and let the rest of the logic flow from there.

Another option (I believe clang took this approach) would be to have the fuzzing library be passed as whole archive to link, but that would preclude it from being bundled in the rlib.

We could also explicitly specify the entrypoint (e.g., /entry:mainCRTStartup) but that brings in more dependency/knowledge of something else that doesn't seem necessary so I think it is cleaner to only rely on the knowledge that main is the post-crt entry point for libfuzzer and get that object included.

@nagisa nagisa merged commit 8c964bf into rust-fuzz:master Sep 30, 2021
@danielframpton
Copy link
Contributor Author

Thanks @nagisa!

@danielframpton danielframpton deleted the windows-fuzz branch September 30, 2021 17:48
@nagisa
Copy link
Member

nagisa commented Sep 30, 2021

Since the Rust side of the functionality is not yet available, we'll wait to release a new version, but let us know via an issue or a comment if you'd like one to be released ASAP.

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.

2 participants