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

D3D12CreateDevice call fails with hr 0x887A0004 on WSL2 #470

Open
BenoitAmbry opened this issue Dec 12, 2024 · 6 comments
Open

D3D12CreateDevice call fails with hr 0x887A0004 on WSL2 #470

BenoitAmbry opened this issue Dec 12, 2024 · 6 comments

Comments

@BenoitAmbry
Copy link

Code works properly when not running under kcov.
Other calls to DXCore seem to work properly.

Repro steps:
clone https://github.com/microsoft/DirectX-Headers.git
edit test/test.cpp
modify last line to be:

    auto hr = D3D12CreateDevice(adapter, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&device));
    if (FAILED(hr)) {
        printf("Failed to create D3D12 device hr = %x\n", hr);
        return -1;
    }
    return 0;

run he following commands:

mkdir build
cd build
cmake ..
make
test/DirectX-Headers-Test
mkdir cov
kcov cov test/DirectX-Headers-Test

Normal run of test/DirectX-Headers-Test doesn't show any error, kcov run shows error:
Failed to create D3D12 device hr = 887a0004
The resulting coverage output will also show that the return 0; line is not hit.

@BenoitAmbry BenoitAmbry changed the title D3D12CreateDevice class fails with hr 0x887A0004 on WSL2 D3D12CreateDevice call fails with hr 0x887A0004 on WSL2 Dec 12, 2024
@SimonKagstrom
Copy link
Owner

Can you try with --verify? (Assuming it has been built with libbfd)

@BenoitAmbry
Copy link
Author

Doesn't help:

kcov --verify cov test/DirectX-Headers-Test
Failed to create D3D12 device hr = 887a0004

@SimonKagstrom
Copy link
Owner

Thanks for testing!

If you look in the coverage report for the actual D3D12CreateDevice, can you see what goes wrong there?

Traditionally, failures have typically been because the DWARF debug info is incorrect, causing breakpoints to be set in the middle of an instruction and making it invalid, hence the --verify. Other than that, I don't really know of any issue apart from timing where it should differ.

I guess --skip-solibs also doesn't make a difference?

@BenoitAmbry
Copy link
Author

BenoitAmbry commented Dec 14, 2024

--skip-solibs does make a difference and now it works for me. But that will not really fix the issue, the code is now not covered at all.
Is there a way to exclude a specific library instead of all of them?

I cannot look at DXCore libraries as I don't have the source code, they come with the OS and are directly provided by microsoft.

@BenoitAmbry
Copy link
Author

After poking around in kcov source code, it seems that the issue is the overloading of dlopen.
If I remove the lines:

	parse_solibs();
	force_breakpoint();

or alternatively completely disabling the dlopen overload, then everything works fine.

If I use --skip-solibs the code works but I get nothing in the coverage.
Note that I am using google tests, so that might explain why --skip-solibs is not working for me.

One other thing I found, it seems that the problems will is with calling getenv() and calling force_breakpoint. If both are removed then the code works fine.
I tried to not setting KCOV_SOLIB_PATH in solib-handler.cc and not calling force_breakpoint, but that did not work.

Seems like the little hack to write and pre-load a library and use LD_PRELOAD doesn't play well with Direct3D, I don't know why, but for now I can properly use kcov on my test cases.

Maybe you can add an option like --skip-solibds to not use dlopen but not disable everything.

@SimonKagstrom
Copy link
Owner

If you build with -fno-pie, and use --skip-solibs, do you get coverage for your tests?

I've done that when using ASAN, which also doesn't play well with the shared library support (but I think that's due to LD_PRELOAD).

Otherwise your suggestion sounds good, although it might not be completely obvious when you need to use it.

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

2 participants