[SPIR-V] -Zi: OpSource text is read from the working directory (and dxcompiler is dlopen'ed) instead of using the in-memory source
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 52/100
Hướng nghiên cứu
Start in tools/clang/lib/SPIRV/EmitVisitor.cpp, especially ReadSourceCode, and inspect how IDxcCompiler3::Compile supplies in-memory source and include-handler buffers. Reproduce the issue with the provided repro from empty and withfiles directories, then check related issue #4805. Done means OpSource uses the compiled in-memory or loaded source, is independent of the working directory, and does not reload dxcompiler.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
This issue was written and submitted by an AI assistant (Claude) on behalf of the repository owner (@kaltinril), after the owner reviewed and agreed to its creation. The owner is accountable for it and will answer questions.
Description
With -spirv -Zi, ReadSourceCode in tools/clang/lib/SPIRV/EmitVisitor.cpp (main) fills each OpSource by:
dlopen("libdxcompiler.so")/LoadLibraryof the library that is already running the compile (dxc::DxCompilerDllLoader), thendlclose, on every call, andIDxcLibrary::CreateBlobFromFileon the file name, relative to the process working directory. The in-memory source is used only if that read fails.
So for an in-memory IDxcCompiler3::Compile with no file name:
- the main
OpSourceembeds./hlsl.hlslfrom the working directory if one exists, instead of the source that was compiled; - every file named by a
#linedirective is read from disk and embedded too; - the output depends on the working directory, and arbitrary files can end up in the module;
- each compile does a
dlopen/dlclosepair perOpSource. On macOS this takes dyld's lock, whichfork()also takes before runningpthread_atforkprepare handlers, so a host that serializes compiles againstfork()in an atfork handler can deadlock.
Related: #4805 (include handler bypassed with -Zi, same function).
Steps to Reproduce
From the extracted linux_dxc_2026_09_28.x86_x64.tar.gz (rel/ below):
// g++ -std=c++17 -I rel/include repro.cpp -o repro -L rel/lib -ldxcompiler
#include <cstdio>
#include <string>
#include "dxc/dxcapi.h"
int main() {
static const char src[] = // in memory; no file name passed
"float4 main() : SV_Target { return 0; }\n"
"#line 1 \"inc.hlsl\"\n"
"float unused() { return 1; }\n";
const wchar_t *args[] = {L"-T", L"ps_6_0", L"-E", L"main", L"-spirv", L"-Zi"};
IDxcCompiler3 *compiler = nullptr;
DxcCreateInstance(CLSID_DxcCompiler, __uuidof(IDxcCompiler3), (void **)&compiler);
DxcBuffer buf = {src, sizeof(src) - 1, 65001};
IDxcResult *result = nullptr;
compiler->Compile(&buf, args, 6, nullptr, __uuidof(IDxcResult), (void **)&result);
IDxcBlob *obj = nullptr;
result->GetResult(&obj);
std::string spv((const char *)obj->GetBufferPointer(), obj->GetBufferSize());
printf("in-memory text: %s, DISK-MAIN: %s, DISK-INC: %s\n",
spv.find("float unused") != std::string::npos ? "yes" : "no",
spv.find("DISK-MAIN") != std::string::npos ? "yes" : "no",
spv.find("DISK-INC") != std::string::npos ? "yes" : "no");
return 0;
}
mkdir empty withfiles
echo "// DISK-MAIN" > withfiles/hlsl.hlsl
echo "// DISK-INC" > withfiles/inc.hlsl
(cd empty && LD_LIBRARY_PATH=$PWD/../rel/lib ../repro)
(cd withfiles && LD_LIBRARY_PATH=$PWD/../rel/lib ../repro)
Actual Behavior
empty: in-memory text: yes, DISK-MAIN: no, DISK-INC: no
withfiles: in-memory text: no, DISK-MAIN: yes, DISK-INC: yes
An LD_PRELOAD shim logging dlopen/dlclose shows, per compile:
dlopen("libdxcompiler.so")
dlclose
dlopen("libdxcompiler.so")
dlclose
Expected: the module embeds the source that was compiled (the in-memory buffer, or the buffers DXC already loaded through its include handler / virtual file system), independent of the working directory, without re-loading the library.
Environment
- DXC version:
libdxcompiler.so: 1.9(5512-01b62ad4)(1.9.2609.5)(official v1.9.2609). Same code path in v1.7.2212.1, where the macOS arm64 fork deadlock was observed. - Host Operating System: Ubuntu 24.04 (WSL2), x86_64
- Ngôn ngữ chính
- C++
- Star
- 3.7k
- Fork
- 926
- Merge trung bình
- 3 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 45
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/DirectXShaderCompiler
-
bug needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
microsoft/DirectXShaderCompiler#9173 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
bug needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
microsoft/DirectXShaderCompiler#9155 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
bug needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
microsoft/DirectXShaderCompiler#9135 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
DXC emits DW_LANG_C_plus_plus instead of DW_LANG_HLSL for HLSLCó thể đã có người làm @rj123-nv đã nhận 18 ngày trước. Đang mởbug needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
microsoft/DirectXShaderCompiler#9087 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
microsoft/DirectXShaderCompiler#9086 ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của microsoft/DirectXShaderCompiler
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
telefonicaid/fiware-orion#4836 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
refactor topic-ui topic-weather
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Command-Install Needs-Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
microsoft/winget-cli#6718 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
leanprover/lean4#16810 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày