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

Fuzzer: make druntime initialization transparent #2225

Closed
JohanEngelen opened this issue Jul 20, 2017 · 2 comments
Closed

Fuzzer: make druntime initialization transparent #2225

JohanEngelen opened this issue Jul 20, 2017 · 2 comments

Comments

@JohanEngelen
Copy link
Member

To use -fsanitize=fuzzer, the user has to manually initialize druntime, because a user-specified main is not supported. The user has to supply the following code:

extern (C) int LLVMFuzzerTestOneInput(const(ubyte*) data, size_t size)
{
    // D runtime must be initialized, but only once.
    static bool init = false;
    if (!init)
    {
        import core.runtime : rt_init;
        rt_init();
        init = true;
    }

   //... do the actual fuzz testing
}

Perhaps we can add functionality to instead let the user write:

extern (C) int LDC_LLVMFuzzerTestOneInput(const(ubyte*) data, size_t size)
{
   //... do the actual fuzz testing
}

where LLVMFuzzerTestOneInput initializes druntime and calls LDC_LLVMFuzzerTestOneInput.
Another option is to extend libFuzzer functionality or make use of what's already there: https://llvm.org/docs/LibFuzzer.html#startup-initialization

@JohanEngelen
Copy link
Member Author

JohanEngelen commented Jul 21, 2017

... or linking with a small LDC library that contains a C module ctor that runs rt_init(). May be useful for other uses too.

@JohanEngelen
Copy link
Member Author

resolved by #2510

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant